|
@@ -8,6 +8,14 @@
|
|
|
import Cocoa
|
|
|
import KMComponentLibrary
|
|
|
|
|
|
+let MIN_SIDE_PANE_WIDTH: CGFloat = 264.0 // 最小值
|
|
|
+let CPDFViewIsReadModeKey = "kKMPDFViewIsReadMode"
|
|
|
+let CPDFViewLeftSidePaneWidthKey = "CPDFOfficeLeftSidePaneWidthKey"
|
|
|
+
|
|
|
+struct KMNMWCFlags {
|
|
|
+ var settingUpWindow: Bool = true
|
|
|
+}
|
|
|
+
|
|
|
@objcMembers class KMMainViewController: KMBaseViewController, NSTextFieldDelegate {
|
|
|
|
|
|
@IBOutlet var contendBox: NSBox!
|
|
@@ -38,6 +46,8 @@ import KMComponentLibrary
|
|
|
var document: CPDFDocument?
|
|
|
var myDocument: NSDocument?
|
|
|
|
|
|
+ var isFirstOpen: Bool = true
|
|
|
+
|
|
|
var insertDocuments: Set<CPDFDocument> = [] //插入新文档时,SDK会出现崩溃,临时记录
|
|
|
|
|
|
//工具栏
|
|
@@ -139,6 +149,7 @@ import KMComponentLibrary
|
|
|
return self.model.isPDFDocumentEdited
|
|
|
}
|
|
|
}
|
|
|
+ var newMwcFlags = KMNMWCFlags(settingUpWindow: true)
|
|
|
|
|
|
var leftSideViewController: KMLeftSideViewController = KMLeftSideViewController.init(type: KMLeftMethodMode())
|
|
|
var searchResults: [KMSearchMode] = []
|
|
@@ -156,7 +167,7 @@ import KMComponentLibrary
|
|
|
|
|
|
let CPDFOfficeLeftSidePaneWidthKey = "CPDFOfficeLeftSidePaneWidthKey"
|
|
|
let CPDFOfficeRightSidePaneWidthKey = "CPDFOfficeRightSidePaneWidthKey"
|
|
|
-
|
|
|
+
|
|
|
var extract: KMExtractImageWindowController?
|
|
|
|
|
|
var functionWidth: Double {
|
|
@@ -274,15 +285,14 @@ import KMComponentLibrary
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
// Do view setup here.
|
|
|
+
|
|
|
+ setupData()
|
|
|
|
|
|
- toolbarManager.pdfViewManager = viewManager
|
|
|
+ setupUI()
|
|
|
}
|
|
|
|
|
|
override func viewDidAppear() {
|
|
|
super.viewDidAppear()
|
|
|
-
|
|
|
- setupUI()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//MARK: - private
|
|
@@ -297,14 +307,51 @@ import KMComponentLibrary
|
|
|
setUpSplitView()
|
|
|
}
|
|
|
|
|
|
+ func setupData() {
|
|
|
+ toolbarManager.pdfViewManager = viewManager
|
|
|
+
|
|
|
+ if (UserDefaults.standard.object(forKey: CPDFViewLeftSidePaneWidthKey) != nil) {
|
|
|
+ UserDefaults.standard.set(MIN_SIDE_PANE_WIDTH, forKey: CPDFViewLeftSidePaneWidthKey)
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+ }
|
|
|
+
|
|
|
+ newMwcFlags.settingUpWindow = true
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: - document load成功
|
|
|
private func documentLoadComplete() {
|
|
|
+ loadUserDefaultsData()
|
|
|
|
|
|
initLeftSideController()
|
|
|
+
|
|
|
+ activityLoadMethod()
|
|
|
+
|
|
|
+ newMwcFlags.settingUpWindow = false
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: - 活动加载相关
|
|
|
+ private func activityLoadMethod() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private func loadUserDefaultsData() {
|
|
|
+ applyLeftSideWidth(0, rightSideWidth: 0) //初始打开左边栏
|
|
|
+
|
|
|
+ let readModel = UserDefaults.standard.bool(forKey: CPDFViewIsReadModeKey)
|
|
|
+ if readModel == true {
|
|
|
+ self.openPDFReadMode()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func applyLeftSideWidth(_ leftSideWidth: CGFloat, rightSideWidth: CGFloat) -> Void {
|
|
|
+ infoContendSplitView.setPosition(infoContendSplitView.maxPossiblePositionOfDivider(at: 1) - infoContendSplitView.dividerThickness - rightSideWidth, ofDividerAt: 1)
|
|
|
+ infoContendSplitView.setPosition(leftSideWidth, ofDividerAt: 0)
|
|
|
}
|
|
|
|
|
|
//MARK: - PDFView
|
|
|
func initPDFView() {
|
|
|
listView.autoresizingMask = [.width, .height]
|
|
|
+ listView.autoScales = true
|
|
|
listView.delegate = self
|
|
|
listView.pdfListViewDelegate = self
|
|
|
listView.document = self.document
|
|
@@ -433,10 +480,6 @@ import KMComponentLibrary
|
|
|
infoContendSplitView.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
infoContendSplitView.delegate = self
|
|
|
infoContendSplitView.layer?.masksToBounds = true
|
|
|
-
|
|
|
- infoContendSplitView.setPosition(-10, ofDividerAt: 0)
|
|
|
- infoContendSplitView.setPosition(CGRectGetWidth(infoContendSplitView.frame), ofDividerAt: 1)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
func setupSplitPDFController() {
|
|
@@ -537,12 +580,13 @@ import KMComponentLibrary
|
|
|
}
|
|
|
|
|
|
private func leftSidePaneIsOpen() -> Bool {
|
|
|
- return infoContendSplitView.isSubviewCollapsed(infoSplitLeftView)
|
|
|
+ return !infoContendSplitView.isSubviewCollapsed(infoSplitLeftView) //第一次点击时存在问题,待解决
|
|
|
}
|
|
|
|
|
|
private func toggleOpenLeftSide(pdfSideBarType: KMPDFSidebarType) {
|
|
|
if(leftSidePaneIsOpen() == false) {
|
|
|
- infoContendSplitView.setPosition(264, ofDividerAt: 0)
|
|
|
+ let leftWidthNumber = UserDefaults.standard.object(forKey: CPDFViewLeftSidePaneWidthKey) as? NSNumber ?? NSNumber(value: MIN_SIDE_PANE_WIDTH)
|
|
|
+ infoContendSplitView.setPosition(leftWidthNumber.doubleValue, ofDividerAt: 0)
|
|
|
}
|
|
|
if pdfSideBarType == .search {
|
|
|
KMPrint(" search")
|
|
@@ -562,7 +606,7 @@ import KMComponentLibrary
|
|
|
|
|
|
private func toggleCloseLeftSide() {
|
|
|
if(leftSidePaneIsOpen() == true) {
|
|
|
- infoContendSplitView.setPosition(-20, ofDividerAt: 0)
|
|
|
+ infoContendSplitView.setPosition(0, ofDividerAt: 0)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -571,7 +615,7 @@ import KMComponentLibrary
|
|
|
if rightSideController == nil {
|
|
|
rightSideController = KMRightSideController.init()
|
|
|
}
|
|
|
- rightSideController?.view.frame = CGRectMake(0, 0, 264, 680)
|
|
|
+ rightSideController?.view.frame = CGRectMake(0, 0, MIN_SIDE_PANE_WIDTH, 680)
|
|
|
rightSideController?.view.autoresizingMask = [.height, .maxXMargin]
|
|
|
}
|
|
|
|
|
@@ -583,10 +627,10 @@ import KMComponentLibrary
|
|
|
@objc func toggleOpenRightSide() -> Void {
|
|
|
initRightSideController()
|
|
|
|
|
|
- rightSideController?.view.frame = CGRectMake(CGRectGetWidth(bottomContendBox.frame)-264, 0, 264, CGRectGetHeight(bottomContendBox.frame))
|
|
|
+ rightSideController?.view.frame = CGRectMake(CGRectGetWidth(bottomContendBox.frame)-MIN_SIDE_PANE_WIDTH, 0, MIN_SIDE_PANE_WIDTH, CGRectGetHeight(bottomContendBox.frame))
|
|
|
bottomContendBox.addSubview(rightSideController!.view)
|
|
|
|
|
|
- infoSplitViewRightConst.constant = 264
|
|
|
+ infoSplitViewRightConst.constant = MIN_SIDE_PANE_WIDTH
|
|
|
|
|
|
rightSideController?.viewManager = self.viewManager
|
|
|
|
|
@@ -602,7 +646,7 @@ import KMComponentLibrary
|
|
|
func updatePDFDisplaySettingView() {
|
|
|
|
|
|
if viewManager.showDisplayView {
|
|
|
- infoSplitViewLeftConst.constant = 264
|
|
|
+ infoSplitViewLeftConst.constant = MIN_SIDE_PANE_WIDTH
|
|
|
} else {
|
|
|
infoSplitViewLeftConst.constant = 44
|
|
|
}
|
|
@@ -611,7 +655,7 @@ import KMComponentLibrary
|
|
|
if displaySettingController == nil {
|
|
|
displaySettingController = KMNDisplayViewController.init()
|
|
|
}
|
|
|
- displaySettingController?.view.frame = CGRectMake(0, 0, 264, CGRectGetHeight(bottomContendBox.frame))
|
|
|
+ displaySettingController?.view.frame = CGRectMake(0, 0, MIN_SIDE_PANE_WIDTH, CGRectGetHeight(bottomContendBox.frame))
|
|
|
displaySettingController?.view.autoresizingMask = [.height, .maxXMargin]
|
|
|
bottomContendBox.addSubview(displaySettingController!.view)
|
|
|
displaySettingController?.pdfView = self.listView
|
|
@@ -1527,45 +1571,61 @@ import KMComponentLibrary
|
|
|
//MARK: - NSSplitViewDelegate
|
|
|
extension KMMainViewController: NSSplitViewDelegate {
|
|
|
|
|
|
- func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
|
|
|
- return true
|
|
|
-
|
|
|
+ func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
|
|
|
+ if splitView == infoContendSplitView {
|
|
|
+ return subview.isEqual(to: infoSplitCenterView) == false
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
- func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
|
|
|
- return true
|
|
|
+ func splitView(_ splitView: NSSplitView, shouldCollapseSubview subview: NSView, forDoubleClickOnDividerAt dividerIndex: Int) -> Bool {
|
|
|
+ if splitView == infoContendSplitView {
|
|
|
+ if(subview.isEqual(to: infoSplitLeftView)) {
|
|
|
+
|
|
|
+ } else if(subview.isEqual(to: infoSplitRightView)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
|
|
|
+ if splitView == infoContendSplitView {
|
|
|
+ return splitView == infoContendSplitView
|
|
|
+ } else if splitView == pdfSplitView {
|
|
|
+ return splitView == pdfSplitView
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
func splitView(_ splitView: NSSplitView, constrainMaxCoordinate proposedMaximumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
|
|
|
-
|
|
|
+ if(splitView == infoContendSplitView && dividerIndex == 1) {
|
|
|
+ return proposedMaximumPosition - MIN_SIDE_PANE_WIDTH
|
|
|
+ }
|
|
|
return proposedMaximumPosition
|
|
|
}
|
|
|
|
|
|
func splitView(_ splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
|
|
|
- return proposedMinimumPosition
|
|
|
- }
|
|
|
-
|
|
|
- func splitView(_ splitView: NSSplitView, constrainSplitPosition proposedPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
|
|
|
- if dividerIndex == 0 {
|
|
|
- if proposedPosition > CGRectGetWidth(infoContendSplitView.frame)/2 - 10 {
|
|
|
- print(CGRectGetWidth(infoContendSplitView.frame)/2 - 10, NSDate())
|
|
|
- return CGRectGetWidth(infoContendSplitView.frame)/2 - 10
|
|
|
- }
|
|
|
- } else if dividerIndex == 1 {
|
|
|
- print(CGRectGetWidth(infoContendSplitView.frame)/2 - 10, NSDate())
|
|
|
-
|
|
|
+ if(splitView == infoContendSplitView && dividerIndex == 0) {
|
|
|
+ return proposedMinimumPosition + MIN_SIDE_PANE_WIDTH
|
|
|
}
|
|
|
- return proposedPosition
|
|
|
+ return proposedMinimumPosition
|
|
|
}
|
|
|
|
|
|
func splitViewDidResizeSubviews(_ notification: Notification) {
|
|
|
let splitView = notification.object as? NSSplitView
|
|
|
- if((splitView?.isEqual(to: infoContendSplitView)) == true) {
|
|
|
+ if(splitView == infoContendSplitView) {
|
|
|
leftSplitViewResizeFinish()
|
|
|
+
|
|
|
+ if(newMwcFlags.settingUpWindow == false && self.view.window?.frameAutosaveName != nil) {
|
|
|
+ let leftWidth = infoContendSplitView.isSubviewCollapsed(infoSplitLeftView) ? 0.0 : infoSplitLeftView.frame.width
|
|
|
+ UserDefaults.standard.set(leftWidth, forKey: CPDFViewLeftSidePaneWidthKey)
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(splitViewResizeFinish), object: nil)
|
|
|
self.perform(#selector(splitViewResizeFinish), with: nil, afterDelay: 0.15)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@objc func leftSplitViewResizeFinish() {
|
|
@@ -3749,11 +3809,6 @@ extension KMMainViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func applyLeftSideWidth(_ leftSideWidth: CGFloat, rightSideWidth: CGFloat) -> Void {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
func removeAllAnnotations() {
|
|
|
let alert = NSAlert()
|
|
|
alert.messageText = NSLocalizedString("This will permanently remove all annotations. Are you sure to continue?", comment: "")
|