123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- //
- // KMToolbarConfigModel.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2024/5/28.
- //
- import Cocoa
- class KMToolbarConfigModel: NSObject {
- var leftCellIdentifiers: [String]? {
- didSet {
- let ids = self.leftCellIdentifiers ?? []
-
- self.leftWidth = 0
- if ids.isEmpty == false {
- self.leftWidth += self.leftMargin + 5
- }
-
- for itemId in ids {
- let item = KMToolbarItemView(itemIdentifier: itemId)
- self.setupMainItem(item)
- self.leftWidth += (item.itemWidth + 5)
- }
- }
- }
-
- var leftCount: Int {
- get {
- return self.leftCellIdentifiers?.count ?? 0
- }
- }
-
- var centerCellIdentifiers: [String]? {
- didSet {
- let ids = self.centerCellIdentifiers ?? []
-
- self.centerWidth = 0
- for itemId in ids {
- let item = KMToolbarItemView(itemIdentifier: itemId)
- self.setupMainItem(item)
- self.centerWidth += (item.itemWidth + 5)
- }
- }
- }
-
- var centerCount: Int {
- get {
- return self.centerCellIdentifiers?.count ?? 0
- }
- }
-
- var rightCellIdentifiers: [String]? {
- didSet {
- let ids = self.rightCellIdentifiers ?? []
-
- self.rightWidth = 0
- if ids.isEmpty == false {
- self.rightWidth += self.rightMargin + 5
- }
- for itemId in ids {
- let item = KMToolbarItemView(itemIdentifier: itemId)
- self.setupMainItem(item)
- self.rightWidth += (item.itemWidth + 5)
- }
- }
- }
-
- var rightCount: Int {
- get {
- return self.rightCellIdentifiers?.count ?? 0
- }
- }
-
- var defaultCellIdentifiers: [String]?
- var allowedCellIdentifiers: [String]? {
- get {
- let left = self.leftCellIdentifiers ?? []
- let center = self.centerCellIdentifiers ?? []
- let right = self.rightCellIdentifiers ?? []
- return left + center + right
- }
- }
-
- var leftWidth: CGFloat = 0
- var centerWidth: CGFloat = 0
- var rightWidth: CGFloat = 0
-
- var leftMargin: CGFloat = 10
- var rightMargin: CGFloat = 10
- var itemH: CGFloat = 48
-
- var contentWidth: CGFloat {
- get {
- return self.leftWidth + self.centerWidth + self.rightWidth
- }
- }
-
- var windowWidth: CGFloat = 1480
-
- var segItemWidth: CGFloat {
- get {
- return (self.windowWidth - self.contentWidth - 26 * 2) * 0.5
- }
- }
-
- func isLeft(at idx: Int) -> Bool {
- if self.leftCount <= 0 {
- return false
- }
- let stardIdx = 0
- let endIdx = self.leftCount
- if idx >= stardIdx && idx < endIdx {
- return true
- }
- return false
- }
-
- func isCenter(at idx: Int) -> Bool {
- if self.centerCount <= 0 {
- return false
- }
- let stardIdx = self.leftCount+1
- let endIdx = stardIdx+self.centerCount
- if idx >= stardIdx && idx < endIdx {
- return true
- }
- return false
- }
-
- func isRight(at idx: Int) -> Bool {
- if self.rightCount <= 0 {
- return false
- }
- let stardIdx = self.leftCount+self.centerCount+2
- let endIdx = stardIdx+self.rightCount
- if idx >= stardIdx && idx < endIdx {
- return true
- }
- return false
- }
-
- func isFirstSegI(at idx: Int) -> Bool {
- return idx == self.leftCount
- }
-
- func isSecondSegI(at idx: Int) -> Bool {
- return idx == (self.leftCount+self.centerCount+1)
- }
- }
- extension KMToolbarConfigModel {
- 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
- }
- }
-
- }
|