怪异的行为:从堆栈拖动到状态项不工作 [英] Weird behavior: dragging from Stacks to status item doesn't work
问题描述
我的应用程序允许拖动到主窗口和状态项。
- 如果我将文件从堆栈拖动到我的窗口
- 如果我将一个文件从Finder拖动到我的窗口,它可以完美地工作。
- 如果我将一个文件从Finder拖动到我的状态项,它会正常工作。
- 如果我将文件从Stack拖动到my
窗口和状态项使用完全相同的拖放处理代码。
有趣的是,当一个文件从Stacks拖到状态项时,游标会按预期变化,因为 - (NSDragOperation)draggingEntered: )sender {
NSPasteboard * pboard;
NSDragOperation sourceDragMask; 方法按预期调用。
当文件被删除时, - (BOOL)performDragOperation:(id)sender {
NSPasteboard * pboard;
NSDragOperation sourceDragMask; 方法未被调用。
这是第一个方法的实现:
- (NSDragOperation)draggingEntered:(id< NSDraggingInfo>)sender {
NSPasteboard * pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if([[pboard types] containsObject:NSColorPboardType]){
if(sourceDragMask& NSDragOperationGeneric){
return NSDragOperationGeneric;
}
}
if([[pboard types] containsObject:NSFilenamesPboardType]){
if(sourceDragMask& NSDragOperationLink){
return NSDragOperationLink;
} else if(sourceDragMask& NSDragOperationCopy){
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
谢谢!
这是一个合法的问题。我已经向苹果提交了一个bug报告。 http://openradar.appspot.com/radar?id=1745403
在此期间,我想出了一个解决方法。即使 performDragOperation:从未被调用, draggingEnded:仍然是。你仍然可以通过检查draggingLocation点是否在NSView的rect内部来判断文件是否被放在NSStatusItem上。这里有一个例子:
- (void)draggingEnded:(id< NSDraggingInfo>)sender
{
if(NSPointInRect([sender draggingLocation],self.frame)){
//文件实际上被放在视图上,所以手动调用performDrag
[self performDragOperation:sender];
}
}
希望这有助于修复错误。 p>
My application allows dragging to both the main window and to a Status item.
- If I drag a file from Stacks to my window, it works perfectly.
- If I drag a file from Finder to my window, it works perfectly.
- If I drag a file from Finder to my status item, it works perfectly.
- If I drag a file from Stack to my status item, it doesn't work.
Both window and status item use the exact same drag and drop handling code.
The funny thing is that when a file is dragged from Stacks onto the status item, the cursor changes as expected because the - (NSDragOperation)draggingEntered:(id )sender { NSPasteboard *pboard; NSDragOperation sourceDragMask; method is called as expected.
When the file is dropped, however, the - (BOOL)performDragOperation:(id )sender { NSPasteboard *pboard; NSDragOperation sourceDragMask; method is NOT called.
Here is the implementation of the first method:
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSColorPboardType] ) {
if (sourceDragMask & NSDragOperationGeneric) {
return NSDragOperationGeneric;
}
}
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
if (sourceDragMask & NSDragOperationLink) {
return NSDragOperationLink;
} else if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
Thanks!
This is a legitimate issue. I've submitted a bug report for this to Apple. http://openradar.appspot.com/radar?id=1745403
In the meantime, I've figured out a workaround. Even though performDragOperation: is never called, draggingEnded: still is. You can still tell if the file was dropped on the NSStatusItem by checking if the "draggingLocation" point was inside NSView's rect. Here's an example:
- (void)draggingEnded:(id<NSDraggingInfo>)sender
{
if(NSPointInRect([sender draggingLocation],self.frame)){
//The file was actually dropped on the view so call the performDrag manually
[self performDragOperation:sender];
}
}
Hope this helps until the bug gets fixed.
这篇关于怪异的行为:从堆栈拖动到状态项不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!