Ver Fonte

【fix】【书签】书签列表,拖拽书签会消失

tangchao há 6 meses atrás
pai
commit
d41568b17c

+ 4 - 4
PDF Office/PDF Master/Class/Common/Category/NSObject+KMExtension.swift

@@ -716,12 +716,12 @@ extension NSOutlineView {
 }
 
 extension KM where Base: NSOutlineView {
-    public func clickedItem<T>() -> T {
-        return base.clickedItem() as! T
+    public func clickedItem<T>() -> T? {
+        return base.clickedItem() as? T
     }
     
-    public func selectedItem<T>() -> T {
-        return base.selectedItem() as! T
+    public func selectedItem<T>() -> T? {
+        return base.selectedItem() as? T
     }
 }
 

+ 26 - 7
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -1714,9 +1714,16 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                 return 0
             }
             if item == nil { // 第一层
+                let bks = self.bookmarks() ?? []
+                let bkNum = bks.isEmpty ? 0 : 1
+                
                 guard let rootOL = self.outlineRoot() else {
-                    self.showOutlineEmptyView()
-                    return 0
+                    if bkNum > 0 {
+                        
+                    } else {
+                        self.showOutlineEmptyView()
+                    }
+                    return 0 + bkNum
                 }
                 // 搜索按钮
                 self.outlineSearchButton.isEnabled = rootOL.numberOfChildren > 0
@@ -1732,14 +1739,16 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                 }
                 
                 if rootOL.numberOfChildren == 0 { // 没有数据
-                    self.showOutlineEmptyView()
-                    return 0
+                    if bkNum > 0 {
+                        
+                    } else {
+                        self.showOutlineEmptyView()
+                    }
+                    return 0 + bkNum
                 }
                 
                 // 有数据
                 self.hideOutlineEmptyView()
-                let bks = self.bookmarks() ?? []
-                let bkNum = bks.isEmpty ? 0 : 1
                 return Int(rootOL.numberOfChildren) + bkNum
             } else { // 第二层 +
                 if item is CPDFBookmark { // 书签
@@ -2060,7 +2069,17 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     if dragPDFOL.index > index {
                         self.dragPDFOutline(self._dragPDFOutline, toIndex: index, newParentOutline: root)
                     } else {
-                        self.dragPDFOutline(self._dragPDFOutline, toIndex: index-1, newParentOutline: root)
+                        if let bks = self.bookmarks(), bks.count > 0 {
+                            if let data = item as? String, data == Self.kOutlineRootBookmarkItem {
+                                
+                            } else {
+                                if index > 1 {
+                                    self.dragPDFOutline(self._dragPDFOutline, toIndex: index-2, newParentOutline: root)
+                                }
+                            }
+                        } else {
+                            self.dragPDFOutline(self._dragPDFOutline, toIndex: index-1, newParentOutline: root)
+                        }
                     }
                 } else {
                     self.dragPDFOutline(self._dragPDFOutline, toIndex: index, newParentOutline: root)