// // KMPageRangeSelectView.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/11/21. // import Cocoa import KMComponentLibrary class KMPageRangeSelectView: NSView { var pageSelectView: ComponentSelect = ComponentSelect() override init(frame frameRect: NSRect) { super.init(frame: frameRect) setUp() } required init?(coder: NSCoder) { super.init(coder: coder) setUp() } func setUp() { pageSelectView.frame = self.bounds pageSelectView.autoresizingMask = [.width, .height] self.addSubview(pageSelectView) pageSelectView.properties = ComponentSelectProperties(size: .s, state: .normal, placeholder: KMLocalizedString("e.g. 1,3-5,10"), errorText: nil, creatable: false, text: KMLocalizedString("All Pages")) pageSelectView.delegate = self let menuItemString:[String] = [KMLocalizedString("All Pages"), KMLocalizedString("Odd Pages Only"), KMLocalizedString("Even Pages Only"), KMLocalizedString("e.g. 1,3-5,10")] var menuItemArr: [ComponentMenuitemProperty] = [] for language in menuItemString { let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: language, identifier: language) menuItemArr.append(itemProperty) } pageSelectView.updateMenuItemsArr(menuItemArr) pageSelectView.selectItemAtIndex(0) } //MARK: - Get func getSelectedPageString(_ document: CPDFDocument, _ pageIndexs: [Int]) -> String { var pages = [Int]() if pageSelectView.indexOfSelect() == 0 { pages = Array(0.. [Int] { let pageRangeSelectIndex = pageSelectView.indexOfSelect() let fileAttribute = KMNFileAttribute() fileAttribute.pdfDocument = document fileAttribute.password = document.password ?? "" if pageRangeSelectIndex == 0 { fileAttribute.bAllPage = true fileAttribute.pagesType = .AllPages } else if pageRangeSelectIndex == 1 { fileAttribute.bAllPage = false fileAttribute.pagesType = .OnlyOdd } else { if(document.pageCount <= 1) { fileAttribute.bAllPage = false fileAttribute.pagesType = .PagesString fileAttribute.pagesString = pageSelectView.properties.text ?? "" } else { fileAttribute.bAllPage = false if(pageRangeSelectIndex == 2) { fileAttribute.pagesType = .OnlyEven } else { fileAttribute.bAllPage = false fileAttribute.pagesType = .PagesString fileAttribute.pagesString = pageSelectView.properties.text ?? "" } } } let pageIndex = fileAttribute.fetchSelectPages() return pageIndex } } extension KMPageRangeSelectView: ComponentSelectDelegate { func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) { if menuItemProperty?.identifier == KMLocalizedString("e.g. 1,3-5,10") { view?.properties.creatable = true view?.properties.text = "" } else { view?.properties.creatable = false } view?.reloadData() } }