|
@@ -536,4 +536,189 @@ extension KMBrowserWindowController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ func createBaseFoldPath() -> String {
|
|
|
+ let folderPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last?.appending("/\(Bundle.main.bundleIdentifier!)")
|
|
|
+ if (FileManager.default.fileExists(atPath: folderPath!) == false) {
|
|
|
+ try?FileManager.default.createDirectory(atPath: folderPath!, withIntermediateDirectories: false)
|
|
|
+ }
|
|
|
+ return folderPath ?? ""
|
|
|
+ }
|
|
|
+
|
|
|
+ func filePathCheck(path: String) -> String {
|
|
|
+ var i: Int = 0
|
|
|
+ let fileURL = URL(fileURLWithPath: path)
|
|
|
+ var newPath: String = path
|
|
|
+ let fileManager = FileManager.default
|
|
|
+ while fileManager.fileExists(atPath: newPath) {
|
|
|
+ i += 1
|
|
|
+
|
|
|
+ newPath = fileURL.deletingPathExtension().path
|
|
|
+ newPath.append("(\(i))")
|
|
|
+ newPath.append(".")
|
|
|
+ newPath.append(fileURL.pathExtension)
|
|
|
+ }
|
|
|
+ return newPath
|
|
|
+ }
|
|
|
+
|
|
|
+ func screenShot_SelectArea(_ sender: Any?) {
|
|
|
+ KMScreenShotHandler.beginScreenshot_SelectRectWithCompleteHandler { ima in
|
|
|
+ if let image = ima {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
|
|
+ let folderPath = self.createBaseFoldPath()
|
|
|
+ let savePathOld = folderPath + "/screenShot.pdf"
|
|
|
+ var savePath = self.filePathCheck(path: savePathOld)
|
|
|
+ let newDocument = CPDFDocument()
|
|
|
+ _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
|
|
|
+ let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
|
|
|
+ if writeSuccess ?? false {
|
|
|
+ if self.checkOpenNewDocument(path: savePath) {
|
|
|
+ self.savePdf(savePath)
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func screenShot_Window(_ sender: Any?) {
|
|
|
+ KMPrint("screenShot_Window")
|
|
|
+ KMScreenShotHandler.beginScreenShot_SelectWindowCompleteHandler { ima in
|
|
|
+ if let image = ima {
|
|
|
+ if image.size.equalTo(.zero) == true {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
|
|
+ let folderPath = self.createBaseFoldPath()
|
|
|
+ let savePathOld = folderPath + "/screenShot.pdf"
|
|
|
+ var savePath = self.filePathCheck(path: savePathOld)
|
|
|
+ let newDocument = CPDFDocument()
|
|
|
+ _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
|
|
|
+ let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
|
|
|
+ if writeSuccess == true {
|
|
|
+ if self.checkOpenNewDocument(path: savePath) {
|
|
|
+ self.savePdf(savePath)
|
|
|
+ }
|
|
|
+ // try? FileManager.default.removeItem(atPath: savePath)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func screenShot_FullScreenDelay(_ sender: Any?) {//不延迟
|
|
|
+ KMPrint("screenShot_FullScreenDelay")
|
|
|
+ KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(0) { ima in
|
|
|
+ if let image = ima {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
|
|
+ let folderPath = self.createBaseFoldPath()
|
|
|
+ let savePathOld = folderPath + "/screenShot.pdf"
|
|
|
+
|
|
|
+ var savePath = self.filePathCheck(path: savePathOld)
|
|
|
+ let newDocument = CPDFDocument()
|
|
|
+ _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
|
|
|
+ let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
|
|
|
+ if writeSuccess == true {
|
|
|
+ if self.checkOpenNewDocument(path: savePath) {
|
|
|
+ self.savePdf(savePath)
|
|
|
+ }
|
|
|
+// try? FileManager.default.removeItem(atPath: savePath)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func screenShot_FullScreen(_ sender: Any?) {//延迟3秒
|
|
|
+ KMPrint("screenShot_FullScreen")
|
|
|
+ KMScreenShotHandler.beginScreenShot_FullSreenWithDelayTime(3) { ima in
|
|
|
+ if let image = ima {
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
|
|
|
+ let folderPath = self.createBaseFoldPath()
|
|
|
+ let savePathOld = folderPath + "/screenShot.pdf"
|
|
|
+
|
|
|
+ var savePath = self.filePathCheck(path: savePathOld)
|
|
|
+ let newDocument = CPDFDocument()
|
|
|
+ _ = newDocument?.km_insert(imageData: image.jpgData() ?? Data(), pageSize: image.size, at: newDocument?.pageCount ?? 0)
|
|
|
+ let writeSuccess = newDocument?.write(to: URL(fileURLWithPath: savePath))
|
|
|
+ if writeSuccess == true {
|
|
|
+ self.savePdf(savePath)
|
|
|
+// try? FileManager.default.removeItem(atPath: savePath)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func checkOpenNewDocument(path: String) -> Bool {
|
|
|
+ let tabCount = self.km_browser?.tabCount() ?? 0
|
|
|
+ if tabCount > 1{
|
|
|
+ if !IAPProductsManager.default().isAvailableAllFunction() {
|
|
|
+ let preferenceNoteShow = UserDefaults.standard.bool(forKey: KMTabbingHintShowFlag)
|
|
|
+ if preferenceNoteShow {
|
|
|
+ menuItemAction_newTagPageToNewWindow("")
|
|
|
+ } else {
|
|
|
+ if !KMDataManager.default.isTabbingWin{
|
|
|
+ KMDataManager.default.isTabbingWin = true
|
|
|
+ let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
|
|
|
+ tabbingWin.selectCallBack = {[weak self] continueOrNot in
|
|
|
+ KMDataManager.default.isTabbingWin = false
|
|
|
+ if continueOrNot {
|
|
|
+ self?.reopenDocumentForNewWindow(savePath: path)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.km_beginSheet(windowC: tabbingWin)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }else {
|
|
|
+ if KMPreference.shared.openDocumentType == .newWindow {
|
|
|
+ self.reopenDocumentForNewWindow(savePath: path)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ func menuItemAction_newTagPageToNewWindow(_ sender: Any) {
|
|
|
+ if (self.canResponseDocumentAction() == false) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ self.openNewWindow(sender)
|
|
|
+ }
|
|
|
+
|
|
|
+ func reopenDocumentForNewWindow(savePath: String) {
|
|
|
+ let browser = KMBrowser.init() as KMBrowser
|
|
|
+ browser.windowController = KMBrowserWindowController.init(browser: browser)
|
|
|
+ browser.addHomeTabContents()
|
|
|
+ browser.windowController.showWindow(self)
|
|
|
+ self.savePdf(savePath)
|
|
|
+ }
|
|
|
+
|
|
|
+ func savePdf(_ filePath: String) -> Void {
|
|
|
+ let docVc = KMDocumentController.shared
|
|
|
+
|
|
|
+ docVc.openDocument(withContentsOf: URL(fileURLWithPath: filePath), display: true) { document, documentWasAlreadyOpen, error in
|
|
|
+ if error != nil {
|
|
|
+ NSApp.presentError(error!)
|
|
|
+ } else {
|
|
|
+ if document is KMMainDocument {
|
|
|
+ let newDocument = document
|
|
|
+ (newDocument as! KMMainDocument).isNewCreated = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|