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

♻️ Refactor preferences window

This commit is contained in:
2022-06-05 12:52:59 +02:00
parent fbf2158488
commit 998bbd231a
6 changed files with 140 additions and 62 deletions

View File

@ -7,7 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
5420395926135DC100FB00FA /* PrefsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395826135DC100FB00FA /* PrefsVC.swift */; }; 5420395926135DC100FB00FA /* GeneralPreferencesVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395826135DC100FB00FA /* GeneralPreferencesVC.swift */; };
5420395F2613607600FB00FA /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395E2613607600FB00FA /* Preferences.swift */; }; 5420395F2613607600FB00FA /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395E2613607600FB00FA /* Preferences.swift */; };
5489625828312FAD004F647A /* CreatedFromFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5489625728312FAD004F647A /* CreatedFromFile.swift */; }; 5489625828312FAD004F647A /* CreatedFromFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5489625728312FAD004F647A /* CreatedFromFile.swift */; };
5489625928313231004F647A /* CreatedFromFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5489625728312FAD004F647A /* CreatedFromFile.swift */; }; 5489625928313231004F647A /* CreatedFromFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5489625728312FAD004F647A /* CreatedFromFile.swift */; };
@ -143,7 +143,7 @@
C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; }; C476FF9822B0DD830098105B /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C476FF9722B0DD830098105B /* Alert.swift */; };
C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; }; C4811D2422D70A4700B5F6B3 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2322D70A4700B5F6B3 /* App.swift */; };
C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; }; C4811D2A22D70F9A00B5F6B3 /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4811D2922D70F9A00B5F6B3 /* MainMenu.swift */; };
C481F79726164A78004FBCFF /* PrefsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395826135DC100FB00FA /* PrefsVC.swift */; }; C481F79726164A78004FBCFF /* GeneralPreferencesVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395826135DC100FB00FA /* GeneralPreferencesVC.swift */; };
C481F79A26164A7C004FBCFF /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395E2613607600FB00FA /* Preferences.swift */; }; C481F79A26164A7C004FBCFF /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5420395E2613607600FB00FA /* Preferences.swift */; };
C484437B2804BB560041A78A /* ValetProxyScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = C484437A2804BB560041A78A /* ValetProxyScanner.swift */; }; C484437B2804BB560041A78A /* ValetProxyScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = C484437A2804BB560041A78A /* ValetProxyScanner.swift */; };
C484437C2804BB560041A78A /* ValetProxyScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = C484437A2804BB560041A78A /* ValetProxyScanner.swift */; }; C484437C2804BB560041A78A /* ValetProxyScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = C484437A2804BB560041A78A /* ValetProxyScanner.swift */; };
@ -288,7 +288,7 @@
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
5420395826135DC100FB00FA /* PrefsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsVC.swift; sourceTree = "<group>"; }; 5420395826135DC100FB00FA /* GeneralPreferencesVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralPreferencesVC.swift; sourceTree = "<group>"; };
5420395E2613607600FB00FA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; }; 5420395E2613607600FB00FA /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
5489625728312FAD004F647A /* CreatedFromFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatedFromFile.swift; sourceTree = "<group>"; }; 5489625728312FAD004F647A /* CreatedFromFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatedFromFile.swift; sourceTree = "<group>"; };
54A18D3F282A566E000A0D81 /* nginx-secure-proxy-custom-tld.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-secure-proxy-custom-tld.test"; sourceTree = "<group>"; }; 54A18D3F282A566E000A0D81 /* nginx-secure-proxy-custom-tld.test */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "nginx-secure-proxy-custom-tld.test"; sourceTree = "<group>"; };
@ -474,7 +474,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C4998F092617633900B2526E /* PrefsWC.swift */, C4998F092617633900B2526E /* PrefsWC.swift */,
5420395826135DC100FB00FA /* PrefsVC.swift */, 5420395826135DC100FB00FA /* GeneralPreferencesVC.swift */,
5420395E2613607600FB00FA /* Preferences.swift */, 5420395E2613607600FB00FA /* Preferences.swift */,
C4C3ED4227834C5200AB15D8 /* CustomPrefs.swift */, C4C3ED4227834C5200AB15D8 /* CustomPrefs.swift */,
C4068CA927B0890D00544CD5 /* MenuBarIcons.swift */, C4068CA927B0890D00544CD5 /* MenuBarIcons.swift */,
@ -1202,7 +1202,7 @@
C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */, C4F8C0A422D4F12C002EFE61 /* DateExtension.swift in Sources */,
C4AF9F7A2754499000D44ED0 /* Valet.swift in Sources */, C4AF9F7A2754499000D44ED0 /* Valet.swift in Sources */,
C4C0E8EA27F88B80002D32A9 /* ValetProxy+Fake.swift in Sources */, C4C0E8EA27F88B80002D32A9 /* ValetProxy+Fake.swift in Sources */,
5420395926135DC100FB00FA /* PrefsVC.swift in Sources */, 5420395926135DC100FB00FA /* GeneralPreferencesVC.swift in Sources */,
C43603A0275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */, C43603A0275E67610028EFC6 /* AppDelegate+Notifications.swift in Sources */,
5489625828312FAD004F647A /* CreatedFromFile.swift in Sources */, 5489625828312FAD004F647A /* CreatedFromFile.swift in Sources */,
C4068CA727B07A1300544CD5 /* SelectPreferenceView.swift in Sources */, C4068CA727B07A1300544CD5 /* SelectPreferenceView.swift in Sources */,
@ -1368,7 +1368,7 @@
C4D936CB27E3EE4A00BD69FE /* DomainListCellProtocol.swift in Sources */, C4D936CB27E3EE4A00BD69FE /* DomainListCellProtocol.swift in Sources */,
C4B97B76275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */, C4B97B76275CF08C003F3378 /* AppDelegate+MenuOutlets.swift in Sources */,
C4F780CD25D80B75000DBC97 /* Alert.swift in Sources */, C4F780CD25D80B75000DBC97 /* Alert.swift in Sources */,
C481F79726164A78004FBCFF /* PrefsVC.swift in Sources */, C481F79726164A78004FBCFF /* GeneralPreferencesVC.swift in Sources */,
C41E871B2763D42300161EE0 /* DomainListVC+ContextMenu.swift in Sources */, C41E871B2763D42300161EE0 /* DomainListVC+ContextMenu.swift in Sources */,
C40C7F3127722E8D00DDDCDC /* Logger.swift in Sources */, C40C7F3127722E8D00DDDCDC /* Logger.swift in Sources */,
C4068CAB27B0890D00544CD5 /* MenuBarIcons.swift in Sources */, C4068CAB27B0890D00544CD5 /* MenuBarIcons.swift in Sources */,

