// // 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 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 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) } }