diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 437d0e6..2a61952 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -74,6 +74,10 @@ C43A8A1A25D9CD1000591B77 /* Utility.swift in Sources */ = {isa = PBXBuildFile; fileRef = C43A8A1925D9CD1000591B77 /* Utility.swift */; }; C43A8A2025D9D1D700591B77 /* brew.json in Resources */ = {isa = PBXBuildFile; fileRef = C43A8A1F25D9D1D700591B77 /* brew.json */; }; C43A8A2425D9D20D00591B77 /* BrewJsonParserTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C43A8A2325D9D20D00591B77 /* BrewJsonParserTest.swift */; }; + C44067F527E2582B0045BD4E /* SiteListNameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44067F427E2582B0045BD4E /* SiteListNameCell.swift */; }; + C44067F727E258410045BD4E /* SiteListPhpCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44067F627E258410045BD4E /* SiteListPhpCell.swift */; }; + C44067F927E2585E0045BD4E /* SiteListTypeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44067F827E2585E0045BD4E /* SiteListTypeCell.swift */; }; + C44067FB27E25FD70045BD4E /* SiteListTLSCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44067FA27E25FD70045BD4E /* SiteListTLSCell.swift */; }; C44C198D276E3A1C0072762D /* ProgressWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44C198C276E3A1C0072762D /* ProgressWindow.swift */; }; C44C198E276E3A1C0072762D /* ProgressWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44C198C276E3A1C0072762D /* ProgressWindow.swift */; }; C44C1991276E44CB0072762D /* ProgressWindow.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C44C1990276E44CB0072762D /* ProgressWindow.storyboard */; }; @@ -266,6 +270,10 @@ C43A8A1925D9CD1000591B77 /* Utility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utility.swift; sourceTree = ""; }; C43A8A1F25D9D1D700591B77 /* brew.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = brew.json; sourceTree = ""; }; C43A8A2325D9D20D00591B77 /* BrewJsonParserTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrewJsonParserTest.swift; sourceTree = ""; }; + C44067F427E2582B0045BD4E /* SiteListNameCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteListNameCell.swift; sourceTree = ""; }; + C44067F627E258410045BD4E /* SiteListPhpCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteListPhpCell.swift; sourceTree = ""; }; + C44067F827E2585E0045BD4E /* SiteListTypeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SiteListTypeCell.swift; sourceTree = ""; }; + C44067FA27E25FD70045BD4E /* SiteListTLSCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SiteListTLSCell.swift; sourceTree = ""; }; C44C198C276E3A1C0072762D /* ProgressWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressWindow.swift; sourceTree = ""; }; C44C1990276E44CB0072762D /* ProgressWindow.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ProgressWindow.storyboard; sourceTree = ""; }; C44CCD3F27AFE2FC00CE40E5 /* AlertableError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertableError.swift; sourceTree = ""; }; @@ -515,6 +523,17 @@ path = Domain; sourceTree = ""; }; + C44067F327E256560045BD4E /* Cells */ = { + isa = PBXGroup; + children = ( + C44067FA27E25FD70045BD4E /* SiteListTLSCell.swift */, + C44067F427E2582B0045BD4E /* SiteListNameCell.swift */, + C44067F627E258410045BD4E /* SiteListPhpCell.swift */, + C44067F827E2585E0045BD4E /* SiteListTypeCell.swift */, + ); + path = Cells; + sourceTree = ""; + }; C44C198F276E3A380072762D /* Progress */ = { isa = PBXGroup; children = ( @@ -536,6 +555,7 @@ C464ADAA275A7A25003FCD53 /* SiteList */ = { isa = PBXGroup; children = ( + C44067F327E256560045BD4E /* Cells */, C464ADAB275A7A3F003FCD53 /* SiteListWC.swift */, C464ADAE275A7A69003FCD53 /* SiteListVC.swift */, C41E87192763D42300161EE0 /* SiteListVC+ContextMenu.swift */, @@ -921,8 +941,10 @@ C4F2E4372752F0870020E974 /* HomebrewDiagnostics.swift in Sources */, C4CCBA6C275C567B008C7055 /* PMWindowController.swift in Sources */, C4B585442770FE3900DA4FBE /* Command.swift in Sources */, + C44067F527E2582B0045BD4E /* SiteListNameCell.swift in Sources */, C41CD0292628D8EE0065BBED /* GlobalKeybindPreference.swift in Sources */, C4EE55AB27708B9E001DF387 /* Preview.swift in Sources */, + C44067F727E258410045BD4E /* SiteListPhpCell.swift in Sources */, C415D3B72770F294005EF286 /* Actions.swift in Sources */, C44C198D276E3A1C0072762D /* ProgressWindow.swift in Sources */, C4C3ED4327834C5200AB15D8 /* CustomPrefs.swift in Sources */, @@ -951,6 +973,7 @@ C44CCD4927AFF3B700CE40E5 /* MainMenu+Async.swift in Sources */, C4C1019B27C65C6F001FACC2 /* Process.swift in Sources */, C4EC1E73279DFCF40010F296 /* Events.swift in Sources */, + C44067FB27E25FD70045BD4E /* SiteListTLSCell.swift in Sources */, C4927F0B27B2DFC200C55AFD /* Errors.swift in Sources */, C4B5853E2770FE3900DA4FBE /* Paths.swift in Sources */, C41C1B4B22B019FF00E7CF16 /* ActivePhpInstallation.swift in Sources */, @@ -968,6 +991,7 @@ C4080FFA27BD956700BF2C6B /* BetterAlertVC.swift in Sources */, C4B5635E276AB09000F12CCB /* VersionExtractor.swift in Sources */, C47331A2247093B7009A0597 /* StatusMenu.swift in Sources */, + C44067F927E2585E0045BD4E /* SiteListTypeCell.swift in Sources */, C4C3ED412783497000AB15D8 /* MainMenu+Startup.swift in Sources */, C4D89BC62783C99400A02B68 /* ComposerJson.swift in Sources */, C46FA23F246C358E00944F05 /* StringExtension.swift in Sources */, diff --git a/phpmon/Domain/App/Base.lproj/Main.storyboard b/phpmon/Domain/App/Base.lproj/Main.storyboard index b0521c5..307551a 100644 --- a/phpmon/Domain/App/Base.lproj/Main.storyboard +++ b/phpmon/Domain/App/Base.lproj/Main.storyboard @@ -1,10 +1,9 @@ - + - + - @@ -532,7 +531,7 @@ Gw + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - + + @@ -951,22 +983,27 @@ Gw + - diff --git a/phpmon/Domain/SiteList/Cells/SiteListNameCell.swift b/phpmon/Domain/SiteList/Cells/SiteListNameCell.swift new file mode 100644 index 0000000..5017d4f --- /dev/null +++ b/phpmon/Domain/SiteList/Cells/SiteListNameCell.swift @@ -0,0 +1,33 @@ +// +// SiteListNameCell.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 16/03/2022. +// Copyright © 2022 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import AppKit + +class SiteListNameCell: NSTableCellView, SiteListCellProtocol +{ + var site: ValetSite? = nil + + @IBOutlet weak var labelSiteName: NSTextField! + @IBOutlet weak var labelPathName: NSTextField! + + func populateCell(with site: ValetSite) { + self.site = site + + var siteName = "\(site.name).\(Valet.shared.config.tld)" + + if (site.isolatedPhpVersion != nil) { + siteName += " [isolated \(site.isolatedPhpVersion!.versionNumber.homebrewVersion)]" + } + + labelSiteName.stringValue = siteName + + // Show the absolute path, except make sure to replace the /Users/username segment with ~ for readability + labelPathName.stringValue = site.absolutePathRelative + } +} diff --git a/phpmon/Domain/SiteList/Cells/SiteListPhpCell.swift b/phpmon/Domain/SiteList/Cells/SiteListPhpCell.swift new file mode 100644 index 0000000..e8743ca --- /dev/null +++ b/phpmon/Domain/SiteList/Cells/SiteListPhpCell.swift @@ -0,0 +1,18 @@ +// +// SiteListPhpCell.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 16/03/2022. +// Copyright © 2022 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import AppKit + +class SiteListPhpCell: NSTableCellView, SiteListCellProtocol +{ + func populateCell(with site: ValetSite) { + + } + +} diff --git a/phpmon/Domain/SiteList/Cells/SiteListTLSCell.swift b/phpmon/Domain/SiteList/Cells/SiteListTLSCell.swift new file mode 100644 index 0000000..71b3571 --- /dev/null +++ b/phpmon/Domain/SiteList/Cells/SiteListTLSCell.swift @@ -0,0 +1,26 @@ +// +// SiteListNameCell.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 16/03/2022. +// Copyright © 2022 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import AppKit + +class SiteListTLSCell: NSTableCellView, SiteListCellProtocol +{ + var site: ValetSite? = nil + + @IBOutlet weak var imageViewLock: NSImageView! + + func populateCell(with site: ValetSite) { + self.site = site + + // Show the green or red lock based on whether the site was secured + imageViewLock.contentTintColor = site.secured + ? NSColor(named: "IconColorGreen") // green + : NSColor(named: "IconColorRed") + } +} diff --git a/phpmon/Domain/SiteList/Cells/SiteListTypeCell.swift b/phpmon/Domain/SiteList/Cells/SiteListTypeCell.swift new file mode 100644 index 0000000..7be8804 --- /dev/null +++ b/phpmon/Domain/SiteList/Cells/SiteListTypeCell.swift @@ -0,0 +1,36 @@ +// +// SiteListTypeCell.swift +// PHP Monitor +// +// Created by Nico Verbruggen on 16/03/2022. +// Copyright © 2022 Nico Verbruggen. All rights reserved. +// + +import Cocoa +import AppKit + +class SiteListTypeCell: NSTableCellView, SiteListCellProtocol +{ + var site: ValetSite? = nil + + @IBOutlet weak var labelDriver: NSTextField! + @IBOutlet weak var imageViewType: NSImageView! + + func populateCell(with site: ValetSite) { + // If the `aliasPath` is nil, we're dealing with a parked site (otherwise: linked). + imageViewType.image = NSImage( + named: site.aliasPath == nil + ? "IconParked" + : "IconLinked" + ) + imageViewType.contentTintColor = NSColor.tertiaryLabelColor + + labelDriver.stringValue = site.driver ?? "driver.not_detected".localized + + // Determine the Laravel version + if site.driver == "Laravel" && site.notableComposerDependencies.keys.contains("laravel/framework") { + let constraint = site.notableComposerDependencies["laravel/framework"]! + labelDriver.stringValue = "Laravel (\(constraint))" + } + } +} diff --git a/phpmon/Domain/SiteList/SiteListCell.swift b/phpmon/Domain/SiteList/SiteListCell.swift index 05ef040..375119c 100644 --- a/phpmon/Domain/SiteList/SiteListCell.swift +++ b/phpmon/Domain/SiteList/SiteListCell.swift @@ -9,18 +9,14 @@ import Cocoa import AppKit +protocol SiteListCellProtocol { + func populateCell(with site: ValetSite) +} + class SiteListCell: NSTableCellView { - var site: ValetSite? = nil - - @IBOutlet weak var labelSiteName: NSTextField! - @IBOutlet weak var labelPathName: NSTextField! @IBOutlet weak var labelDriverType: NSTextField! - - @IBOutlet weak var imageViewLock: NSImageView! - @IBOutlet weak var imageViewType: NSImageView! - - @IBOutlet weak var labelDriver: NSTextField! + @IBOutlet weak var buttonPhpVersion: NSButton! @IBOutlet weak var imageViewPhpVersionOK: NSImageView! @@ -30,54 +26,14 @@ class SiteListCell: NSTableCellView } func populateCell(with site: ValetSite) { - self.site = site - - // Make sure to show the TLD - var siteName = "\(site.name).\(Valet.shared.config.tld)" - - if (site.isolatedPhpVersion != nil) { - siteName += " [isolated \(site.isolatedPhpVersion!.versionNumber.homebrewVersion)]" - } - - labelSiteName.stringValue = siteName - - // Show the absolute path, except make sure to replace the /Users/username segment with ~ for readability - labelPathName.stringValue = site.absolutePathRelative - - // If the `aliasPath` is nil, we're dealing with a parked site (otherwise: linked). - imageViewType.image = NSImage( - named: site.aliasPath == nil - ? "IconParked" - : "IconLinked" - ) - imageViewType.contentTintColor = NSColor.tertiaryLabelColor - - // Show the green or red lock based on whether the site was secured - imageViewLock.contentTintColor = site.secured ? - NSColor(named: "IconColorGreen") // green - : NSColor(named: "IconColorRed") - - // Show the current driver - labelDriverType.stringValue = site.driverDeterminedByComposer - ? "Project Type".uppercased() - : "Driver Type".uppercased() - - labelDriver.stringValue = site.driver ?? "driver.not_detected".localized - - // Determine the Laravel version - if site.driver == "Laravel" && site.notableComposerDependencies.keys.contains("laravel/framework") { - let constraint = site.notableComposerDependencies["laravel/framework"]! - labelDriver.stringValue = "Laravel (\(constraint))" - } - // Show the PHP version buttonPhpVersion.title = " PHP \(site.composerPhp) " buttonPhpVersion.isHidden = (site.composerPhp == "???") - imageViewPhpVersionOK.isHidden = (site.composerPhp == "???" || !site.composerPhpCompatibleWithLinked) } + /* @IBAction func pressedPhpVersion(_ sender: Any) { guard let site = self.site else { return } @@ -114,4 +70,5 @@ class SiteListCell: NSTableCellView } } } + */ } diff --git a/phpmon/Domain/SiteList/SiteListVC.swift b/phpmon/Domain/SiteList/SiteListVC.swift index 57ca9c0..1d13368 100644 --- a/phpmon/Domain/SiteList/SiteListVC.swift +++ b/phpmon/Domain/SiteList/SiteListVC.swift @@ -174,13 +174,22 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource { } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { + let mapping: [String: String] = [ + "AutomaticTableColumnIdentifier.0": "siteListTLSCell", + "AutomaticTableColumnIdentifier.1": "siteListNameCell", + "AutomaticTableColumnIdentifier.2": "siteListPhpCell", + "AutomaticTableColumnIdentifier.3": "siteListDriverCell", + ] + + let columnName = tableColumn!.identifier.rawValue + guard let userCell = tableView.makeView( - withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "siteItem"), owner: self - ) as? SiteListCell else { return nil } + withIdentifier: NSUserInterfaceItemIdentifier(rawValue: mapping[columnName]!), owner: self + ) as? SiteListCellProtocol else { return nil } userCell.populateCell(with: sites[row]) - return userCell + return userCell as? NSView } func tableViewSelectionDidChange(_ notification: Notification) {