I have a question about NSImageCell. It can display a NSImage, but there is no way to edit it. Other cells allows modification of their contents (you can edit text, check controls and so on) but you cannot edit (copy, paste) a NSImageCell.
If you drag and drop an image on a NSImageWell, everything is fine. Why can’t it be the same with NSImageCell?
Of course my column is editable, my cell is editable too in IB. What am I missing?
I believe you need to play around with Core Graphics, as NSImage is immutable. NSIMageWell are just one way to display an image, and not an image editor, as far as I know.
There is some nice things in core graphics about image manipulation, but don’t expect Photoshop-level capabilities.
Thank you for lending me these abilities (or at least these projects) ! I am still very far from playing with Core Graphics, I would just be able to click the cell and paste the image, or drag and drop. In fact, to do with my cell with the same thing as with a NSImageWell.
So what? Create a subclass of NSActionCell? I do not want to turn my tableView into a view-based one.
Er. When something is not implemented in cocoa, this means usually that I want something weird. Is is?
No, not something weird, something custom. Quite different!
This is why you can subclass classes. To make them do something it doesn’t do ordinarily.
But if I understand correctly you want to have a nscell inside a table view that you can drag and drop images in and will place it inside the nscell?
Why don’t you use a drag and drop and use the replace option and then you get the URL of the image that was dropped onto the row and replace the nscell’s contents?
Cocoa. And by the way, what wrong with this *** formatter? It is supposed to accept only a single word in a TextField.
What is this thing called NSCFString subtly disguised as an obj, I cannot get anything useful from it: return obj, NSString stringWithString: obj, [obj stringValue]. only errors or a wiped out text field. @end
Replace “NSTableViewDraggingDestinationFeedbackStyleNone” with “NSTableViewDraggingDestinationFeedbackStyleSourceList” to get the “replace” feedback to the user.
And for the dragging part:
- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
{
NSPasteboard* pasteBoardContent = [info draggingPasteboard];
NSArray* acceptedTypes = [NSArray arrayWithObject:(NSString*)kUTTypeFolder];
NSArray* pasteboardURLs = [pasteBoardContent readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]]
options:[NSDictionary dictionaryWithObject:acceptedTypes
forKey:NSPasteboardURLReadingContentsConformToTypesKey]];
//This returns the mouse cursor you want to give as feedback to the user when they drag something on the table view.
if (pasteboardURLs.count > 0) {
return NSDragOperationCopy;
} else {
return NSDragOperationNone;
}
}
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id < NSDraggingInfo >)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
NSPasteboard* pasteBoardContent = [info draggingPasteboard];
NSArray* acceptedTypes = [NSArray arrayWithObject:(NSString*)kUTTypeFolder];
NSArray* pasteboardURLs = [pasteBoardContent readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]]
options:[NSDictionary dictionaryWithObject:acceptedTypes
forKey:NSPasteboardURLReadingContentsConformToTypesKey]];
if (pasteboardURLs.count > 0) {
//Do something with the URLS in pasteboardURLs
//not forgetting the row value to know which row to replace in your array controller's arranged objects.
}
return YES;
}
You can replace NSDragOperationCopy by any other kind of cursor, just check the docs for “NSDraggingInfo Protocol Reference”. Also, you can replace kUTTypeFolder by any other types, just check the docs for “UTType Reference”.
Well, i cant promise it’ll work as is, you’ll have to do some adjustments to fit your needs. But this is what I is. It’s fairly logical, just read thru the whole thing slowly, you’ll see the logic of it.