NSBrowser fills NSPasteboard but won't drop

457 views Asked by At

I have an NSBroswer with a series of entries that look up a text blob. If the blob exists then - (BOOL)browser:canDragRowsWithIndexes:inColumn:withEvent: returns YES.

This invokes - (BOOL)browser:writeRowsWithIndexes:inColumn:toPasteboard:

In here I do the following:

NSUInteger changeCount;
BOOL retBOOL = YES;

changeCount = [pasteboard clearContents];
changeCount = [pasteboard declareTypes:@[NSPasteboardTypeString, NSPasteboardTypeHTML]
                                 owner:self];
didSet = [pasteboard setString:self.currentHTMLCode
                       forType:NSPasteboardTypeString];
retBOOL = retBOOL & didSet;
didSet = [pasteboard setString:[NSString stringWithFormat:@"<pre>%@</pre>", self.currentHTMLCode]
                       forType:NSPasteboardTypeHTML];
retBOOL = retBOOL & didSet;

Now the data analysis of the pasteboard coming out (with retBOOL: Yes) is:

pasteboard: : <NSPasteboard: 0x101931870>
     name: : Apple CFPasteboard drag
     change count: : 77
     types: : (
    "public.utf8-plain-text",
    NSStringPboardType,
    "public.html",
    "Apple HTML pasteboard type"
)
     items: : (
    "<NSPasteboardItem: 0x1005a5cb0>"
)
         PBItem: : <NSPasteboardItem: 0x1005a5cb0>
             PBType: : public.utf8-plain-text
                 String for type [public.utf8-plain-text] = 89958 characters
             PBType: : public.html
                 String for type [public.html] = 89969 characters
retValue: YES

So my problem is that when I drag this to SimpleText or BBEdit, nothing drops. I don't see a highlight of the target document. (Note: I also have a drag image routine, and I see the drag image)

Any ideas why I seem to be populating the pasteboard but it refuses to drop in the other app?

1

There are 1 answers

0
unixo On BEST ANSWER

I downloaded the example project SimpleBrowser by Apple, added

[_browser setDraggingSourceOperationMask:NSDragOperationAll forLocal:NO];

in awakeFromNib and implemented almost part of your code and it works with TextEdit, Safari & Word. Here's the sample code