objective c - Reading Multiple Dragged-n-Dropped Files -
i have small window inside main xib (mainmenu.xib) nsimageview control os x application. view control has nsimageview subclass supposed accept files user brings (drag n drop). since have no experience in developing mac application objective-c, i've searched around, checking out sample projects apple, , got idea. well, make story short, i've copied code posted here. works. great... following concise version.
- (nsdragoperation)draggingentered:(id <nsdragginginfo>)sender{ return nsdragoperationcopy; } - (nsdragoperation)draggingupdated:(id <nsdragginginfo>)sender{ } - (void)draggingexited:(id <nsdragginginfo>)sender{ } - (bool)preparefordragoperation:(id <nsdragginginfo>)sender{ return yes; } - (bool)performdragoperation:(id<nsdragginginfo>)sender { nspasteboard *pboard = [sender draggingpasteboard]; if ([[pboard types] containsobject:nsurlpboardtype]) { nsurl *fileurl = [nsurl urlfrompasteboard:pboard]; nslog(@"path: %@", [self convertpath:fileurl]); // <== that's need } return yes; } - (nsstring *)convertpath:(nsurl *)url { return url.path; }
for now, drop box gets file paths 1 @ time regardless of number of files user drags , drops onto drop box. know how application read multiple files user brings.
thank you,
change performdragoperation: method this:
- (bool)performdragoperation:(id<nsdragginginfo>)sender { nspasteboard *pboard = [sender draggingpasteboard]; if ([[pboard types] containsobject:nsurlpboardtype]) { nsarray *urls = [pboard readobjectsforclasses:@[[nsurl class]] options:nil]; nslog(@"urls are: %@", urls); } return yes; }
Comments
Post a Comment