|
@@ -378,40 +378,6 @@ struct KMNMWCFlags {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private func saveAsPath() {
|
|
|
- let saveAccessCtr = KMSavePanelAccessoryController()
|
|
|
- var fileName = listView.document.documentURL.deletingPathExtension().lastPathComponent
|
|
|
- fileName = String(format: "%@_%@.pdf", fileName, "Redact")
|
|
|
- let outputSavePanel = NSSavePanel()
|
|
|
- outputSavePanel.allowedFileTypes = ["pdf"]
|
|
|
- outputSavePanel.nameFieldStringValue = fileName
|
|
|
- outputSavePanel.accessoryView = saveAccessCtr.view
|
|
|
- outputSavePanel.beginSheetModal(for: NSApp.mainWindow!) { result in
|
|
|
- if result == .OK {
|
|
|
- self.listView.document.applyRedactions()
|
|
|
- self.showProgressWindow(message: KMLocalizedString("Save") + "PDF")
|
|
|
- self.progressC?.maxValue = 3.0
|
|
|
- self.progressC?.increment(by: 1.0)
|
|
|
- let savePDFPath = outputSavePanel.url!.path
|
|
|
- // 执行进度 [假进度]
|
|
|
- self.progressC?.increment(by: 1.0)
|
|
|
- self.progressC?.increment(by: 1.0)
|
|
|
- let isSuccess = self.listView.document.write(toFile: savePDFPath)
|
|
|
- if (isSuccess) {
|
|
|
- if (saveAccessCtr.openAutomaticButton.state == .on) {
|
|
|
- NSDocumentController.shared.km_safe_openDocument(withContentsOf: outputSavePanel.url!, display: true) { _, _, _ in
|
|
|
- }
|
|
|
- } else {
|
|
|
- let url = URL(fileURLWithPath: savePDFPath)
|
|
|
- NSWorkspace.shared.activateFileViewerSelecting([url])
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self.hiddenProgressWindow()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private func reloadDigitalSigns() {
|
|
|
let signatures = listView.document.signatures()
|
|
|
|
|
@@ -3551,17 +3517,6 @@ struct KMNMWCFlags {
|
|
|
}
|
|
|
|
|
|
// MARK: -显示加密弹窗
|
|
|
-
|
|
|
-
|
|
|
- //MARK: - Redact密文
|
|
|
- func showRedactProperty(readactAnnotation: CPDFRedactAnnotation?) {
|
|
|
- let properties = KMRedactPropertiesWindowController()
|
|
|
- properties.readactAnnotation = readactAnnotation
|
|
|
-
|
|
|
- properties.own_beginSheetModal(for: self.view.window) { result in
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
//MARK: - 测量
|
|
|
func refreshMeasureInfo() {
|
|
@@ -4397,6 +4352,8 @@ extension KMMainViewController: KMPDFToolbarControllerDelegate {
|
|
|
} else if itemIdentifier == KMPDFToolbar_protect_redact_Exit_Identifier {
|
|
|
toolbarViewModeChanged()
|
|
|
|
|
|
+ alertTipViewController.reloadRedactAlertUI()
|
|
|
+ alertTipViewController.reloadAlertUIFrame()
|
|
|
} else if itemIdentifier == KMPDFToolbar_protect_security_Identifier {
|
|
|
self.showSecureWindow()
|
|
|
|
|
@@ -7367,10 +7324,108 @@ extension KMMainViewController : CDistanceSettingWindowControllerDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//MARK: - extension
|
|
|
+//MARK: - Redact密文
|
|
|
extension KMMainViewController {
|
|
|
+ func showRedactProperty(readactAnnotation: CPDFRedactAnnotation?) {
|
|
|
+ let properties = KMRedactPropertiesWindowController()
|
|
|
+ properties.readactAnnotation = readactAnnotation
|
|
|
+
|
|
|
+ properties.own_beginSheetModal(for: self.view.window) { result in
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ func redactApplyAction(needAlert: Bool = true) {
|
|
|
+ if needAlert {
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
+ guard let self = self else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if UserDefaults.standard.object(forKey: "kApplyRedactAlert") != nil {
|
|
|
+ self.listView.document.applyRedactions()
|
|
|
+ self.listView.layoutDocumentView()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .informational
|
|
|
+ alert.messageText = KMLocalizedString("This action will permanently remove the redacted information from this document.")
|
|
|
+ alert.informativeText = KMLocalizedString("""
|
|
|
+ After you save this document, you will not be able to retrieve the redacted information.
|
|
|
+ """)
|
|
|
+ alert.addButton(withTitle: KMLocalizedString("Apply"))
|
|
|
+ alert.addButton(withTitle: KMLocalizedString("Cancel"))
|
|
|
+ alert.showsSuppressionButton = true
|
|
|
+ let response = alert.runModal()
|
|
|
+ if response.rawValue == 1000 {
|
|
|
+ if alert.suppressionButton?.state == .on {
|
|
|
+ UserDefaults.standard.set("YES", forKey: "kApplyRedactAlert")
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+ }
|
|
|
+
|
|
|
+ self.listView.document.applyRedactions()
|
|
|
+ self.listView.layoutDocumentView()
|
|
|
+ } else if response.rawValue == 1001 {
|
|
|
+ //取消
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ self.listView.document.applyRedactions()
|
|
|
+ self.listView.layoutDocumentView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func redactMultipageAction(redactAnnotation:CPDFRedactAnnotation) {
|
|
|
+ let pagesWindowController = KMRedactSelectPagesWindowController(document: listView.document)
|
|
|
+ pagesWindowController.own_beginSheetModal(for: self.view.window) { result in
|
|
|
+
|
|
|
+ }
|
|
|
+ pagesWindowController.callback = { [weak self] pages in
|
|
|
+ if pages.count > 0 {
|
|
|
+ self?.listView.redactAddAnnotationPages(pages, redactAnnotation: redactAnnotation)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func setPropertiesDefault(annotation:CPDFRedactAnnotation) {
|
|
|
+ CPDFRedactAnnotation.update_defaultOutlineColor(annotation.borderColor())
|
|
|
+ CPDFRedactAnnotation.update_defaultFillColor(annotation.interiorColor())
|
|
|
+ CPDFRedactAnnotation.update_defaultTextColor(annotation.fontColor())
|
|
|
+ CPDFRedactAnnotation.update_defaultFontSize(annotation.fontSize)
|
|
|
+
|
|
|
+ CPDFRedactAnnotation.update_defaultFontAlignment(annotation.alignment())
|
|
|
+ CPDFRedactAnnotation.update_defaultOverlayText(annotation.overlayText())
|
|
|
+ }
|
|
|
|
|
|
+ func enterRedactAlert() {
|
|
|
+ if UserDefaults.standard.object(forKey: "kRedact") != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let alert = NSAlert()
|
|
|
+ alert.alertStyle = .informational
|
|
|
+ alert.informativeText = KMLocalizedString("Redaction allows you to permanently mask and remove sensitive content.")
|
|
|
+ alert.messageText = KMLocalizedString("""
|
|
|
+ Redaction requires two steps:
|
|
|
+ 1. Mark for Redaction
|
|
|
+ 2. Apply Redactions
|
|
|
+
|
|
|
+ Note: Redactions are not applied permanently until you select Apply Redactions.
|
|
|
+ """)
|
|
|
+ alert.addButton(withTitle: KMLocalizedString("OK"))
|
|
|
+ alert.showsSuppressionButton = true
|
|
|
+ let response = alert.runModal()
|
|
|
+ if response.rawValue == 1000 {
|
|
|
+ if alert.suppressionButton?.state == .on {
|
|
|
+ UserDefaults.standard.set("YES", forKey: "kRedact")
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//MARK: - extension
|
|
|
+extension KMMainViewController {
|
|
|
func removeAllAnnotations() {
|
|
|
let alert = NSAlert()
|
|
|
alert.messageText = KMLocalizedString("This will permanently remove all annotations. Are you sure to continue?", comment: "")
|
|
@@ -7635,170 +7690,6 @@ extension KMMainViewController {
|
|
|
return pageCount > 30
|
|
|
}
|
|
|
|
|
|
- // MARK: - Redact 【标记密文】
|
|
|
- func redactApplyAction(needAlert: Bool = true) {
|
|
|
-// if needAlert {
|
|
|
-// let returnCode = KMAlertTool.runModelForMainThread_r(message: "", informative: KMLocalizedString("This will permanently remove the redacted information from this document. Once you save this document, you won’t be able to retrieve the redacted information."), buttons: [KMLocalizedString("Apply"), KMLocalizedString("Cancel")])
|
|
|
-// if returnCode == .alertFirstButtonReturn {
|
|
|
-// DispatchQueue.main.async {
|
|
|
-// self.saveAsPath()
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// self.saveAsPath()
|
|
|
-// }
|
|
|
-
|
|
|
- if needAlert {
|
|
|
- DispatchQueue.main.async { [weak self] in
|
|
|
- guard let self = self else {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if UserDefaults.standard.object(forKey: "kApplyRedactAlert") != nil {
|
|
|
- self.saveAsPath()
|
|
|
- return
|
|
|
- }
|
|
|
- let alert = NSAlert()
|
|
|
- alert.alertStyle = .informational
|
|
|
- alert.messageText = KMLocalizedString("This action will permanently remove the redacted information from this document.")
|
|
|
- alert.informativeText = KMLocalizedString("""
|
|
|
- After you save this document, you will not be able to retrieve the redacted information.
|
|
|
- """)
|
|
|
- alert.addButton(withTitle: KMLocalizedString("Apply"))
|
|
|
- alert.addButton(withTitle: KMLocalizedString("Cancel"))
|
|
|
- alert.showsSuppressionButton = true
|
|
|
- let response = alert.runModal()
|
|
|
- if response.rawValue == 1000 {
|
|
|
- if alert.suppressionButton?.state == .on {
|
|
|
- UserDefaults.standard.set("YES", forKey: "kApplyRedactAlert")
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- }
|
|
|
-
|
|
|
- self.saveAsPath()
|
|
|
- } else if response.rawValue == 1001 {
|
|
|
- //取消
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- self.saveAsPath()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func redactMultipageAction(redactAnnotation:CPDFRedactAnnotation) {
|
|
|
- let pagesWindowController = KMRedactSelectPagesWindowController(document: listView.document)
|
|
|
- pagesWindowController.own_beginSheetModal(for: self.view.window) { result in
|
|
|
-
|
|
|
- }
|
|
|
- pagesWindowController.callback = { [weak self] pages in
|
|
|
- if pages.count > 0 {
|
|
|
- self?.listView.redactAddAnnotationPages(pages, redactAnnotation: redactAnnotation)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func setPropertiesDefault(annotation:CPDFRedactAnnotation) {
|
|
|
- CPDFRedactAnnotation.update_defaultOutlineColor(annotation.borderColor())
|
|
|
- CPDFRedactAnnotation.update_defaultFillColor(annotation.interiorColor())
|
|
|
- CPDFRedactAnnotation.update_defaultTextColor(annotation.fontColor())
|
|
|
- CPDFRedactAnnotation.update_defaultFontSize(annotation.fontSize)
|
|
|
-
|
|
|
- CPDFRedactAnnotation.update_defaultFontAlignment(annotation.alignment())
|
|
|
- CPDFRedactAnnotation.update_defaultOverlayText(annotation.overlayText())
|
|
|
- }
|
|
|
-
|
|
|
- func exeRedactConfirm(_ type: KMRedactConfirmType, callback: @escaping () -> ()?) {
|
|
|
- let windowController = KMRedactConfirmWindowController(type)
|
|
|
- self.currentWindowController = windowController
|
|
|
- self.view.window?.beginSheet(windowController.window!)
|
|
|
- windowController.itemClick = { [weak self] index in
|
|
|
- if (index == 2) { /// 取消
|
|
|
- self?.view.window?.endSheet((self?.currentWindowController.window)!)
|
|
|
- self?.currentWindowController = nil
|
|
|
- callback()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- self?.view.window?.endSheet((self?.currentWindowController.window)!)
|
|
|
- self?.currentWindowController = nil
|
|
|
-
|
|
|
- let panel = NSSavePanel()
|
|
|
- panel.nameFieldStringValue = "[新文件]"+((self?.listView.document?.documentURL.lastPathComponent) ?? "")
|
|
|
- let button = NSButton.init(checkboxWithTitle: "保存后打开文档", target: nil, action: nil)
|
|
|
- button.state = .on
|
|
|
- panel.accessoryView = button
|
|
|
- panel.isExtensionHidden = true
|
|
|
- panel.beginSheetModal(for: (self?.view.window!)!) { response in
|
|
|
- if response != .OK {
|
|
|
- callback()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if (type == .redactOne) {
|
|
|
- let anno = self!.listView.activeAnnotation
|
|
|
- if (anno == nil || (anno?.isKind(of: CPDFRedactAnnotation.self)) == false) {
|
|
|
- callback()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- (anno as! CPDFRedactAnnotation).applyRedaction()
|
|
|
- } else if (type == .redactAll) {
|
|
|
- self?.listView.document?.applyRedactions()
|
|
|
- } else if (type == .eraserOne) {
|
|
|
- let anno = self!.listView.activeAnnotation
|
|
|
- if (anno == nil || (anno?.isKind(of: CPDFRedactAnnotation.self)) == false) {
|
|
|
- callback()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- anno?.page.erasureRedact(from: anno!.bounds)
|
|
|
- } else if (type == .eraserAll) {
|
|
|
- KMRedactTools.eraserDocument((self?.listView.document)!) { result, errorAnno in
|
|
|
- if (result == false) {
|
|
|
- callback()
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self!.listView.document?.write(to: panel.url)
|
|
|
- if (button.state == .on) {
|
|
|
- NSDocumentController.shared.openDocument(withContentsOf: panel.url!, display: true) { document, alreadyOpen, error in
|
|
|
-
|
|
|
- }
|
|
|
- } else {
|
|
|
- NSWorkspace.shared.activateFileViewerSelecting([panel.url!])
|
|
|
- }
|
|
|
- callback()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func enterRedactAlert() {
|
|
|
- if UserDefaults.standard.object(forKey: "kRedact") != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- let alert = NSAlert()
|
|
|
- alert.alertStyle = .informational
|
|
|
- alert.informativeText = KMLocalizedString("Redaction allows you to permanently mask and remove sensitive content.")
|
|
|
- alert.messageText = KMLocalizedString("""
|
|
|
- Redaction requires two steps:
|
|
|
- 1. Mark for Redaction
|
|
|
- 2. Apply Redactions
|
|
|
-
|
|
|
- Note: Redactions are not applied permanently until you select Apply Redactions.
|
|
|
- """)
|
|
|
- alert.addButton(withTitle: KMLocalizedString("OK"))
|
|
|
- alert.showsSuppressionButton = true
|
|
|
- let response = alert.runModal()
|
|
|
- if response.rawValue == 1000 {
|
|
|
- if alert.suppressionButton?.state == .on {
|
|
|
- UserDefaults.standard.set("YES", forKey: "kRedact")
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// MARK: - 保存文档
|
|
|
internal func needSaveDocument() -> Bool {
|
|
|
if (self.isPDFDocumentEdited) {
|