123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- //
- // KMPDFEditPageRangeWindowController.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/11/10.
- //
- import Cocoa
- class KMPDFEditPageRangeWindowController: NSWindowController {
- weak var pdfDocument: CPDFDocument?
- var pageSelectCallBack: (([Int]) -> Void)?
-
- @IBOutlet var pageRangeLabel: NSTextField!
- @IBOutlet var pageRangeTextField: NSTextField!
- @IBOutlet var totalPageCountLabel: NSTextField!
- @IBOutlet var detailLabel: NSTextField!
- @IBOutlet var cancelButton: NSButton!
- @IBOutlet var okButton: NSButton!
-
- private var fileAttri_: KMFileAttribute?
-
- override var windowNibName: NSNib.Name? {
- return "KMPDFEditPageRangeWindowController"
- }
-
- deinit {
- KMPrint("KMPDFEditPageRangeWindowController deinit.")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- self.pageRangeLabel.stringValue = KMLocalizedString("Page Range", nil)
- self.pageRangeTextField.placeholderString = KMLocalizedString("e.g. 1,3-5,10", nil)
- // self.totalPageCountLabel.integerValue = self.pdfDocument.pageCount;
-
- self.totalPageCountLabel.stringValue = String(format: KMLocalizedString(", Total %ld Pages", nil), self.pdfDocument?.pageCount ?? 0)
- self.detailLabel.stringValue = ""
- self.cancelButton.title = KMLocalizedString("Cancel", nil)
- self.okButton.title = KMLocalizedString("OK", nil)
-
- self.window?.title = KMLocalizedString("Page Range", nil)
-
- self.fileAttri_ = KMFileAttribute()
- self.fileAttri_?.filePath = self.pdfDocument?.documentURL.path ?? ""
- if let cnt = self.pdfDocument?.pageCount {
- self.fileAttri_?.pageCnt = Int(cnt)
- }
- self.fileAttri_?.bAllPage = false
- self.fileAttri_?.pagesType = .custom
- }
-
- @IBAction func buttonClicked_Cancel(_ sender: AnyObject?) {
- if let win = self.window {
- self.window?.sheetParent?.endSheet(win)
- }
- }
- @IBAction func buttonClicked_Done(_ sender: AnyObject?) {
- self.fileAttri_?.pagesString = self.pageRangeTextField.stringValue
-
- if self.fileAttri_ == nil || self.fileAttri_!.fetchSelectPages().isEmpty {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = String(format: "%@ %@", self.pdfDocument?.documentURL.lastPathComponent.lastPathComponent ?? "", KMLocalizedString("Invalid page range or the page number is out of range. Please try again.", nil))
- // alert.runModal()
- alert.beginSheetModal(for: self.window!) { res in
- self.window?.makeFirstResponder(self.pageRangeTextField)
- }
- return
- } else {
- if (self.pageSelectCallBack != nil) {
- self.pageSelectCallBack!(self.fileAttri_?.fetchSelectPages() ?? [])
- }
- }
- }
- }
|