dropping to the Finder

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

dropping to the Finder

Richard Gaskin
In one of my apps I have a list of things I'd like folks to be able to
drag to the Finder, and then when they're dropped I'll assemble the
needed parts and write them to a file at the drag destination.

I can't figure out how to get the path where the user dropped.

Did I miss something obvious?  I hope so.

TIA -

--
  Richard Gaskin
  Fourth World
  Rev training and consulting: http://www.fourthworld.com
  Webzine for Rev developers: http://www.revjournal.com
  revJournal blog: http://revjournal.com/blog.irv
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Jan Schenkel
--- On Fri, 2/26/10, Richard Gaskin <[hidden email]> wrote:

> In one of my apps I have a list of
> things I'd like folks to be able to drag to the Finder, and
> then when they're dropped I'll assemble the needed parts and
> write them to a file at the drag destination.
>
> I can't figure out how to get the path where the user
> dropped.
>
> Did I miss something obvious?  I hope so.
>
> TIA -
>
> --
>  Richard Gaskin
>

Unfortunately, you can't get the drag destination for such a drag'n'drop operation.
The only workaround I've found so far, is to actually already write the data to a temporary file in the dragStart event, and set the dragData["file"] to the path of this temporary file - finally, in dragEnd, check if the temp file is still there and delete it.

While that's ok for small data files, it makes it difficult to write an FTP client where the user can drag a remote file to his local machine...

Jan Schenkel
=====
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)




_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Jeffrey Massung
In reply to this post by Richard Gaskin
On Fri, Feb 26, 2010 at 10:12 AM, Richard Gaskin <[hidden email]
> wrote:

> In one of my apps I have a list of things I'd like folks to be able to drag
> to the Finder, and then when they're dropped I'll assemble the needed parts
> and write them to a file at the drag destination.
>
> I can't figure out how to get the path where the user dropped.
>


Richard,

To my knowledge that's impossible (on every OS). As I understand the
drag/drop paradigm, you can't see where something is dropped to if the
target is another application.

You may want to consider trying a different paradigm if you need to do some
processing after the drag operation completes. For example, you could
either:

* Drag a folder from the finder into your app and use that as the
destination or
* Select the files and use "ask file" to save the "operation" to a target
location.

Just some thoughts.

Jeff M.
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Richard Gaskin
In reply to this post by Richard Gaskin
Jeff Massung wrote:

> On Fri, Feb 26, 2010 at 10:12 AM, Richard Gaskin wrote:
>> In one of my apps I have a list of things I'd like folks to be able to drag
>> to the Finder, and then when they're dropped I'll assemble the needed parts
>> and write them to a file at the drag destination.
>>
>> I can't figure out how to get the path where the user dropped.
>
> To my knowledge that's impossible (on every OS). As I understand the
> drag/drop paradigm, you can't see where something is dropped to if the
> target is another application.

But as Jan suggested, how do most FTP clients work?  In Interarchy I can
drop to any folder and it works great.  I'd like to be able to do
something similar - there must be a way.

> You may want to consider trying a different paradigm if you need to do some
> processing after the drag operation completes. For example, you could
> either:
>
> * Drag a folder from the finder into your app and use that as the
> destination or
> * Select the files and use "ask file" to save the "operation" to a target
> location.
>
> Just some thoughts.

I may have to resort to something like that in the short term.  What a
drag (pun intended).

--
  Richard Gaskin
  Fourth World
  Rev training and consulting: http://www.fourthworld.com
  Webzine for Rev developers: http://www.revjournal.com
  revJournal blog: http://revjournal.com/blog.irv
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Jeffrey Massung
On Fri, Feb 26, 2010 at 10:46 AM, Richard Gaskin <[hidden email]
> wrote:

> Jeff Massung wrote:
>
>  On Fri, Feb 26, 2010 at 10:12 AM, Richard Gaskin wrote:
>>
>>> In one of my apps I have a list of things I'd like folks to be able to
>>> drag
>>> to the Finder, and then when they're dropped I'll assemble the needed
>>> parts
>>> and write them to a file at the drag destination.
>>>
>>> I can't figure out how to get the path where the user dropped.
>>>
>>
>> To my knowledge that's impossible (on every OS). As I understand the
>> drag/drop paradigm, you can't see where something is dropped to if the
>> target is another application.
>>
>
> But as Jan suggested, how do most FTP clients work?  In Interarchy I can
> drop to any folder and it works great.  I'd like to be able to do something
> similar - there must be a way.
>


Sorry, Richard, perhaps I'm misunderstanding, but most FTP clients aren't
doing anything special that I'm aware of. Usually it's the target
application's responsibility to know what to do with whatever is dropped on
it.

