mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 21:20:07 +01:00
👌 Polished context menu order and code
This commit is contained in:
93
phpmon/Domain/SiteList/SiteListVC+ContextMenu.swift
Normal file
93
phpmon/Domain/SiteList/SiteListVC+ContextMenu.swift
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// SiteListVC+ContextMenu.swift
|
||||
// PHP Monitor
|
||||
//
|
||||
// Created by Nico Verbruggen on 10/12/2021.
|
||||
// Copyright © 2021 Nico Verbruggen. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
extension SiteListVC {
|
||||
|
||||
internal func reloadContextMenu() {
|
||||
guard let site = selectedSite else {
|
||||
tableView.menu = nil
|
||||
return
|
||||
}
|
||||
|
||||
let menu = NSMenu()
|
||||
|
||||
addSystemApps(to: menu)
|
||||
addSeparator(to: menu)
|
||||
addDetectedApps(to: menu)
|
||||
addSeparator(to: menu)
|
||||
|
||||
addUnlink(to: menu, with: site)
|
||||
addToggleSecure(to: menu, with: site)
|
||||
|
||||
tableView.menu = menu
|
||||
}
|
||||
|
||||
private func addSystemApps(to menu: NSMenu) {
|
||||
menu.addItem(withTitle: "site_list.system_apps".localized, action: nil, keyEquivalent: "")
|
||||
menu.addItem(
|
||||
withTitle: "site_list.open_in_finder".localized,
|
||||
action: #selector(self.openInFinder),
|
||||
keyEquivalent: "F"
|
||||
)
|
||||
menu.addItem(
|
||||
withTitle: "site_list.open_in_terminal".localized,
|
||||
action: #selector(self.openInTerminal),
|
||||
keyEquivalent: "T"
|
||||
)
|
||||
menu.addItem(
|
||||
withTitle: "site_list.open_in_browser".localized,
|
||||
action: #selector(self.openInBrowser),
|
||||
keyEquivalent: "O"
|
||||
)
|
||||
}
|
||||
|
||||
private func addDetectedApps(to menu: NSMenu) {
|
||||
if (applications.count > 0) {
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(withTitle: "site_list.detected_apps".localized, action: nil, keyEquivalent: "")
|
||||
|
||||
for (index, editor) in applications.enumerated() {
|
||||
let editorMenuItem = EditorMenuItem(
|
||||
title: "Open with \(editor.name)",
|
||||
action: #selector(self.openWithEditor(sender:)),
|
||||
keyEquivalent: "\(index + 1)"
|
||||
)
|
||||
editorMenuItem.editor = editor
|
||||
menu.addItem(editorMenuItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func addUnlink(to menu: NSMenu, with site: Valet.Site) {
|
||||
if (site.aliasPath != nil) {
|
||||
menu.addItem(
|
||||
withTitle: "site_list.unlink".localized,
|
||||
action: #selector(self.unlinkSite),
|
||||
keyEquivalent: "U"
|
||||
)
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
}
|
||||
}
|
||||
|
||||
private func addToggleSecure(to menu: NSMenu, with site: Valet.Site) {
|
||||
menu.addItem(
|
||||
withTitle: site.secured
|
||||
? "site_list.unsecure".localized
|
||||
: "site_list.secure".localized,
|
||||
action: #selector(toggleSecure),
|
||||
keyEquivalent: "L"
|
||||
)
|
||||
}
|
||||
|
||||
private func addSeparator(to menu: NSMenu) {
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -261,67 +261,6 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
||||
|
||||
// MARK: - Context Menu
|
||||
|
||||
private func reloadContextMenu() {
|
||||
let menu = NSMenu()
|
||||
|
||||
guard let site = selectedSite else {
|
||||
tableView.menu = nil
|
||||
return
|
||||
}
|
||||
|
||||
if (site.aliasPath != nil) {
|
||||
menu.addItem(
|
||||
withTitle: "site_list.unlink".localized,
|
||||
action: #selector(self.unlinkSite),
|
||||
keyEquivalent: "U"
|
||||
)
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
}
|
||||
|
||||
menu.addItem(
|
||||
withTitle: site.secured
|
||||
? "site_list.unsecure".localized
|
||||
: "site_list.secure".localized,
|
||||
action: #selector(toggleSecure),
|
||||
keyEquivalent: "L"
|
||||
)
|
||||
|
||||
if (applications.count > 0) {
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(withTitle: "site_list.detected_apps".localized, action: nil, keyEquivalent: "")
|
||||
|
||||
for (index, editor) in applications.enumerated() {
|
||||
let editorMenuItem = EditorMenuItem(
|
||||
title: "Open with \(editor.name)",
|
||||
action: #selector(self.openWithEditor(sender:)),
|
||||
keyEquivalent: "\(index + 1)"
|
||||
)
|
||||
editorMenuItem.editor = editor
|
||||
menu.addItem(editorMenuItem)
|
||||
}
|
||||
}
|
||||
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(withTitle: "site_list.system_apps".localized, action: nil, keyEquivalent: "")
|
||||
menu.addItem(
|
||||
withTitle: "site_list.open_in_finder".localized,
|
||||
action: #selector(self.openInFinder),
|
||||
keyEquivalent: "F"
|
||||
)
|
||||
menu.addItem(
|
||||
withTitle: "site_list.open_in_terminal".localized,
|
||||
action: #selector(self.openInTerminal),
|
||||
keyEquivalent: "T"
|
||||
)
|
||||
menu.addItem(
|
||||
withTitle: "site_list.open_in_browser".localized,
|
||||
action: #selector(self.openInBrowser),
|
||||
keyEquivalent: "O"
|
||||
)
|
||||
|
||||
tableView.menu = menu
|
||||
}
|
||||
|
||||
@objc func openWithEditor(sender: EditorMenuItem) {
|
||||
guard let editor = sender.editor else { return }
|
||||
editor.openDirectory(file: selectedSite!.absolutePath!)
|
||||
|
||||
Reference in New Issue
Block a user