123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- //
- // KMHomeContentView.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/10/27.
- //
- import Cocoa
- typealias KMHomeContentViewHistoryDidSelect = (_ view: KMHomeContentView, _ url: KMFile) -> Void
- typealias KMHomeContentViewHistoryShowPathAction = (_ view: KMHomeContentView, _ url: KMFile) -> Void
- typealias KMHomeContentViewHistoryrRemoveFileAction = (_ view: KMHomeContentView, _ url: KMFile) -> Void
- typealias KMHomeContentViewHistoryrRemoveAllFileAction = (_ view: KMHomeContentView) -> Void
- typealias KMHomeContentViewQucikToolsDidSelect = (_ view: KMHomeContentView, _ item: KMQucikToolsModel) -> Void
- typealias KMHomeContentViewQucikToolsAddAction = (_ view: KMHomeContentView, _ item: KMQucikToolsModel) -> Void
- typealias KMHomeContentViewQucikToolsRemoveAction = (_ view: KMHomeContentView, _ item: KMQucikToolsModel) -> Void
- let kRecentlyListModel = "kRecentlyListModel"
- let kQucikToolsViewShow = "kQucikToolsViewShow"
- enum KMHomeQucikToolsShowType: Int {
- case expand = 0
- case collapse
- }
- class KMHomeContentView: KMBaseXibView {
- @IBOutlet weak var qucikToolsLabel: NSTextField!
- @IBOutlet weak var qucikToolsView: KMQucikToolsView!
- @IBOutlet weak var leftButton: NSButton!
- @IBOutlet weak var pageLabel: NSTextField!
- @IBOutlet weak var rightButton: NSButton!
- @IBOutlet weak var moreButton: KMButton!
- @IBOutlet weak var qucikToolsConstraintHeight: NSLayoutConstraint!
-
-
- @IBOutlet weak var recentlyLabel: NSTextField!
- @IBOutlet weak var historyListView: KMHomeHistoryListView!
- @IBOutlet weak var horizontalButton: KMButton!
- @IBOutlet weak var verticalButton: KMButton!
- @IBOutlet weak var cleanButton: KMButton!
-
- var historyDidSelect: KMHomeContentViewHistoryDidSelect?
- var historyShowPathAction: KMHomeContentViewHistoryShowPathAction?
- var historyRemoveFileAction: KMHomeContentViewHistoryrRemoveFileAction?
- var historyRemoveAllFileAction: KMHomeContentViewHistoryrRemoveAllFileAction?
-
- var qucikToolsDidSelect: KMHomeContentViewQucikToolsDidSelect?
- var qucikToolsAddAction: KMHomeContentViewQucikToolsAddAction?
- var qucikToolsRemoveAction: KMHomeContentViewQucikToolsRemoveAction?
-
- var qucikToolsType: KMHomeQucikToolsShowType = .expand {
- didSet {
- self.qucikToolsView.type = qucikToolsType
- if qucikToolsType == .collapse {
- self.qucikToolsConstraintHeight.constant = 166
- } else {
- self.qucikToolsConstraintHeight.constant = 262
- }
- }
- }
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- self.setup()
- }
-
- override func setup() {
- self.qucikToolsView.didSelect = { [unowned self] view, item in
- guard let callBack = qucikToolsDidSelect else { return }
-
- callBack(self, item)
- }
-
- self.qucikToolsView.pageChange = { [unowned self] view in
- self.updatePageLabel()
- }
-
- self.qucikToolsView.addAction = { [unowned self] view, item in
- self.qucikToolsAddAction?(self, item)
- }
-
- self.qucikToolsView.removeAction = { [unowned self] view, item in
- self.qucikToolsRemoveAction?(self, item)
- }
-
- self.historyListView.didSelect = { [unowned self] view, item in
- guard let callBack = historyDidSelect else { return }
-
- callBack(self, item)
- }
-
- self.historyListView.removeFileAction = { [unowned self] view, item in
- guard let callBack = historyRemoveFileAction else { return }
-
- callBack(self, item)
- }
-
- self.historyListView.showPathAction = { [unowned self] view, item in
- guard let callBack = historyShowPathAction else { return }
-
- callBack(self, item)
- }
-
- cleanButton.mouseMoveCallback = { [unowned self] enter in
- if self.historyListView.data.count == 0 {
- self.cleanButton.image = NSImage(named: "KMImageNameHomeDeletNor")
- } else {
- if enter {
- self.cleanButton.image = NSImage(named: "KMImageNameHomeDeletHor")
- } else {
- self.cleanButton.image = NSImage(named: "KMImageNameHomeDeletNor")
- }
- }
- }
-
- moreButton.mouseMoveCallback = { [unowned self] enter in
- if enter {
- self.moreButton.image = NSImage(named: "KMImageNameUXIconHomeMorePre")
- } else {
- self.moreButton.image = NSImage(named: "KMImageNameUXIconHomeMoreNor")
- }
- }
-
-
- let type = UserDefaults.standard.object(forKey: kRecentlyListModel) ?? 0
- historyListView.showType = KMHomeHistoryListViewShowType.init(rawValue: type as! Int) ?? .horizontal
-
- let type2 = UserDefaults.standard.object(forKey: kQucikToolsViewShow) ?? 0
- self.qucikToolsType = KMHomeQucikToolsShowType.init(rawValue: type2 as! Int) ?? .expand
-
- self.updatePageLabel()
- self.updateRecentlyListState()
- }
-
- func updatePageLabel() {
- // self.pageLabel.stringValue = "\(qucikToolsView.currentPage()) / \(max(qucikToolsView.pageCount(), 1))"
- }
-
- func updateRecentlyListState() {
- let showType = self.historyListView.showType
- if showType == .horizontal {
- verticalButton.image = NSImage(named: "KMImageNameUXIconHomeViewthumbnailNor")
- horizontalButton.image = NSImage(named: "KMImageNameUXIconHomeViewlistPre")
- } else if showType == .vertical {
- verticalButton.image = NSImage(named: "KMImageNameUXIconHomeViewthumbnailPre")
- horizontalButton.image = NSImage(named: "KMImageNameUXIconHomeViewlistNor")
- }
-
- UserDefaults.standard.setValue(showType.rawValue, forKey: kRecentlyListModel)
- }
-
- override func updateUI() {
- self.contentView.wantsLayer = true
- if(KMAppearance.isDarkMode()){
- self.contentView.layer?.backgroundColor = NSColor.init(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
- } else {
- self.contentView.layer?.backgroundColor = NSColor.init(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
- }
-
- self.pageLabel.textColor = KMAppearance.Layout.h0Color()
- self.qucikToolsLabel.textColor = KMAppearance.Layout.h0Color()
- self.recentlyLabel.textColor = KMAppearance.Layout.h0Color()
- }
-
- override func updateLanguage() {
- self.qucikToolsLabel.stringValue = NSLocalizedString("Advanced Editing Tools", comment: "")
- self.recentlyLabel.stringValue = NSLocalizedString("Recent", comment: "");
-
- self.horizontalButton.toolTip = NSLocalizedString("Thumbnails", comment: "")
- self.verticalButton.toolTip = NSLocalizedString("List", comment: "")
- self.cleanButton.toolTip = NSLocalizedString("Delete",comment: "")
- }
-
- override func reloadData() {
- self.historyListView.reloadData()
-
- if self.historyListView.data.count == 0 {
- self.cleanButton.isEnabled = false
- } else {
- self.cleanButton.isEnabled = true
- }
- }
- }
- //MARK: Action
- extension KMHomeContentView {
- @IBAction func leftButtonAction(_ sender: Any) {
- self.qucikToolsView.previousPage()
- }
-
- @IBAction func rightButtonAction(_ sender: Any) {
- self.qucikToolsView.nextPage()
- }
-
- @IBAction func moreButtonAction(_ sender: NSButton) {
- let collapse = NSLocalizedString("Collapse All", comment: "")
- let quickTools = NSLocalizedString("Manage Quick Tools", comment: "")
- let expand = NSLocalizedString("Expand All", comment: "")
-
- var array: [String] = []
- if qucikToolsType == .expand {
- array = [collapse, quickTools]
- } else {
- array = [expand, quickTools]
- }
-
- let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(array)
- vc.background = KMAppearance.Layout.bgColor()
- vc.textColor = KMAppearance.Layout.h0Color()
- vc.enterFillColor = KMAppearance.Interactive.s0Color()
- let createFilePopover: NSPopover = NSPopover.init()
- createFilePopover.contentViewController = vc
- createFilePopover.delegate = self
- createFilePopover.animates = true
- createFilePopover.behavior = .semitransient
- createFilePopover.setValue(true, forKey: "shouldHideAnchor")
- createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 10, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
-
- // vc.customBoxWidthLayoutConstraint.constant = sender.frame.width
- vc.downCallback = { [unowned self] (downEntered: Bool, count: String) -> Void in
- if downEntered {
- createFilePopover.close()
- if count == collapse {
- self.qucikToolsType = .collapse
- } else if count == expand {
- self.qucikToolsType = .expand
- } else if count == quickTools {
- let homeQuickToolsWindowController: KMHomeQuickToolsWindowController = KMHomeQuickToolsWindowController.sharedHomeQuickTools
- homeQuickToolsWindowController.window?.center()
- NSWindow.currentWindow().addChildWindow(homeQuickToolsWindowController.window!, ordered: NSWindow.OrderingMode.above)
- homeQuickToolsWindowController.dataChange = { [unowned self] controller in
- self.qucikToolsView.reloadData()
- }
- }
- self.updatePageLabel()
-
- UserDefaults.standard.setValue(qucikToolsType.rawValue, forKey: kQucikToolsViewShow)
- }
- }
- }
-
- @IBAction func horizontalButtonAction(_ sender: Any) {
- self.historyListView.showType = .horizontal
- self.updateRecentlyListState()
- }
-
- @IBAction func verticalButtonAction(_ sender: Any) {
- self.historyListView.showType = .vertical
- self.updateRecentlyListState()
- }
-
- @IBAction func cleanButtonAction(_ sender: Any) {
- guard let callBack = historyRemoveAllFileAction else { return }
- callBack(self)
- }
- }
- extension KMHomeContentView: NSPopoverDelegate {
-
- }
|