Picture this sparsely populated NSMatrix
, five coloured columns (0-4), with the most recently added column in orange. These are populated with stand-in objects (random numbers) with the (x,y) coordinates noted. "Blank" cells have stand-in NULL objects. This is kinda working.
I have four data "sources" (A-D) at the top that I want draggable onto the matrix. They are tagged with numbers that represent target rows (0-3). I can't get these to drag even though I think I've done NSDragSource
correctly.
Example behaviours:
If I drag cell B (with 0,2) onto the "centre" area of the column (4,y), its contents will merge with the two empty cells (rows 0 and 2). If I drag onto the left or right area of the column, I will get a prepended or appended column -- in this case, a sparse one.
If I drag cell A (with 0,1,2,3) onto any cell, it will create a new column.
If I drag cell D onto column (0,y) or (4,y) it will merge; dragging it anywhere else will create new sparse column. Doing so with C anywhere will create a new sparse column.
As one could surmise, this complex merging behaviour has led me here rather than, say, to NSTableView
.
I don't so much have a problem of identifying the left/center/right areas or merging the data or creating new columns -- I need help creating the proper NSPasteboard
interactions and/or the NSDragging
setup: (I ultimately want to using a custom NSManagedObject
in Core Data that will be identify which rows are populated, but I'm starting here).
- I'm trying to prototype a
NSStringPboardType
attached to the fourNSTextFields
that will be draggable. No dice. - I can make my
NSMatrix
receive strings (or anNSFilenamesPboardType
) from the pasteboard. No problem there.
Once I receive the appropriate incoming cell (string), I can riffle through it and figure out whether to merge with the current column, or create a new column -- again, that's not the issue.
Things I have done...
1) Subclassed the NSTextField...
@interface CellStringView : NSTextField <NSDraggingSource>
2) Registered the text fields' dragged types & attempted a drag session...
- (void)awakeFromNib {
[self registerForDraggedTypes:@[NSStringPboardType]];
}
- (NSDragOperation)draggingSession:(NSDraggingSession *)session
sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
if (context == NSDraggingContextWithinApplication) {
return NSDragOperationCopy;
}
else
return NSDragOperationNone;
}
-(void)dealloc {
[self unregisterDraggedTypes];
}
My draggingSession:sourceOperationMaskForDraggingContext:
method is never even called.
I'm new to this NSPasteboard
stuff, so any help would be appreciated.