mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
✨ Add options to open site with Code / PhpStorm (#58)
This commit is contained in:
@ -16,6 +16,8 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
|
|
||||||
@IBOutlet weak var tableView: NSTableView!
|
@IBOutlet weak var tableView: NSTableView!
|
||||||
|
|
||||||
|
public var editorAvailability: [String] = []
|
||||||
|
|
||||||
// MARK: - Display
|
// MARK: - Display
|
||||||
|
|
||||||
public static func show(delegate: NSWindowDelegate? = nil) {
|
public static func show(delegate: NSWindowDelegate? = nil) {
|
||||||
@ -37,7 +39,15 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
|
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
|
|
||||||
override func viewDidLoad() {}
|
override func viewDidLoad() {
|
||||||
|
if (Shell.fileExists("/usr/local/bin/code")) {
|
||||||
|
self.editorAvailability.append("vscode")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Shell.fileExists("/Applications/PhpStorm.app/Contents/Info.plist")) {
|
||||||
|
self.editorAvailability.append("phpstorm")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func viewWillAppear() {}
|
override func viewWillAppear() {}
|
||||||
|
|
||||||
@ -86,33 +96,80 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu.addItem(
|
menu.addItem(
|
||||||
withTitle: site.secured ? "Unsecure" : "Secure",
|
withTitle: site.secured
|
||||||
|
? "site_list.unsecure".localized
|
||||||
|
: "site_list.secure".localized,
|
||||||
action: #selector(self.secure),
|
action: #selector(self.secure),
|
||||||
keyEquivalent: "L"
|
keyEquivalent: "L"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (self.editorAvailability.count > 0) {
|
||||||
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
|
||||||
|
if self.editorAvailability.contains("vscode") {
|
||||||
menu.addItem(
|
menu.addItem(
|
||||||
withTitle: "Open in Browser...",
|
withTitle: "site_list.open_with_vs_code".localized,
|
||||||
|
action: #selector(self.openWithVSCode),
|
||||||
|
keyEquivalent: ""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if editorAvailability.contains("phpstorm") {
|
||||||
|
menu.addItem(
|
||||||
|
withTitle: "site_list.open_with_pstorm".localized,
|
||||||
|
action: #selector(self.openWithPhpStorm),
|
||||||
|
keyEquivalent: ""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.addItem(NSMenuItem.separator())
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.addItem(
|
||||||
|
withTitle: "site_list.open_in_finder".localized,
|
||||||
|
action: #selector(self.openInFinder),
|
||||||
|
keyEquivalent: "F"
|
||||||
|
)
|
||||||
|
menu.addItem(
|
||||||
|
withTitle: "site_list.open_in_browser".localized,
|
||||||
action: #selector(self.openInBrowser),
|
action: #selector(self.openInBrowser),
|
||||||
keyEquivalent: "O"
|
keyEquivalent: "O"
|
||||||
)
|
)
|
||||||
tableView.menu = menu
|
tableView.menu = menu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Secure / unsecure
|
||||||
|
|
||||||
@objc public func secure() {
|
@objc public func secure() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public func openInBrowser() {
|
// MARK: Open with IDE / Editor
|
||||||
if self.tableView.selectedRow == -1 {
|
|
||||||
return
|
@objc public func openWithPhpStorm() {
|
||||||
|
let site = Valet.shared.sites[self.tableView.selectedRow]
|
||||||
|
Shell.run("open -a /Applications/PhpStorm.app \(site.absolutePath)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc public func openWithVSCode() {
|
||||||
|
let site = Valet.shared.sites[self.tableView.selectedRow]
|
||||||
|
Shell.run("/usr/local/bin/code \(site.absolutePath)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Open in Browser & Finder
|
||||||
|
|
||||||
|
@objc public func openInBrowser() {
|
||||||
let site = Valet.shared.sites[self.tableView.selectedRow]
|
let site = Valet.shared.sites[self.tableView.selectedRow]
|
||||||
let prefix = site.secured ? "https://" : "http://"
|
let prefix = site.secured ? "https://" : "http://"
|
||||||
let url = "\(prefix)\(site.name).\(Valet.shared.config.tld)"
|
let url = "\(prefix)\(site.name).\(Valet.shared.config.tld)"
|
||||||
NSWorkspace.shared.open(URL(string: url)!)
|
NSWorkspace.shared.open(URL(string: url)!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc public func openInFinder() {
|
||||||
|
let site = Valet.shared.sites[self.tableView.selectedRow]
|
||||||
|
Shell.run("open \(site.absolutePath)")
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Deinitialization
|
// MARK: - Deinitialization
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
@ -51,6 +51,15 @@
|
|||||||
|
|
||||||
"site_list.title" = "Linked & Parked Domains";
|
"site_list.title" = "Linked & Parked Domains";
|
||||||
|
|
||||||
|
// SITE LIST ACTIONS
|
||||||
|
|
||||||
|
"site_list.secure" = "Secure";
|
||||||
|
"site_list.unsecure" = "Unsecure";
|
||||||
|
"site_list.open_in_finder" = "Open in Finder";
|
||||||
|
"site_list.open_in_browser" = "Open in Browser";
|
||||||
|
"site_list.open_with_vs_code" = "Open with Visual Studio Code";
|
||||||
|
"site_list.open_with_pstorm" = "Open with PhpStorm";
|
||||||
|
|
||||||
// PREFERENCES
|
// PREFERENCES
|
||||||
|
|
||||||
"prefs.title" = "PHP Monitor";
|
"prefs.title" = "PHP Monitor";
|
||||||
|
Reference in New Issue
Block a user