Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 如何检测和处理从NSPathControl到垃圾箱停靠图标的拖动?_Macos_Nspathcontrol - Fatal编程技术网

Macos 如何检测和处理从NSPathControl到垃圾箱停靠图标的拖动?

Macos 如何检测和处理从NSPathControl到垃圾箱停靠图标的拖动?,macos,nspathcontrol,Macos,Nspathcontrol,查找器可以在其窗口底部显示NSPathControl。如果用户将某个项目从该路径控件拖动到Dock的垃圾箱图标,则该项目将相应地被丢弃 我喜欢在我的项目中实现同样的目标。但是,我不知道如何实现这一点,因为没有与其他控件(如NSTableView)一样的draggingSession:endedAtPoint:operation: 如何跟踪NSPathControl的拖动会话,以了解该项目已被拖动到垃圾箱,以便我可以删除它?或者有没有一种方法可以让删除自动发生 (当然,我已经将DragingSou

查找器可以在其窗口底部显示
NSPathControl
。如果用户将某个项目从该路径控件拖动到Dock的垃圾箱图标,则该项目将相应地被丢弃

我喜欢在我的项目中实现同样的目标。但是,我不知道如何实现这一点,因为没有与其他控件(如
NSTableView
)一样的
draggingSession:endedAtPoint:operation:

如何跟踪
NSPathControl
的拖动会话,以了解该项目已被拖动到垃圾箱,以便我可以删除它?或者有没有一种方法可以让删除自动发生


(当然,我已经将
DragingSourceOperationMask
设置为
NSDragOperationEvery
,并且可以将其拖到垃圾箱中—只是拖到垃圾箱中的项目不会被删除。)

我建议您尝试以下方法:

  • 子类NSPathControl类,假设您将其命名为MyNSPathControl

  • 声明您的NSPathControlDelegate,并允许拖动操作(根据)

  • 将委托设置为MyNSPathControl
  • 声明MyNSPathControl的扩展实现NSDragingSource
  • 当拖动到垃圾箱时,我可以在操作参数中使用nsdragooperation.delete。 要访问拖动的内容,您应该从会话访问粘贴板,然后访问其项目


    关于删除本身:我认为您需要手动执行。我建议您尝试以下方法:

  • 子类NSPathControl类,假设您将其命名为MyNSPathControl

  • 声明您的NSPathControlDelegate,并允许拖动操作(根据)

  • 将委托设置为MyNSPathControl
  • 声明MyNSPathControl的扩展实现NSDragingSource
  • 当拖动到垃圾箱时,我可以在操作参数中使用nsdragooperation.delete。 要访问拖动的内容,您应该从会话访问粘贴板,然后访问其项目

    关于删除本身:我认为您需要手动完成

    class DragDelegate : NSObject, NSPathControlDelegate {
        func pathControl(_ pathControl: NSPathControl, shouldDrag pathItem: NSPathControlItem, with pasteboard: NSPasteboard) -> Bool {
            return true;
        }
    }
    
    class MyNSPathControl : NSPathControl {
        var myDelegate = DragDelegate()
        override func awakeFromNib() {
            super.awakeFromNib()
            self.delegate = myDelegate
        }
    }
    
    extension DraggableView: NSDraggingSource {
        func draggingSession(_ session: NSDraggingSession, sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {
            return .every
        }
    
        func draggingSession(_ session: NSDraggingSession, willBeginAt screenPoint: NSPoint) {
            
        }
    
        func draggingSession(_ session: NSDraggingSession, movedTo screenPoint: NSPoint) {
    
        }
    
        func draggingSession(_ session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {
        //  Here it goes
        }
    }