I was under the impression that you wanted to know where it was dropped and
then begin to do some work (like combing all the files into a single zip)
and then perform the transfer.

As an example of what I'm thinking, if I browse to an image in FireFox, and
then drag the image to my desktop, FireFox isn't doing anything here (that
I'm aware of) other than creating a drag object containing data that points
to the image's URL. Explorer (or the Finder on Mac) is then responsible for
accepting the drag data of that type and handling it appropriately (in this
case, starting either a download or creating an alias/shortcut to the
hyperlink location).

This is my very cursory understanding of this, though. I haven't worked with
a lot of FTP clients, and the ones I have had 2 directory trees: local and
report, and I dragged and dropped within the application.

On Win32 I know you can also hook into the messages sent to another
window/process (not sure about OS X). It's possible some of the applications
you have used in the past do this and when they receive a remote file drop
event they end up sending a message back to the main application to initiate
the transfer.

Jeff M.
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Richard Gaskin
In reply to this post by Richard Gaskin
Jeff Massung wrote:

> On Fri, Feb 26, 2010 at 10:46 AM, Richard Gaskin wrote:
...

>> But as Jan suggested, how do most FTP clients work?  In Interarchy I can
>> drop to any folder and it works great.  I'd like to be able to do something
>> similar - there must be a way.
>
> Sorry, Richard, perhaps I'm misunderstanding, but most FTP clients aren't
> doing anything special that I'm aware of. Usually it's the target
> application's responsibility to know what to do with whatever is dropped on
> it.
>
> I was under the impression that you wanted to know where it was dropped and
> then begin to do some work (like combing all the files into a single zip)
> and then perform the transfer.
>
> As an example of what I'm thinking, if I browse to an image in FireFox, and
> then drag the image to my desktop, FireFox isn't doing anything here (that
> I'm aware of) other than creating a drag object containing data that points
> to the image's URL. Explorer (or the Finder on Mac) is then responsible for
> accepting the drag data of that type and handling it appropriately (in this
> case, starting either a download or creating an alias/shortcut to the
> hyperlink location).
>
> This is my very cursory understanding of this, though. I haven't worked with
> a lot of FTP clients, and the ones I have had 2 directory trees: local and
> report, and I dragged and dropped within the application.

I've used a few like that myself (GoLive and FileZilla work that way).
It may be just a Mac convention that supports this so well, but I use
Interarchy for FTP and it does a wonderful job of behaving Finder-like:
  I just drag the file name from its listing into the Finder and it
starts the download.  Beautiful, simple, lets the user interact with
their files directly in the context they're most familiar with.


> On Win32 I know you can also hook into the messages sent to another
> window/process (not sure about OS X). It's possible some of the applications
> you have used in the past do this and when they receive a remote file drop
> event they end up sending a message back to the main application to initiate
> the transfer.

Exactly.  I'm not sure what the API looks like for Win and Linux, but I
was able to turn up the Cocoa API and posted it to a new RQCC request to
extend the dragDestination to include a list of file paths when dragging
to the Finder, Windows Explorer, or Linux file manager:

<http://quality.runrev.com/qacenter/show_bug.cgi?id=8634>


In the meantime I thought of a crude hack:

If I had a shell call to get the paths of all open windows, I could
cache the file listings from each into an array, do the drag, and after
the drop check the file listings again, comparing them to the ones I've
cached until I find the one in which the change is the name of the file
I've dragged.

It's a lot of overhead, but provides so much usability that I'm willing
to give it a try if only I could find the shell commands to get that
list of open windows for OS X, Win, and Linux.

--
  Richard Gaskin
  Fourth World
  Rev training and consulting: http://www.fourthworld.com
  Webzine for Rev developers: http://www.revjournal.com
  revJournal blog: http://revjournal.com/blog.irv
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

slylabs13

On Feb 26, 2010, at 10:22 AM, Richard Gaskin wrote:

> It's a lot of overhead, but provides so much usability that I'm willing to give it a try if only I could find the shell commands to get that list of open windows for OS X, Win, and Linux.
http://ss64.com/osx/_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Jim Ault
In reply to this post by Richard Gaskin

On Feb 26, 2010, at 10:22 AM, Richard Gaskin wrote:

> I've used a few like that myself (GoLive and FileZilla work that  
> way). It may be just a Mac convention that supports this so well,  
> but I use Interarchy for FTP and it does a wonderful job of behaving  
> Finder-like:  I just drag the file name from its listing into the  
> Finder and it starts the download.  Beautiful, simple, lets the user  
> interact with their files directly in the context they're most  
> familiar with.


