Преглед на файлове

【toolbar】对齐item替换UI

tangchao преди 1 година
родител
ревизия
a5548ecce5

+ 0 - 16
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -340,22 +340,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "E33CE6EB-AF37-4B1D-89A4-DB97337F719D"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "374"
-            endingLineNumber = "374"
-            landmarkName = "scanOCRModelSelect(sender:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent

+ 8 - 8
PDF Office/PDF Master/Class/Batch/Catogary/NSWindow+PopOver.swift

@@ -7,21 +7,21 @@
 
 import Foundation
 
-let KMWindowPopOverKey = "KMWindowPopOverKey"
-let KMWindowPopOverSourcesRectKey = "KMWindowPopOverSourcesRectKey"
+var KMWindowPopOverKey = "KMWindowPopOverKey"
+var KMWindowPopOverSourcesRectKey = "KMWindowPopOverSourcesRectKey"
 extension NSWindow {
     var popover: NSPopover? {
         get {
-            return objc_getAssociatedObject(self,KMWindowPopOverKey) as? NSPopover
+            return objc_getAssociatedObject(self, &KMWindowPopOverKey) as? NSPopover
         }
         set {
-            objc_setAssociatedObject(self, KMWindowPopOverKey, newValue, .OBJC_ASSOCIATION_RETAIN)
+            objc_setAssociatedObject(self, &KMWindowPopOverKey, newValue, .OBJC_ASSOCIATION_RETAIN)
         }
     }
     
     var sourcesRect: CGRect? {
         get {
-            guard let value = objc_getAssociatedObject(self, KMWindowPopOverSourcesRectKey) as? NSValue else {
+            guard let value = objc_getAssociatedObject(self, &KMWindowPopOverSourcesRectKey) as? NSValue else {
                 return nil
             }
             return value.rectValue
@@ -29,9 +29,9 @@ extension NSWindow {
         set {
             if let newValue = newValue {
                 let value = NSValue(rect: newValue)
-                objc_setAssociatedObject(self, KMWindowPopOverSourcesRectKey, value, .OBJC_ASSOCIATION_RETAIN)
+                objc_setAssociatedObject(self, &KMWindowPopOverSourcesRectKey, value, .OBJC_ASSOCIATION_RETAIN)
             } else {
-                objc_setAssociatedObject(self, KMWindowPopOverSourcesRectKey, nil, .OBJC_ASSOCIATION_RETAIN)
+                objc_setAssociatedObject(self, &KMWindowPopOverSourcesRectKey, nil, .OBJC_ASSOCIATION_RETAIN)
             }
         }
     }
@@ -40,7 +40,7 @@ extension NSWindow {
         super.mouseMoved(with: event)
         let point = event.locationInWindow
         if NSStringFromClass(event.window!.classForCoder).elementsEqual("_NSPopoverWindow") == false {
-            if !sourcesRect!.contains(point) {
+            if let data = sourcesRect?.contains(point), data == false {
                 if (self.popover != nil) {
                     NotificationCenter.default.post(name: NSNotification.Name("KMPopOverClosedByWindowNotification"), object: self.popover)
                     popover!.close()

+ 15 - 19
PDF Office/PDF Master/Class/Common/Category/View/NSMenu+KMExtension.swift

@@ -53,22 +53,23 @@ extension NSMenu {
 //    func addItem_r(withTitle title: String, action: Selector?, target: AnyObject?) -> NSMenuItem {
 //        return self.addItem(title: title, action: action, target: target)
 //    }
+    
+    func insertItem(title: String, imageNamed: String?, action: Selector?, target: AnyObject?, tag: Int, atIndex: Int) -> NSMenuItem? {
+        let item = NSMenuItem(title: title, imageNamed: imageNamed, action: action, target: target, tag: tag)
+        self.insertItem(item, at: atIndex)
+        return item
+    }
+    
+    func addItem(title: String, imageNamed: String?, action: Selector?, target: AnyObject?, tag: Int) {
+        _ = self.addItem_r(title: title, imageNamed: imageNamed, action: action, target: target, tag: tag)
+    }
+    
+    func addItem_r(title: String, imageNamed: String?, action: Selector?, target: AnyObject?, tag: Int) -> NSMenuItem? {
+        return self.insertItem(title: title, imageNamed: imageNamed, action: action, target: target, tag: tag, atIndex: self.numberOfItems)
+    }
 }
 
 /*
- + (NSMenu *)menu {
-     return [[NSMenu alloc] initWithTitle:@""];
- }
-
- - (NSMenuItem *)insertItemWithTitle:(NSString *)aString imageNamed:(NSString *)anImageName action:(SEL)aSelector target:(id)aTarget tag:(NSInteger)aTag atIndex:(NSInteger)anIndex {
-     NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:aString imageNamed:anImageName action:aSelector target:aTarget tag:aTag];
-     [self insertItem:item atIndex:anIndex];
-     return item;
- }
-
- - (NSMenuItem *)addItemWithTitle:(NSString *)aString imageNamed:(NSString *)anImageName action:(SEL)aSelector target:(id)aTarget tag:(NSInteger)aTag {
-     return [self insertItemWithTitle:aString imageNamed:anImageName action:aSelector target:aTarget tag:aTag atIndex:[self numberOfItems]];
- }
 
  - (NSMenuItem *)insertItemWithSubmenuAndTitle:(NSString *)aString atIndex:(NSInteger)anIndex {
      NSMenuItem *item = [[NSMenuItem alloc] initWithSubmenuAndTitle:aString];
@@ -76,12 +77,7 @@ extension NSMenu {
      return item;
  }
 
- - (NSMenuItem *)addItemWithTitle:(NSString *)aString forView:(NSView*)view action:(SEL)aSelector target:(id)aTarget tag:(NSInteger)aTag atIndex:(NSInteger)anIndex {
-     NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:aString inView:view action:aSelector target:aTarget tag:aTag];
-     [self insertItem:item atIndex:anIndex];
-     return item;
-     
- }
+
 
  - (NSMenuItem *)addItemWithSubmenuAndTitle:(NSString *)aString {
      return [self insertItemWithSubmenuAndTitle:aString atIndex:[self numberOfItems]];

+ 24 - 33
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMCustomButtonPopMenuViewController.swift

@@ -54,21 +54,13 @@ import Masonry
         for i in 0..<numberOfLine {
             var image: NSImage?
             var title: String?
-            
-//            if self.responds(to: Selector.init(("imageForLineAtIndex:"))) {
-//                image = self.dataSources?.imageForLine(at: i)
-//                title = self.dataSources?.stringForLine(at: i)
-//            }
             if let data = self.dataSources?.imageForLine(at: i) {
                 image = data
             }
             if let data = self.dataSources?.stringForLine(at: i) {
                 title = data
             }
-//            if self.responds(to: Selector.init(("stringForLineAtIndex:"))) {
-//                title = self.dataSources?.stringForLine(at: i)
-//            }
-
+            
             var v: KMPopMenuButton
             if let image1 = image {
                 v = KMPopMenuButton(title: title!, image: image1, target: self, action: #selector(buttonClicked(_:)))
@@ -83,18 +75,30 @@ import Masonry
                 v.isEnabled = ((self.dataSources?.itemEnable(at: i)) != nil)
             }
             
-            self.view.addSubview(v)
-            
-            v.mas_makeConstraints { make in
-                if let viewBool = referenceView?.isEqual(self.view), viewBool  {
-                    make?.top.equalTo()(referenceView)?.offset()(CGFloat(10))
-                } else {
-                    make?.top.equalTo()(referenceView?.mas_bottom)?.offset()(CGFloat(2))
+            if let data = self.dataSources?.needInsertSeperateLine(at: i), data {
+                let box = NSBox(frame: .zero)
+                box.boxType = .separator
+                self.view.addSubview(box)
+                
+                box.mas_makeConstraints { make in
+                    make?.top.equalTo()(referenceView?.mas_bottom)?.offset()(2)
+                    make?.left.equalTo()(self.view)?.offset()(CGFloat(21))
+                    make?.centerX.equalTo()(self.view)
                 }
-                make?.left.right().equalTo()(self.view)
-                make?.height.offset()(24)
+                referenceView = box
+            } else {
+                self.view.addSubview(v)
+                v.mas_makeConstraints { make in
+                    if let viewBool = referenceView?.isEqual(self.view), viewBool  {
+                        make?.top.equalTo()(referenceView)?.offset()(CGFloat(10))
+                    } else {
+                        make?.top.equalTo()(referenceView?.mas_bottom)?.offset()(CGFloat(2))
+                    }
+                    make?.left.right().equalTo()(self.view)
+                    make?.height.offset()(24)
+                }
+                referenceView = v
             }
-            referenceView = v
             
             if self.responds(to: Selector.init(("needHightLightLineAtIndex:"))) {
                 if let needBool = self.dataSources?.needHightLightLine(at: i) {
@@ -102,20 +106,7 @@ import Masonry
                 }
             }
             
-            if self.responds(to: Selector.init(("needInsertSeperateLineAtIndex:"))) {
-                if let needBool = self.dataSources?.needInsertSeperateLine(at: i) {
-                    let box = NSBox(frame: .zero)
-                    box.boxType = .separator
-                    self.view.addSubview(box)
-                    
-                    box.mas_makeConstraints { make in
-                        make?.top.equalTo()(referenceView?.mas_bottom)?.offset()(2)
-                        make?.left.equalTo()(self.view)?.offset()(CGFloat(21))
-                        make?.centerX.equalTo()(self.view)
-                    }
-                    referenceView = box
-                }
-            }
+
             
             if i == numberOfLine - 1 {
                 referenceView?.mas_updateConstraints({ make in

+ 7 - 1
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarItemView.swift

@@ -600,7 +600,7 @@ extension KMToolbarItemView: KMCustomButtonPopMenuViewControllerDelegate, KMCust
 //        if (self.itemIdentifier == KMToolbarPageEditPageRangeItemIdentifier) {
             if let items = self.menuFormRepresentation?.submenu?.items {
                 let item = items[index]
-                item.target?.perform(item.action, with: item)
+                _ = item.target?.perform(item.action, with: item)
             }
 //        }
     }
@@ -624,6 +624,9 @@ extension KMToolbarItemView: KMCustomButtonPopMenuViewControllerDelegate, KMCust
     }
     
     func needInsertSeperateLine(at index: Int) -> Bool {
+        if let items = self.menuFormRepresentation?.submenu?.items {
+            return items[index].isSeparatorItem
+        }
         return false
     }
     
@@ -632,6 +635,9 @@ extension KMToolbarItemView: KMCustomButtonPopMenuViewControllerDelegate, KMCust
     }
     
     func imageForLine(at index: Int) -> NSImage? {
+        if let items = self.menuFormRepresentation?.submenu?.items {
+            return items[index].image
+        }
         return nil
     }
     

+ 22 - 0
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -379,6 +379,14 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
        
     }
     
+    @objc private func _alignmentAction(sender: NSMenuItem) {
+        if let data = self._currentItemView {
+            self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
+        } else {
+            self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolFormAlignIdentifier), index: sender.tag, info: nil)
+        }
+    }
+    
     // Form 更多操作
     @IBAction func formsMoreOperationAction(sender:KMToolbarClickButton) {
         
@@ -1388,9 +1396,23 @@ extension KMToolbarViewController {
             item?.toolTip = NSLocalizedString("Alignment", comment: "")
             item?.titleName = NSLocalizedString("Alignment", comment: "")
             item?.boxImagePosition = .imageExpandLeft
+            item?.needExpandAction = true
             item?.btnAction = #selector(formsAlignmentAction)
             
             let menuItem = NSMenuItem.init(title: "Alignment", action: #selector(formsAlignmentAction), target: self)
+            let subMenu = NSMenu()
+            subMenu.addItem(title: NSLocalizedString("Align Left", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignLeftNor", action: #selector(_alignmentAction), target: self, tag: 0)
+            subMenu.addItem(title: NSLocalizedString("Align Vertically", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignVercenterNor", action: #selector(_alignmentAction), target: self, tag: 1)
+            subMenu.addItem(title: NSLocalizedString("Align Right", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignRightNor", action: #selector(_alignmentAction), target: self, tag: 2)
+            subMenu.addItem(NSMenuItem.separator())
+            subMenu.addItem(title: NSLocalizedString("Align Top", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignUpNor", action: #selector(_alignmentAction), target: self, tag: 3)
+            subMenu.addItem(title: NSLocalizedString("Align Horizontally", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignHorcenterNor", action: #selector(_alignmentAction), target: self, tag: 4)
+            subMenu.addItem(title: NSLocalizedString("Align Bottom", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignDownNor", action: #selector(_alignmentAction), target: self, tag: 5)
+            subMenu.addItem(NSMenuItem.separator())
+            subMenu.addItem(title: NSLocalizedString("Distribute Horizontally", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignHorsplitNor", action: #selector(_alignmentAction), target: self, tag: 6)
+            subMenu.addItem(title: NSLocalizedString("Distribute Vertically", comment: ""), imageNamed: "KMImageNameUXIconPropertybarAlignVersplitNor", action: #selector(_alignmentAction), target: self, tag: 7)
+            
+            menuItem.submenu = subMenu
             menuItem.tag = item!.btnTag
             item?.menuFormRepresentation = menuItem
         } else if identifier == KMToolbarToolFormMoreIdentifier {

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -2956,6 +2956,8 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
             KMPrint("KMToolbarToolBatesItemIdentifier \(index)")
         } else if (toolbarItem.itemIdentifier == KMToolbarComparisonItemIdentifier) {
             KMPrint("KMToolbarComparisonItemIdentifier \(index)")
+        } else if (toolbarItem.itemIdentifier == KMToolbarToolFormAlignIdentifier) {
+            KMPrint("KMToolbarToolFormAlignIdentifier \(index)")
         }
     }