123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146 |
- import Foundation
- extension KMLeftSideViewController {
- @IBAction func leftSideViewMoreButtonAction(_ sender: AnyObject?) {
- let button = sender as? NSButton
- let tag = button?.tag ?? 0
- if (tag == 300) {
- var selectedRow = 0
- if (self.snapshotTableView.selectedRow >= 0) {
- selectedRow = self.snapshotTableView.selectedRow;
- } else {
- return
- }
- let model = self.snapshots[selectedRow]
- let controller = model.windowC
- let menu = NSMenu()
- let itemExport = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
- let subMenu = NSMenu()
- var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
- t?.representedObject = controller
- t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
- t?.representedObject = controller
- t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
- t?.representedObject = controller
- itemExport?.submenu = subMenu
- let itemPrint = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
- itemPrint?.representedObject = controller
- menu.addItem(.separator())
- let itemSelectAll = menu.addItem(title: KMLocalizedString("Select All", "Menu item title"), action: #selector(menuItemClick_SelectAll), target: self)
- itemSelectAll?.representedObject = controller
- menu.addItem(.separator())
- let itemDeleteAllSnapshot = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
- itemDeleteAllSnapshot?.representedObject = controller
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
- } else if (tag == 302) {
- let menu = NSMenu()
- let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(toc_expandAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.tocOutlineView
- let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(toc_foldAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.tocOutlineView
- let item = self.listView.document.outlineRoot()
- var num = 0
- for i in 0 ..< Int(item?.numberOfChildren ?? 0) {
- let outline = item?.child(at: UInt(i))
- if self.tocOutlineView.isItemExpanded(outline) {
- num += 1
- }
- }
- if let cnt = item?.numberOfChildren, cnt > 0 && num == 0 {
- self.tocType = .fold
- } else if let cnt = item?.numberOfChildren, cnt > 0 && num == cnt {
- self.tocType = .unfold
- } else {
- self.tocType = .none
- }
- if (self.tocType == .unfold) {
- expandAllCommentsItem?.state = .on
- foldAllCommentsItem?.state = .off
- } else if (self.tocType == .fold) {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .on
- } else {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .off
- }
- let removeEntryItem = menu.addItem(title: KMLocalizedString("Remove All Outlines", nil), action: #selector(leftSideEmptyAnnotationClick_DeleteOutline), target: self)
- removeEntryItem?.representedObject = self.tocOutlineView
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: sender as! NSButton)
- } else if (tag == 304) {
- let menu = NSMenu()
- let object = KMPopupMenuObject()
- object.menuTag = 1001
- menu.delegate = object
- object.enterControllerCallback = { [weak self] isEnter in
- if (isEnter) {
- self?.moreButtonLayer?.isHidden = false
- } else {
- self?.moreButtonLayer?.isHidden = true
- }
- }
- let expandAllCommentsItem = menu.addItem(title: KMLocalizedString("Expand All", nil), action: #selector(note_expandAllComments), target: self)
- expandAllCommentsItem?.representedObject = self.noteOutlineView
- let foldAllCommentsItem = menu.addItem(title: KMLocalizedString("Collapse All", nil), action: #selector(note_foldAllComments), target: self)
- foldAllCommentsItem?.representedObject = self.noteOutlineView
- if (self.foldType == .unfold) {
- expandAllCommentsItem?.state = .on
- foldAllCommentsItem?.state = .off
- } else if (self.foldType == .fold) {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .on
- } else {
- expandAllCommentsItem?.state = .off
- foldAllCommentsItem?.state = .off
- }
- let showAnnotationItem = menu.addItem(title: KMLocalizedString("Show Note", nil), action: nil, target: self)
- let subMenu = NSMenu()
- var t = subMenu.addItem(title: KMLocalizedString("Page", nil), action: #selector(noteShowNoteAction), target: self)
- let pageKey = self.noteTypeDict[Self.noteFilterPageKey] as? Bool ?? false
- if pageKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 101
- t = subMenu.addItem(title: KMLocalizedString("Time", nil) , action: #selector(noteShowNoteAction), target: self)
- let timeKey = self.noteTypeDict[Self.noteFilterTimeKey] as? Bool ?? false
- if timeKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 102
- t = subMenu.addItem(title: KMLocalizedString("Author", nil) , action: #selector(noteShowNoteAction), target: self)
- let authorKey = self.noteTypeDict[Self.noteFilterAutherKey] as? Bool ?? false
- if authorKey {
- t?.state = .off
- } else {
- t?.state = .on
- }
- t?.representedObject = self.noteOutlineView
- t?.tag = 103
- showAnnotationItem?.submenu = subMenu
- menu.addItem(.separator())
- let exportAnnotationsItem = menu.addItem(title: NSLocalizedString("Export Annotations…", comment: ""), action: nil, target: self)
- let subMenu2 = NSMenu()
- var t2 = subMenu2.addItem(title: NSLocalizedString("PDF", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 0
- t2 = subMenu2.addItem(title: NSLocalizedString("PDF Bundle", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 1
- t2 = subMenu2.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 2
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as Text", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 3
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTF", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 4
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as RTFD", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 5
- t2 = subMenu2.addItem(title: NSLocalizedString("Notes as FDF", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- t2?.representedObject = self.noteOutlineView
- t2?.tag = 6
- exportAnnotationsItem?.submenu = subMenu2
- menu.addItem(.separator())
- let removeAllAnnotationsItem = menu.addItem(title: NSLocalizedString("Remove All Annotations", comment: ""), action: #selector(leftSideEmptyAnnotationClick_DeleteAnnotation), target: self)
- removeAllAnnotationsItem?.representedObject = self.noteOutlineView
- NSMenu.popUpContextMenu(menu, with: NSApp.currentEvent!, for: button!, with: nil)
- }
- }
-
- func searchFieldChangeAction(_ editContent: String) {
- if self.findState == .note {
-
- self.updateNoteFilterPredicate()
- } else {
- self.updateSnapshotFilterPredicate()
- }
- if editContent.count > 0 {
- let findPboard = NSPasteboard(name: .find)
- findPboard.clearContents()
- findPboard.writeObjects([editContent as NSPasteboardWriting])
- }
- }
-
- @IBAction func search(_ sender: NSSearchField) {
- if sender.stringValue.isEmpty {
- self.applySearchTableHeader("")
- }
- self.delegate?.searchAction?(searchString: sender.stringValue, isCase: self.mwcFlags.caseInsensitiveSearch == 1)
- }
- }
- extension KMLeftSideViewController {
- @objc func toggleSelectedSnapshots(_ sender: AnyObject?) {
- let indexs = self.snapshotTableView.selectedRowIndexes
- if indexs.isEmpty {
- return
- }
- let model = self.snapshots[indexs.last!]
- let windowC = model.windowC
- if let data = windowC?.window?.isVisible, data {
- windowC?.miniaturize()
- } else {
- windowC?.deminiaturize()
- }
-
- var rowIndexSet = IndexSet()
- let row = self.snapshotTableView.selectedRow
- if row >= 0 && row < self.snapshots.count {
- rowIndexSet.insert(row)
- }
- var columnIndexSet = IndexSet()
- columnIndexSet.insert(0)
- self.snapshotTableView.reloadData(forRowIndexes: rowIndexSet, columnIndexes: columnIndexSet)
- }
-
-
-
- override func interfaceThemeDidChanged(_ appearance: NSAppearance.Name) {
- super.interfaceThemeDidChanged(appearance)
-
- self.updateViewColor()
- self.leftView.interfaceThemeDidChanged(appearance)
- }
- }
- extension KMLeftSideViewController: NSMenuDelegate {
- func menuNeedsUpdate(_ menu: NSMenu) {
- if menu.isEqual(to: self.tocOutlineView.menu) {
- menu.removeAllItems()
- _ = 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())
- _ = menu.addItem(withTitle: NSLocalizedString("Delete", comment: ""), action: #selector(outlineContextMenuItemClicked_RemoveEntry), target: self, tag: KMOutlineViewMenuItemTag.remove.rawValue)
- menu.addItem(.separator())
- _ = 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())
- _ = 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?
- menu.removeAllItems()
- if menu.isEqual(to: self.thumbnailTableView.menu) {
- let row = self.thumbnailTableView.clickedRow
- if self.listView.document.documentURL == nil || self.thumbnailTableView.selectedRowIndexes.contains(row) == false{
- return
- }
- if (row != -1 && self.listView.document.isLocked == false) {
- if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
- item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: nil, target: self)
- } else {
- item = menu.addItem(title: KMLocalizedString("Cut", "Menu item title"), action: #selector(cutPage), target: self)
- }
- item?.representedObject = IndexSet(integer: row)
-
-
- item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(copyPage), target: self)
- item?.representedObject = IndexSet(integer: row)
-
- if (self.copyPages.count > 0) {
- item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: #selector(pastePage), target: self)
- }else{
- item = menu.addItem(title: KMLocalizedString("Paste", "Menu item title"), action: nil, target: self)
- }
- item?.representedObject = IndexSet(integer: row)
- menu.addItem(.separator())
- if(self.thumbnailTableView.selectedRowIndexes.count == self.listView.document.pageCount) {
- item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: nil, target: self)
- } else {
- item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deletePage), target: self)
- }
- item?.representedObject = IndexSet(integer: row)
- menu.addItem(.separator())
- item = menu.addItem(title: KMLocalizedString("Rotate", "Menu item title"), action: #selector(rotatePageMenuAction), target: self)
- item?.representedObject = IndexSet(integer: row)
- 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)
- item?.submenu = subMenu
- item?.representedObject = IndexSet(integer: row)
- item = menu.addItem(title: KMLocalizedString("Extract", "Menu item title"), action: #selector(extractPage), target: self)
- item?.representedObject = IndexSet(integer: row)
- item = menu.addItem(title: KMLocalizedString("Page Edit", "Menu item title"), action: #selector(pageEdit), target: self)
- menu.addItem(.separator())
- var displayStr = ""
- if (self.isDisplayPageSize) {
- displayStr = KMLocalizedString("Hide Page Size", "Menu item title")
- } else {
- displayStr = KMLocalizedString("Display Page Size", "Menu item title")
- }
- item = menu.addItem(title: displayStr, action: #selector(displayPageSize), target: self)
- item?.representedObject = IndexSet(integer: row)
-
- if let doct = self.listView?.document {
- item = menu.addItem(title: KMLocalizedString("Share", "Menu item title"), action: nil, target: self)
-
- var tName = self.fileNameWithSelectedPages(self.thumbnailTableView.selectedRowIndexes)
- if (tName.count > 50) {
- tName = tName.substring(to: 50)
- }
- item?.submenu = NSSharingServicePicker.menu(forSharingItems: [doct.documentURL as Any], subjectContext: tName, withTarget: self, selector: #selector(sharePage), serviceDelegate: nil)
- }
- }
- } else if menu.isEqual(to: self.findTableView.menu) {
- var rowIndexes = self.findTableView.selectedRowIndexes
- let row = self.findTableView.clickedRow
- if (row != -1) {
- if rowIndexes.contains(row) == false {
- rowIndexes = IndexSet(integer: row)
- }
-
- var selections: [CPDFSelection] = []
- for (i, data) in self.searchResults.enumerated() {
- if rowIndexes.contains(i) {
- selections.append(data.selection)
- }
- }
- if self.listView.hideNotes == false && self.listView.allowsNotes() {
- item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.circle.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.square.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.highlight.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.underline.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.strikeOut.rawValue)
- item?.representedObject = selections
- }
- }
- } else if menu.isEqual(to: self.groupedFindTableView.menu) {
- var rowIndexes = self.groupedFindTableView.selectedRowIndexes
- let row = self.groupedFindTableView.clickedRow
- if (row != -1) {
- if rowIndexes.contains(row) == false {
- rowIndexes = IndexSet(integer: row)
- }
- var selections: [CPDFSelection] = []
- for (i, data) in self.groupSearchResults.enumerated() {
- if rowIndexes.contains(i) {
- for searchM in data.datas {
- selections.append(searchM.selection)
- }
- }
- }
- item = menu.addItem(title: KMLocalizedString("Select", "Menu item title"), action: #selector(selectSelections), target: self)
- item?.representedObject = selections
- menu.addItem(.separator())
- if self.listView.hideNotes == false && self.listView.allowsNotes() {
- item = menu.addItem(withTitle: KMLocalizedString("Add New Circle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.circle.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Rectangle", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.square.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Highlight", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.highlight.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Underline", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.underline.rawValue)
- item?.representedObject = selections
- item = menu.addItem(withTitle: KMLocalizedString("Add New Strikethrough", "Menu item title"), action: #selector(addAnnotationsForSelections), target: self, tag: CAnnotationType.strikeOut.rawValue)
- item?.representedObject = selections
- }
- }
- } else if menu.isEqual(to: self.snapshotTableView.menu) {
- let row = self.snapshotTableView.clickedRow
- if (row != -1) {
- let model = self.snapshots[row]
- let controller = model.windowC
- if let data = controller?.window?.isVisible, data {
- item = menu.addItem(title: KMLocalizedString("Hide", "Menu item title"), action: #selector(hideSnapshot), target: self)
- item?.representedObject = controller
- } else {
- item = menu.addItem(title: KMLocalizedString("Show", "Menu item title"), action: #selector(showSnapshot), target: self)
- item?.representedObject = controller
- }
- menu.addItem(.separator())
- item = menu.addItem(title: KMLocalizedString("Export", "Menu item title"), action: nil, target: self)
- let subMenu = NSMenu()
- var t = subMenu.addItem(title: KMLocalizedString("PNG", "Menu item title"), action: #selector(menuItemClick_ExportPNG), target: self)
- t?.representedObject = controller
- t = subMenu.addItem(title: KMLocalizedString("JPG", "Menu item title"), action: #selector(menuItemClick_ExportJPG), target: self)
- t?.representedObject = controller
-
- t = subMenu.addItem(title: KMLocalizedString("PDF", "Menu item title"), action: #selector(menuItemClick_ExportPDF), target: self)
- t?.representedObject = controller
- item?.submenu = subMenu
- item = menu.addItem(title: KMLocalizedString("Print", "Menu item title"), action: #selector(menuItemClick_Print), target: self)
- item?.representedObject = controller
- menu.addItem(.separator())
-
- item = menu.addItem(title: KMLocalizedString("Copy", "Menu item title"), action: #selector(menuItemClick_Copy), target: self)
- item?.representedObject = controller
- menu.addItem(.separator())
- item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteSnapshot), target: self)
- item?.representedObject = controller
- item = menu.addItem(title: KMLocalizedString("Delete All Snapshots", "Menu item title"), action: #selector(deleteAllSnapshot), target: self)
- item?.representedObject = controller
- }
- } else if menu.isEqual(to: self.noteOutlineView.menu) {
- var items: NSArray?
- var rowIndexes = self.noteOutlineView.selectedRowIndexes
- let row = self.noteOutlineView.clickedRow
- if (row != -1) {
- if rowIndexes.contains(row) == false {
- rowIndexes = IndexSet(integer: row)
- }
- items = self.noteOutlineView.itemsAtRowIndexes(rowIndexes) as NSArray
-
-
- guard let foldNote = self.fetchNote(for: row) else {
- return
- }
- var isFold = true
- if self.allFoldNotes.contains(foldNote) {
- isFold = false
- }
- item = menu.addItem(title: KMLocalizedString("Expand", nil), action: #selector(unfoldNoteAction), target: self)
- if (isFold) {
- item?.state = .off
- } else {
- item?.state = .on
- }
- item?.representedObject = items
- item = menu.addItem(title: KMLocalizedString("Collapse", nil), action: #selector(foldNoteAction), target: self)
- if (isFold) {
- item?.state = .on
- } else {
- item?.state = .off
- }
- item?.representedObject = items
-
- menu.addItem(.separator())
- if self.listView.hideNotes == false && (items?.count ?? 0) == 1 {
- let annotation = self.noteItems(items!).lastObject as? CPDFAnnotation
- if let data = annotation?.isEditable(), data {
- if annotation?.type == nil {
- if annotation!.isNote() {
-
- item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteTextFromTable), target: self)
- item?.representedObject = annotation
- }
- } else if let data = self.noteOutlineView.tableColumn(withIdentifier: NSUserInterfaceItemIdentifier("note"))?.isHidden, data {
- item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
- item?.representedObject = annotation
- } else {
- item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editNoteFromTable), target: self)
- item?.representedObject = annotation
- item = menu.addItem(title: KMLocalizedString("Edit", "Menu item title"), action: #selector(editThisAnnotation), target: self)
- item?.representedObject = annotation
- item?.keyEquivalentModifierMask = [.option]
- item?.isAlternate = true
- }
- }
- }
- if menu.numberOfItems > 0 {
- item = menu.addItem(title: NSLocalizedString("Export Annotations…", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
-
- let subMenu = NSMenu()
- item?.submenu = subMenu
- item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 0
- item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 1
- item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 2
- item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 3
- item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 4
- item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 5
- item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 6
-
- menu.addItem(.separator())
- if self.outlineView(self.noteOutlineView, canDeleteItems: items as! [Any]) {
- item = menu.addItem(title: KMLocalizedString("Delete", "Menu item title"), action: #selector(deleteNotes), target: self)
- item?.representedObject = items
- }
- item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
- }
- } else {
- let subMenu = NSMenu()
- item?.submenu = subMenu
- item = subMenu.addItem(title: NSLocalizedString("PDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 0
- item = subMenu.addItem(title: NSLocalizedString("PDF Bundle", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 1
- item = subMenu.addItem(title: NSLocalizedString("PDF Reader Pro Edition Notes", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 2
- item = subMenu.addItem(title: NSLocalizedString("Notes as Texts", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 3
- item = subMenu.addItem(title: NSLocalizedString("Notes as RTF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 4
- item = subMenu.addItem(title: NSLocalizedString("Notes as RTFD", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 5
- item = subMenu.addItem(title: NSLocalizedString("Notes as FDF", tableName: "MainMenu", comment: "Menu item title"), action: #selector(exportAnnotationNotes), target: self)
- item?.tag = 6
-
- item = menu.addItem(title: NSLocalizedString("Remove All Annotations", tableName: "MainMenu", comment: "Menu item title"), action: #selector(removeAllAnnotations), target: self)
- }
- }
- }
- }
- extension KMLeftSideViewController: NSMenuItemValidation {
- func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
- if (self.listView.document == nil || self.listView.document!.isLocked) {
- return false
- }
- let action = menuItem.action
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (action == #selector(toggleCaseInsensitiveSearch)) {
- let state = UserDefaults.standard.integer(forKey: SKCaseInsensitiveSearchKey)
- menuItem.state = state == 1 ? .on : .off
- return true
- } else if (action == #selector(toggleWholeWordSearch)) {
- menuItem.state = self.mwcFlags.wholeWordSearch == 1 ? .on : .off
- return true
- } else if action == #selector(toggleCaseInsensitiveNoteSearch) {
- menuItem.state = self.caseInsensitiveNoteSearch ? .on : .off
- return true
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
- action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
- action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
- action == #selector(outlineContextMenuItemClicked_RemoveEntry) ||
- action == #selector(outlineContextMenuItemClicked_Edit) ||
- action == #selector(outlineContextMenuItemClicked_SetDestination) ||
- action == #selector(outlineContextMenuItemClicked_Rename) ||
- action == #selector(outlineContextMenuItemClicked_Promote) ||
- action == #selector(outlineContextMenuItemClicked_Demote)) {
- if let data = self.listView.document?.isLocked, data {
- return false
- }
- if (self.isSearchOutlineMode) {
- if (action == #selector(outlineContextMenuItemClicked_AddEntry) ||
- action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
- action == #selector(outlineContextMenuItemClicked_AddAuntEntry) ||
- action == #selector(outlineContextMenuItemClicked_Edit) ||
- action == #selector(outlineContextMenuItemClicked_Rename)
- ) {
- return false
- }
- }
- if (self.tocOutlineView.selectedRowIndexes.count > 1) {
- if (menuItem.tag == KMOutlineViewMenuItemTag.remove.rawValue) {
- return true
- }
- return false
- } else if (self.tocOutlineView.selectedRowIndexes.count > 0) {
- if (action == #selector(outlineContextMenuItemClicked_AddChildEntry) ||
- action == #selector(outlineContextMenuItemClicked_SetDestination)) {
- return true
- }
- }
- if (self.tocOutlineView.clickedRow == -1) {
- if (action == #selector(outlineContextMenuItemClicked_AddEntry)) {
- return true
- } else {
- return false
- }
- } else {
- let clickedOutline = self.tocOutlineView.item(atRow: self.tocOutlineView.clickedRow) as? CPDFOutline
- if let data = clickedOutline?.index, data > 0 {
- if (action == #selector(outlineContextMenuItemClicked_Demote)) {
- return true
- }
- } else {
- if (action == #selector(outlineContextMenuItemClicked_Demote)) {
- return false
- }
- }
- let parentOutLine = clickedOutline?.parent
- let grandparentOutLine = parentOutLine?.parent
-
- if (grandparentOutLine != nil) {
-
- if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
- return true
- } else if (action == #selector(outlineContextMenuItemClicked_Promote)){
- return true
- }
- } else {
- if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
- return false
- }else if (action == #selector(outlineContextMenuItemClicked_Promote)){
- return false
- }
- }
- }
- return true
- }
- else if action == #selector(toggleOutlineCaseInsensitiveSearch) {
- menuItem.state = self.outlineIgnoreCaseFlag ? .on : .off
- return true
- }
- if (action == #selector(unfoldNoteAction) ||
- action == #selector(foldNoteAction)) {
- let row = self.noteOutlineView.clickedRow
- let foldNote = self.fetchNote(for: row)
-
- if foldNote is CPDFMarkupAnnotation || foldNote is CPDFTextAnnotation {
- return true
- } else {
- return false
- }
- } else if (action == #selector(menuItemClick_ExportPNG) ||
- action == #selector(menuItemClick_ExportJPG) ||
- action == #selector(menuItemClick_ExportPDF)) {
- if (self.snapshotTableView.selectedRow == -1 ) {
- return false
- } else {
- return true
- }
- }
- else if (action == #selector(menuItemClick_SelectAll)) {
- menuItem.state = self.snapshotListIsAllSelected() ? .on : .off
- return true
- }
- return true
- }
- }
- extension KMLeftSideViewController: NSPopoverDelegate {
- func popoverWillClose(_ notification: Notification) {
- guard let popover = notification.object as? NSPopover else {
- return
- }
- if let vc = popover.contentViewController as? KMOutlineEditViewController {
- self.editOutlineUI(vc)
- self.tocOutlineView.reloadData()
- }
- }
- }
- extension KMLeftSideViewController: NSSearchFieldDelegate {
- func controlTextDidChange(_ obj: Notification) {
- if self.outlineSearchField.isEqual(to: obj.object) {
- if (self.outlineSearchField.stringValue.isEmpty == false) {
- self.isSearchOutlineMode = true
-
- self.tocOutlineView.reloadData()
- self.tocOutlineView.expandItem(nil, expandChildren: true)
- self.tocType = .unfold
- } else {
- self.isSearchOutlineMode = false
- self.showSearchOutlineBlankState(false)
- self.tocOutlineView.reloadData()
- }
-
- self.outlineAddButton.isEnabled = !self.isSearchOutlineMode
- } else if self.snapshotSearchField.isEqual(to: obj.object) {
- let searchString = self.snapshotSearchField.stringValue
- self.searchSnapshots.removeAll()
- if searchString.isEmpty {
- self.isSearchSnapshotMode = false
- self.searchSnapshots = self.snapshots.filter({ model in
- let data = model.windowC?.string.contains(searchString) ?? false
- return data
- })
- } else {
- self.isSearchSnapshotMode = true
- }
- var snapshots = self.searchSnapshots
- if self.isSearchSnapshotMode == false {
- snapshots = self.snapshots
- }
- Task { @MainActor in
- self.updataLeftSideSnapView()
- self.snapshotTableView.reloadData()
- }
- if (snapshots.count > 0) {
- self.leftSideEmptyVC.outlineSearchView.removeFromSuperview()
- } else {
- let view = self.snapshotTableView.enclosingScrollView
- let emptyVcSize = self.leftSideEmptyVC.outlineSearchView.frame.size
- self.leftSideEmptyVC.outlineSearchView.frame = NSMakeRect((view!.frame.size.width-emptyVcSize.width)/2.0,(view!.frame.size.height-emptyVcSize.height)/2.0, emptyVcSize.width, emptyVcSize.height)
- self.leftSideEmptyVC.outlineSearchView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
- self.snapshotTableView.enclosingScrollView?.documentView?.addSubview(self.leftSideEmptyVC.outlineSearchView)
- }
- }
- }
- }
- extension KMLeftSideViewController: NSTextFieldDelegate {
- func controlTextDidBeginEditing(_ obj: Notification) {
- if self.noteOutlineView.isEqual(to: obj.object) {
- }
- }
-
- func controlTextDidEndEditing(_ obj: Notification) {
- if self.noteOutlineView.isEqual(to: obj.object) {
- } else if let data = self.renamePDFOutlineTextField?.isEqual(to: obj.object), data {
- let textField = obj.object as! NSTextField
- if let editPDFOutline = self.renamePDFOutline {
- if self.isRenameNoteOutline == false {
- if textField.stringValue == editPDFOutline.label {
- return
- }
- }
- self.renamePDFOutline(editPDFOutline, label: textField.stringValue)
- self.updateSelectRowHeight()
- self.tocOutlineView.reloadData()
- }
- }
- }
- }
- extension KMLeftSideViewController {
- @objc func toggleCaseInsensitiveNoteSearch(_ sender: AnyObject?) {
- self.caseInsensitiveNoteSearch = !self.caseInsensitiveNoteSearch
- if self.searchField.stringValue.isEmpty == false {
- self.searchNotes(self.searchField)
- }
- UserDefaults.standard.sync_setValue(self.caseInsensitiveNoteSearch, forKey: SKCaseInsensitiveNoteSearchKey)
- }
-
- @objc func searchNotes(_ sender: AnyObject?) {
- self.noteSearchMode = false
- if self.findState == .note {
- if self.noteSearchField.isEqual(to: sender) {
- self.noteSearchMode = true
- }
- self.updateNoteFilterPredicate()
- } else {
- self.updateSnapshotFilterPredicate()
- }
- let textfield = sender as? NSSearchField
- if let data = textfield?.stringValue.isEmpty, data == false {
- let findPboard = NSPasteboard(name: .find)
- findPboard.clearContents()
- }
- }
-
- func updateSnapshotFilterPredicate() {
- let searchString = self.snapshotSearchField.stringValue
- self.searchSnapshots.removeAll()
- if self.findState == .snapshot && searchString.isEmpty == false {
- self.searchSnapshots = self.snapshots.filter({ model in
- let data = model.windowC?.string.contains(searchString) ?? false
- return data
- })
- }
- Task { @MainActor in
- self.updataLeftSideSnapView()
- self.snapshotTableView.reloadData()
- }
- }
-
- func snapshotListIsAllSelected() -> Bool {
- if self.snapshots.isEmpty {
- return false
- }
- for model in self.snapshots {
- if model.isSelected == false {
- return false
- }
- }
- return true
- }
- }
|