objective c - Drag file from NSTableView to other osx application -
i want drag file nstableview row copy application (i.e. finder). implemented first 2 steps ('configuring table view', 'beginning drag operation') of guide , thought trick: http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/tableview/tasks/usingdraganddrop.html
however, when attempt drag row, row text follows mouse file not copy when released. here's i'm sending uitableview upon initialization:
#define librarysongdatatype @"nsfilecontentspboardtype" - (void)awakefromnib { [self setdraggingsourceoperationmask:nsuintegermax forlocal:yes]; // allow interapplication drags [self registerfordraggedtypes:[nsarray arraywithobject:librarysongdatatype] ]; // nsfilecontentspboardtype }
here's how i'm handling drag in nstableview's data source (an nsarraycontroller):
- (bool)tableview:(nstableview *)atableview writerowswithindexes:(nsindexset *)rowindexes topasteboard:(nspasteboard *)pboard { nslog(@"writerowswithindexes"); nsdata *data = [nskeyedarchiver archiveddatawithrootobject:rowindexes]; [pboard setdata:data fortype:librarysongdatatype]; return yes; }
to clear, i'm not trying drag files table view, i'm trying drag file(s) out of it.
firstly, document did refer when wrote line ?
[self setdraggingsourceoperationmask:nsuintegermax forlocal:yes];
this doesn't make sense. don't use nsuintegermax
. use operation masks defined here. it's written there nsuintegermax
stands everything, shouldn't use it; apple may re-define bit in future. should use nsdragoperationcopy
or specific. if copied line webpage or book, should stop trusting book/webpage.
secondly, forlocal:
should no
pass data application; local
here means application local.
third, instead of setting archived data in
[pboard setdata:data fortype:librarysongdatatype];
consider making nsfilewrapper
, set using writefilewrapper:
, see here. way can specify file name created in finder. otherwise, system doesn't have idea data represent.
Comments
Post a Comment