From 5c9c51f580948010f81190422d62ca7e864d966d Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Sun, 25 Aug 2024 13:35:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Mark=20domain=20as=20favorite=20(UI?= =?UTF-8?q?=20only)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Please note that this functionality is currently not persistent. As such, reloading the domain list will reset any changes you have made. --- phpmon/Domain/App/Base.lproj/Main.storyboard | 17 ++++++------- .../Valet/Domains/ValetListable.swift | 2 ++ .../Valet/Proxies/ValetProxy.swift | 5 ++++ .../Integrations/Valet/Sites/ValetSite.swift | 6 +++++ .../UI/Cells/DomainListNameCell.swift | 6 +++-- .../Domain List/UI/DomainListVC+Actions.swift | 24 +++++++++++++++++++ .../UI/DomainListVC+ContextMenu.swift | 12 ++++++++++ .../Modules/Domain List/UI/DomainListVC.swift | 4 +++- phpmon/en.lproj/Localizable.strings | 2 ++ 9 files changed, 67 insertions(+), 11 deletions(-) diff --git a/phpmon/Domain/App/Base.lproj/Main.storyboard b/phpmon/Domain/App/Base.lproj/Main.storyboard index ebdbf76..6884dea 100644 --- a/phpmon/Domain/App/Base.lproj/Main.storyboard +++ b/phpmon/Domain/App/Base.lproj/Main.storyboard @@ -1,6 +1,7 @@ + @@ -825,11 +826,18 @@ Gw + + + + + + + - + @@ -1091,13 +1099,6 @@ Gw - - - - - - - diff --git a/phpmon/Domain/Integrations/Valet/Domains/ValetListable.swift b/phpmon/Domain/Integrations/Valet/Domains/ValetListable.swift index 8846b09..7f0ca82 100644 --- a/phpmon/Domain/Integrations/Valet/Domains/ValetListable.swift +++ b/phpmon/Domain/Integrations/Valet/Domains/ValetListable.swift @@ -24,4 +24,6 @@ protocol ValetListable { func getListableUrl() -> URL? + func getListableFavorited() -> Bool + } diff --git a/phpmon/Domain/Integrations/Valet/Proxies/ValetProxy.swift b/phpmon/Domain/Integrations/Valet/Proxies/ValetProxy.swift index 43b909f..20c1f8c 100644 --- a/phpmon/Domain/Integrations/Valet/Proxies/ValetProxy.swift +++ b/phpmon/Domain/Integrations/Valet/Proxies/ValetProxy.swift @@ -13,6 +13,7 @@ class ValetProxy: ValetListable { var tld: String var target: String var secured: Bool = false + var favorited: Bool = false init(domain: String, target: String, secure: Bool, tld: String) { self.domain = domain @@ -61,6 +62,10 @@ class ValetProxy: ValetListable { return URL(string: "\(self.secured ? "https://" : "http://")\(self.domain).\(self.tld)") } + func getListableFavorited() -> Bool { + return self.favorited + } + // MARK: - Interactions func determineSecured() { diff --git a/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift b/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift index 7c2c8ba..ff3bfa6 100644 --- a/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift +++ b/phpmon/Domain/Integrations/Valet/Sites/ValetSite.swift @@ -61,6 +61,8 @@ class ValetSite: ValetListable { ?? "???" } + var favorited: Bool = false + init( name: String, tld: String, @@ -305,6 +307,10 @@ class ValetSite: ValetListable { return URL(string: "\(self.secured ? "https://" : "http://")\(self.name).\(Valet.shared.config.tld)") } + func getListableFavorited() -> Bool { + return self.favorited + } + // MARK: - Interactions func toggleSecure() async throws { diff --git a/phpmon/Modules/Domain List/UI/Cells/DomainListNameCell.swift b/phpmon/Modules/Domain List/UI/Cells/DomainListNameCell.swift index 663e885..aedf6ab 100644 --- a/phpmon/Modules/Domain List/UI/Cells/DomainListNameCell.swift +++ b/phpmon/Modules/Domain List/UI/Cells/DomainListNameCell.swift @@ -16,12 +16,14 @@ class DomainListNameCell: NSTableCellView, DomainListCellProtocol { @IBOutlet weak var labelPathName: NSTextField! func populateCell(with site: ValetSite) { - labelSiteName.stringValue = "\(site.name).\(site.tld)" + let favoritePrefix = site.favorited ? "★ " : "" + labelSiteName.stringValue = "\(favoritePrefix)\(site.name).\(site.tld)" labelPathName.stringValue = site.absolutePathRelative } func populateCell(with proxy: ValetProxy) { - labelSiteName.stringValue = "\(proxy.domain).\(proxy.tld)" + let favoritePrefix = proxy.favorited ? "★ " : "" + labelSiteName.stringValue = "\(favoritePrefix)\(proxy.domain).\(proxy.tld)" labelPathName.stringValue = proxy.target } } diff --git a/phpmon/Modules/Domain List/UI/DomainListVC+Actions.swift b/phpmon/Modules/Domain List/UI/DomainListVC+Actions.swift index 817bac4..01acad5 100644 --- a/phpmon/Modules/Domain List/UI/DomainListVC+Actions.swift +++ b/phpmon/Modules/Domain List/UI/DomainListVC+Actions.swift @@ -67,6 +67,14 @@ extension DomainListVC { // MARK: - Interactions with `valet` or terminal + @objc func toggleFavorite() { + guard let selected = self.selected else { + return + } + + Task { await toggleFavorite(domain: selected) } + } + @objc func toggleSecure() { if selected is ValetSite { Task { await toggleSecure(site: selected as! ValetSite) } @@ -94,6 +102,22 @@ extension DomainListVC { } } + func toggleFavorite(domain: any ValetListable) async { + waitAndExecute { + do { + if let site = domain as? ValetSite { + site.favorited.toggle() + } + if let proxy = domain as? ValetProxy { + proxy.favorited.toggle() + } + + // Reload the entire table as the sorting may be affected + self.reloadTable() + } + } + } + func toggleSecure(site: ValetSite) async { waitAndExecute { do { diff --git a/phpmon/Modules/Domain List/UI/DomainListVC+ContextMenu.swift b/phpmon/Modules/Domain List/UI/DomainListVC+ContextMenu.swift index 070e3b5..59ff860 100644 --- a/phpmon/Modules/Domain List/UI/DomainListVC+ContextMenu.swift +++ b/phpmon/Modules/Domain List/UI/DomainListVC+ContextMenu.swift @@ -65,6 +65,7 @@ extension DomainListVC { menu.addItem(HeaderView.asMenuItem(text: "domain_list.actions".localized)) + addToggleFavorite(to: menu, favorited: site.favorited) addToggleSecure(to: menu, secured: site.secured) addUnlink(to: menu, with: site) @@ -172,6 +173,16 @@ extension DomainListVC { ) } + private func addToggleFavorite(to menu: NSMenu, favorited: Bool) { + menu.addItem( + withTitle: favorited + ? "domain_list.unfavorite".localized + : "domain_list.favorite".localized, + action: #selector(toggleFavorite), + keyEquivalent: "" + ) + } + private func addMenuItemsForExtensions(to menu: NSMenu, for extensions: [PhpExtension], version: String) { var items: [NSMenuItem] = [ NSMenuItem(title: "domain_list.applies_to".localized(version)) @@ -200,6 +211,7 @@ extension DomainListVC { let menu = NSMenu() addOpenProxyInBrowser(to: menu) addSeparator(to: menu) + addToggleFavorite(to: menu, favorited: proxy.favorited) addToggleSecure(to: menu, secured: proxy.secured) addRemoveProxy(to: menu) return menu diff --git a/phpmon/Modules/Domain List/UI/DomainListVC.swift b/phpmon/Modules/Domain List/UI/DomainListVC.swift index 6611d69..7c4615e 100644 --- a/phpmon/Modules/Domain List/UI/DomainListVC.swift +++ b/phpmon/Modules/Domain List/UI/DomainListVC.swift @@ -221,7 +221,9 @@ class DomainListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource default: break } - self.domains = descriptor.ascending ? sorted.reversed() : sorted + sorted = descriptor.ascending ? sorted.reversed() : sorted + + self.domains = sorted.sorted { $0.getListableFavorited() && !$1.getListableFavorited() } } func addedNewSite(name: String, secureAfterLinking: Bool) async { diff --git a/phpmon/en.lproj/Localizable.strings b/phpmon/en.lproj/Localizable.strings index bdbf38e..a46de8a 100644 --- a/phpmon/en.lproj/Localizable.strings +++ b/phpmon/en.lproj/Localizable.strings @@ -330,6 +330,8 @@ You may be asked for your password during the uninstallation process if file per "domain_list.always_use_php" = "Always use PHP %@"; "domain_list.isolation_unavailable" = "Isolation Not Supported (in Valet 2)"; +"domain_list.favorite" = "Favorite Domain"; +"domain_list.unfavorite" = "Unfavorite Domain"; "domain_list.actions" = "Actions"; "domain_list.unlink" = "Unlink Directory"; "domain_list.secure" = "Secure Domain";