|
@@ -352,6 +352,7 @@ class KMLeftSideViewController: KMSideViewController {
|
|
|
// [noteOutlineView setTypeSelectHelper:[SKTypeSelectHelper typeSelectHelperWithMatchOption:SKSubstringMatch]];
|
|
|
self.noteOutlineView.indentationPerLevel = 0
|
|
|
// [noteOutlineView registerForDraggedTypes:[NSColor readableTypesForPasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]]];
|
|
|
+ self.noteOutlineView.registerForDraggedTypes(NSColor.readableTypes(for: NSPasteboard(name: .drag)))
|
|
|
self.noteOutlineView.target = self
|
|
|
self.noteOutlineView.doubleAction = #selector(selectSelectedNote)
|
|
|
|
|
@@ -4067,13 +4068,17 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
|
|
|
|
|
|
func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
|
|
|
var dragOp = NSDragOperation(rawValue: 0)
|
|
|
-// if outlineView.isEqual(to: self.noteOutlineView)
|
|
|
-// NSPasteboard *pboard = [info draggingPasteboard];
|
|
|
-// if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]] &&
|
|
|
-// anIndex == NSOutlineViewDropOnItemIndex && [(PDFAnnotation *)item type] != nil)
|
|
|
-// dragOp = NSDragOperationEvery;
|
|
|
-// } else
|
|
|
- if outlineView.isEqual(to: self.tocOutlineView) {
|
|
|
+ if outlineView.isEqual(to: self.noteOutlineView) {
|
|
|
+ let pboard = info.draggingPasteboard
|
|
|
+ if pboard.canReadObject(forClasses: [NSColor.self], options: [:]) && index == NSOutlineViewDropOnItemIndex {
|
|
|
+ // if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]] &&
|
|
|
+ // anIndex == NSOutlineViewDropOnItemIndex && [(PDFAnnotation *)item type] != nil)
|
|
|
+ // dragOp = NSDragOperationEvery;
|
|
|
+ if let note = item as? CPDFAnnotation, note.type != nil {
|
|
|
+ dragOp = .every
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if outlineView.isEqual(to: self.tocOutlineView) {
|
|
|
if (index == -1) {
|
|
|
dragOp = NSDragOperation(rawValue: 0)
|
|
|
} else {
|
|
@@ -4104,13 +4109,21 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
|
|
|
|
|
|
func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
|
|
|
if outlineView.isEqual(to: self.noteOutlineView) {
|
|
|
-// NSPasteboard *pboard = [info draggingPasteboard];
|
|
|
-// if ([pboard canReadObjectForClasses:[NSArray arrayWithObject:[NSColor class]] options:[NSDictionary dictionary]]) {
|
|
|
-// BOOL isShift = ([NSEvent standardModifierFlags] & NSEventModifierFlagShift) != 0;
|
|
|
-// BOOL isAlt = ([NSEvent standardModifierFlags] & NSEventModifierFlagOption) != 0;
|
|
|
+ let pboard = info.draggingPasteboard
|
|
|
+ if pboard.canReadObject(forClasses: [NSColor.self], options: [:]) {
|
|
|
// [item setColor:[NSColor colorFromPasteboard:pboard] alternate:isAlt updateDefaults:isShift];
|
|
|
-// return YES;
|
|
|
-// }
|
|
|
+ let isShift = NSEvent.modifierFlags.contains(.shift)
|
|
|
+ let isAlt = NSEvent.modifierFlags.contains(.option)
|
|
|
+ guard let note = item as? CPDFAnnotation else {
|
|
|
+ NSSound.beep()
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if let color = NSColor(from: pboard) {
|
|
|
+ note.setColor(color, alternate: isAlt, updateDefaults: isShift)
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
} else if outlineView.isEqual(to: self.tocOutlineView) {
|
|
|
if (index < 0) {
|
|
|
return false
|