123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- //
- // KMToolbarConfigViewController.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2024/5/23.
- //
- import Cocoa
- class KMToolbarConfigViewController: NSViewController {
-
- @IBOutlet weak var collectionView: NSCollectionView!
-
- private let cellIdentifier_ = NSUserInterfaceItemIdentifier(rawValue: "ToolbarConfigCellIdentifier")
-
- var model = KMToolbarConfigModel()
-
- deinit {
- Swift.debugPrint("KMToolbarConfigViewController deinit.")
- }
-
- convenience init() {
- self.init(nibName: "KMToolbarConfigViewController", bundle: nil)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.view.wantsLayer = true
- self.view.layer?.backgroundColor = NSColor.red.cgColor
-
- self.initDefalutValue()
- }
-
- func initDefalutValue() {
- 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_)
- }
-
- 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
- }
-
- 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
- }
- }
-
- }
- extension KMToolbarConfigViewController: NSCollectionViewDelegate, NSCollectionViewDataSource, NSCollectionViewDelegateFlowLayout {
- func numberOfSections(in collectionView: NSCollectionView) -> Int {
- return 1
- }
-
- func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.model.cellIdentifiers?.count ?? 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
-
- return cell
- }
-
- // Layout
-
- func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
- let itemId = self.model.cellIdentifiers?[indexPath.item] ?? ""
- let item = KMToolbarItemView(itemIdentifier: itemId)
- self._setupMainItem(item)
- return NSSize(width: item.itemWidth, height: 48)
- }
-
- func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
- return 100
- }
-
- func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
- return 20
- }
-
- func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
- return .init(top: 10, left: 20, bottom: 5, right: 40)
- }
-
-
- }
|