|
@@ -7,14 +7,20 @@
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
+typealias KMToolbarConfigViewControllerCallback = (NSApplication.ModalResponse) -> Void
|
|
|
class KMToolbarConfigViewController: NSViewController {
|
|
|
|
|
|
@IBOutlet weak var collectionView: NSCollectionView!
|
|
|
+ @IBOutlet weak var removedCollectionView: NSCollectionView!
|
|
|
+ @IBOutlet weak var cancelButton: NSButton!
|
|
|
+ @IBOutlet weak var confirmButton: NSButton!
|
|
|
|
|
|
private let cellIdentifier_ = NSUserInterfaceItemIdentifier(rawValue: "ToolbarConfigCellIdentifier")
|
|
|
|
|
|
var model = KMToolbarConfigModel()
|
|
|
|
|
|
+ var callback: KMToolbarConfigViewControllerCallback?
|
|
|
+
|
|
|
deinit {
|
|
|
Swift.debugPrint("KMToolbarConfigViewController deinit.")
|
|
|
}
|
|
@@ -26,8 +32,8 @@ class KMToolbarConfigViewController: NSViewController {
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
- self.view.wantsLayer = true
|
|
|
- self.view.layer?.backgroundColor = NSColor.red.cgColor
|
|
|
+// self.view.wantsLayer = true
|
|
|
+// self.view.layer?.backgroundColor = NSColor.red.cgColor
|
|
|
|
|
|
self.initDefalutValue()
|
|
|
}
|
|
@@ -36,252 +42,28 @@ class KMToolbarConfigViewController: NSViewController {
|
|
|
self.collectionView.delegate = self
|
|
|
self.collectionView.dataSource = self
|
|
|
|
|
|
-// let layout = NSCollectionViewFlowLayout()
|
|
|
-// layout.sectionInset = NSEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
|
|
|
-// layout.minimumInteritemSpacing = 20
|
|
|
-// layout.minimumLineSpacing = 30
|
|
|
-// layout.itemSize = NSSize(width: 60, height: 44)
|
|
|
-// self.collectionView.collectionViewLayout = layout
|
|
|
-
|
|
|
self.collectionView.register(KMToolbarConfigViewItem.self, forItemWithIdentifier: self.cellIdentifier_)
|
|
|
+ (self.collectionView.collectionViewLayout as? NSCollectionViewFlowLayout)?.scrollDirection = .horizontal
|
|
|
+
|
|
|
+ self.cancelButton.title = NSLocalizedString("Cancel", comment: "")
|
|
|
+ self.cancelButton.target = self
|
|
|
+ self.cancelButton.action = #selector(buttonClick)
|
|
|
+ self.confirmButton.title = NSLocalizedString("Confirm", comment: "")
|
|
|
+ self.confirmButton.target = self
|
|
|
+ self.confirmButton.action = #selector(buttonClick)
|
|
|
}
|
|
|
|
|
|
- private func _setupMainItem(_ item: KMToolbarItemView?) {
|
|
|
- let identifier = item?.itemIdentifier
|
|
|
- if identifier == KMLeftControlToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconBtnTriLeftNor")
|
|
|
- item?.titleName = NSLocalizedString("Panel", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("View Settings", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- } else if identifier == KMDocumentZoomToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarZoominNor")
|
|
|
- item?.titleName = NSLocalizedString("", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.btnTag = 1
|
|
|
- item?.toolTip = NSLocalizedString("Zoom In", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- } else if identifier == KMDocumentZoomOutToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarZoomoutNor")
|
|
|
- item?.titleName = NSLocalizedString("", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.btnTag = 0
|
|
|
- item?.toolTip = NSLocalizedString("Zoom Out", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- } else if identifier == KMDocumentZoomViewToolbarItemIdentifier{
|
|
|
- item?.titleName = NSLocalizedString("Zoom", comment: "")
|
|
|
- item?.target = self
|
|
|
-
|
|
|
- let view = KMToolbarZoomItemView(zoomView: nil)
|
|
|
- item?.customizeView = view
|
|
|
- } else if identifier == KMDocumentNextPageToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameToolbarPagenextNor")
|
|
|
- item?.titleName = NSLocalizedString("Next", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("Go To Next Page", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- } else if identifier == KMDocumentPreviousPageToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Zoom", comment: "")
|
|
|
- item?.target = self
|
|
|
-
|
|
|
- let view = KMToolbarPreviousNextItemView()
|
|
|
- item?.customizeView = view
|
|
|
- } else if identifier == KMDocumentHomeToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameToolbarHomeNor")
|
|
|
- item?.titleName = NSLocalizedString("Home", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("A Welcome Gift from Us", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- } else if identifier == KMDocumentAnnotationToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Tools", comment: "")
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarMytoolsNor")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = String(format: "%@: %@, %@, %@, %@", KMLocalizedString("Tool Mode", nil),KMLocalizedString("Annotate", nil),KMLocalizedString("Scroll", nil),KMLocalizedString("Magnify", nil),KMLocalizedString("Select", nil))
|
|
|
- item?.btnTag = KMToolbarViewType.Annatiton.rawValue
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- } else if identifier == KMDocumentPageToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Page Edit", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarPageeditNor")
|
|
|
- item?.toolTip = NSLocalizedString("PDF page editor: insert, delete, extract, rotate, reposition, and replace pages in a PDF", comment: "")
|
|
|
- item?.btnTag = KMToolbarViewType.Page.rawValue
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- } else if identifier == KMDocumentConversonToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Converter", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarConvertNor")
|
|
|
- item?.toolTip = NSLocalizedString("Convert PDFs to Microsoft Word, PowerPoint, Excel, RTF, Text, Image, CSV, and more Offline", comment: "")
|
|
|
- item?.btnTag = KMToolbarViewType.Conversion.rawValue
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
-
|
|
|
- } else if identifier == KMDocumentScanOCRToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("OCR", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameToolbarOCRNor")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMToolbarToolEnhancedScanIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameMainToolEnhancedScan")
|
|
|
- item?.target = self
|
|
|
- item?.btnTag = 0
|
|
|
- item?.toolTip = NSLocalizedString("Enhanced Scan", comment: "")
|
|
|
- item?.titleName = NSLocalizedString("Enhanced Scan", comment: "")
|
|
|
- item?.boxImagePosition = .imageLeft
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- } else if identifier == KMToolbarToolOCRTextIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameMainToolOCRText")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("OCR Text Recognition", comment: "")
|
|
|
- item?.titleName = NSLocalizedString("OCR Text Recognition", comment: "")
|
|
|
- item?.boxImagePosition = .imageLeft
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
-
|
|
|
- } else if identifier == KMDocumentEditToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Edit PDF", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarEditNor")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.btnTag = KMToolbarViewType.editPDF.rawValue
|
|
|
- item?.toolTip = NSLocalizedString("Edit text and image in PDF ", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
-
|
|
|
- } else if identifier == KMDocumentFormToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Forms", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarFormNor")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.btnTag = KMToolbarViewType.Form.rawValue
|
|
|
- item?.toolTip = NSLocalizedString("Edit PDF Form", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
+ @objc func buttonClick(_ sender: NSButton) {
|
|
|
+ var resp: NSApplication.ModalResponse = .cancel
|
|
|
+ if self.confirmButton.isEqual(to: sender) {
|
|
|
+ resp = .OK
|
|
|
}
|
|
|
|
|
|
- else if identifier == KMDocumentFillSginToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Fill & Sign", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarFillsignNor")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.btnTag = KMToolbarViewType.FillSign.rawValue
|
|
|
- item?.toolTip = NSLocalizedString("Fill and sign forms", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMDocumentToolToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Editor", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarEdittoolNor")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.btnTag = KMToolbarViewType.Tool.rawValue
|
|
|
- item?.toolTip = NSLocalizedString("Edit, delete, cut, copy, paste, and insert text in PDFs", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMDocumentRedactToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Redact Text", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarRedactNor")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.toolTip = NSLocalizedString("Mark for redaction", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMDocumentAITranslationToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "ic_function_other_AITranslation")
|
|
|
- item?.titleName = "AI Translation"
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("AI Translation", comment: "")
|
|
|
- item?.boxImagePosition = .imageOnly
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMDocumentPrintToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameMainToolbarPrint")
|
|
|
- item?.titleName = "Print"
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("Print", comment: "")
|
|
|
- item?.boxImagePosition = .imageOnly
|
|
|
- } else if identifier == KMDocumentViewDisplayToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarPageviewNor")
|
|
|
- item?.titleName = NSLocalizedString("Page Display", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("Page Display", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMDocumentAIToolsToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconAINor")
|
|
|
- item?.titleName = NSLocalizedString("AI Tools", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("AI Tools", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMDocumentShareToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
|
|
|
- item?.titleName = NSLocalizedString("Share", comment: "")
|
|
|
- item?.target = self
|
|
|
-// item?.toolTip = NSLocalizedString("Share the file with others", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- } else if identifier == KMDocumentSearchToolbarItemIdentifier {
|
|
|
- item?.titleName = NSLocalizedString("Search", comment: "")
|
|
|
- item?.target = self
|
|
|
- let view = NSView()
|
|
|
- view.frame = NSMakeRect(0, 0, 150, 40)
|
|
|
- let boxView = NSView()
|
|
|
- boxView.frame = NSMakeRect(0, 16, 150, 22)
|
|
|
- view.addSubview(boxView)
|
|
|
- let searchView = NSSearchField()
|
|
|
- searchView.frame = NSMakeRect(0, 0, 150, 22)
|
|
|
- searchView.placeholderString = NSLocalizedString("Search", comment: "")
|
|
|
- searchView.sendsWholeSearchString = true
|
|
|
- searchView.sendsSearchStringImmediately = true
|
|
|
- searchView.drawsBackground = false
|
|
|
-// searchView.delegate = self
|
|
|
-// self.searchField = searchView
|
|
|
-
|
|
|
-// self.refreshSearchBarMenu()
|
|
|
-
|
|
|
- boxView.addSubview(searchView)
|
|
|
- let titleLabel = NSTextField(labelWithString: NSLocalizedString("Search", comment: ""))
|
|
|
- view.addSubview(titleLabel)
|
|
|
- titleLabel.frame = NSMakeRect(0, 0, 130, 14)
|
|
|
- titleLabel.alignment = .center
|
|
|
- titleLabel.textColor = KMAppearance.subtitleColor()
|
|
|
- titleLabel.font = KMToolbarMainItemView.textFont
|
|
|
-
|
|
|
- item?.customizeView = view
|
|
|
- } else if identifier == KMRightControlToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
|
|
|
- item?.titleName = NSLocalizedString("Properties", comment: "")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("Show/Hide Annotation Properties Panel", comment: "")
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- } else if identifier == KMToolbarToolRedactItemIdentifier {
|
|
|
- item?.image = NSImage(named: "KMImageNameMainToolsRedact")
|
|
|
- item?.target = self
|
|
|
- item?.btnTag = KMToolbarType.redact.rawValue
|
|
|
- item?.toolTip = NSLocalizedString("Redact", comment: "")
|
|
|
- item?.titleName = NSLocalizedString("Redact", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.promptIdentifier = identifier
|
|
|
- } else if identifier == KMDocumentDigitalSignToolbarItemIdentifier {
|
|
|
- item?.image = NSImage(named: "DigitalSign_icon")
|
|
|
- item?.target = self
|
|
|
- item?.toolTip = NSLocalizedString("Digital signature ensures the authenticity and integrity of digital files. Click and drag the cursor to create a signature field on the page.", comment: "")
|
|
|
- item?.titleName = NSLocalizedString("Digital Sign", comment: "")
|
|
|
- item?.selectBackgroundType = .imageBox
|
|
|
- item?.boxImagePosition = .imageAbove
|
|
|
- item?.promptIdentifier = identifier
|
|
|
+ guard let block = self.callback else {
|
|
|
+ return
|
|
|
}
|
|
|
+ block(resp)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
|
|
@@ -290,15 +72,31 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
- return self.model.cellIdentifiers?.count ?? 0
|
|
|
+ if let cnt = self.model.allowedCellIdentifiers?.count {
|
|
|
+ return cnt + 2
|
|
|
+ }
|
|
|
+ return 0
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
|
|
let cell = collectionView.makeItem(withIdentifier: self.cellIdentifier_, for: indexPath) as! KMToolbarConfigViewItem
|
|
|
- let itemId = self.model.cellIdentifiers?[indexPath.item] ?? ""
|
|
|
- let item = KMToolbarItemView(itemIdentifier: itemId)
|
|
|
- self._setupMainItem(item)
|
|
|
- cell.itemView = item
|
|
|
+ if indexPath.item == self.model.leftCount {
|
|
|
+ cell.itemView = nil
|
|
|
+ } else if indexPath.item == (self.model.leftCount + self.model.centerCount) {
|
|
|
+ cell.itemView = nil
|
|
|
+ } else {
|
|
|
+ var idx = indexPath.item
|
|
|
+ if idx > (self.model.leftCount + self.model.centerCount) {
|
|
|
+ idx = idx - 2
|
|
|
+ } else if idx > self.model.leftCount {
|
|
|
+ idx = idx - 1
|
|
|
+ }
|
|
|
+
|
|
|
+ let itemId = self.model.allowedCellIdentifiers?[idx] ?? ""
|
|
|
+ let item = KMToolbarItemView(itemIdentifier: itemId)
|
|
|
+ self.model.setupMainItem(item)
|
|
|
+ cell.itemView = item
|
|
|
+ }
|
|
|
|
|
|
return cell
|
|
|
}
|
|
@@ -306,22 +104,36 @@ extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionV
|
|
|
// Layout
|
|
|
|
|
|
func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
|
|
|
- let itemId = self.model.cellIdentifiers?[indexPath.item] ?? ""
|
|
|
+ if indexPath.item == self.model.leftCount {
|
|
|
+ return NSSize(width: self.model.segItemWidth, height: 48)
|
|
|
+ } else if indexPath.item == (self.model.leftCount + self.model.centerCount) {
|
|
|
+ return NSSize(width: self.model.segItemWidth, height: 48)
|
|
|
+ }
|
|
|
+
|
|
|
+ var idx = indexPath.item
|
|
|
+ if idx > (self.model.leftCount + self.model.centerCount) {
|
|
|
+ idx = idx - 2
|
|
|
+ } else if idx > self.model.leftCount {
|
|
|
+ idx = idx - 1
|
|
|
+ }
|
|
|
+ let itemId = self.model.allowedCellIdentifiers?[idx] ?? ""
|
|
|
let item = KMToolbarItemView(itemIdentifier: itemId)
|
|
|
- self._setupMainItem(item)
|
|
|
+ self.model.setupMainItem(item)
|
|
|
return NSSize(width: item.itemWidth, height: 48)
|
|
|
}
|
|
|
|
|
|
+ // 纵向间距
|
|
|
func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
|
|
- return 100
|
|
|
+ return 5
|
|
|
}
|
|
|
|
|
|
+ // 横向间距
|
|
|
func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
|
|
- return 20
|
|
|
+ return 5
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
|
|
|
- return .init(top: 10, left: 20, bottom: 5, right: 40)
|
|
|
+ return .init(top: 6, left: 10, bottom: 6, right: 10)
|
|
|
}
|
|
|
|
|
|
|