This is true Richard, but the Interarchy drag-drop interface drops  
data that is recognized by the accepting app, such as the Finder, that  
matches what the Finder is expecting.  In the case of moving files, it  
would be the full path and it triggers the 'move file command' if on  
the same drive, and 'copy file command' if on different volumes or  
servers.

You task is more complex.  You are saying that you want your app to  
receive a report back from the Finder that contains the location the  
user chose.  This is not the normal semaphore unless you use  
AppleScripting (which is Mac only of course).  Beyond that, you want  
is to do work that the destination app may not understand, such as  
build a text file and save it.

As far as file listings, the [ls] command can be 'piped' to a text  
file on the hard drive or an environmental memory variable for access  
by your app.  The [ls] command will produce a list, and if you use  
Google, I am sure you can locate a directory walk script out there  
somewhere.

My take would be that the user defines the destination by drag-drop to  
your app, then you check permissions, and go forth.

Hope this helps

Jim Ault
Las Vegas



_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Richard Gaskin
In reply to this post by Richard Gaskin
Jim Ault wrote:

> On Feb 26, 2010, at 10:22 AM, Richard Gaskin wrote:
>
>> I've used a few like that myself (GoLive and FileZilla work that
>> way). It may be just a Mac convention that supports this so well,
>> but I use Interarchy for FTP and it does a wonderful job of behaving
>> Finder-like:  I just drag the file name from its listing into the
>> Finder and it starts the download.  Beautiful, simple, lets the user
>> interact with their files directly in the context they're most
>> familiar with.
>
> This is true Richard, but the Interarchy drag-drop interface drops
> data that is recognized by the accepting app, such as the Finder, that
> matches what the Finder is expecting.  In the case of moving files, it
> would be the full path and it triggers the 'move file command' if on
> the same drive, and 'copy file command' if on different volumes or
> servers.
>
> You task is more complex.  You are saying that you want your app to
> receive a report back from the Finder that contains the location the
> user chose.  This is not the normal semaphore unless you use
> AppleScripting (which is Mac only of course).  Beyond that, you want
> is to do work that the destination app may not understand, such as
> build a text file and save it.

Actually, as an FTP app Interarchy is facing the same issue I am:  there
is no file to move at the time the drop is made.  There's not even any
data; it still needs to be downloaded.

If there's a simpler way to accomplish this I'd love to find it, but it
would appear that Interarchy (and the many other FTP tools that use
drag-and-drop) are getting info from the Finder to know which file to
download their data into.

I don't know specifically what Interarchy is doing what it's doing under
the hood, but I was able to turn up some Cocoa info on this which I
included in my RQCC request:
<http://quality.runrev.com/qacenter/show_bug.cgi?id=8634>

 From my brief reading in the Cocoa specs, it seems the
namesOfPromisedFilesDroppedAtDestination part of the drop record
returned to the drag source app contains the paths to the files the
receiver promises to create.


> As far as file listings, the [ls] command can be 'piped' to a text
> file on the hard drive or an environmental memory variable for access
> by your app.  The [ls] command will produce a list, and if you use
> Google, I am sure you can locate a directory walk script out there
> somewhere.

Traversing all files would take too long, but fortunately we only need
to know about the folders that are open, and their subfolders.

Just to see how this might play out I ran a little test, with favorable
results: getting "the files" from a dozen random folders containing a
total of about 1200 files takes only 12 milliseconds on my
three-year-old Mac (2.1GHz).

So even if it took 10 times as long that's still about a tenth of a
second, plenty of time since we're responding to a user action.

Now the trick is to find a quick way to determine which folders are open.

As much as I appreciate Bob's posting the list of command line calls for
OS X (thanks Bob) I didn't see one there that gives me a list of open
folders - and that means AppleScript, and that means MUCH slower
performance.  And it still doesn't provide a solution for Win and Linux. :(


> My take would be that the user defines the destination by drag-drop to
> your app, then you check permissions, and go forth.

That's what I have in place now as a workaround, but it's quite a drag
to have to sacrifice consistent interactions:  we let folks upload via
drag-and-drop, but make them go through that gawdawful file picker
dialog to download, while other products do it so much more gracefully.

There must be a way....

--
  Richard Gaskin
  Fourth World
  Rev training and consulting: http://www.fourthworld.com
  Webzine for Rev developers: http://www.revjournal.com
  revJournal blog: http://revjournal.com/blog.irv

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Sarah Reichelt-2
> That's what I have in place now as a workaround, but it's quite a drag to
> have to sacrifice consistent interactions:  we let folks upload via
> drag-and-drop, but make them go through that gawdawful file picker dialog to
> download, while other products do it so much more gracefully.

