1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 12:00:09 +02:00

Add search functionality

This commit is contained in:
2021-12-03 21:25:10 +01:00
parent 87713bbe64
commit 93bdb0ed7f
5 changed files with 94 additions and 17 deletions

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "search.svg",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 512 512" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<path d="M505,442.7L405.3,343C400.8,338.5 394.7,336 388.3,336L372,336C399.6,300.7 416,256.3 416,208C416,93.1 322.9,0 208,0C93.1,0 0,93.1 0,208C0,322.9 93.1,416 208,416C256.3,416 300.7,399.6 336,372L336,388.3C336,394.7 338.5,400.8 343,405.3L442.7,505C452.1,514.4 467.3,514.4 476.6,505L504.9,476.7C514.3,467.3 514.3,452.1 505,442.7ZM208,336C137.3,336 80,278.8 80,208C80,137.3 137.2,80 208,80C278.7,80 336,137.2 336,208C336,278.7 278.8,336 208,336Z" style="fill:rgb(191,191,191);fill-rule:nonzero;"/>
</svg>

After

Width:  |  Height:  |  Size: 954 B

View File

@ -53,7 +53,7 @@
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-343" y="-16"/>
<point key="canvasLocation" x="-444" y="-1"/>
</scene>
<!--Window Controller-->
<scene sceneID="PQa-AT-b2a">
@ -314,17 +314,17 @@ Gw
<objects>
<viewController storyboardIdentifier="siteList" id="JZI-Vd-9oq" customClass="SiteListVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" misplaced="YES" id="rIZ-4U-bhj">
<rect key="frame" x="0.0" y="0.0" width="574" height="262"/>
<rect key="frame" x="0.0" y="0.0" width="574" height="199"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="69" horizontalPageScroll="10" verticalLineScroll="69" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p0j-eB-I2i">
<rect key="frame" x="0.0" y="0.0" width="574" height="259"/>
<rect key="frame" x="0.0" y="0.0" width="574" height="154"/>
<clipView key="contentView" id="6IL-DW-37w">
<rect key="frame" x="1" y="1" width="572" height="257"/>
<rect key="frame" x="1" y="1" width="572" height="152"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" multipleSelection="NO" autosaveColumns="NO" rowHeight="69" rowSizeStyle="automatic" viewBased="YES" id="cp3-34-pQj">
<rect key="frame" x="0.0" y="0.0" width="572" height="257"/>
<rect key="frame" x="0.0" y="0.0" width="572" height="152"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="17" height="0.0"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -421,7 +421,7 @@ Gw
</subviews>
</clipView>
<scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="TDE-ff-DQT">
<rect key="frame" x="1" y="254" width="557" height="15"/>
<rect key="frame" x="1" y="243" width="572" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="wFn-93-f10">
@ -429,24 +429,50 @@ Gw
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<textField focusRingType="none" verticalHuggingPriority="750" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p3I-BT-dOY">
<rect key="frame" x="37" y="164" width="531" height="23"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" focusRingType="none" placeholderString="Search for a domain..." usesSingleLineMode="YES" id="Hgd-Oz-Ggp">
<font key="font" metaFont="system" size="19"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</textFieldCell>
<connections>
<outlet property="delegate" destination="JZI-Vd-9oq" id="IR9-kH-rEv"/>
</connections>
</textField>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Z1T-9h-9ms">
<rect key="frame" x="10" y="166" width="24" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="dge-tM-IOH"/>
<constraint firstAttribute="width" constant="24" id="gHC-jb-3kU"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="Search" id="0ya-55-GjS"/>
</imageView>
</subviews>
<constraints>
<constraint firstItem="p0j-eB-I2i" firstAttribute="leading" secondItem="rIZ-4U-bhj" secondAttribute="leading" id="2Tx-yb-xrv"/>
<constraint firstItem="p0j-eB-I2i" firstAttribute="top" secondItem="rIZ-4U-bhj" secondAttribute="top" id="IUP-Wr-dSF"/>
<constraint firstItem="p0j-eB-I2i" firstAttribute="top" secondItem="p3I-BT-dOY" secondAttribute="bottom" constant="10" id="77g-3w-AMb"/>
<constraint firstAttribute="bottom" secondItem="p0j-eB-I2i" secondAttribute="bottom" id="QEw-5m-u1s"/>
<constraint firstAttribute="trailing" secondItem="p3I-BT-dOY" secondAttribute="trailing" constant="8" id="mje-P5-UjW"/>
<constraint firstItem="p3I-BT-dOY" firstAttribute="leading" secondItem="Z1T-9h-9ms" secondAttribute="trailing" constant="5" id="nPc-UE-WhI"/>
<constraint firstItem="Z1T-9h-9ms" firstAttribute="leading" secondItem="rIZ-4U-bhj" secondAttribute="leading" constant="10" id="oRZ-EK-xb6"/>
<constraint firstItem="p3I-BT-dOY" firstAttribute="top" secondItem="rIZ-4U-bhj" secondAttribute="top" constant="10" id="qw7-3Q-kUm"/>
<constraint firstItem="Z1T-9h-9ms" firstAttribute="centerY" secondItem="p3I-BT-dOY" secondAttribute="centerY" id="shq-ZM-Iyw"/>
<constraint firstAttribute="trailing" secondItem="p0j-eB-I2i" secondAttribute="trailing" id="zWH-TD-RZv"/>
</constraints>
</view>
<connections>
<outlet property="tableView" destination="cp3-34-pQj" id="sdw-Ac-27X"/>
<outlet property="textFieldSearch" destination="p3I-BT-dOY" id="EXF-u8-Rm6"/>
</connections>
</viewController>
<customObject id="HgD-aB-bQb" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="250" y="700.5"/>
<point key="canvasLocation" x="250" y="699.5"/>
</scene>
</scenes>
<resources>
<image name="GreenLock" width="448" height="512"/>
<image name="Search" width="512" height="512"/>
</resources>
</document>

