|
@@ -11,11 +11,11 @@ import KMComponentLibrary
|
|
|
@objc protocol KMPDFToolbarControllerDelegate: AnyObject {
|
|
|
|
|
|
@objc optional func kmPDFToolbarControllerDidToolbarItemClicked(_ controller: KMPDFToolbarController, _ itemIdentifier: String)
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
class KMPDFToolbarController: NSViewController {
|
|
|
-
|
|
|
+
|
|
|
@IBOutlet var contendBox: NSBox!
|
|
|
|
|
|
@IBOutlet var mainToolbarContendView: NSView!
|
|
@@ -33,9 +33,13 @@ class KMPDFToolbarController: NSViewController {
|
|
|
@IBOutlet var tabsMoreButton: ComponentButton!
|
|
|
|
|
|
@IBOutlet var rightToolsView: NSView!
|
|
|
-
|
|
|
+
|
|
|
@IBOutlet var secondContendView: NSView!
|
|
|
|
|
|
+ @IBOutlet var tabsLeftConst: NSLayoutConstraint!
|
|
|
+ @IBOutlet var tabsRightConst: NSLayoutConstraint!
|
|
|
+
|
|
|
+
|
|
|
@IBOutlet var rightViewWidthConst: NSLayoutConstraint!
|
|
|
|
|
|
var scrollDocumentView: NSView = NSView.init()
|
|
@@ -64,39 +68,48 @@ class KMPDFToolbarController: NSViewController {
|
|
|
private var convert_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Convert"), identifier: "markup_Menuitem_PropertyKey")
|
|
|
private var protect_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Protect"), identifier: "markup_Menuitem_PropertyKey")
|
|
|
private var tools_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Tools"), identifier: "markup_Menuitem_PropertyKey")
|
|
|
-
|
|
|
+
|
|
|
var pdfView: CPDFListView?
|
|
|
|
|
|
var secondToolBar: KMPDFSecToolbarController = KMPDFSecToolbarController.init()
|
|
|
|
|
|
weak open var delegate: KMPDFToolbarControllerDelegate?
|
|
|
-
|
|
|
-
|
|
|
- override func viewDidLayout() {
|
|
|
- super.viewDidLayout()
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
override func viewWillLayout() {
|
|
|
super.viewWillLayout()
|
|
|
|
|
|
- tabsScrollView.frame = CGRectMake(max(0, CGRectGetWidth(tabsContendView.frame)/2 - tabsView.viewWidth/2),
|
|
|
- 0,
|
|
|
- min(tabsView.viewWidth, CGRectGetWidth(tabsContendView.frame)-21),
|
|
|
- tabsContendView.frame.size.height)
|
|
|
-
|
|
|
- if tabsView.viewWidth > CGRectGetWidth(tabsContendView.frame)-21 {
|
|
|
- tabsMoreButton.isHidden = false
|
|
|
+ var pointX: CGFloat = (CGRectGetWidth(view.frame) - tabsView.viewWidth)/2
|
|
|
+
|
|
|
+ var xValue: CGFloat = 0
|
|
|
+
|
|
|
+ if pointX-12-264 > 10 {
|
|
|
+ xValue = pointX - 12 - 264
|
|
|
+ tabsLeftConst.constant = xValue
|
|
|
+ tabsRightConst.constant = CGRectGetWidth(view.frame) - tabsView.viewWidth - 12 - 264 - rightViewWidthConst.constant - 12 - xValue
|
|
|
} else {
|
|
|
- tabsMoreButton.isHidden = true
|
|
|
+ xValue = 10
|
|
|
+ let rightXValue = CGRectGetWidth(view.frame) - tabsView.viewWidth - 12 - 264 - rightViewWidthConst.constant - 12 - xValue
|
|
|
+
|
|
|
+ if rightXValue < 10 {
|
|
|
+ tabsMoreButton.superview?.isHidden = false
|
|
|
+ tabsRightConst.constant = 44
|
|
|
+ } else {
|
|
|
+ tabsMoreButton.superview?.isHidden = true
|
|
|
+ tabsRightConst.constant = rightXValue
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewDidLayout() {
|
|
|
+ super.viewDidLayout()
|
|
|
+
|
|
|
+ refreshTabsScrollViewVisiableRect()
|
|
|
}
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
// Do view setup here.
|
|
|
-
|
|
|
+
|
|
|
contendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
|
|
|
|
|
|
leftToolsView.wantsLayer = true
|
|
@@ -108,6 +121,9 @@ class KMPDFToolbarController: NSViewController {
|
|
|
tabsContendView.wantsLayer = true
|
|
|
tabsContendView.layer?.backgroundColor = contendBox.fillColor.cgColor
|
|
|
|
|
|
+ tabsMoreButton.superview?.wantsLayer = true
|
|
|
+ tabsMoreButton.superview?.layer?.backgroundColor = contendBox.fillColor.cgColor
|
|
|
+
|
|
|
tabsView = ComponentTabs.init()
|
|
|
|
|
|
scrollDocumentView.wantsLayer = true
|
|
@@ -135,22 +151,22 @@ class KMPDFToolbarController: NSViewController {
|
|
|
|
|
|
toolsView.properties = KMPDFToolbarManager.manager.toolsProperty
|
|
|
toolsView.delegate = self
|
|
|
-
|
|
|
+
|
|
|
selectZoom.properties = KMPDFToolbarManager.manager.selectZoomProperty
|
|
|
selectZoom.delegate = self
|
|
|
|
|
|
- tabsView.updateItemProperty([KMPDFToolbarManager.manager.markupMode_Property,
|
|
|
+ tabsView.updateItemProperty([KMPDFToolbarManager.manager.markupMode_Property,
|
|
|
KMPDFToolbarManager.manager.editMode_Property,
|
|
|
- KMPDFToolbarManager.manager.formMode_Property,
|
|
|
+ KMPDFToolbarManager.manager.formMode_Property,
|
|
|
KMPDFToolbarManager.manager.fillMode_Property,
|
|
|
- KMPDFToolbarManager.manager.convertMode_Property,
|
|
|
+ KMPDFToolbarManager.manager.convertMode_Property,
|
|
|
KMPDFToolbarManager.manager.protectMode_Property,
|
|
|
KMPDFToolbarManager.manager.toolsMode_Property])
|
|
|
tabsView.frame = CGRectMake(0, 0, tabsView.viewWidth, CGRectGetHeight(tabsContendView.frame))
|
|
|
tabsView.delegate = self
|
|
|
|
|
|
- tabsScrollView.frame = CGRectMake(CGRectGetWidth(tabsContendView.frame)/2 - tabsView.viewWidth/2, 0, tabsView.viewWidth, tabsContendView.frame.size.height)
|
|
|
- tabsScrollView.autoresizingMask = [.minXMargin, .maxXMargin]
|
|
|
+ // tabsScrollView.frame = CGRectMake(CGRectGetWidth(tabsContendView.frame)/2 - tabsView.viewWidth/2, 0, tabsView.viewWidth, tabsContendView.frame.size.height)
|
|
|
+ // tabsScrollView.autoresizingMask = [.minXMargin, .maxXMargin]
|
|
|
|
|
|
scrollDocumentView.frame = CGRectMake(0, 0, tabsView.viewWidth, 28)
|
|
|
|
|
@@ -158,7 +174,7 @@ class KMPDFToolbarController: NSViewController {
|
|
|
tabsView.autoresizingMask = [.width, .height]
|
|
|
|
|
|
scrollDocumentView.addSubview(tabsView)
|
|
|
-
|
|
|
+
|
|
|
tabsMoreButton.properties = ComponentButtonProperty(type: .text_gray,
|
|
|
size: .xs,
|
|
|
onlyIcon: true,
|
|
@@ -173,7 +189,7 @@ class KMPDFToolbarController: NSViewController {
|
|
|
ppt_Menuitem_Property,
|
|
|
print_Menuitem_Property,
|
|
|
share_Menuitem_Property]
|
|
|
-
|
|
|
+
|
|
|
moreTabsItems = [markup_Menuitem_Property,
|
|
|
edit_Menuitem_Property,
|
|
|
form_Menuitem_Property,
|
|
@@ -181,8 +197,8 @@ class KMPDFToolbarController: NSViewController {
|
|
|
convert_Menuitem_Property,
|
|
|
protect_Menuitem_Property,
|
|
|
tools_Menuitem_Property]
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//MARK: - 刷新一级工具栏
|
|
@@ -228,6 +244,35 @@ class KMPDFToolbarController: NSViewController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ func refreshTabsScrollViewVisiableRect() {
|
|
|
+ if tabsView.viewWidth > CGRectGetWidth(tabsContendView.frame)-21 {
|
|
|
+ if KMPDFManager.manager.toolMode != .None {
|
|
|
+ var pointx: CGFloat = 0
|
|
|
+ print(tabsScrollView.documentVisibleRect)
|
|
|
+ let _manager = KMPDFToolbarManager.manager
|
|
|
+
|
|
|
+ if KMPDFManager.manager.toolMode == .Markup {
|
|
|
+ pointx = 0
|
|
|
+ } else if KMPDFManager.manager.toolMode == .Edit {
|
|
|
+ pointx = _manager.markupMode_Property.propertyInfo.viewWidth
|
|
|
+ } else if KMPDFManager.manager.toolMode == .Form {
|
|
|
+ pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth
|
|
|
+ } else if KMPDFManager.manager.toolMode == .Fill {
|
|
|
+ pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth
|
|
|
+ } else if KMPDFManager.manager.toolMode == .Convert {
|
|
|
+ pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth
|
|
|
+ } else if KMPDFManager.manager.toolMode == .Protect {
|
|
|
+ pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.convertMode_Property.propertyInfo.viewWidth
|
|
|
+ } else if KMPDFManager.manager.toolMode == .Tools {
|
|
|
+ pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.convertMode_Property.propertyInfo.viewWidth + _manager.protectMode_Property.propertyInfo.viewWidth
|
|
|
+ }
|
|
|
+ if tabsScrollView.documentVisibleRect.origin.x > pointx {
|
|
|
+ tabsScrollView.scroll(tabsScrollView.contentView, to: CGPoint(x: pointx, y: 0))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//MARK: -右侧工具模块
|
|
|
func setUpRightViews() {
|
|
|
let subviews = rightToolsView.subviews
|
|
@@ -259,7 +304,7 @@ class KMPDFToolbarController: NSViewController {
|
|
|
adddividerB = true
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for property in _manager.validRightPropertys {
|
|
|
if adddividerA == true {
|
|
|
if property == _manager.aiToolsProperty ||
|
|
@@ -324,7 +369,7 @@ class KMPDFToolbarController: NSViewController {
|
|
|
itemXvalue -= 12
|
|
|
|
|
|
rightViewWidthConst.constant = itemXvalue
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//MARK: - 二级工具栏
|
|
@@ -453,11 +498,11 @@ class KMPDFToolbarController: NSViewController {
|
|
|
if (customRightGroupView?.superview) != nil {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
updateRightMenuItemSelectedState()
|
|
|
|
|
|
let items: [ComponentMenuitemProperty] = [ComponentMenuitemProperty.header(KMLocalizedString("Show Right Tools")), undoRedo_Menuitem_Property, save_Menuitem_Property, ComponentMenuitemProperty.divider(),
|
|
|
- aiTools_Menuitem_Property, batch_Menuitem_Property, tts_Menuitem_Property, ppt_Menuitem_Property, print_Menuitem_Property, share_Menuitem_Property]
|
|
|
+ aiTools_Menuitem_Property, batch_Menuitem_Property, tts_Menuitem_Property, ppt_Menuitem_Property, print_Menuitem_Property, share_Menuitem_Property]
|
|
|
|
|
|
showGroupView(items, point)
|
|
|
customRightGroupView.clickedAutoHide = false
|
|
@@ -488,7 +533,7 @@ class KMPDFToolbarController: NSViewController {
|
|
|
customRightGroupView.groupDelegate = self
|
|
|
customRightGroupView.showWithPoint(CGPoint(x: point.x, y: point.y-viewHeight), relativeTo: self.contendBox)
|
|
|
customRightGroupView?.updateGroupInfo(items)
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func hideGroupView() {
|
|
@@ -540,9 +585,8 @@ class KMPDFToolbarController: NSViewController {
|
|
|
|
|
|
var clickEnabled = true
|
|
|
let windowPoint = event.locationInWindow
|
|
|
-
|
|
|
- var point = view.convert(windowPoint, from: nil)
|
|
|
- if tabsMoreButton.isHidden == false {
|
|
|
+
|
|
|
+ if tabsMoreButton.superview?.isHidden == false {
|
|
|
if CGRectContainsPoint(tabsMoreButton.frame, mainToolbarContendView.convert(windowPoint, from: nil)) {
|
|
|
clickEnabled = false
|
|
|
}
|
|
@@ -735,21 +779,23 @@ extension KMPDFToolbarController: ComponentTabsDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ refreshTabsScrollViewVisiableRect()
|
|
|
+
|
|
|
delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, property.identifier)
|
|
|
|
|
|
reloadData()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//MARK: - KMPDFSecToolbarControllerDelegate:二级工具栏
|
|
|
extension KMPDFToolbarController: KMPDFSecToolbarControllerDelegate {
|
|
|
func kmPDFSecToolbarControllerDidItemClicked(_ controller: KMPDFSecToolbarController, _ property: Any) {
|
|
|
if let value = property as? ComponentButtonProperty {
|
|
|
delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, value.identifier)
|
|
|
-
|
|
|
+
|
|
|
} else if let value = property as? ComponentMenuitemProperty {
|
|
|
delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, value.identifier)
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -763,7 +809,7 @@ extension KMPDFToolbarController: ComponentGroupDelegate {
|
|
|
}
|
|
|
|
|
|
func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
|
|
|
-
|
|
|
+
|
|
|
guard let property = menuItemProperty else {
|
|
|
return
|
|
|
}
|
|
@@ -797,9 +843,9 @@ extension KMPDFToolbarController: ComponentGroupDelegate {
|
|
|
if share_Menuitem_Property.itemSelected {
|
|
|
validItems.append(_manager.shareProperty)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
let sortArray = _manager.totalRightPropertys
|
|
|
-
|
|
|
+
|
|
|
let sortedArray = validItems.sorted {
|
|
|
guard let indexA = sortArray.firstIndex(of: $0 as NSObject),
|
|
|
let indexB = sortArray.firstIndex(of: $1 as NSObject) else {
|
|
@@ -834,7 +880,7 @@ extension KMPDFToolbarController: ComponentGroupDelegate {
|
|
|
_manager.toolMode = .Tools
|
|
|
}
|
|
|
tabsView.refreshItems()
|
|
|
-
|
|
|
+
|
|
|
delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, property.identifier)
|
|
|
|
|
|
reloadData()
|