View File

@ -324,14 +324,15 @@
<!--Window Controller--> <!--Window Controller-->
<scene sceneID="PQa-AT-b2a"> <scene sceneID="PQa-AT-b2a">
<objects> <objects>
<customObject id="OF0-qs-3Oh" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<windowController storyboardIdentifier="preferencesWindow" showSeguePresentationStyle="single" id="hLJ-Fd-wRr" customClass="PrefsWC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController"> <windowController storyboardIdentifier="preferencesWindow" showSeguePresentationStyle="single" id="hLJ-Fd-wRr" customClass="PrefsWC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="h4c-3b-nko"> <window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="h4c-3b-nko">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="372" y="403" width="480" height="270"/> <rect key="contentRect" x="372" y="403" width="550" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="2304" height="1271"/> <rect key="screenRect" x="0.0" y="0.0" width="2304" height="1271"/>
<view key="contentView" id="2yL-50-11x"> <view key="contentView" id="2yL-50-11x">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/> <rect key="frame" x="0.0" y="0.0" width="550" height="270"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
</view> </view>
<toolbar key="toolbar" implicitIdentifier="611E3485-DC7F-46A0-8528-11CF9366370C" autosavesConfiguration="NO" allowsUserCustomization="NO" showsBaselineSeparator="NO" displayMode="iconAndLabel" sizeMode="regular" id="fcq-wR-7iv"> <toolbar key="toolbar" implicitIdentifier="611E3485-DC7F-46A0-8528-11CF9366370C" autosavesConfiguration="NO" allowsUserCustomization="NO" showsBaselineSeparator="NO" displayMode="iconAndLabel" sizeMode="regular" id="fcq-wR-7iv">
@ -343,17 +344,16 @@
</connections> </connections>
</window> </window>
<connections> <connections>
<segue destination="AW2-rV-rbS" kind="relationship" relationship="window.shadowedContentViewController" id="3dX-9V-eA0"/> <segue destination="PCI-2c-55Y" kind="relationship" relationship="window.shadowedContentViewController" id="egC-A4-am8"/>
</connections> </connections>
</windowController> </windowController>
<customObject id="OF0-qs-3Oh" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="-374" y="238"/> <point key="canvasLocation" x="-374" y="238"/>
</scene> </scene>
<!--Preferences--> <!--Preferences-->
<scene sceneID="iyi-IS-7Ps"> <scene sceneID="iyi-IS-7Ps">
<objects> <objects>
<viewController title="Preferences" storyboardIdentifier="preferences" showSeguePresentationStyle="single" id="AW2-rV-rbS" customClass="PrefsVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController"> <viewController title="Preferences" identifier="preferencesTemplateVC" storyboardIdentifier="preferencesTemplateVC" showSeguePresentationStyle="single" id="AW2-rV-rbS" customClass="GenericPreferenceVC" customModule="PHP_Monitor" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="Pf1-A5-3Xz"> <view key="view" wantsLayer="YES" id="Pf1-A5-3Xz">
<rect key="frame" x="0.0" y="0.0" width="550" height="498"/> <rect key="frame" x="0.0" y="0.0" width="550" height="498"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
@ -378,7 +378,27 @@
</viewController> </viewController>
<customObject id="eQC-8B-FkX" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> <customObject id="eQC-8B-FkX" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="260" y="217"/> <point key="canvasLocation" x="835" y="-28"/>
</scene>
<!--Tab View Controller-->
<scene sceneID="B5x-d3-c7D">
<objects>
<customObject id="pNW-tM-SQu" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<tabViewController tabStyle="toolbar" canPropagateSelectedChildViewControllerTitle="NO" id="PCI-2c-55Y" sceneMemberID="viewController">
<tabView key="tabView" type="noTabsNoBorder" id="l0U-9a-nM6">
<rect key="frame" x="0.0" y="0.0" width="508" height="300"/>
<autoresizingMask key="autoresizingMask"/>
<font key="font" metaFont="message"/>
<connections>
<outlet property="delegate" destination="PCI-2c-55Y" id="6gR-GR-cwq"/>
</connections>
</tabView>
<connections>
<outlet property="tabView" destination="l0U-9a-nM6" id="tfn-UN-1Aa"/>
</connections>
</tabViewController>
</objects>
<point key="canvasLocation" x="283" y="-252"/>
</scene> </scene>
<!--Window Controller--> <!--Window Controller-->
<scene sceneID="4XS-kY-YIS"> <scene sceneID="4XS-kY-YIS">
@ -532,7 +552,7 @@ Gw
</connections> </connections>
</button> </button>
<button wantsLayer="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="n5T-nn-k3j"> <button wantsLayer="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="n5T-nn-k3j">
<rect key="frame" x="13" y="13" width="82" height="32"/> <rect key="frame" x="13" y="13" width="81" height="32"/>
<buttonCell key="cell" type="push" title="Tertiary" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="mzA-Uu-gyf"> <buttonCell key="cell" type="push" title="Tertiary" bezelStyle="rounded" alignment="center" borderStyle="border" inset="2" id="mzA-Uu-gyf">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@ -651,7 +671,7 @@ Gw
<color key="fillColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="fillColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
</box> </box>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PVw-cM-qAB"> <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="PVw-cM-qAB">
<rect key="frame" x="325" y="13" width="142" height="32"/> <rect key="frame" x="326" y="13" width="141" height="32"/>
<buttonCell key="cell" type="push" title="[i18n] Create Link" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="WwW-Wv-I8s"> <buttonCell key="cell" type="push" title="[i18n] Create Link" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="WwW-Wv-I8s">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/> <font key="font" metaFont="system"/>
@ -732,7 +752,7 @@ Gw
</textFieldCell> </textFieldCell>
</textField> </textField>
<textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="900-Z2-tID"> <textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="900-Z2-tID">
<rect key="frame" x="139" y="23" width="180" height="14"/> <rect key="frame" x="140" y="23" width="180" height="14"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="That domain name already exists." id="jOt-n6-TQf"> <textFieldCell key="cell" lineBreakMode="clipping" title="That domain name already exists." id="jOt-n6-TQf">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<color key="textColor" name="systemRedColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="systemRedColor" catalog="System" colorSpace="catalog"/>
@ -1381,7 +1401,7 @@ Gw
</constraints> </constraints>
<textFieldCell key="cell" selectable="YES" alignment="left" id="3i9-RG-Ift"> <textFieldCell key="cell" selectable="YES" alignment="left" id="3i9-RG-Ift">
<font key="font" metaFont="smallSystem"/> <font key="font" metaFont="smallSystem"/>
<mutableString key="title">[i18n] Links are used to directly serve projects. If you have a Laravel, Symfony, WordPress, etc. folder with code, you'll want to create a link and choose the folder where your code lives.If you are in need of a proxy, you can proxy e.g. a container to a particular domain name. This can be useful in combination with Docker, for example.</mutableString> <string key="title">[i18n] Links are used to directly serve projects. If you have a Laravel, Symfony, WordPress, etc. folder with code, you'll want to create a link and choose the folder where your code lives.If you are in need of a proxy, you can proxy e.g. a container to a particular domain name. This can be useful in combination with Docker, for example.</string>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>

