|
@@ -11,14 +11,14 @@ import KMComponentLibrary
|
|
|
let kUrlToPDFFolderPath = (try? FileManager.default.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true).appendingPathComponent(Bundle.main.bundleIdentifier ?? "").appendingPathComponent("WebPage"))?.path ?? ""
|
|
|
|
|
|
@objc protocol KMURLCreatePDFWindowControllerDelegate: AnyObject {
|
|
|
-
|
|
|
+
|
|
|
//选择打开文件
|
|
|
@objc optional func urlCreateWCDidChooseFileToOpen(_ vc: KMURLCreatePDFWindowController, _ fileURL: URL)
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
-
|
|
|
+
|
|
|
@IBOutlet var contendBox: NSBox!
|
|
|
|
|
|
@IBOutlet var titleLabel: NSTextField!
|
|
@@ -44,12 +44,12 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
|
|
|
var choosedFilePath: String?
|
|
|
var filePath: String?
|
|
|
-
|
|
|
+
|
|
|
weak open var delegate: KMURLCreatePDFWindowControllerDelegate?
|
|
|
-
|
|
|
+
|
|
|
override func windowDidLoad() {
|
|
|
super.windowDidLoad()
|
|
|
-
|
|
|
+
|
|
|
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
|
|
|
|
|
setUpProperty()
|
|
@@ -82,9 +82,9 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
urlRadio.setTarget(self, action: #selector(typeRadioChanged(_:)))
|
|
|
|
|
|
fileRadio.properties = ComponentCheckBoxProperty(size: .s,
|
|
|
- state: .normal,
|
|
|
- text: NSLocalizedString("File", comment: ""),
|
|
|
- checkboxType: .normal)
|
|
|
+ state: .normal,
|
|
|
+ text: NSLocalizedString("File", comment: ""),
|
|
|
+ checkboxType: .normal)
|
|
|
fileRadio.setTarget(self, action: #selector(typeRadioChanged(_:)))
|
|
|
|
|
|
inputView.properties = ComponentInputProperty(size: .s,
|
|
@@ -111,7 +111,7 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
iconImage: NSImage(named: "file_icon"))
|
|
|
fileInputAddon.setTarget(self, action: #selector(chooseURLAction(_ :)))
|
|
|
|
|
|
-
|
|
|
+
|
|
|
cancelButton.properties = ComponentButtonProperty(type: .default_tertiary,
|
|
|
size: .s,
|
|
|
state: .normal,
|
|
@@ -119,9 +119,9 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
cancelButton.setTarget(self, action: #selector(cancelButtonClicked(_ :)))
|
|
|
|
|
|
openButton.properties = ComponentButtonProperty(type: .primary,
|
|
|
- size: .s,
|
|
|
- state: .normal,
|
|
|
- buttonText: NSLocalizedString("Open", comment: ""))
|
|
|
+ size: .s,
|
|
|
+ state: .normal,
|
|
|
+ buttonText: NSLocalizedString("Open", comment: ""))
|
|
|
openButton.setTarget(self, action: #selector(openButtonClicked(_ :)))
|
|
|
|
|
|
}
|
|
@@ -132,7 +132,7 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
|
|
|
fileInputBGView.isHidden = isFromURL ? true : false
|
|
|
inputView.isHidden = isFromURL ? false : true
|
|
|
-
|
|
|
+
|
|
|
cancelButton.properties.state = .normal
|
|
|
openButton.properties.state = .normal
|
|
|
|
|
@@ -165,11 +165,11 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
urlRadio.reloadData()
|
|
|
|
|
|
fileRadio.reloadData()
|
|
|
-
|
|
|
+
|
|
|
cancelButton.reloadData()
|
|
|
|
|
|
openButton.reloadData()
|
|
|
-
|
|
|
+
|
|
|
fileInputView.reloadData()
|
|
|
|
|
|
}
|
|
@@ -187,7 +187,9 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
|
|
|
choosedFilePath = nil
|
|
|
inputView.properties.text = ""
|
|
|
-
|
|
|
+
|
|
|
+ hideWaitting()
|
|
|
+
|
|
|
reloadData()
|
|
|
|
|
|
KMURLToPDF.shareInstance.stopLoading()
|
|
@@ -207,13 +209,13 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
openPanel.allowedFileTypes = ["html", "HTML"]
|
|
|
openPanel.allowsMultipleSelection = false
|
|
|
openPanel.beginSheetModal(for: self.window!) { [weak self] result in
|
|
|
- if result == NSApplication.ModalResponse.OK {
|
|
|
- if let url = openPanel.url {
|
|
|
- self?.choosedFilePath = url.path
|
|
|
-
|
|
|
- self?.reloadData()
|
|
|
-
|
|
|
- }
|
|
|
+ if result == NSApplication.ModalResponse.OK {
|
|
|
+ if let url = openPanel.url {
|
|
|
+ self?.choosedFilePath = url.path
|
|
|
+
|
|
|
+ self?.reloadData()
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -239,7 +241,7 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
url = URL(fileURLWithPath: choosedFilePath)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if let url = url {
|
|
|
showWaitting()
|
|
|
|
|
@@ -264,7 +266,7 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
alert.alertStyle = .critical
|
|
|
alert.messageText = NSLocalizedString("Conversion Failed", comment: "")
|
|
|
alert.beginSheetModal(for: window) { [weak self] result in
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -290,7 +292,7 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
alert.alertStyle = .critical
|
|
|
alert.messageText = NSLocalizedString("Conversion Failed", comment: "")
|
|
|
alert.beginSheetModal(for: window) { [weak self] result in
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -307,7 +309,7 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
}
|
|
|
contendBox.contentView?.addSubview(posterMaskView!, positioned: .below, relativeTo: self.cancelButton)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func hideWaitting() {
|
|
|
posterMaskView?.removeFromSuperview()
|
|
|
}
|
|
@@ -324,7 +326,9 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
|
|
|
choosedFilePath = nil
|
|
|
self.handler = handler
|
|
|
-
|
|
|
+
|
|
|
+ hideWaitting()
|
|
|
+
|
|
|
reloadData()
|
|
|
}
|
|
|
|
|
@@ -358,7 +362,7 @@ class KMURLCreatePDFWindowController: NSWindowController {
|
|
|
let urlTest = NSPredicate(format: "SELF MATCHES %@", urlRegex)
|
|
|
return urlTest.evaluate(with: url)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func urlValueEncode(_ str: String) -> String? {
|
|
|
let allowedCharacterSet = CharacterSet(charactersIn: "!*'();:@&=+$,?%#[]{}").inverted
|
|
|
return str.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet)
|