|
@@ -109,8 +109,6 @@ struct KMNMWCFlags {
|
|
|
//Search
|
|
|
var searchIndex: Int = 0
|
|
|
|
|
|
- //Form
|
|
|
- var formAlertView: KMFormAlertView?
|
|
|
//Secure
|
|
|
var secureAlertView: KMSecureAlertView?
|
|
|
|
|
@@ -4307,275 +4305,13 @@ extension KMMainViewController: KMNLeftSideViewControllerDelegate {
|
|
|
//MARK: - 旧代码,需要用到的内容需要拖出来,写好注释
|
|
|
|
|
|
extension KMMainViewController {
|
|
|
-
|
|
|
- func awakeFromNibFunction() {
|
|
|
- self.addBackgroundMaskView()
|
|
|
-
|
|
|
-
|
|
|
- listView.delegate = self
|
|
|
- listView.pdfListViewDelegate = self
|
|
|
- if (document != nil) {
|
|
|
- self.listView.document = self.document
|
|
|
- self.listView.document?.delegate = self
|
|
|
-
|
|
|
- let autoScale = listView.autoScales
|
|
|
- if !autoScale {
|
|
|
- listView.scaleFactor = 1.0
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- self.initPDFLeftViewVC()
|
|
|
- self.leftSideViewController.mainViewController = self
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- func viewDidAppearFunction() {
|
|
|
- //春季活动
|
|
|
- if ((KMAdvertisementManager.manager.info.popWindowContent) != nil) {
|
|
|
- if KMAdvertisementManager.manager.info.popWindowContent!.content!.count > 0 {
|
|
|
- let info = KMAdvertisementManager.manager.info.popWindowContent!.content?.first
|
|
|
- if KMAdvertisementManager.checkAdvertisementValid(info!) {
|
|
|
- self.loadRecommondPopWindow()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- self.addEventMonitor()
|
|
|
-
|
|
|
- self.view.window?.makeFirstResponder(self.listView)
|
|
|
- // 更新属性页面的信息
|
|
|
- NotificationCenter.default.post(name: KMInfoWindowC.windowDidBecomeMainNotification, object: self.myDocument)
|
|
|
- self.interfaceThemeDidChanged(self.view.window?.appearance?.name ?? (NSApp.appearance?.name ?? .aqua))
|
|
|
-
|
|
|
- if (self.document == nil) {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if (self.document == nil || self.document!.isLocked == false) {
|
|
|
- self.loadFunctionGuide()
|
|
|
- }
|
|
|
-
|
|
|
- if (self.document?.isLocked == false) {
|
|
|
- if self.model.needConvertNotes && self.tabViewIsDragging() == false {
|
|
|
- self.showConvertNotesProgress()
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
- if (self.view.window == nil) {
|
|
|
- return
|
|
|
- }
|
|
|
- if (self.model.password != nil) {
|
|
|
- if let data = self.listView.document?.unlock(withPassword: self.model.password), data {
|
|
|
- self.model.isSaveKeyChain = false
|
|
|
- if self.model.needConvertNotes && self.tabViewIsDragging() == false {
|
|
|
- self.showConvertNotesProgress()
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
|
|
|
- if self.view.window != nil && self.tabViewIsDragging() == false {
|
|
|
- self.passwordWindow = KMPasswordInputWindow.openWindow(window: self.view.window!, url: self.document!.documentURL) { [weak self] result , password in
|
|
|
- if (result == .cancel) {
|
|
|
- (self?.myDocument as? KMMainDocument)?.browser?.closeTab()
|
|
|
- return
|
|
|
- }
|
|
|
- self?.model.isSaveKeyChain = true
|
|
|
- self?.listView.document = self?.document
|
|
|
- self?.document?.unlock(withPassword: password)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if self.model.needConvertNotes && self.tabViewIsDragging() == false {
|
|
|
- self.showConvertNotesProgress()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func viewWillDisappearFunction() {
|
|
|
- if self.interactionMode != .presentation {
|
|
|
- self.removeEventMonitor()
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- func viewWillLayoutFunction() {
|
|
|
- if (KMTools.isFullScreen(self.view.window ?? NSWindow())) { // 全屏
|
|
|
- self.listView.backgroundColor = KMPreferenceManager.shared.displayBackgroundFullScreenColor
|
|
|
- } else {
|
|
|
- self.listView.backgroundColor = KMPreferenceManager.shared.displayBackgroundNormalColor
|
|
|
- }
|
|
|
- if let guideWC = self.guideInfoWindowController{
|
|
|
- var rect = self.view.window!.frame
|
|
|
- rect.size.height -= 20
|
|
|
- guideWC.window?.setFrame(rect, display: false)
|
|
|
- guideWC.window?.minSize = rect.size
|
|
|
- guideWC.window?.maxSize = rect.size
|
|
|
- guideWC.show()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func viewDidLoadOld() {
|
|
|
- mwcFlags.settingUpWindow = 1
|
|
|
-
|
|
|
- self.initToolbar()
|
|
|
-
|
|
|
- if (UserDefaults.standard.object(forKey: CPDFOfficeLeftSidePaneWidthKey) != nil) {
|
|
|
- UserDefaults.standard.set(256, forKey: CPDFOfficeLeftSidePaneWidthKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- }
|
|
|
- if (UserDefaults.standard.object(forKey: CPDFOfficeRightSidePaneWidthKey) != nil) {
|
|
|
- UserDefaults.standard.set(256, forKey: CPDFOfficeRightSidePaneWidthKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- }
|
|
|
-
|
|
|
- if (KMPreferenceManager.shared.openLastUnlockedDocumentWhenAppStart) {
|
|
|
- if (self.listView.document != nil) {
|
|
|
- let pageNumber = KMPreferenceManager.shared.getPageNumber(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
- let pageScale = KMPreferenceManager.shared.getPageScale(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
- if (pageNumber != nil && pageNumber! >= 0 && pageNumber! < (self.listView.document?.pageCount ?? 0)) {
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
|
|
- if (pageScale != nil) {
|
|
|
- self.listView.scaleFactor = CGFloat(pageScale!)
|
|
|
- }
|
|
|
- self.listView.go(toPageIndex: pageNumber!, animated: false)
|
|
|
- }
|
|
|
- } else {
|
|
|
- self._goToFirstPageForFristAppear()
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- self._goToFirstPageForFristAppear()
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(rename(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerRename"), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(closeTab(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseTabs"), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(showInFinder(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerShowInFinder"), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(preferenceDidChangeNotification), name: KMPreferenceManager.didChangeNotification, object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(documentDidUnlockNotification), name: Notification.Name("CPDFDocumentDidUnlockNotification"), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(annotationsAttributeHasChange), name: NSNotification.Name.CPDFListViewAnnotationsAttributeHasChange, object:nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminateNotification), name: NSApplication.willTerminateNotification, object: nil)
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(CEditPDFToolModeChangeStateUnkownNotification), name: Notification.Name.init("CEditPDFToolModeChangeStateUnkown"), object: nil)
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(handlePageChangedNotification), name: NSNotification.Name.CPDFViewPageChanged, object: self.listView)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(handleDisplayBoxChangedNotification), name: NSNotification.Name.CPDFViewDisplayBoxChanged, object: self.listView)
|
|
|
-
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(didAddContentViewNotification), name: NSWindow.didAddContentViewNotification, object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(addAutoSaveEvent), name: AutoSaveManager.kTimeValueChangedNotificationName, object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(didRemoveAnnotationNotification), name: NSNotification.Name.CPDFPageDidRemoveAnnotation, object: nil)
|
|
|
-
|
|
|
- Task {
|
|
|
- self.addAutoSaveEvent()
|
|
|
- }
|
|
|
-
|
|
|
- self.toggleCloseRightSide()
|
|
|
-
|
|
|
- self.addKeyEventMonitor()
|
|
|
-
|
|
|
- self.addAdsBannerView()
|
|
|
-
|
|
|
- var snapshotSetups: NSArray?
|
|
|
- if KMPreferenceManager.shared.rememberSnapshot {
|
|
|
- if let fileUrl = (self.myDocument as? KMMainDocument)?.fileURL {
|
|
|
- snapshotSetups = SKBookmarkController.shared().snapshotsForRecentDocument(at: fileUrl) as NSArray?
|
|
|
- }
|
|
|
- }
|
|
|
- if let cnt = snapshotSetups?.count, cnt > 0 {
|
|
|
- if let data = self.listView.document?.isLocked, data {
|
|
|
- self.savedNormalSetup.setObject(snapshotSetups as Any, forKey: "snapshots" as NSCopying)
|
|
|
- } else {
|
|
|
- self.showSnapshots(setups: snapshotSetups)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let readModel = UserDefaults.standard.bool(forKey: "kKMPDFViewIsReadMode")
|
|
|
- if readModel == true {
|
|
|
- self.openPDFReadMode()
|
|
|
- }
|
|
|
-
|
|
|
- let hasWindowSetup = savedNormalSetup.count > 0
|
|
|
- if UserDefaults.standard.dictionary(forKey: KMDefaultPDFDisplaySettingsKey) != nil {
|
|
|
- let pdfSettings: NSDictionary = hasWindowSetup ? savedNormalSetup : UserDefaults.standard.dictionary(forKey: KMDefaultPDFDisplaySettingsKey)! as NSDictionary
|
|
|
- self.applyPDFSettings(pdfSettings)
|
|
|
- } else {
|
|
|
- self.applyPDFSettings(savedNormalSetup)
|
|
|
- }
|
|
|
-
|
|
|
- //文字
|
|
|
- let fontManager = NSFontManager.shared
|
|
|
- fontManager.target = self
|
|
|
- fontManager.action = #selector(changeFont(_:))
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //MARK: - PDFListView
|
|
|
-
|
|
|
- func initPDFLeftViewVC() {
|
|
|
- var frame = self.leftView.frame
|
|
|
- frame.size.width += 44
|
|
|
- self.leftView.frame = frame
|
|
|
- leftSideViewController.isFirst = true
|
|
|
- leftSideViewController.listView = self.listView
|
|
|
- leftSideViewController.view.frame = CGRect(x: 0, y:0 , width: self.leftView.frame.size.width, height: self.leftView.frame.size.height)
|
|
|
- leftSideViewController.view.autoresizingMask = [.height,.width]
|
|
|
- leftSideViewController.delegate = self
|
|
|
- self.leftView.addSubview(leftSideViewController.view)
|
|
|
- }
|
|
|
-
|
|
|
- func addAdsBannerView() {
|
|
|
-#if VERSION_FREE
|
|
|
- if !IAPProductsManager.default().isAvailableAllFunction(){
|
|
|
- guard let document = self.listView.document else {
|
|
|
- return
|
|
|
- }
|
|
|
- if !document.isLocked {
|
|
|
- }
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(purchaseStateUpdateNoti), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(purchaseStateUpdateNoti), name: NSNotification.Name(rawValue: "kDeviceActivateNotification"), object: nil)
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-#endif
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // MARK: Private Methods
|
|
|
-
|
|
|
- private func _isArabicLanguage() -> Bool {
|
|
|
- return NSLocalizedString("Right click a color and select “Change Color...“.", comment: "") == "انقر بزر الماوس الأيمن فوق اللون وحدد \"تغيير اللون...\"."
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
internal func removeNotifications() {
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
self.leftSideViewController.clearAnnotationFilterData()
|
|
|
self.leftSideViewController.clearNotification()
|
|
|
}
|
|
|
-
|
|
|
- func checkShouldAutoOpenLeftVC() {
|
|
|
- if KMPreference.shared.showLeftSideBar == false {
|
|
|
- return
|
|
|
- }
|
|
|
- if self.model.leftPanelOpen {
|
|
|
- return
|
|
|
- }
|
|
|
- let readModel = UserDefaults.standard.bool(forKey: "kKMPDFViewIsReadMode")
|
|
|
- if readModel == true {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- DispatchQueue.main.async {
|
|
|
- self.leftSideViewController.showThumbnail()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
func removeAllAnnotations() {
|
|
|
let alert = NSAlert()
|
|
|
alert.messageText = NSLocalizedString("This will permanently remove all annotations. Are you sure to continue?", comment: "")
|
|
@@ -5150,30 +4886,7 @@ extension KMMainViewController {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- // MARK: - Toolbar
|
|
|
-
|
|
|
- func toolbarItemClickForExitMode(_ toolbarItem: KMToolbarItemView) {
|
|
|
- if(toolbarItem.itemIdentifier != KMDocumentPageToolbarItemIdentifier) {
|
|
|
- if (hasEnterPageEdit()) {
|
|
|
- self.exitPageEdit()
|
|
|
- }
|
|
|
- }
|
|
|
- if toolbarItem.itemIdentifier != KMDocumentRedactToolbarItemIdentifier {
|
|
|
- if self.hasEnterRedact() {
|
|
|
- self.exitRedact()
|
|
|
- }
|
|
|
- }
|
|
|
- if toolbarItem.itemIdentifier != KMDocumentDigitalSignToolbarItemIdentifier {
|
|
|
- if self.hasShowDigitalSign() {
|
|
|
- self.exitDigitalSign()
|
|
|
- }
|
|
|
- }
|
|
|
- if toolbarItem.itemIdentifier != KMDocumentEditToolbarItemIdentifier && toolbarItem.itemIdentifier != KMRightControlToolbarItemIdentifier && toolbarItem.itemIdentifier != KMLeftControlToolbarItemIdentifier {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
// MARK: - Private Methods
|
|
|
|
|
|
private func getPDFEditController() -> KMPDFEditViewController? {
|
|
@@ -5199,8 +4912,7 @@ extension KMMainViewController {
|
|
|
}
|
|
|
|
|
|
private func addBackgroundMaskView() {
|
|
|
- self.removeBackgroundMaskView()
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -5294,52 +5006,13 @@ extension KMMainViewController {
|
|
|
}
|
|
|
|
|
|
// MARK: - Secure 【安全】
|
|
|
-
|
|
|
- public func showSecureLimitTip() {
|
|
|
- self.hiddenSecureLimitTip()
|
|
|
-
|
|
|
- if self.secureAlertView == nil {
|
|
|
- self.secureAlertView = KMSecureAlertView()
|
|
|
- self.secureAlertView?.show(in: self.listView)
|
|
|
- self.secureAlertView?.closeAction = { [unowned self] view in
|
|
|
- self.hiddenSecureLimitTip()
|
|
|
-
|
|
|
- self.removeFromAlertView()
|
|
|
- self.showFormAlertView()
|
|
|
- }
|
|
|
-
|
|
|
- self.secureAlertView?.passwordAction = { [unowned self] view in
|
|
|
- self.removeOwnerPassword()
|
|
|
-
|
|
|
- self.removeFromAlertView()
|
|
|
- self.showFormAlertView()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
|
|
|
public func hiddenSecureLimitTip() {
|
|
|
self.secureAlertView?.removeFromSuperview()
|
|
|
self.secureAlertView = nil
|
|
|
}
|
|
|
-
|
|
|
- //MARK: - Form
|
|
|
-
|
|
|
- func showFormAlertView() {
|
|
|
- if (formAlertView == nil) {
|
|
|
- formAlertView = KMFormAlertView()
|
|
|
- formAlertView?.isCloseSecureView = self.secureAlertView != nil ? false : true
|
|
|
- formAlertView?.showInView(self.listView)
|
|
|
- } else {
|
|
|
- self.removeFromAlertView()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func removeFromAlertView() {
|
|
|
- formAlertView?.removeFromSuperview()
|
|
|
- formAlertView = nil
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
override func mouseMoved(with event: NSEvent) {
|
|
|
self.view.window?.mouseMoved(with: event)
|
|
|
}
|
|
@@ -5827,24 +5500,11 @@ extension KMMainViewController {
|
|
|
self._secureOptions = nil
|
|
|
self.documentAttribute = nil
|
|
|
}
|
|
|
-
|
|
|
- public func recordRemoveSecureFlag() {
|
|
|
- self._removeSecureFlag = true
|
|
|
- self.clearSecureOptions()
|
|
|
- self.recordIsPDFDocumentEdited(type: .removePassword)
|
|
|
- self._needSave = true
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
public func clearRemoveSecureFlag() {
|
|
|
self._removeSecureFlag = false
|
|
|
}
|
|
|
|
|
|
- public func clearSaveWatermarkFlag() {
|
|
|
- km_synchronized(self) {
|
|
|
- self._saveWatermarkFlag = false
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public func recordIsPDFDocumentEdited(type: KMSubscribeWaterMarkType = .none) {
|
|
|
km_synchronized(self) {
|
|
|
self.model.isPDFDocumentEdited = true
|
|
@@ -5876,41 +5536,7 @@ extension KMMainViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- func dealDocumentDidLoaded() {
|
|
|
- self.removeBackgroundMaskView()
|
|
|
- if (!self.listView.document!.allowsCopying || !self.listView.document!.allowsPrinting) {
|
|
|
- self.showSecureLimitTip()
|
|
|
- }
|
|
|
-
|
|
|
- if self.model.needConvertNotes {
|
|
|
- self.showConvertNotesProgress()
|
|
|
- }
|
|
|
- if (self._documentFirstLoad) {
|
|
|
- self.checkShouldAutoOpenLeftVC()
|
|
|
- if (KMPreferenceManager.shared.openLastUnlockedDocumentWhenAppStart) {
|
|
|
- let pageNumber = KMPreferenceManager.shared.getPageNumber(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
- let pageScale = KMPreferenceManager.shared.getPageScale(forKey: self.listView.document?.documentURL.path ?? "")
|
|
|
- if (pageScale != nil) {
|
|
|
- self.listView.scaleFactor = CGFloat(pageScale!)
|
|
|
- }
|
|
|
- if (pageNumber != nil && pageNumber! >= 0 && pageNumber! < (self.listView.document?.pageCount ?? 0)) {
|
|
|
- self.listView.go(toPageIndex: pageNumber!, animated: false)
|
|
|
- } else {
|
|
|
- self._goToFirstPageForFristAppear()
|
|
|
- }
|
|
|
- } else {
|
|
|
- self._goToFirstPageForFristAppear()
|
|
|
- }
|
|
|
- self._documentFirstLoad = false
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func tabViewIsDragging() -> Bool {
|
|
|
- let level = self.view.window?.level ?? .normal
|
|
|
- return level == .floating
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
// MARK: - Noti Actions
|
|
|
|
|
|
internal func documentDidUnlockNotification(_ sender: Notification) {
|