|
@@ -13,6 +13,12 @@ import CoreFoundation
|
|
|
case email = 2
|
|
|
}
|
|
|
|
|
|
+@objc enum KMExportOption: Int {
|
|
|
+ case `default` = 0
|
|
|
+ case withoutNotes
|
|
|
+ case withEmbeddedNotes
|
|
|
+}
|
|
|
+
|
|
|
typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> ()
|
|
|
@objcMembers class KMMainDocument: CTTabContents {
|
|
|
struct MDFlags {
|
|
@@ -23,6 +29,9 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
|
|
|
var needsPasswordToConvert: UInt32 // assuming this is a 1-bit field, change to appropriate data type
|
|
|
}
|
|
|
|
|
|
+ static let kLastExportedTypeKey = "SKLastExportedType"
|
|
|
+ static let kLastExportedOptionKey = "SKLastExportedOption"
|
|
|
+
|
|
|
var mainViewController: KMMainViewController?
|
|
|
var homeWindowController: KMHomeWindowController?
|
|
|
var homeViewController: KMHomeViewController?
|
|
@@ -65,6 +74,8 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var exportAccessoryC: SKExportAccessoryController?
|
|
|
+
|
|
|
weak var watermarkSaveDelegate: AnyObject?
|
|
|
private var _trackEvents = IndexSet()
|
|
|
|
|
@@ -288,6 +299,86 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ override func saveTo(_ sender: Any?) {
|
|
|
+ guard let pdfDoc = self.mainViewController?.listView.document else {
|
|
|
+ NSSound.beep()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if pdfDoc.allowsPrinting == false || pdfDoc.allowsCopying == false {
|
|
|
+ Task {
|
|
|
+ _ = await KMAlertTool.runModel(message: NSLocalizedString("This is a secured document. Editing is not permitted.", comment: ""))
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let idx = (sender as? NSMenuItem)?.tag ?? 0
|
|
|
+ var typeName = KMPDFDocumentType
|
|
|
+ if idx == 0 {
|
|
|
+ typeName = KMPDFDocumentType
|
|
|
+ } else if idx == 1 {
|
|
|
+ typeName = KMPDFBundleDocumentType
|
|
|
+ } else if idx == 2 {
|
|
|
+ typeName = KMNotesDocumentType
|
|
|
+ } else if idx == 3 {
|
|
|
+ typeName = KMNotesTextDocumentType
|
|
|
+ } else if idx == 4 {
|
|
|
+ typeName = KMNotesRTFDocumentType
|
|
|
+ } else if idx == 5 {
|
|
|
+ typeName = KMNotesRTFDDocumentType
|
|
|
+ } else if idx == 6 {
|
|
|
+ typeName = KMNotesDocumentType
|
|
|
+ }
|
|
|
+
|
|
|
+ KMDataManager.ud_set(typeName, forKey: Self.kLastExportedTypeKey)
|
|
|
+ super.saveTo(sender)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func prepareSavePanel(_ savePanel: NSSavePanel) -> Bool {
|
|
|
+ var success = super.prepareSavePanel(savePanel)
|
|
|
+ let exportUsingPanel = self.mdFlags?.exportUsingPanel ?? 0
|
|
|
+ if success && exportUsingPanel > 0 {
|
|
|
+// *formatPopup = [[savePanel accessoryView] subviewOfClass:[NSPopUpButton class]];
|
|
|
+ var formatPopup: NSPopUpButton?
|
|
|
+ let svs = savePanel.accessoryView?.subviews ?? []
|
|
|
+ for sv in svs {
|
|
|
+ if let data = sv as? NSPopUpButton {
|
|
|
+ formatPopup = data
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (formatPopup != nil) {
|
|
|
+ let lastExportedType = KMDataManager.ud_string(forKey: Self.kLastExportedTypeKey)
|
|
|
+// NSInteger lastExportedOption = [[NSUserDefaults standardUserDefaults] integerForKey:SKLastExportedOptionKey];
|
|
|
+ var lastExportedOption = KMDataManager.ud_integer(forKey: Self.kLastExportedOptionKey)
|
|
|
+ if lastExportedOption == 0 {
|
|
|
+ lastExportedOption = KMExportOption.withEmbeddedNotes.rawValue
|
|
|
+ }
|
|
|
+ if (lastExportedType != nil) {
|
|
|
+ let idx = formatPopup?.indexOfItem(withRepresentedObject: lastExportedType) ?? -1
|
|
|
+ let selectedIdx = formatPopup?.indexOfSelectedItem ?? 0
|
|
|
+ if idx != -1 && idx != selectedIdx {
|
|
|
+ formatPopup?.selectItem(at: idx)
|
|
|
+ formatPopup?.sendAction(formatPopup?.action, to: formatPopup?.target)
|
|
|
+// [savePanel setAllowedFileTypes:[NSArray arrayWithObjects:[self fileNameExtensionForType:lastExportedType saveOperation:NSSaveToOperation], nil]];
|
|
|
+ if let data = self.fileNameExtension(forType: lastExportedType!, saveOperation: .saveToOperation) {
|
|
|
+ savePanel.allowedFileTypes = [data]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.mdFlags?.exportOption = UInt32(lastExportedOption)
|
|
|
+//
|
|
|
+ self.exportAccessoryC = SKExportAccessoryController()
|
|
|
+ self.exportAccessoryC?.addFormatPopUpButton(formatPopup)
|
|
|
+ self.exportAccessoryC?.matrix.target = self
|
|
|
+ self.exportAccessoryC?.matrix.action = #selector(changeExportOption)
|
|
|
+ savePanel.accessoryView = self.exportAccessoryC?.view
|
|
|
+ self._updateExportAccessoryView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return success
|
|
|
+ }
|
|
|
+
|
|
|
override func runModalSavePanel(for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
|
|
|
if (self.isNewCreated) {
|
|
|
// if let data = self.mainViewController, !data.isPDFDocumentEdited && !data.needSave && !self.isDocumentEdited {
|
|
@@ -460,6 +551,10 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+ func changeExportOption(_ sender: NSMatrix?) {
|
|
|
+ self.mdFlags?.exportOption = UInt32(sender?.selectedCell()?.tag ?? 0)
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: Private Methods
|
|
|
|
|
|
func pdfChangedNotification(_ notification: Notification) -> Void {
|
|
@@ -908,6 +1003,35 @@ typealias KMMainDocumentCloudUploadHanddler = (@escaping(Bool, String)->()) -> (
|
|
|
private func _km_runModalSavePanel(for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?) {
|
|
|
super.runModalSavePanel(for: saveOperation, delegate: delegate, didSave: didSaveSelector, contextInfo: contextInfo)
|
|
|
}
|
|
|
+
|
|
|
+ private func _updateExportAccessoryView() {
|
|
|
+ let typeName = self.fileTypeFromLastRunSavePanel ?? ""
|
|
|
+ let matrix = self.exportAccessoryC?.matrix
|
|
|
+ matrix?.selectCell(withTag: Int(self.mdFlags?.exportOption ?? 0))
|
|
|
+
|
|
|
+ if self._canAttachNotesForType(typeName) {
|
|
|
+ matrix?.isHidden = false
|
|
|
+ let ws = NSWorkspace.shared
|
|
|
+ let isLocked = self.mainViewController?.listView.document.isLocked ?? false
|
|
|
+ let allowsPrinting = self.mainViewController?.listView.document.allowsPrinting ?? false
|
|
|
+ if ws.type(typeName, conformsToType: KMPDFDocumentType) && isLocked == false && allowsPrinting {
|
|
|
+ (matrix?.cell(withTag: KMExportOption.withEmbeddedNotes.rawValue))?.isEnabled = true
|
|
|
+ } else {
|
|
|
+ (matrix?.cell(withTag: KMExportOption.withEmbeddedNotes.rawValue))?.isEnabled = false
|
|
|
+ if let data = self.mdFlags?.exportOption, data == KMExportOption.withEmbeddedNotes.rawValue {
|
|
|
+ self.mdFlags?.exportOption = UInt32(KMExportOption.default.rawValue)
|
|
|
+ matrix?.selectCell(withTag: KMExportOption.default.rawValue)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ matrix?.isHidden = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func _canAttachNotesForType(_ typeName: String) -> Bool {
|
|
|
+ let ws = NSWorkspace.shared
|
|
|
+ return ws.type(typeName, conformsToType: KMPDFDocumentType) || ws.type(typeName, conformsToType: KMPostScriptDocumentType) || ws.type(typeName, conformsToType: KMDVIDocumentType) || ws.type(typeName, conformsToType: KMXDVDocumentType)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension KMMainDocument {
|