View File

@ -10,14 +10,18 @@ import Cocoa
import HotKey
import Carbon
class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource, NSTextFieldDelegate {
// MARK: - Outlets
@IBOutlet weak var textFieldSearch: NSTextField!
@IBOutlet weak var tableView: NSTableView!
public var editorAvailability: [String] = []
public var sites: [Valet.Site] = []
// MARK: - Display
public static func show(delegate: NSWindowDelegate? = nil) {
@ -47,6 +51,7 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
if (Shell.fileExists("/Applications/PhpStorm.app/Contents/Info.plist")) {
self.editorAvailability.append("phpstorm")
}
self.sites = Valet.shared.sites
}
override func viewWillAppear() {}
@ -56,13 +61,13 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
// MARK: - Table View
func numberOfRows(in tableView: NSTableView) -> Int {
return Valet.shared.sites.count
return self.sites.count
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
guard let userCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "siteItem"), owner: self) as? SiteListCell else { return nil }
let item = Valet.shared.sites[row]
let item = self.sites[row]
/// Make sure to show the TLD
userCell.labelSiteName.stringValue = "\(item.name).\(Valet.shared.config.tld)"
@ -88,13 +93,13 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
func tableViewSelectionDidChange(_ notification: Notification) {
let menu = NSMenu()
let site = Valet.shared.sites[self.tableView.selectedRow]
if self.tableView.selectedRow == -1 {
tableView.menu = nil
return
}
let site = self.sites[self.tableView.selectedRow]
menu.addItem(
withTitle: site.secured
? "site_list.unsecure".localized
@ -147,28 +152,46 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
// MARK: Open with IDE / Editor
@objc public func openWithPhpStorm() {
let site = Valet.shared.sites[self.tableView.selectedRow]
let site = self.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]
let site = self.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 = self.sites[self.tableView.selectedRow]
let prefix = site.secured ? "https://" : "http://"
let url = "\(prefix)\(site.name).\(Valet.shared.config.tld)"
NSWorkspace.shared.open(URL(string: url)!)
}
@objc public func openInFinder() {
let site = Valet.shared.sites[self.tableView.selectedRow]
let site = self.sites[self.tableView.selectedRow]
Shell.run("open \(site.absolutePath)")
}
// MARK: - (Search) Text Field Delegate
func controlTextDidChange(_ obj: Notification) {
let searchString = self.textFieldSearch.stringValue.lowercased()
if searchString.isEmpty {
self.sites = Valet.shared.sites
tableView.reloadData()
return
}
self.sites = Valet.shared.sites.filter({ site in
return site.name.lowercased().contains(searchString)
})
tableView.reloadData()
}
// MARK: - Deinitialization

View File

@ -25,6 +25,8 @@ class SiteListWC: NSWindowController {
default:
break
}
} else {
super.keyDown(with: event)
}
}