While being able to implement drag & drop properly would be great, my
work-around is to get the user to select a downloads folder, just like
a web browser does. Then any downloaded file just goes directly to the
selected download folder without having to use a file picker.

If you are implementing your plan of scanning the open windows, don't
forget the desktop, which may not show up as a window but will be a
popular recipient of a drag&drop operation.

Cheers,
Sarah
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Terry Judd
In reply to this post by Richard Gaskin
> If there's a simpler way to accomplish this I'd love to find it, but it
> would appear that Interarchy (and the many other FTP tools that use
> drag-and-drop) are getting info from the Finder to know which file to
> download their data into.

On OSX, what about querying the path of the front Finder window just before
the drop is made via applescript.

Try...

Tell application "Finder" to get (POSIX path of (target of front window as
alias))

Although dropping onto the desktop while other windows are open might give
you the wrong result and if the drag target is still in the background when
you make the drop you're in trouble as well.

Terry...

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Björnke von Gierke
In reply to this post by Richard Gaskin
i might have an idea for you. Be warned, it's a dirty workaround. and only halfway there. seriously, i'm not fond of it.

I tested this:
on mousedown
   set the dragdata["files"] to "/Users/bvg/Desktop/GreeceMap.jpg"
end mousedown

Note that the file does exist. But, when I start a drag from that button, the file will be _duplicated_ in the finder wherever I drop it, including proper renaming (when dropped onto the desktop, a file "greeceMap 2. jpg" is created). Note that other OSes might behave differently (might depend on the dragAction?). However, there is no easy way to actually know _where_ the user dropped the file, as you noticed. So what you can do is this:

The user selects the files for download, and then you download the file into a temporary hidden location (eg. temp folder), and then, when you're finished downloading you let the user start a drag action, while setting your dragdata["files"] to the temp files.

Another Idea i just had when rereading my post: all files in mac os have a unique id, independent of name and place in the folder hierarchy. I think there's command line and other ways (applescript) to query that id. you could let the user drag a fake file of which you _know_ the id, then find out where it's now at in the finder... that'd actually work! No idea how to querry the id tho.


--

official ChatRev page:
http://bjoernke.com?target=chatrev

Chat with other RunRev developers:
go stack URL "http://bjoernke.com/chatrev/chatrev1.3b3.rev"

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Quentin Long
In reply to this post by Richard Gaskin
    Possible solution/workaround for dragging stuff directly to the
Finder: Use 'scaffolding' --some sort of tiny (like, 1-byte), invisible
file with an exotic/unique name, which has no use in and of itself, but
exists to provide a useful side-effect. Drag your 'scaffolding' file to
the destination normally. When the 'scaffolding' file is dropped, get
its filepath from the Finder; schlep all the *real* files to that
location; and (silently) delete the 'scaffolding' file.
    The big question here is, how to stage-manage the process so that
the user is never aware of the 'scaffolding' file and thinks it all
Just Works...


ANTHRO fantasy and science fiction: It's furry. It's the *good* stuff.
Always free online: http://anthrozine.com
Offline: ANTHROlogy One ( http://www.lulu.com/content/536807 ) THE
HUMAN MEMOIRS ( http://www.lulu.com/content/541536 ), etc
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: dropping to the Finder

Richard Gaskin
In reply to this post by Richard Gaskin
cubist wrote:

 > Possible solution/workaround for dragging stuff directly to
 > the Finder: Use 'scaffolding' --some sort of tiny (like,
 > 1-byte), invisible file with an exotic/unique name, which
 > has no use in and of itself, but exists to provide a useful
 > side-effect. Drag your 'scaffolding' file to the destination
 > normally. When the 'scaffolding' file is dropped, get its
 > filepath from the Finder; schlep all the *real* files to that
 > location; and (silently) delete the 'scaffolding' file.
 > The big question here is, how to stage-manage the process so
 > that the user is never aware of the 'scaffolding' file and
 > thinks it all
 > Just Works...

With the tempName function making and moving the file would be a snap,
and snappy.

I think the truly hard part is where you write, "get its filepath from
the Finder"....

Hmmm...

Actually, since a newly-dropped file becomes the Finder selection, that
wouldn't be too hard at all with a line of AppleScript.

Now to figure out how I get that info on Win and Linux....

And Björnke, thanks for the tip about the file ID.  I'd forgotten about
that.  May come in handy if all else fails and I need to look at writing
an external for this.

--
  Richard Gaskin
  Fourth World
  Rev training and consulting: http://www.fourthworld.com
  Webzine for Rev developers: http://www.revjournal.com
  revJournal blog: http://revjournal.com/blog.irv
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution