overwriting the drop function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

overwriting the drop function

Axel Grude-2
I want to try a different approach now, by wrapping gFolderTreeView.drop.

there is only one problem, when I call the original function it makes a mistake
whenever it uses "this". "this" isn't pointing to gFolderTreeView anymore. How can I
fix it?


Here is my new code:

let originalDrop = gFolderTreeView.drop;
// let's wrap the drop function in our own
gFolderTreeView.drop = function (aRow, aOrientation) {
     let retVal = originalDrop.call(aRow, aOrientation);
     myownObject.onFolderTreeViewDrop(aRow, aOrientation);
     return retVal;
}


when I trace into the original drop function using originalDrop.call it fails in:

folderPane.js#636:

     let dt = this._currentTransfer;

since "this" is not set correctly the datatransfer cannot be retrieved. Is it possible
to 'set' this=gFolderTreeView before I do the original call? My understanding is that
'this' usually points to the containing object; just don't know how to provide that
from within my own drop function.

I am cross posting this to the thunderbird development group, as they know more about
gFolderTreeView.

thanks in advance
   Axel



On 04/05/12 21:46, Axel Grude wrote:

> Hi,
>
> I have made a drop handler on the folder pane, but unfortunately it triggers too
> early; I can retrieve the messages from the dragSession but not the name / URL of the
> folder that it is dragged to. Has anybody else an idea how to solve this?
>
> shortened version of the code;
>
> // setting up the event handler on folder tree:
> document.getElementById('folderTree')
> .addEventListener("drop", onFolderTreeDrop, false);
>
> // start of the drop event handler
> onFolderTreeDrop: function(evt, dropData, dragSession) {
> let Ci = Components.interfaces;
> var DropTarget = evt.target;
> if (!dragSession)
> dragSession = Components.classes["@mozilla.org/widget/dragservice;1"]
> .getService(Ci.nsIDragService)
> .getCurrentSession();
> let dataTransfer =
> evt.dataTransfer ? evt.dataTransfer : gFolderTreeView._currentTransfer;
>
> now, I am able to get the messages from the dragSession, but they still have the old
> folder URL.
>
> The ftv_drop function in Thunderbird's folderPane code is triggered after this, and
> operates on the treeview. Unfortunately I haven't found any way to register events on
> the treeview, for all I know this might not be possible. Am I going about this the
> wrong way?
>
> any serious comments welcome.
> thanks
> Axel
>

_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|

Re: overwriting the drop function

Andrew Sutherland-3
You are mis-using "call".  The first argument is the "this" to use for
the call.  See:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call

You should really wrap the call to your own function in a try/catch so
in the event your code breaks you don't break the core Thunderbird
functionality.

Unfortunately, I can't speak to the larger DnD issue, but the
addEventListener solution does seem more hygienic than monkey-patching.

Andrew

On 05/05/2012 04:45 AM, Axel Grude wrote:

> I want to try a different approach now, by wrapping gFolderTreeView.drop.
>
> there is only one problem, when I call the original function it makes a
> mistake whenever it uses "this". "this" isn't pointing to
> gFolderTreeView anymore. How can I fix it?
>
>
> Here is my new code:
>
> let originalDrop = gFolderTreeView.drop;
> // let's wrap the drop function in our own
> gFolderTreeView.drop = function (aRow, aOrientation) {
>      let retVal = originalDrop.call(aRow, aOrientation);
>      myownObject.onFolderTreeViewDrop(aRow, aOrientation);
>      return retVal;
> }
>
>
> when I trace into the original drop function using originalDrop.call it
> fails in:
>
> folderPane.js#636:
>
>      let dt = this._currentTransfer;
>
> since "this" is not set correctly the datatransfer cannot be retrieved.
> Is it possible to 'set' this=gFolderTreeView before I do the original
> call? My understanding is that 'this' usually points to the containing
> object; just don't know how to provide that from within my own drop
> function.
>
> I am cross posting this to the thunderbird development group, as they
> know more about gFolderTreeView.
>
> thanks in advance
>    Axel
>
>
>
> On 04/05/12 21:46, Axel Grude wrote:
>> Hi,
>>
>> I have made a drop handler on the folder pane, but unfortunately it
>> triggers too
>> early; I can retrieve the messages from the dragSession but not the
>> name / URL of the
>> folder that it is dragged to. Has anybody else an idea how to solve this?
>>
>> shortened version of the code;
>>
>> // setting up the event handler on folder tree:
>> document.getElementById('folderTree')
>> .addEventListener("drop", onFolderTreeDrop, false);
>>
>> // start of the drop event handler
>> onFolderTreeDrop: function(evt, dropData, dragSession) {
>> let Ci = Components.interfaces;
>> var DropTarget = evt.target;
>> if (!dragSession)
>> dragSession = Components.classes["@mozilla.org/widget/dragservice;1"]
>> .getService(Ci.nsIDragService)
>> .getCurrentSession();
>> let dataTransfer =
>> evt.dataTransfer ? evt.dataTransfer : gFolderTreeView._currentTransfer;
>>
>> now, I am able to get the messages from the dragSession, but they
>> still have the old
>> folder URL.
>>
>> The ftv_drop function in Thunderbird's folderPane code is triggered
>> after this, and
>> operates on the treeview. Unfortunately I haven't found any way to
>> register events on
>> the treeview, for all I know this might not be possible. Am I going
>> about this the
>> wrong way?
>>
>> any serious comments welcome.
>> thanks
>> Axel
>>
>


_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|

Re: overwriting the drop function

Axel Grude-3
On 06/05/12 01:20, Andrew Sutherland wrote:

> You are mis-using "call". The first argument is the "this" to use for the call. See:
> https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call
>
> You should really wrap the call to your own function in a try/catch so in the event
> your code breaks you don't break the core Thunderbird functionality.
>
> Unfortunately, I can't speak to the larger DnD issue, but the addEventListener
> solution does seem more hygienic than monkey-patching.
>
> Andrew
Thanks Andrew.

I will add the try-catch but using the dnd addEventListener here i had tried
unsuccessfully for a long time, unfortunately there is no information on the
targetFolder (the internal drop target) at the time of the drop (dragSession not
filled properly). I tried different ways from the treeView but it seems to hide that
information fairly well, hence the monkey patching. :)

regards
   Axel
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird