Browse Source

【综合】页面编辑偶发crash修复

tangchao 1 year ago
parent
commit
e134853bbe

+ 2 - 2
PDF Office/PDF Master/Class/PDFTools/PageEdit/Window/KMPDFEditExtractWindow.swift

@@ -17,8 +17,8 @@ class KMPDFEditExtractWindow: NSWindowController {
     
     private var _extractPerPageFlag = false //是否按页提取标志位;
     private var _selectedPagesName = ""
-    private var _pdfDocument: CPDFDocument?
-    private var _attribute: KMFileAttribute?
+    private weak var _pdfDocument: CPDFDocument?
+    private weak var _attribute: KMFileAttribute?
     
     convenience init(document: CPDFDocument, selectedPagesName pageString: String) {
         self.init(windowNibName: "KMPDFEditExtractWindow")

+ 15 - 15
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Action.swift

@@ -17,18 +17,18 @@ extension KMLeftSideViewController: NSMenuDelegate {
     func menuNeedsUpdate(_ menu: NSMenu) {
         if menu.isEqual(to: self.tocOutlineView.menu) {
             menu.removeAllItems()
-            var item = menu.addItem(withTitle: NSLocalizedString("Add Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddEntry), target: self, tag: KMOutlineViewMenuItemTag.addEntry.rawValue)
-            item = menu.addItem(withTitle: NSLocalizedString("Add Sub-Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddChildEntry), target: self, tag: KMOutlineViewMenuItemTag.addChild.rawValue)
-            item = menu.addItem(withTitle: NSLocalizedString("Add To A Higher Level", comment: ""), action: #selector(outlineContextMenuItemClicked_AddAuntEntry), target: self, tag: KMOutlineViewMenuItemTag.addAunt.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Add Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddEntry), target: self, tag: KMOutlineViewMenuItemTag.addEntry.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Add Sub-Item", comment: ""), action: #selector(outlineContextMenuItemClicked_AddChildEntry), target: self, tag: KMOutlineViewMenuItemTag.addChild.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Add To A Higher Level", comment: ""), action: #selector(outlineContextMenuItemClicked_AddAuntEntry), target: self, tag: KMOutlineViewMenuItemTag.addAunt.rawValue)
             menu.addItem(.separator())
-            item = menu.addItem(withTitle: NSLocalizedString("Delete", comment: ""), action: #selector(outlineContextMenuItemClicked_RemoveEntry), target: self, tag: KMOutlineViewMenuItemTag.remove.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Delete", comment: ""), action: #selector(outlineContextMenuItemClicked_RemoveEntry), target: self, tag: KMOutlineViewMenuItemTag.remove.rawValue)
             menu.addItem(.separator())
-            item = menu.addItem(withTitle: NSLocalizedString("Edit", comment: ""), action: #selector(outlineContextMenuItemClicked_Edit), target: self, tag: KMOutlineViewMenuItemTag.edit.rawValue)
-            item = menu.addItem(withTitle: NSLocalizedString("Change Destination", comment: ""), action: #selector(outlineContextMenuItemClicked_SetDestination), target: self, tag: KMOutlineViewMenuItemTag.setDestination.rawValue)
-            item = menu.addItem(withTitle: NSLocalizedString("Rename", comment: ""), action: #selector(outlineContextMenuItemClicked_Rename), target: self, tag: KMOutlineViewMenuItemTag.rename.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Edit", comment: ""), action: #selector(outlineContextMenuItemClicked_Edit), target: self, tag: KMOutlineViewMenuItemTag.edit.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Change Destination", comment: ""), action: #selector(outlineContextMenuItemClicked_SetDestination), target: self, tag: KMOutlineViewMenuItemTag.setDestination.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Rename", comment: ""), action: #selector(outlineContextMenuItemClicked_Rename), target: self, tag: KMOutlineViewMenuItemTag.rename.rawValue)
             menu.addItem(.separator())
-            item = menu.addItem(withTitle: NSLocalizedString("Promote", comment: ""), action: #selector(outlineContextMenuItemClicked_Promote), target: self, tag: KMOutlineViewMenuItemTag.promote.rawValue)
-            item = menu.addItem(withTitle: NSLocalizedString("Demote", comment: ""), action: #selector(outlineContextMenuItemClicked_Demote), target: self, tag: KMOutlineViewMenuItemTag.demote.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Promote", comment: ""), action: #selector(outlineContextMenuItemClicked_Promote), target: self, tag: KMOutlineViewMenuItemTag.promote.rawValue)
+            _ = menu.addItem(withTitle: NSLocalizedString("Demote", comment: ""), action: #selector(outlineContextMenuItemClicked_Demote), target: self, tag: KMOutlineViewMenuItemTag.demote.rawValue)
             return
         }
         var item: NSMenuItem?
@@ -73,9 +73,9 @@ extension KMLeftSideViewController: NSMenuDelegate {
 
                 item = menu.addItem(title: KMLocalizedString("Insert", "Menu item title"), action: nil, target: self)
                 let subMenu = NSMenu()
-                subMenu.addItem(title: KMLocalizedString("Blank Page", "Menu item title"), action: #selector(quickInsert), target: self)
-                subMenu.addItem(title: KMLocalizedString("Blank Page - Custom...", "Menu item title"), action: #selector(insert), target: self)
-                subMenu.addItem(title: KMLocalizedString("From PDF", "Menu item title"), action: #selector(insertPDF), target: self)
+                _ = subMenu.addItem(title: KMLocalizedString("Blank Page", "Menu item title"), action: #selector(quickInsert), target: self)
+                _ = subMenu.addItem(title: KMLocalizedString("Blank Page - Custom...", "Menu item title"), action: #selector(insert), target: self)
+                _ = subMenu.addItem(title: KMLocalizedString("From PDF", "Menu item title"), action: #selector(insertPDF), target: self)
                 item?.submenu = subMenu
                 item?.representedObject = IndexSet(integer: row)
 
@@ -101,12 +101,12 @@ extension KMLeftSideViewController: NSMenuDelegate {
 //                if (tName.length > 50) {
 //                   tName = [tName substringWithRange:NSMakeRange(0, 50)];
 //                }
-                var tName = self.listView.document.documentURL.lastPathComponent
+                let tName = self.listView.document.documentURL.lastPathComponent
                 item?.submenu = NSSharingServicePicker.menu(forSharingItems: [self.listView.document.documentURL], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
             }
         } else if menu.isEqual(to: self.findTableView.menu) {
             var rowIndexes = self.findTableView.selectedRowIndexes
-            var row = self.findTableView.clickedRow
+            let row = self.findTableView.clickedRow
             if (row != -1) {
                 if rowIndexes.contains(row) == false {
                     rowIndexes = IndexSet(integer: row)
@@ -134,7 +134,7 @@ extension KMLeftSideViewController: NSMenuDelegate {
             }
         } else if menu.isEqual(to: self.groupedFindTableView.menu) {
             var rowIndexes = self.groupedFindTableView.selectedRowIndexes
-            var row = self.groupedFindTableView.clickedRow
+            let row = self.groupedFindTableView.clickedRow
             if (row != -1) {
                 if rowIndexes.contains(row) == false {
                     rowIndexes = IndexSet(integer: row)

+ 3 - 0
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarItemView.swift

@@ -299,6 +299,9 @@ extension KMToolbarItemView {
         if (self.itemIdentifier == KMToolbarDividerItemIdentifier || self.customizeView != nil || self.image == nil) {
             return
         }
+        if self.unEnabled {
+            return
+        }
         if (!self.isSelected) {
             if self.selectBackgroundType == .none {
                 self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor