Drag and drop just to extract file path

I'm writing a Cocoa GUI app to facilitate working with a command-line program. The scenario is quite similar to what I see in the Apple FileMerge.app. I'd have a NSView (or a drop pocket of whichever class appropriate) into which I can drag the file icons just in order to retrieve file's path, one by one, no visualization, no checking for file types, just for assembling a list of files to eventually be passed to the data crunching program as command line arguments. I've come across CocoaDragAndDrop sample program, which does great work in displaying dragged picture tiff and pdf files. Probably 90% of the code there is beyond what I need, but the semantics are so unlike anything I've ever come across (I'm miles away from image processing). I can't even figure where to start since everything seems so interconnected. Is there a simplest case example of Drag and drop which only serves file path extraction? From the aforementioned sample code I'm struggling to figure out what is the part which is absolutely needed only to retrieve the path? Do I have to init a [NSImage canInitWIthPasteboard: ... ...] if a file is a plain text file, or a raw data file? The app doesn't need to know what the file is, since passing the absolute path as text argument cannot do any harm in this case - the number crunching command line program takes care of the content. Do I need coders? Do I need a sourceOperationMaskForDragingContext? Does Drag and Drop even cover such trivial demands?
Thanks in advance!
Regards, UU

Thanks for your kind replay. Please let's stay on-topic: my question shouldn't have pointed at if "Apple works like this or like that".
IMHO, it's quit opposite: many things are cut-and-paste compatible, yet I'm missing few basic explanations.
The following code can be derived from the API reference:
#import "DragTView.h"
#import "AppDelegate.h"
@implementation DragTView
- (id)initWithFrame:(NSRect)frame{
    self = [super initWithFrame:frame];
    if (self) [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
    return self;
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender{
    highlight=YES;
    [self setNeedsDisplay: YES];
    return NSDragOperationGeneric;
- (void)draggingExited:(id <NSDraggingInfo>)sender{
    highlight=NO;
    [self setNeedsDisplay: YES];
- (void)drawRect:(NSRect)rect
    [super drawRect:rect];
    if ( highlight ) {
        [[NSColor grayColor] set];
        [NSBezierPath setDefaultLineWidth: 5];
        [NSBezierPath strokeRect: rect];
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
    highlight=NO;
    [self setNeedsDisplay: YES];
    return YES;
- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender {
    NSArray *draggedFilenames = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
    NSURL* fileURL;
    NSTextField* pathField = [(AppDelegate*)[[NSApplication sharedApplication] delegate] pathField];
    if (([[[draggedFilenames objectAtIndex:0] pathExtension] isEqual:@"txt"]){
        fileURL=[NSURL URLFromPasteboard: [sender draggingPasteboard]];
        [pathField setStringValue:  [fileURL path] ];
        return YES;
    } else return NO;
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender{
@end
It reveals the file path, yet, it boils down to fifty meaningless lines of code, since the pathField object (of class NSTextField) would itself reveal a dropped file's path without a single extra line of drag-and-drop code. What I find confusing is the following:
How should a drag operation be set up, so a text file can be dragged to the DragTView object (declared as @interface DragView: NSImageView <NSDraggingSource, NSDraggingDestination>), which would than show the image of file's icon (without dragged file itself being an image file)? This is rather unclear in the documentation, with all due respect to Apple.
Thanks in advance.

Similar Messages

  • An mp3 file on my computer will not import to itunes by either the drag-and-drop or the Add File to Library method.  Can't figure out what I'm doing wrong.  My OS is Windows 7.

    I purchased an mp3 from a private website on my laptop.  The itunes library i sync ipod to is on my desktop, so i copied the mp3 onto a flash drive and then into my desktop in the Downloads folder and Desktop folder as well as the itunes music folder, 3 places.  I opened itunes on the desktop and read the instructions for importing music that's already in my computer.  Neither the drag-and-drop or the Add File to Library method works.  I've tried both ways over and over.  Cannot figure out what the problem is.  I do note that the name of the mp3 file doesn't show the .mp3 extension, it appears as simply it's title, Eating Healthy, without any extension at all.  Could the filename be the problem, or do you have any other idea what I'm doing wrong?  My OS is Windows 7, using IE9.  Thanks.
    ADDENDUM AFTER READING ANOTHER DISCUSSION HERE:  I have now tried right clicking the song in Windows Explorer and choosing Open With, clicking itunes.  The mp3 plays in itunes but does not add to the library.

    I don't have a Recently Added playlist.  However, I discovered that the file I had named Eating Healthy was given the name You Can Enjoy Eating Healthy when it copied to iTunes.  I'm guessing iTunes pulled the full name of the piece from the internet.  Upshot--the mp3 did transfer to iTunes on all 3 tries, but I was looking in my alphabetized list under E, not Y, so I didn't see it there.  Thanks for your help. 

  • How do I stop a copy of backup files? Time Machine filled my extern HD, I bought a 2TB, drag and drop the old backup files and now my iMac has been stuck in "preparing copy" mode all night.

    My 235 MB external HD was full, I bought a new 2TB and dragged and dropped the old backup files to it. Now my iMac is frozen in "preparing copy" mode.  How can I 'unfreeze' it? How should I move the backup files from one external HD to the other?

    This has been answered here so may times (especially by pondini, e.g. in this thread Time Machine stuck in repeating "preparing files" cycle), so please search this forum the next time before asking such a question.

  • Drag and Drop an Attached AutoCad File in a PDF Portfolio to and Open Drawing in AutoCad

    I currently Printed all my Details to PDF and combined them all into a catalog to view them. I them attached all the AutoCad files to the PDF. I can open the AutoCad file in the pdf, but it will open it as a new drawing int AutoCad. I would like to Drag and drop from the PDF file to a drawing that is already opened in AutoCad. Any suggestions?
    Thanks

    Hello,
    I think you posted this question in the wrong forum: this is one of the Captivate forums and I do not see a relation to it, but can be wrong.
    Lilybiri

  • DRAG AND DROP - Where are my files?

    I open My Music and highlight a few songs - drag and drop into Itune Library. It looks fine I can play the songs.
    But.. but.. my files are not liested in My Music anymore.
    I run a search and could not find anywhere but still in Itunes.
    I like to play my songs with Windows Media Player(10 years a head in quality and perfomance than Itunes) and I can't find it.( I use Itunes just because I have Ipod )

    Download the 'Forms and Reports Feature/Benefit Demos' from the Sample code page. It is contained in there.
    http://technet.oracle.com/sample_code/products/forms/content.html

  • Drag-and-drop tree list from files/folder

    Hello all. I'm new to Flex and I'm looking for some help or
    for someone to point me in the right direction. I want to write a
    simple AIR application to accept a multiple text files (or a folder
    full of text files) when the files/folder is dragged into a tree
    list. The file/folder name will be the node name. When selected,
    the contents of the file will be displayed in a text area. The text
    file will contain a 4 x 4 number matrix with each column separated
    by a tab and each row separated by a return. (I plan on plotting
    the numbers in the matrix in the future).
    What I'm most confused about is how to go about
    dragging-and-dropping files into a tree list and creating item
    names based on the file/folder name? And does the file content need
    to go into an array collection?
    Maybe I'm going about this in a difficult way. If there is an
    easier way, I'd appreciate it if someone could share. Thank you
    all.

    I have the same problema and I´m not able to find the reason.
    The solution to get the event raised has been to copy configurations from wd standard appl FPM_TEST_DND_FORM and use my own Z feeder class : all  seems to work perfectly , but , if I try to do it from scratch the event  FPM_DROP_COMPLETED it´s not raised .
    I´ve compared both configurations/class ( the one that I´ve done from scratch  that it doesn´t raise the event and the one that I´ve adapted copying from standard that it raises perfectly  the event) and I haven´t  seen any difference (maybe I haven´t found) .

  • Drag and drop operation resulted in files gone missing

    I would really appreciate some help as I have lost about 80 files. Here's what happened: I had a big folder of several hundred files and I was moving those files– photographs – into subfolders.I selected the photo in bridge and then used a drag and drop method to move it. It all went well except in two instances. One group of photos I dragged it to the wrong folder but when I searched I found them. Another group has gone missing. I have searched the whole computer for names of some of the photos in the missing group.it is as if they vanished into thin air. What could have possibly happened?
    Thanks in advance!

    I selected the photo in bridge and then used a drag and drop method to move it. It all went well except in two instances.
    I always use the drag and drop method and if it goes wrong I usually are to fast and don't wait for Bridge to have completed or I did not point to the correct folder.
    Without knowing what system you are on and what version of bridge you are using I agree with Curt that the files must be somewhere on your system (also check the Bin) and you better use a dedicated system search for it.
    And what is "group.it"? If I do a google search it stops without result and group.it also has not understandable  or related results?

  • Drag and drop, like magic the files just vanish!

    Ever since upgrading my mid 2009 MacBook Pro to Lion, I have been having trouble copying or moving files by dragging them. I especially seem to have trouble dragging files to the desktop...  I drag them there, but they just vanish without a trace.  I also don't seem to be able to option-drag a file to make a copy of it... I drag it to a new location and it just vanishes completely.  This is driving me mad.  Anyone else having this issue?
    I've run a permission repair a few times, but it's made no difference.  Any ideas?

    I pasted this in answer to another thread but will post again here:
    Yes I have had this problem on both my iMac and MBA. It was driving me mad! Can import files to applications like Lightroom and export but trying to copy files to another location through Finder and the files disappeared after appearing to copy.
    Solution is to Force Quit Finder and Relaunch. I then rebooted and all is now fine.
    Another solution I read is to paste this in Terminal:
    killall Finder && open /System/Library/CoreServices/Finder.app
    Hope this helps others.

  • Difficult: Drag and Drop: how to get the path of the drag-source ??

    I have to write an applet, after a "Drag&Drop"-Operation from a MS-Word-document to this applet, the applet is supposed to show the path of the document.
    Does anyone know how to do this ?
    thanks

    http://forum.java.sun.com/thread.jsp?forum=4&thread=300727

  • Can't drag and drop or import into files

    I moved my audio files from "c" drive to another drive and had a bear of a time getting itunes to recognize it...but after reinstalling finally it seems to be working okay... Except when I copy and paste my audio files into itunes nothing happens. When I import (or add a new file) I can't put them in a specific file. So all of my audio files are just in the big "my music" file which is a very big jumbled up file to sort through. Any ideas?
    Thanks in advance.
    Sandra

    Now I believe that there was something wrong with the install. I uninstalled iTunes and reinstalled the same package. It works just fine now.
    It probably comes down to Windows disallowing a part of the install.
    After I reinstalled, I was able to right click on my iPod icon and choose restore from backup so I could get my iPod back to the way it was. It doesn't seem to restore your "Folders", but it does get all your music and stuff back into your iPod's RAM.
    I hope this solves your problem too. Take care!

  • Cannot drag and drop from music to file - why??

    I have just set up on itunes but having downloaded music from a CD, I can't then move it from 'music' to a new folder (or any other folder for that matter). Why might this be - is there something I might not have done or something needs disabling?
    Any help greatly appreciated.. Thanks!

    Welcome to AD!
    You can move tracks to a playlist, and create Playlist Folders. But you can't just drag songs into a folder.
    You can only drag playlists into a Playlist Folder.

  • Drag and drop image from local files site list to page.

    Not working on all my documents. Must be some setting. Any ideas what is wrong?

    To be honest, I never drag & drop in DW.  I always use Insert > Image, Select image source...
    Nancy O.

  • File drag and drop with Labview 7 and Mac OS X Tiger?

    Hi folks,
    I've lost the ability to drag and drop files into front panel file path
    controls, since I upgraded to a new OS X version. Specifically:
    What used to work:
        - Labview 7.0
        - Mac OS X 10.3.x
        - drag file icon from desktop and drop onto file path control (file path control shows path to dropped file)
    New action taken:
        - lost old Mac (Titanium) with OS X 10.3.x
        - bought new Mac (Aluminum) with OS X 10.4
        - installed OS X 10.4 "over" 10.3 disk (did not build from scratch)
    What happens now (three days after birth of new system):
        - all my past Labview apps still seem to run
        - but, if I drag a file from the desktop and drop it onto the file path control I see:
              - file path control
    "outlines" indicating that it understands the intended drag and drop
    action
              - when the file is dropped the file path control does not report the new value
              - And the file path control still has it's old value
    Anyone else seeing this? Am I missing something obvious (Labview or OS X preferences)?
    Thanks in advance,
    RMP

    Hello,
    I don't know how seriously Apple sees the problem, but it doesn't seem plausible that they would rev the OS on account of just this problem with LabVIEW, particularly since we worked around it for the latest version of LabVIEW.  I understand you are working with another engineer at NI via direct email regarding this issue, and that is going to be a better forum for discussing the possibility of obtaining the Apple bug report number.  In the event R&D is willing to reveal it, I presume they will be more comfortable doing so on a case by case basis, as opposed to posting it on the external discussion forum.
    Thank you, and sorry for the inconvenience you have encountered due to this issue.
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • Drag and Drop - Incomplete Wireless Copying of Files

    Ever since I upgraded to 10.6.4, I have a problem doing the "drag and drop" method of copying files wirelessly from my Mac to the HP MediaSmart server connected to my Apple AirPort N Base station.
    I used to be able to simply copy files without problems from my FireWire CF card reader to the server fast and with no problems. After the upgrade, the wireless copying has become slow and the transfer is incomplete. For example today I tried to drag and drop 97 photo files and it only copied 30 of those files in random order. So I repeat the process over and over again (without replacing the already copied files) until all 97 files are copied. If I re-copy everything from scratch by over-writing existing copied files, it will only successfully copy a few files again.
    If I copy direct from the card reader to the hard drive in my computer, the copying is lightning fast and with no problem.
    If I copy from the computer hard drive to the server connected to the AirPort, the same inconsistent copying occurs.
    So it's somewhere in the wireless link that has a problem.
    The solution is to use the "Image Capture" app so that it will successfully copy all files from the card reader to the server. But as I mentioned the process is slow.
    I have installed the latest Apple updates at the time they come out. I am at 10.6.5 and have the latest AirPort update that was recently released. I still have the same problem.
    Anyone know about this problem? How do I report issues like this directly to Apple?
    Thanks for any assistance and feedback.

    I am having the same problem. I just bought a USB Hard-drive and was copying a 2.7 M folder from one HD to the USB and it leaves out like 15 files. I tried copying to the desktop and it does the same thing. I can open the folder, cmd-A, cmd-c, then paste and it took all the files. Very strange.

  • K3b wont let me drag and drop files or folders

    I use k3b and since switching to arch havent had to use it till now. I open it just fine but it wont let me  drag and drop from dolphin (files or folders)
    though I can manually browse using its interface at the top and add files just fine...
    anyone experience same problem or know how to fix?? I couldnt find it in settings.
    again using k3b version : 1.93.0rc4-1
    thanks

    SMith319
    I'm having the very same problem, dragging and dropping new albums from iphoto to my iWeb created website, after having no trouble doing this for the last 2 years.
    I have able to drag and drop just 2 weeks ago and now it doesn't work.
    It's an album page, not a photo page, I am certain because there are already 5 albums posted on that page.
    Very strange. I wonder if its some sort of update problem they need to fix. All my software is updated (although I dont have ilife '09) but I wonder if some sort of new bug has be created through the most recent updates.
    If anyone has a solution I would be most grateful as I've run out of ideas and am unable to post new albums in any way shape or form, drop and drop or not..
    Thanks.

Maybe you are looking for

  • HR_MAINTAIN_MASTERDATA in HRECM00_ACTIVATION Method ACTIVATE_PROCESS

    Hi all, I am using the FM HR_MAINTAIN_MASTERDATA to update a custom infotype during ECM avtivation process. The coe in this FM is going for a dump. When I copy past the code in a regular report program  this runs with out any issues. raisisng a ticke

  • How to add new payment Options in WEB SHOP

    Hi all We need to add new payment options in the B2C shop, but we don't find any customizing place to do it, we read about the BADI CRM_RISK_MGMT_BADI, but in the documentation said that we can set a Default payment option or exclude, but nothing abo

  • Messages Quits on Launch and Address Book won't remember me

    Hi, everyone. After upgrading  to Mavericks, a bunch of odd things have happened. 1. Can't use Safari Autofill because apparently... 2. Address Book refuses to remember which is my personal card, eventhough I've set my card a dozen times 3. Messages

  • How to start a new listener in 11g

    Dear all, i am doing internal test upgrade of a 9.2.0.8 database to 11.2.0.1 as a part of 11i to R12 up gradation. Right now i am in the database part(Manual Upgrade), and following the Metalink doc :837570.1 I have completed the "Upgrading Database

  • Sync pc photos to photostream

    I have quite a few photo albums on my Windows 7 PC. I have just started using the iPad Mini and Photostream. Using Photostream, how do i share all my win7 PC photos so i can view on my iPad Mini? My PC photos are stored in the default 'Pictures' fold