123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- //
- // KMHomeViewController+UI.swift
- // PDF Master
- //
- // Created by wanjun on 2022/10/13.
- //
- import Foundation
- extension KMHomeViewController {
-
- // MARK: Private Methods
- func productPromotionShow(_ pdfProSeries: NSArray, withOthers others: NSArray, isInitialize initialize: Bool) {
- if pdfProSeries.count > 0 {
- if (self.pdfProSeriesBoxHeightConstraint.constant == 0.0) || initialize {
- var height = CGFloat(pdfProSeries.count) * 32.0
- for name in pdfProSeries {
- height -= 32.0
- let dict: Dictionary = self.productPromotionData[name] as! Dictionary<NSString, NSString>
- let subBox = KMBox(frame: CGRect(origin: CGPoint(x: 0, y: height), size: CGSize(width: self.pdfProSeriesBox.frame.width, height: 32.0)))
- subBox.boxType = .custom
- subBox.borderWidth = 0.0
- self.pdfProSeriesBox.contentView?.addSubview(subBox)
- subBox.downCallback = {(downEntered, mouseBox, event) -> Void in
- if downEntered {
- self.productPromotionClickAction(dict["Name"]!)
- }
- }
-
- let subImageView = NSImageView(frame: NSZeroRect)
- subImageView.image = NSImage(named: dict["Image"]! as NSImage.Name)
- subBox.addSubview(subImageView)
- subImageView.mas_makeConstraints { (make) in
- make?.width.height().equalTo()(16)
- make?.centerY.equalTo()(0)
- make?.left.equalTo()(18)
- }
- let subLabel = NSTextField(frame: NSZeroRect)
- subLabel.isBezeled = false
- subLabel.isEditable = false
- subLabel.backgroundColor = .clear
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.lineSpacing = 22.0
- subLabel.attributedStringValue = NSAttributedString(string: dict["Name"]! as String, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
- subLabel.font = NSFont(name: "SFProText-Regular", size: 14)
- subLabel.textColor = NSColor(hex: "#616469")
- subLabel.sizeToFit()
- subBox.addSubview(subLabel)
- subLabel.mas_makeConstraints { (make) in
- make?.left.equalTo()(subImageView.mas_right)?.offset()(10)
- make?.centerY.equalTo()(0)
- }
- }
-
- pdfSeriesButtonVC.image = NSImage(named: "icon_btn_expand_lv2_down_false")!
- self.pdfProSeriesBoxHeightConstraint.constant = CGFloat(pdfProSeries.count) * 32.0
- }
- } else {
- pdfSeriesButtonVC.image = NSImage(named: "icon_btn_expand_lv2_right_false")!
- self.pdfProSeriesBox.contentView = NSView.init()
- self.pdfProSeriesBoxHeightConstraint.constant = 0.0
- }
-
- if others.count > 0 {
- if (self.othersBoxHeightConstraint.constant == 0.0) || initialize {
- var height = CGFloat(others.count) * 32.0
- for name in others {
- height -= 32.0
- let dict: Dictionary = self.productPromotionData[name] as! Dictionary<NSString, NSString>
- let subBox = KMBox(frame: CGRect(x: 0, y: height, width: self.othersBox.frame.width, height: 32.0))
- subBox.boxType = .custom
- subBox.borderWidth = 0.0
- self.othersBox.contentView?.addSubview(subBox)
- subBox.downCallback = {(downEntered, mouseBox, event) -> Void in
- if downEntered {
- self.productPromotionClickAction(dict["Name"]!)
- }
- }
-
- let subImageView = NSImageView(frame: NSZeroRect)
- subImageView.image = NSImage(named: dict["Image"]! as NSImage.Name)
- subImageView.imageScaling = .scaleProportionallyDown
- subImageView.imageAlignment = .alignCenter
- subImageView.sizeToFit()
- subBox.addSubview(subImageView)
- subImageView.mas_makeConstraints { (make) in
- make?.width.height().equalTo()(16)
- make?.centerY.equalTo()(0)
- make?.left.equalTo()(18)
- }
- let subLabel = NSTextField(frame: NSZeroRect)
- subLabel.isBezeled = false
- subLabel.isEditable = false
- subLabel.backgroundColor = .clear
- let paragraphStyle = NSMutableParagraphStyle()
- paragraphStyle.lineSpacing = 22.0
- subLabel.attributedStringValue = NSAttributedString(string: dict["Name"]! as String, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
- subLabel.font = NSFont(name: "SFProText-Regular", size: 14)
- subLabel.textColor = NSColor(red: 0.38, green: 0.392, blue: 0.412, alpha: 1.0)
- subLabel.sizeToFit()
- subBox.addSubview(subLabel)
- subLabel.mas_makeConstraints { (make) in
- make?.left.equalTo()(subImageView.mas_right)?.offset()(10)
- make?.centerY.equalTo()(0)
- }
- }
-
- self.pdfOthersButtonVC.image = NSImage(named: "icon_btn_expand_lv2_down_false")!
- self.othersBoxHeightConstraint.constant = CGFloat(others.count) * 32.0
- }
- } else {
- self.pdfOthersButtonVC.image = NSImage(named: "icon_btn_expand_lv2_right_false")!
- self.othersBox.contentView = NSView.init()
- self.othersBoxHeightConstraint.constant = 0.0
- }
-
- pdfSeriesButtonVC.updateUI()
- pdfOthersButtonVC.updateUI()
- }
-
- func refreshRightBoxUI(_ state: KMHomeToolState) {
- rightFullBox.isHidden = true
- rightTopBox.isHidden = true
- rightBottomBox.isHidden = true
-
- homeButtonVC.state = .Norm
- pdfToolsButtonVC.state = .Norm
- cloudDocumentsButtonVC.state = .Norm
- switch state {
- case .Home:
- rightTopBox.isHidden = false
- rightBottomBox.isHidden = false
- rightTopBox.contentView = fastToolViewController.view
- rightBottomBox.contentView = historyFileViewController.view
- rightFullBox.contentView = nil
-
- let isQuickToolsType:Bool = UserDefaults.standard.bool(forKey: "kHomeQucikToolsTypeKey")
- if isQuickToolsType {
- rightTopBoxHeightConstraint.constant = 230 + ScrollerViewWidget
- } else {
- rightTopBoxHeightConstraint.constant = 326 + ScrollerViewWidget
- }
-
- homeButtonVC.state = .Sel
- refreshUI()
- break
- case .PDFTools:
- rightFullBox.isHidden = false
- rightFullBox.contentView = pdfToolsViewController.view
- rightTopBox.contentView = nil
- rightBottomBox.contentView = nil
- pdfToolsButtonVC.state = .Sel
- refreshUI()
- break
- case .CloudDocuments:
- rightFullBox.isHidden = false
- rightFullBox.contentView = cloudDocumentsViewController.view
- rightTopBox.contentView = nil
- rightBottomBox.contentView = nil
-
- cloudDocumentsButtonVC.state = .Sel
- refreshUI()
- break
- default:
-
- break
- }
- }
- }
- // MARK: - NSSplitViewDelegate
- extension KMHomeViewController: NSSplitViewDelegate {
- func splitView(_ splitView: NSSplitView, constrainMinCoordinate proposedMinimumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return 270.0
- }
-
- func splitView(_ splitView: NSSplitView, constrainMaxCoordinate proposedMaximumPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return 270.0
- }
-
- func splitView(_ splitView: NSSplitView, shouldAdjustSizeOfSubview view: NSView) -> Bool {
- return false
- }
-
- func splitViewDidResizeSubviews(_ notification: Notification) {
- let rect = self.homeSplitView.frame
- self.leftBox.setFrameSize(CGSize(width: 270, height: rect.size.height))
-
- self.rightBox.frame = CGRect(origin: CGPoint(x: 271.0, y: 0), size: CGSize(width: rect.width - 271.0, height: rect.height))
-
- refreshProductActiveSpacing()
- }
-
- func splitView(_ splitView: NSSplitView, constrainSplitPosition proposedPosition: CGFloat, ofSubviewAt dividerIndex: Int) -> CGFloat {
- return proposedPosition
- }
-
- func splitView(_ splitView: NSSplitView, canCollapseSubview subview: NSView) -> Bool {
- return false
- }
-
- func splitView(_ splitView: NSSplitView, shouldCollapseSubview subview: NSView, forDoubleClickOnDividerAt dividerIndex: Int) -> Bool {
- return false
- }
-
- func splitView(_ splitView: NSSplitView, shouldHideDividerAt dividerIndex: Int) -> Bool {
- return splitView.isEqual(to: self.homeSplitView)
- }
-
- func splitView(_ splitView: NSSplitView, effectiveRect proposedEffectiveRect: NSRect, forDrawnRect drawnRect: NSRect, ofDividerAt dividerIndex: Int) -> NSRect {
- return proposedEffectiveRect
- }
-
- func splitView(_ splitView: NSSplitView, additionalEffectiveRectOfDividerAt dividerIndex: Int) -> NSRect {
- return NSMakeRect(0, 0, 0, 0)
- }
- }
- // MARK: - KMHomeFastToolViewControllerDelegate
- extension KMHomeViewController: KMHomeFastToolViewControllerDelegate {
- func fastToolViewController(_ viewController: KMHomeFastToolViewController, foldChangeState: Bool) {
- if foldChangeState {
- rightTopBoxHeightConstraint.constant = 230.0 + ScrollerViewWidget
- } else {
- rightTopBoxHeightConstraint.constant = 326.0 + ScrollerViewWidget
- }
- }
- func fastToolDidSelectAllTools(_ viewController: KMHomeFastToolViewController) {
- fastToolDidSelectAllTools()
- }
- func fastToolViewController(_ viewController: KMHomeFastToolViewController, didSelectItemsAt indexPaths: [Int]) {
- for index in indexPaths {
- fastToolItemAction(DataNavigationViewButtonActionType(rawValue: index) ?? .Batch)
- }
- }
- }
- // MARK: - KMHomeHistoryFileViewControllerDelegate
- extension KMHomeViewController: KMHomeHistoryFileViewControllerDelegate {
- func historyFileViewController(_ viewController: KMHomeHistoryFileViewController, deleteDocuments indexPaths: [URL]) {
- historyFile(deleteDocuments: indexPaths)
- }
-
- func historyFileViewController(_ viewController: KMHomeHistoryFileViewController, didSelectItemsAt indexPaths: [URL]) {
- for url in indexPaths {
- openHistoryFilePath(url: url)
- }
- }
- }
- // MARK: - KMPDFToolsViewControllerDelegate
- extension KMHomeViewController: KMPDFToolsViewControllerDelegate {
- func pdfToolsViewController(_ viewController: KMPDFToolsViewController, didSelectItemsAt indexPaths: [Int]) {
- for index in indexPaths {
- fastToolItemAction(DataNavigationViewButtonActionType(rawValue: index) ?? .Batch)
- }
- }
- }
- // MARK: - KMHomeDragViewDelegate
- extension KMHomeViewController: KMHomeDragViewDelegate {
- func homeDragView(_ viewController: KMHomeDragView, filePath: URL) {
- self.openFile(withFilePath: filePath)
- }
- }
|