|
@@ -5,11 +5,10 @@
|
|
|
// Created by tangchao on 2022/12/5.
|
|
|
//
|
|
|
|
|
|
-import Cocoa
|
|
|
import PDFKit
|
|
|
|
|
|
typealias KMConvertBaseWindowControllerItemClick = (Int) -> ()
|
|
|
-class KMConvertBaseWindowController: NSWindowController {
|
|
|
+class KMConvertBaseWindowController: KMBaseWindowController {
|
|
|
|
|
|
@IBOutlet weak var titleLabel: NSTextField!
|
|
|
|
|
@@ -42,9 +41,6 @@ class KMConvertBaseWindowController: NSWindowController {
|
|
|
var pageRangeString: String = ""
|
|
|
var settingView: KMConvertSettingView?
|
|
|
|
|
|
- private var maskView: NSButton?
|
|
|
- private var indicator: NSProgressIndicator?
|
|
|
-
|
|
|
var subType: Int = 0
|
|
|
|
|
|
var fileExtension: String {
|
|
@@ -78,8 +74,6 @@ class KMConvertBaseWindowController: NSWindowController {
|
|
|
override func windowDidLoad() {
|
|
|
super.windowDidLoad()
|
|
|
|
|
|
- self.totalNumberLabel.lineBreakMode = .byTruncatingTail
|
|
|
-
|
|
|
if (self.documentModel != nil) {
|
|
|
let document = CPDFDocument(url: self.documentModel!.documentURL)
|
|
|
if (document!.isLocked) {
|
|
@@ -96,49 +90,96 @@ class KMConvertBaseWindowController: NSWindowController {
|
|
|
self.prePDFView?.documentView().enclosingScrollView?.hasHorizontalScroller = false
|
|
|
}
|
|
|
|
|
|
+ if let pageCount = self.prePDFView?.document.pageCount {
|
|
|
+ self.settingView?.pageCount = Int(pageCount)
|
|
|
+ }
|
|
|
+
|
|
|
+ batchButton.title = NSLocalizedString("Batch", comment: "")
|
|
|
+ batchButton.isBordered = false
|
|
|
+ batchButton.wantsLayer = true
|
|
|
+ batchButton.layer?.borderWidth = 1
|
|
|
+ batchButton.layer?.cornerRadius = 4
|
|
|
+ batchButton.target = self
|
|
|
+ batchButton.action = #selector(batchButtonAction)
|
|
|
+ batchButton.isHidden = true
|
|
|
+
|
|
|
+ self.updateBackAndNextButtonState()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func initSubViews() {
|
|
|
+ super.initSubViews()
|
|
|
+
|
|
|
+ let view = self.initSettingView()
|
|
|
+ view?.frame = self.rightScrollView.bounds
|
|
|
+ view?.autoresizingMask = [.width, .height]
|
|
|
+ self.settingView = view
|
|
|
+ self.rightScrollView.documentView = view
|
|
|
+
|
|
|
+ view?.pageRangeDidChange = { [unowned self] pageRange in
|
|
|
+ self.pageRange = pageRange
|
|
|
+ if (pageRange != .custom) {
|
|
|
+ self.updatePreView(pageRange: pageRange)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ view?.pageRangeDidInputFinishCallback = { [unowned self] string in
|
|
|
+ self.pageRangeString = string
|
|
|
+ let array = self.findSelectPage(pageRangeString: string)
|
|
|
+ if array.count == 0 {
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .warning
|
|
|
+ alert.messageText = NSLocalizedString("Invalid page range or the page number is out of range. Please try again.", comment: "")
|
|
|
+ alert.runModal()
|
|
|
+ } else {
|
|
|
+ self.updatePreView(pageRange: .custom, pageString: string)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.backButtonVC = KMDesignButton.init(withType: .Image)
|
|
|
+ self.backBox.contentView = self.backButtonVC!.view
|
|
|
+
|
|
|
+ self.nextButtonVC = KMDesignButton.init(withType: .Image)
|
|
|
+ self.nextBox.contentView = self.nextButtonVC!.view
|
|
|
+
|
|
|
+ self.canelButtonVC = KMDesignButton.init(withType: .Text)
|
|
|
+ self.canelBox.contentView = self.canelButtonVC!.view
|
|
|
+
|
|
|
+ self.convertButtonVC = KMDesignButton.init(withType: .Text)
|
|
|
+ self.convertBox.contentView = self.convertButtonVC!.view
|
|
|
+ }
|
|
|
+
|
|
|
+ override func initDefaultValue() {
|
|
|
+ super.initDefaultValue()
|
|
|
+
|
|
|
+ self.totalNumberLabel.lineBreakMode = .byTruncatingTail
|
|
|
+
|
|
|
self.prePDFView?.setDisplay(.singlePage)
|
|
|
self.prePDFView?.layoutDocumentView()
|
|
|
self.prePDFView?.autoScales = true
|
|
|
self.prePDFView?.delegate = self
|
|
|
|
|
|
self.backBox.fillColor = .clear
|
|
|
- self.backButtonVC = KMDesignButton.init(withType: .Image)
|
|
|
- self.backBox.contentView = self.backButtonVC!.view
|
|
|
self.backButtonVC?.target = self
|
|
|
self.backButtonVC?.action = #selector(backButtonAction)
|
|
|
self.backButtonVC?.image = NSImage(named: "KMImageNameLeftButtonImage")!
|
|
|
self.backButtonVC?.image_disabled = NSImage(named: "KMImageNameLeftButtonImageDis")!
|
|
|
self.backButtonVC?.pagination()
|
|
|
|
|
|
- numberBox.wantsLayer = true
|
|
|
+ self.numberBox.wantsLayer = true
|
|
|
self.numberBox.layer?.backgroundColor = NSColor.white.cgColor
|
|
|
- numberBox.layer?.borderWidth = 1
|
|
|
- numberBox.layer?.cornerRadius = 4
|
|
|
- numberTextField.focusRingType = .none
|
|
|
- numberTextField.delegate = self
|
|
|
+ self.numberBox.layer?.borderWidth = 1
|
|
|
+ self.numberBox.layer?.cornerRadius = 4
|
|
|
+ self.numberTextField.focusRingType = .none
|
|
|
+ self.numberTextField.delegate = self
|
|
|
self.numberTextField.isBordered = false
|
|
|
|
|
|
self.nextBox.fillColor = .clear
|
|
|
- self.nextButtonVC = KMDesignButton.init(withType: .Image)
|
|
|
- self.nextBox.contentView = self.nextButtonVC!.view
|
|
|
self.nextButtonVC?.target = self
|
|
|
self.nextButtonVC?.action = #selector(nextButtonAction)
|
|
|
self.nextButtonVC?.image = NSImage(named: "KMImageNameRightButtonImage")!
|
|
|
self.nextButtonVC?.image_disabled = NSImage(named: "KMImageNameRightButtonImageDis")!
|
|
|
self.nextButtonVC?.pagination()
|
|
|
-
|
|
|
- batchButton.title = NSLocalizedString("Batch", comment: "")
|
|
|
- batchButton.isBordered = false
|
|
|
- batchButton.wantsLayer = true
|
|
|
- batchButton.layer?.borderWidth = 1
|
|
|
- batchButton.layer?.cornerRadius = 4
|
|
|
- batchButton.target = self
|
|
|
- batchButton.action = #selector(batchButtonAction)
|
|
|
- batchButton.isHidden = true
|
|
|
|
|
|
self.canelBox.fillColor = .clear
|
|
|
- self.canelButtonVC = KMDesignButton.init(withType: .Text)
|
|
|
- self.canelBox.contentView = self.canelButtonVC!.view
|
|
|
self.canelButtonVC?.target = self
|
|
|
self.canelButtonVC?.action = #selector(cancelButtonAction)
|
|
|
self.canelButtonVC?.stringValue = NSLocalizedString("Cancel", comment: "")
|
|
@@ -146,19 +187,16 @@ class KMConvertBaseWindowController: NSWindowController {
|
|
|
self.canelButtonVC?.button.keyEquivalent = KMKeyEquivalent.esc.string()
|
|
|
|
|
|
self.convertBox.fillColor = .clear
|
|
|
- self.convertButtonVC = KMDesignButton.init(withType: .Text)
|
|
|
- self.convertBox.contentView = self.convertButtonVC!.view
|
|
|
self.convertButtonVC?.target = self
|
|
|
self.convertButtonVC?.action = #selector(convertButtonAction)
|
|
|
self.convertButtonVC?.stringValue = NSLocalizedString("Convert", comment: "")
|
|
|
self.convertButtonVC?.button(type: .Cta, size: .m)
|
|
|
// convertButtonVC.button.keyEquivalent = KMKeyEquivalent.enter
|
|
|
+
|
|
|
self.rightScrollView.hasVerticalScroller = false
|
|
|
self.rightScrollView.hasHorizontalScroller = false
|
|
|
|
|
|
self.initUIProperty()
|
|
|
-
|
|
|
- self.updateBackAndNextButtonState()
|
|
|
}
|
|
|
|
|
|
private func initUIProperty() {
|
|
@@ -178,6 +216,11 @@ class KMConvertBaseWindowController: NSWindowController {
|
|
|
self.batchButton.font = .SFProTextRegular(14)
|
|
|
}
|
|
|
|
|
|
+ func initSettingView() -> KMConvertSettingView? {
|
|
|
+ let settingView = KMConvertSettingView.createFromNib()
|
|
|
+ return settingView
|
|
|
+ }
|
|
|
+
|
|
|
public func initConvert() -> KMPDFConvert {
|
|
|
return KMPDFConvert()
|
|
|
}
|
|
@@ -427,50 +470,6 @@ class KMConvertBaseWindowController: NSWindowController {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
- /// 开始加载loading
|
|
|
- func beginLoading() {
|
|
|
- DispatchQueue.main.async { [self] in
|
|
|
- self.maskView = NSButton()
|
|
|
- self.maskView?.isBordered = false
|
|
|
- self.maskView?.title = ""
|
|
|
- self.maskView?.wantsLayer = true
|
|
|
- self.maskView?.layer?.backgroundColor = NSColor(white: 1, alpha: 0.3 ).cgColor
|
|
|
- self.maskView?.target = self
|
|
|
- self.maskView?.action = #selector(maskViewClick)
|
|
|
- self.maskView?.frame = (self.window?.contentView!.bounds)!
|
|
|
- self.maskView?.autoresizingMask = [.width, .height]
|
|
|
- self.window?.contentView?.addSubview(self.maskView!)
|
|
|
-
|
|
|
- self.indicator = NSProgressIndicator()
|
|
|
- self.indicator?.style = .spinning
|
|
|
- self.indicator?.controlSize = .regular
|
|
|
- self.indicator?.isIndeterminate = true
|
|
|
- self.window?.contentView?.addSubview(self.indicator!)
|
|
|
- let indicatorSize: CGFloat = 32
|
|
|
- self.indicator?.frame = NSMakeRect(0.5*(NSWidth((self.window?.contentView!.frame)!)-indicatorSize), 0.5*(NSHeight((self.window?.contentView!.frame)!)-indicatorSize), indicatorSize, indicatorSize)
|
|
|
- self.indicator?.autoresizingMask = NSView.AutoresizingMask(rawValue: 45)
|
|
|
-
|
|
|
- self.indicator?.startAnimation(nil)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// 结束加载loading
|
|
|
- func endLoading() {
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.indicator?.stopAnimation(nil)
|
|
|
-
|
|
|
- self.indicator?.removeFromSuperview()
|
|
|
- self.indicator = nil
|
|
|
-
|
|
|
- self.maskView?.removeFromSuperview()
|
|
|
- self.maskView = nil
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @objc func maskViewClick() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
// MARK: -
|
|
|
// MARK: Private Methods
|
|
|
|
|
@@ -650,6 +649,8 @@ class KMConvertBaseWindowController: NSWindowController {
|
|
|
|
|
|
// MARK: Progress
|
|
|
func showProgressWindow() {
|
|
|
+ self.hiddenProgressWindow()
|
|
|
+
|
|
|
let progress = SKProgressController()
|
|
|
progress.message = NSLocalizedString("Converting...", comment: "")
|
|
|
progress.window?.backgroundColor = NSColor(hex: "#36383B")
|