奇怪的 NSPasteboard 和 TextEdit 交互
我正在从应用程序中的两个位置拖放字符串。一种来自自定义 NSView
,另一种来自 NSTableDataSource
委托。第一个允许我将文本拖动到 TextEdit 应用程序中,第二个则不允许。我可以从这两个应用程序拖动到其他应用程序,例如 Terminal 或 TextMate。据我所知,我对两者使用几乎相同的代码。
我正在尝试找出问题所在。它原则上有效,因为我可以拖动到某些应用程序。但是 TextEdit 发生了什么?
从自定义 NSView:
(void)mouseDown:(NSEvent *)theEvent
{
NSString *testString = @"TEST";
NSImage *dragImage;
NSPoint dragPosition;
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObjects: NSStringPboardType, nil] owner:nil];
[pboard setString:testString forType:NSStringPboardType];
dragImage = // blah
dragPosition = [self convertPoint:[theEvent locationInWindow] fromView:nil];
[self dragImage:dragImage
at:dragPosition
offset:NSZeroSize
event:theEvent
pasteboard:pboard
source:self
slideBack:YES];
}
}
从表委托:
(BOOL)tableView: (NSTableView *)aTableView writeRowsWithIndexes: (NSIndexSet *)indexes toPasteboard: (NSPasteboard *)pboard
{
NSString *testString = @"TEST";
[pboard declareTypes:[NSArray arrayWithObjects: NSStringPboardType, nil] owner:nil];
[pboard setString:testString forType:NSStringPboardType];
return YES;
}
如果我打印出第一个的 pboard 类型:
"public.utf8-plain-text",
NSStringPboardType,
第二个:
"public.utf8-plain-text",
NSStringPboardType,
同样,第一个的内容:
2010-11-16 13:56:01.832 XXX[1654:a0f] public.utf8-plain-text:TEST
2010-11-16 13:56:01.838 XXX[1654:a0f] NSStringPboardType:TEST
第二个
2010-11-16 13:56:05.623 XXX[1654:a0f] public.utf8-plain-text:TEST
2010-11-16 13:56:05.623 XXX[1654:a0f] NSStringPboardType:TEST
据我所知,两者的行为应该相同相同。但他们不是。有想法吗?
I am drag-dropping a string from two places in my app. One from a custom NSView
and one from a NSTableDataSource
delegate. The first one allows me to drag text into the TextEdit application, the second one does not. I can drag from both to other apps such as Terminal or TextMate. As far as I can tell, I'm using close to identical code for both.
I'm trying to figure out what's wrong. It's working in principle because I can drag to some apps. But what's going on with TextEdit?
From the custom NSView:
(void)mouseDown:(NSEvent *)theEvent
{
NSString *testString = @"TEST";
NSImage *dragImage;
NSPoint dragPosition;
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObjects: NSStringPboardType, nil] owner:nil];
[pboard setString:testString forType:NSStringPboardType];
dragImage = // blah
dragPosition = [self convertPoint:[theEvent locationInWindow] fromView:nil];
[self dragImage:dragImage
at:dragPosition
offset:NSZeroSize
event:theEvent
pasteboard:pboard
source:self
slideBack:YES];
}
}
From the table delegate:
(BOOL)tableView: (NSTableView *)aTableView writeRowsWithIndexes: (NSIndexSet *)indexes toPasteboard: (NSPasteboard *)pboard
{
NSString *testString = @"TEST";
[pboard declareTypes:[NSArray arrayWithObjects: NSStringPboardType, nil] owner:nil];
[pboard setString:testString forType:NSStringPboardType];
return YES;
}
If I print out the pboard's types for the first one:
"public.utf8-plain-text",
NSStringPboardType,
And for the second:
"public.utf8-plain-text",
NSStringPboardType,
Likewise, the content for the first:
2010-11-16 13:56:01.832 XXX[1654:a0f] public.utf8-plain-text:TEST
2010-11-16 13:56:01.838 XXX[1654:a0f] NSStringPboardType:TEST
And second
2010-11-16 13:56:05.623 XXX[1654:a0f] public.utf8-plain-text:TEST
2010-11-16 13:56:05.623 XXX[1654:a0f] NSStringPboardType:TEST
So as far as I can tell, the two should be behaving identically. But they're not. Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论