Prechádzať zdrojové kódy

【工具栏】- 手动输入缩放比例,回车生效

liaoxiaoyue 1 rok pred
rodič
commit
513382de4b

+ 5 - 0
PDF Office/PDF Office/Class/PDFWindowController/Toolbar/KMToolbarController.swift

@@ -19,6 +19,7 @@ import Cocoa
     @objc optional func changePDFViewGoToPreviousPageAction()
     @objc optional func showPDFViewPrintViewController()
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomModel selectedTag:Int)
+    @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String)
     @objc optional func mainToolDidClicked(_ toolController: KMToolbarController, _ type: KMToolbarViewType, _ item: KMToolBoxItem)
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareDocument item:NSMenuItem)
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareFlatten item:NSMenuItem)
@@ -392,6 +393,10 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
     func toolbarViewController(_ viewController: KMToolbarViewController, zoomModel selectedTag: Int) {
         self.delegate?.toolbarViewController?(viewController, zoomModel: selectedTag)
     }
+
+    func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String) {
+        self.delegate?.toolbarViewController?(viewController, zoomSting: zoomSting)
+    }
     
     func changePDFViewZoomInAction() {
         self.delegate?.changePDFViewZoomInAction?()

+ 10 - 1
PDF Office/PDF Office/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -58,6 +58,7 @@ import Cocoa
     @objc optional func changePDFViewGotoNextPageAction()
     @objc optional func changePDFViewGoToPreviousPageAction()
     @objc optional func showPDFViewPrintViewController()
+    @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomSting : String)
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, zoomModel selectedTag:Int)
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareDocument item:NSMenuItem)
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, shareFlatten item:NSMenuItem)
@@ -68,7 +69,7 @@ import Cocoa
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, rightPanel toolbarItem: KMToolBoxItem)
 }
 
-class KMToolbarViewController: NSViewController {
+class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
 
     var toolbar : KMToolbar!
     var toolbarType : KMToolbarViewType = KMToolbarViewType.None
@@ -83,6 +84,7 @@ class KMToolbarViewController: NSViewController {
     var shareButton = KMToolbarClickButton()
     override func viewDidLoad() {
         super.viewDidLoad()
+        self.zoomTextField.delegate = self
         NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewAnnotationTypeChangeNotification"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(listViewAnnotationTypeChangeNotification), name: Notification.Name("CPDFListViewToolModeChangeNotification"), object: nil)
     }
@@ -267,6 +269,13 @@ class KMToolbarViewController: NSViewController {
         }
         return KMToolBoxItem()
     }
+    
+    func controlTextDidEndEditing(_ obj: Notification) {
+        let textField = obj.object as? NSTextField
+        if textField == self.zoomTextField {
+            self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
+        }
+    }
 }
 
 extension KMToolbarViewController : KMNewToolbarDelegate,NSToolbarItemValidation {

+ 6 - 1
PDF Office/PDF Office/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1157,7 +1157,7 @@ extension KMMainViewController {
     
     // 开启/关闭右边栏
     @objc func toggleRightPane() -> Void {
-        if lastRightPanWidth > 1 {
+        if lastRightPanWidth > 5 {
             applyLeftSideWidth(lastLeftPanWidth, rightSideWidth: 0)
         } else {
             applyLeftSideWidth(lastLeftPanWidth, rightSideWidth: defaultRightWidth)
@@ -1362,6 +1362,11 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
        viewController.zoomTextField.stringValue =  "\(Int(self.listView.scaleFactor*100))%"
     }
     
+    func toolbarViewController(_ viewController: KMToolbarViewController, zoomSting: String) {
+        self.listView.scaleFactor = CGFloat((NSString(string: zoomSting)).floatValue / 100.0)
+        viewController.zoomTextField.stringValue =  "\(Int(self.listView.scaleFactor*100))%"
+    }
+    
     func changePDFViewZoomInAction() {
         self.listView.zoomIn(nil)
         self.updateZoomInOutButtonState()