View File

@ -166,7 +166,7 @@ class MainMenu: NSObject, NSWindowDelegate, NSMenuDelegate, PhpSwitcherDelegate
} }
@objc func openPrefs() { @objc func openPrefs() {
PrefsVC.show() PrefsWC.show()
} }
@objc func openDomainList() { @objc func openDomainList() {

View File

@ -1,5 +1,5 @@
// //
// PrefsVC.swift // GeneralPreferencesVC.swift
// PHP Monitor // PHP Monitor
// //
// Created by Nico Verbruggen on 30/03/2021. // Created by Nico Verbruggen on 30/03/2021.
@ -9,56 +9,54 @@
import Cocoa import Cocoa
import Carbon import Carbon
class PrefsVC: NSViewController { class GenericPreferenceVC: NSViewController {
// MARK: - Window Identifier // MARK: - Content
@IBOutlet weak var stackView: NSStackView! @IBOutlet weak var stackView: NSStackView!
// MARK: - Display var views: [NSView] = []
public static func create(delegate: NSWindowDelegate?) { override func viewDidLoad() {
let storyboard = NSStoryboard(name: "Main", bundle: nil) super.viewDidLoad()
self.views.forEach({ self.stackView.addArrangedSubview($0) })
let windowController = storyboard.instantiateController(
withIdentifier: "preferencesWindow"
) as! PrefsWC
windowController.window!.title = "prefs.title".localized
windowController.window!.subtitle = "prefs.subtitle".localized
windowController.window!.delegate = delegate
windowController.window!.styleMask = [.titled, .closable, .miniaturizable]
windowController.window!.delegate = windowController
windowController.positionWindowInTopLeftCorner()
App.shared.preferencesWindowController = windowController
} }
public static func show(delegate: NSWindowDelegate? = nil) { // MARK: - Deinitialization
if App.shared.preferencesWindowController == nil {
Self.create(delegate: delegate) deinit {
Log.perf("PrefsVC deallocated")
} }
App.shared.preferencesWindowController!.showWindow(self) }
NSApp.activate(ignoringOtherApps: true)
} class GeneralPreferencesVC: GenericPreferenceVC {
// MARK: - Icon and title
var icon: String = "gear"
// MARK: - Lifecycle // MARK: - Lifecycle
override func viewDidLoad() { public static func fromStoryboard() -> GenericPreferenceVC {
[ let vc = NSStoryboard(name: "Main", bundle: nil)
.instantiateController(withIdentifier: "preferencesTemplateVC") as! GenericPreferenceVC
vc.views = [
getDynamicIconPreferenceView(), getDynamicIconPreferenceView(),
getIconOptionsPreferenceView(), getIconOptionsPreferenceView(),
getIconDensityPreferenceView(), getIconDensityPreferenceView(),
getAutoRestartPreferenceView(), getAutoRestartPreferenceView(),
getAutomaticComposerUpdatePreferenceView(), getAutomaticComposerUpdatePreferenceView(),
getShortcutPreferenceView(), // getShortcutPreferenceView(),
getIntegrationsPreferenceView(), getIntegrationsPreferenceView(),
getAutomaticUpdateCheckPreferenceView() getAutomaticUpdateCheckPreferenceView()
].forEach({ self.stackView.addArrangedSubview($0) }) ]
return vc
} }
private func getDynamicIconPreferenceView() -> NSView { private static func getDynamicIconPreferenceView() -> NSView {
return CheckboxPreferenceView.make( return CheckboxPreferenceView.make(
sectionText: "prefs.dynamic_icon".localized, sectionText: "prefs.dynamic_icon".localized,
descriptionText: "prefs.dynamic_icon_desc".localized, descriptionText: "prefs.dynamic_icon_desc".localized,
@ -70,7 +68,7 @@ class PrefsVC: NSViewController {
) )
} }
private func getIconOptionsPreferenceView() -> NSView { private static func getIconOptionsPreferenceView() -> NSView {
return SelectPreferenceView.make( return SelectPreferenceView.make(
sectionText: "", sectionText: "",
descriptionText: "prefs.icon_options_desc".localized, descriptionText: "prefs.icon_options_desc".localized,
@ -83,7 +81,7 @@ class PrefsVC: NSViewController {
) )
} }
private func getIconDensityPreferenceView() -> NSView { private static func getIconDensityPreferenceView() -> NSView {
return CheckboxPreferenceView.make( return CheckboxPreferenceView.make(
sectionText: "prefs.info_density".localized, sectionText: "prefs.info_density".localized,
descriptionText: "prefs.display_full_php_version_desc".localized, descriptionText: "prefs.display_full_php_version_desc".localized,
@ -96,7 +94,7 @@ class PrefsVC: NSViewController {
) )
} }
private func getAutoRestartPreferenceView() -> NSView { private static func getAutoRestartPreferenceView() -> NSView {
return CheckboxPreferenceView.make( return CheckboxPreferenceView.make(
sectionText: "prefs.services".localized, sectionText: "prefs.services".localized,
descriptionText: "prefs.auto_restart_services_desc".localized, descriptionText: "prefs.auto_restart_services_desc".localized,
@ -106,7 +104,7 @@ class PrefsVC: NSViewController {
) )
} }
private func getAutomaticComposerUpdatePreferenceView() -> NSView { private static func getAutomaticComposerUpdatePreferenceView() -> NSView {
CheckboxPreferenceView.make( CheckboxPreferenceView.make(
sectionText: "prefs.switcher".localized, sectionText: "prefs.switcher".localized,
descriptionText: "prefs.auto_composer_update_desc".localized, descriptionText: "prefs.auto_composer_update_desc".localized,
@ -116,15 +114,17 @@ class PrefsVC: NSViewController {
) )
} }
private func getShortcutPreferenceView() -> NSView { /*
private static func getShortcutPreferenceView() -> NSView {
return HotkeyPreferenceView.make( return HotkeyPreferenceView.make(
sectionText: "prefs.global_shortcut".localized, sectionText: "prefs.global_shortcut".localized,
descriptionText: "prefs.shortcut_desc".localized, descriptionText: "prefs.shortcut_desc".localized,
self self
) )
} }
*/
private func getIntegrationsPreferenceView() -> NSView { private static func getIntegrationsPreferenceView() -> NSView {
return CheckboxPreferenceView.make( return CheckboxPreferenceView.make(
sectionText: "prefs.integrations".localized, sectionText: "prefs.integrations".localized,
descriptionText: "prefs.open_protocol_desc".localized, descriptionText: "prefs.open_protocol_desc".localized,
@ -134,7 +134,7 @@ class PrefsVC: NSViewController {
) )
} }
private func getAutomaticUpdateCheckPreferenceView() -> NSView { private static func getAutomaticUpdateCheckPreferenceView() -> NSView {
return CheckboxPreferenceView.make( return CheckboxPreferenceView.make(
sectionText: "prefs.updates".localized, sectionText: "prefs.updates".localized,
descriptionText: "prefs.automatic_update_check_desc".localized, descriptionText: "prefs.automatic_update_check_desc".localized,
@ -153,10 +153,4 @@ class PrefsVC: NSViewController {
listeningForHotkeyView = nil listeningForHotkeyView = nil
} }
} }
// MARK: - Deinitialization
deinit {
Log.perf("PrefsVC deallocated")
}
} }

View File

@ -21,11 +21,73 @@ class PrefsWC: PMWindowController {
return "Preferences" return "Preferences"
} }
public static func create(delegate: NSWindowDelegate?) {
let storyboard = NSStoryboard(name: "Main", bundle: nil)
let windowController = storyboard.instantiateController(
withIdentifier: "preferencesWindow"
) as! PrefsWC
windowController.window!.title = "prefs.title".localized
windowController.window!.subtitle = "prefs.subtitle".localized
windowController.window!.delegate = delegate
windowController.window!.styleMask = [.titled, .closable, .miniaturizable]
windowController.window!.delegate = windowController
App.shared.preferencesWindowController = windowController
}
public static func show(delegate: NSWindowDelegate? = nil) {
if App.shared.preferencesWindowController == nil {
Self.create(delegate: delegate)
guard let preferencesWC = App.shared.preferencesWindowController else {
return
}
guard let tabVC = preferencesWC.contentViewController as? NSTabViewController else {
return
}
for vc in preferencesWC.tabVCs {
tabVC.addChild(vc.viewController)
let item = tabVC.tabViewItem(for: vc.viewController)
item?.image = NSImage(systemSymbolName: vc.icon, accessibilityDescription: "")
item?.label = vc.label
}
tabVC.preferredContentSize = NSSize(
width: tabVC.view.frame.size.width,
height: tabVC.view.frame.size.height
)
}
App.shared.preferencesWindowController?.showWindow(self)
NSApp.activate(ignoringOtherApps: true)
}
struct PrefTabView {
let viewController: GenericPreferenceVC
let label: String
let icon: String
}
public lazy var tabVCs: [PrefTabView] = {
return [
PrefTabView(
viewController: GeneralPreferencesVC.fromStoryboard(),
label: "General",
icon: "gear"
)
]
}()
// MARK: - Key Interaction // MARK: - Key Interaction
override func keyDown(with event: NSEvent) { override func keyDown(with event: NSEvent) {
super.keyDown(with: event) super.keyDown(with: event)
/*
if let vc = contentViewController as? PrefsVC { if let vc = contentViewController as? PrefsVC {
if vc.listeningForHotkeyView != nil { if vc.listeningForHotkeyView != nil {
if event.keyCode == Keys.Escape || event.keyCode == Keys.Space { if event.keyCode == Keys.Escape || event.keyCode == Keys.Space {
@ -36,6 +98,7 @@ class PrefsWC: PMWindowController {
} }
} }
} }
*/
} }
} }

View File

@ -11,7 +11,8 @@ import Cocoa
class HotkeyPreferenceView: NSView, XibLoadable { class HotkeyPreferenceView: NSView, XibLoadable {
weak var delegate: PrefsVC? #warning("Refactor so this applies to any given preferences VC")
weak var delegate: GeneralPreferencesVC?
@IBOutlet weak var labelSection: NSTextField! @IBOutlet weak var labelSection: NSTextField!
@IBOutlet weak var labelDescription: NSTextField! @IBOutlet weak var labelDescription: NSTextField!
@ -19,7 +20,7 @@ class HotkeyPreferenceView: NSView, XibLoadable {
@IBOutlet weak var buttonSetShortcut: NSButton! @IBOutlet weak var buttonSetShortcut: NSButton!
@IBOutlet weak var buttonClearShortcut: NSButton! @IBOutlet weak var buttonClearShortcut: NSButton!
static func make(sectionText: String, descriptionText: String, _ prefsVC: PrefsVC) -> NSView { static func make(sectionText: String, descriptionText: String, _ prefsVC: GeneralPreferencesVC) -> NSView {
let view = Self.createFromXib()! let view = Self.createFromXib()!
view.labelSection.stringValue = sectionText view.labelSection.stringValue = sectionText
view.labelDescription.stringValue = descriptionText view.labelDescription.stringValue = descriptionText