mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-09 21:20:07 +01:00
👌 Quality of life changes, reload button
This commit is contained in:
@@ -20,6 +20,8 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
||||
|
||||
public var sites: [Valet.Site] = []
|
||||
|
||||
var lastSearchedFor = ""
|
||||
|
||||
// MARK: - Display
|
||||
|
||||
public static func show(delegate: NSWindowDelegate? = nil) {
|
||||
@@ -28,8 +30,10 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
||||
let windowController = (storyboard.instantiateController(withIdentifier: "siteListWindow")) as! SiteListWC
|
||||
|
||||
windowController.window!.title = "site_list.title".localized
|
||||
windowController.window!.subtitle = "site_list.subtitle".localized
|
||||
windowController.window!.delegate = delegate
|
||||
windowController.window!.styleMask = [.titled, .closable, .resizable]
|
||||
windowController.window!.minSize = NSSize(width: 550, height: 200)
|
||||
windowController.window!.maxSize = NSSize(width: 800, height: 10000)
|
||||
|
||||
App.shared.siteListWindowController = windowController
|
||||
@@ -49,6 +53,7 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
||||
if (Shell.fileExists("/Applications/PhpStorm.app/Contents/Info.plist")) {
|
||||
self.editorAvailability.append("phpstorm")
|
||||
}
|
||||
|
||||
self.sites = Valet.shared.sites
|
||||
}
|
||||
|
||||
@@ -56,6 +61,19 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
||||
|
||||
override func viewWillDisappear() {}
|
||||
|
||||
// MARK: - Site Data Loading
|
||||
|
||||
func reloadSites() {
|
||||
// Reload site information
|
||||
Valet.shared.reloadSites()
|
||||
|
||||
// Update the site list
|
||||
self.sites = Valet.shared.sites
|
||||
|
||||
// Re-apply any existing search
|
||||
self.searchedFor(text: lastSearchedFor)
|
||||
}
|
||||
|
||||
// MARK: - Table View
|
||||
|
||||
func numberOfRows(in tableView: NSTableView) -> Int {
|
||||
@@ -207,6 +225,8 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
||||
// MARK: - (Search) Text Field Delegate
|
||||
|
||||
func searchedFor(text: String) {
|
||||
self.lastSearchedFor = text
|
||||
|
||||
let searchString = text.lowercased()
|
||||
|
||||
if searchString.isEmpty {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
class SiteListWC: NSWindowController, NSSearchFieldDelegate {
|
||||
class SiteListWC: NSWindowController, NSSearchFieldDelegate, NSToolbarDelegate {
|
||||
|
||||
@IBOutlet weak var searchToolbarItem: NSSearchToolbarItem!
|
||||
|
||||
@@ -18,14 +18,20 @@ class SiteListWC: NSWindowController, NSSearchFieldDelegate {
|
||||
self.searchToolbarItem.searchField.becomeFirstResponder()
|
||||
}
|
||||
|
||||
var contentVC: SiteListVC {
|
||||
return self.contentViewController as! SiteListVC
|
||||
}
|
||||
|
||||
func controlTextDidChange(_ notification: Notification) {
|
||||
guard let searchField = notification.object as? NSSearchField else {
|
||||
print("Unexpected control in update notification")
|
||||
return
|
||||
}
|
||||
|
||||
let window = self.contentViewController as! SiteListVC
|
||||
window.searchedFor(text: searchField.stringValue)
|
||||
contentVC.searchedFor(text: searchField.stringValue)
|
||||
}
|
||||
|
||||
@IBAction func pressedReload(_ sender: Any) {
|
||||
contentVC.reloadSites()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user