small refactoring

This commit is contained in:
Stuart Breckenridge 2020-07-12 14:07:52 +08:00
parent 2eb20c86af
commit 31b93c5d13
No known key found for this signature in database
GPG Key ID: 79BD673276AE83CE
9 changed files with 159 additions and 140 deletions

View File

@ -32,14 +32,14 @@
<objects>
<viewController title="General" storyboardIdentifier="General" id="iuH-lz-18x" customClass="GeneralPreferencesViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="WnV-px-wCT">
<rect key="frame" x="0.0" y="0.0" width="501" height="217"/>
<rect key="frame" x="0.0" y="0.0" width="501" height="221"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView horizontalHuggingPriority="1000" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="Ut3-yd-q6G">
<rect key="frame" x="80" y="16" width="340" height="185"/>
<rect key="frame" x="80" y="16" width="340" height="189"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ucw-vG-yLt">
<rect key="frame" x="29" y="162" width="92" height="16"/>
<rect key="frame" x="29" y="166" width="92" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Refresh feeds:" id="F7c-lm-g97">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -47,7 +47,7 @@
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="SFF-mL-yc8">
<rect key="frame" x="125" y="157" width="218" height="25"/>
<rect key="frame" x="125" y="161" width="218" height="25"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="200" id="N1a-qV-4Os"/>
</constraints>
@ -82,7 +82,7 @@
</popUpButtonCell>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rbK-cS-VQl">
<rect key="frame" x="-2" y="131" width="123" height="16"/>
<rect key="frame" x="-2" y="135" width="123" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Default RSS reader:" id="bUb-r3-SmS">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -90,7 +90,7 @@
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cSu-T2-Jby">
<rect key="frame" x="125" y="126" width="218" height="25"/>
<rect key="frame" x="125" y="130" width="218" height="25"/>
<popUpButtonCell key="cell" type="push" title="NetNewsWire" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="bEy-Qx-Grl" id="Dyk-WN-XOo" userLabel="Popup">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
@ -105,7 +105,7 @@
</connections>
</popUpButton>
<button verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="Ubm-Pk-l7x">
<rect key="frame" x="125" y="67" width="215" height="18"/>
<rect key="frame" x="125" y="71" width="215" height="18"/>
<buttonCell key="cell" type="check" title="Open in background in browser" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="t0a-LN-rCv">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
@ -154,7 +154,7 @@
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="j0t-Wa-UTL">
<rect key="frame" x="145" y="32" width="197" height="28"/>
<rect key="frame" x="145" y="32" width="197" height="32"/>
<textFieldCell key="cell" controlSize="small" title="Hold the Shift key to invert this preference." id="EMq-9M-zTJ">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -162,7 +162,7 @@
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ci4-fW-KjU">
<rect key="frame" x="125" y="95" width="218" height="25"/>
<rect key="frame" x="125" y="99" width="218" height="25"/>
<popUpButtonCell key="cell" type="push" title="Safari" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="ObP-qK-qDJ" id="hrm-aT-Rc2" userLabel="Popup">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
@ -177,7 +177,7 @@
</connections>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Wsb-Lr-8Q7">
<rect key="frame" x="45" y="100" width="76" height="16"/>
<rect key="frame" x="45" y="104" width="76" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Web pages:" id="CgU-dE-Qtb">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -416,16 +416,16 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="7UM-iq-OLB" customClass="PreferencesTableViewBackgroundView" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="20" y="44" width="160" height="223"/>
<rect key="frame" x="20" y="44" width="160" height="233"/>
<subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="26" horizontalPageScroll="10" verticalLineScroll="26" verticalPageScroll="10" hasHorizontalScroller="NO" horizontalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="PaF-du-r3c">
<rect key="frame" x="1" y="0.0" width="158" height="222"/>
<rect key="frame" x="1" y="0.0" width="158" height="232"/>
<clipView key="contentView" id="cil-Gq-akO">
<rect key="frame" x="0.0" y="0.0" width="158" height="222"/>
<rect key="frame" x="0.0" y="0.0" width="158" height="232"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" viewBased="YES" id="aTp-KR-y6b">
<rect key="frame" x="0.0" y="0.0" width="188" height="222"/>
<rect key="frame" x="0.0" y="0.0" width="188" height="232"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -532,7 +532,7 @@
<rect key="frame" x="83" y="20" width="97" height="24"/>
</customView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Y7D-xQ-wep">
<rect key="frame" x="188" y="20" width="242" height="247"/>
<rect key="frame" x="188" y="20" width="242" height="257"/>
</customView>
</subviews>
<constraints>
@ -587,16 +587,16 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="pjs-G4-byk" customClass="PreferencesTableViewBackgroundView" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="20" y="44" width="160" height="216"/>
<rect key="frame" x="20" y="44" width="160" height="226"/>
<subviews>
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="26" horizontalPageScroll="10" verticalLineScroll="26" verticalPageScroll="10" hasHorizontalScroller="NO" horizontalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="29T-r2-ckC">
<rect key="frame" x="1" y="0.0" width="158" height="215"/>
<rect key="frame" x="1" y="0.0" width="158" height="225"/>
<clipView key="contentView" id="dXw-GY-TP8">
<rect key="frame" x="0.0" y="0.0" width="158" height="215"/>
<rect key="frame" x="0.0" y="0.0" width="158" height="225"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnSelection="YES" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" viewBased="YES" id="dfn-Vn-oDp">
<rect key="frame" x="0.0" y="0.0" width="188" height="215"/>
<rect key="frame" x="0.0" y="0.0" width="188" height="225"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
@ -699,7 +699,7 @@
<rect key="frame" x="83" y="20" width="97" height="24"/>
</customView>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="N1N-pE-gBL">
<rect key="frame" x="188" y="20" width="242" height="240"/>
<rect key="frame" x="188" y="20" width="242" height="250"/>
</customView>
</subviews>
<constraints>

View File

@ -77,7 +77,6 @@ struct MainApp: App {
.navigationTitle("Preferences")
.environmentObject(defaults)
}
.windowToolbarStyle(UnifiedWindowToolbarStyle())
#endif

View File

@ -0,0 +1,35 @@
//
// MacPreferencesModel.swift
// Multiplatform macOS
//
// Created by Stuart Breckenridge on 12/7/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import Foundation
class MacPreferencesModel {
enum PreferencePane: Int, CaseIterable {
case general = 0
case accounts = 1
case advanced = 2
var description: String {
switch self {
case .general:
return "General"
case .accounts:
return "Accounts"
case .advanced:
return "Advanced"
}
}
}
var currentPreferencePane: PreferencePane = PreferencePane.general
// General Preferences
}

View File

@ -7,83 +7,63 @@
import SwiftUI
struct MacPreferenceViewModel {
enum PreferencePane: Int, CaseIterable {
case general = 0
case accounts = 1
case advanced = 2
var description: String {
switch self {
case .general:
return "General"
case .accounts:
return "Accounts"
case .advanced:
return "Advanced"
}
}
}
var currentPreferencePane: PreferencePane = PreferencePane.general
}
struct MacPreferencesView: View {
@EnvironmentObject var defaults: AppDefaults
@State private var viewModel = MacPreferenceViewModel()
@EnvironmentObject var defaults: AppDefaults
@StateObject private var viewModel = MacPreferencesModel()
var body: some View {
VStack {
if viewModel.currentPreferencePane == .general {
AnyView(GeneralPreferencesView().environmentObject(defaults))
}
else if viewModel.currentPreferencePane == .accounts {
AnyView(AccountsPreferencesView().environmentObject(defaults))
}
else {
AnyView(AdvancedPreferencesView().environmentObject(defaults))
}
}
.toolbar {
ToolbarItem {
Button(action: {
viewModel.currentPreferencePane = .general
}, label: {
Image(systemName: "checkmark.rectangle")
Text("General")
})
}
ToolbarItem {
Button(action: {
viewModel.currentPreferencePane = .accounts
}, label: {
Image(systemName: "network")
Text("Accounts")
})
}
ToolbarItem {
Button(action: {
viewModel.currentPreferencePane = .advanced
}, label: {
Image(systemName: "gearshape.fill")
Text("Advanced")
})
}
}
.presentedWindowToolbarStyle(UnifiedCompactWindowToolbarStyle())
.presentedWindowStyle(TitleBarWindowStyle())
.navigationTitle(Text(viewModel.currentPreferencePane.description))
}
var body: some View {
VStack {
switch viewModel.currentPreferencePane {
case .general:
GeneralPreferencesView()
.environmentObject(defaults)
case .accounts:
AccountsPreferencesView()
.environmentObject(defaults)
case .advanced:
AdvancedPreferencesView()
.environmentObject(defaults)
}
}
.toolbar {
ToolbarItem {
Button(action: {
viewModel.currentPreferencePane = .general
}, label: {
Image(systemName: "checkmark.rectangle")
Text("General")
})
}
ToolbarItem {
Button(action: {
viewModel.currentPreferencePane = .accounts
}, label: {
Image(systemName: "network")
Text("Accounts")
})
}
ToolbarItem {
Button(action: {
viewModel.currentPreferencePane = .advanced
}, label: {
Image(systemName: "gearshape.fill")
Text("Advanced")
})
}
}
.presentedWindowToolbarStyle(UnifiedCompactWindowToolbarStyle())
.presentedWindowStyle(TitleBarWindowStyle())
.navigationTitle(Text(viewModel.currentPreferencePane.description))
}
}
struct MacPreferencesView_Previews: PreviewProvider {
static var previews: some View {
MacPreferencesView()
}
static var previews: some View {
MacPreferencesView()
}
}

View File

@ -0,0 +1,34 @@
//
// GeneralPreferencesView.swift
// macOS
//
// Created by Stuart Breckenridge on 27/6/20.
//
import SwiftUI
struct GeneralPreferencesView: View {
@EnvironmentObject private var defaults: AppDefaults
var body: some View {
VStack {
Form {
Picker("Refresh Feeds",
selection: $defaults.interval,
content: {
ForEach(RefreshInterval.allCases, content: { interval in
Text(interval.description()).tag(interval.rawValue)
})
})
.frame(width: 300, alignment: .center)
Toggle("Open webpages in background in browser", isOn: $defaults.openInBrowserInBackground)
Toggle("Hide Unread Count in Dock", isOn: $defaults.hideDockUnreadCount)
}
Spacer()
}.frame(width: 300, alignment: .center)
}
}

View File

@ -1,33 +0,0 @@
//
// GeneralPreferencesView.swift
// macOS
//
// Created by Stuart Breckenridge on 27/6/20.
//
import SwiftUI
struct GeneralPreferencesView: View {
@EnvironmentObject private var defaults: AppDefaults
var body: some View {
VStack {
Form {
Picker("Refresh Feeds",
selection: $defaults.interval,
content: {
ForEach(RefreshInterval.allCases, content: { interval in
Text(interval.description()).tag(interval.rawValue)
})
}).frame(width: 300, alignment: .center)
Toggle("Open webpages in background in browser", isOn: $defaults.openInBrowserInBackground)
Toggle("Hide Unread Count in Dock", isOn: $defaults.hideDockUnreadCount)
}
Spacer()
}.frame(width: 300, alignment: .center)
}
}

View File

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1717535624BADF33004498C6 /* MacPreferencesModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1717535524BADF33004498C6 /* MacPreferencesModel.swift */; };
172199C924AB228900A31D04 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199C824AB228900A31D04 /* SettingsView.swift */; };
172199ED24AB2E0100A31D04 /* SafariView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199EC24AB2E0100A31D04 /* SafariView.swift */; };
172199F124AB716900A31D04 /* SidebarToolbarModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 172199F024AB716900A31D04 /* SidebarToolbarModifier.swift */; };
@ -1778,6 +1779,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1717535524BADF33004498C6 /* MacPreferencesModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacPreferencesModel.swift; sourceTree = "<group>"; };
172199C824AB228900A31D04 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
172199EC24AB2E0100A31D04 /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = "<group>"; };
172199F024AB716900A31D04 /* SidebarToolbarModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarToolbarModifier.swift; sourceTree = "<group>"; };
@ -2503,20 +2505,21 @@
1729528F24AA1A4F00D65E66 /* Preferences */ = {
isa = PBXGroup;
children = (
1717535524BADF33004498C6 /* MacPreferencesModel.swift */,
1729529624AA1CD000D65E66 /* MacPreferencesView.swift */,
1729529924AA1CE100D65E66 /* View */,
1729529924AA1CE100D65E66 /* Preferences Subviews */,
);
path = Preferences;
sourceTree = "<group>";
};
1729529924AA1CE100D65E66 /* View */ = {
1729529924AA1CE100D65E66 /* Preferences Subviews */ = {
isa = PBXGroup;
children = (
1729529224AA1CAA00D65E66 /* GeneralPreferencesView.swift */,
1729529024AA1CAA00D65E66 /* AccountsPreferencesView.swift */,
1729529124AA1CAA00D65E66 /* AdvancedPreferencesView.swift */,
1729529224AA1CAA00D65E66 /* GeneralPreferencesView.swift */,
);
path = View;
path = "Preferences Subviews";
sourceTree = "<group>";
};
17930ED224AF10CD00A9BA52 /* Add */ = {
@ -4145,46 +4148,46 @@
TargetAttributes = {
51314636235A7BBE00387FDC = {
CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
LastSwiftMigration = 1120;
ProvisioningStyle = Automatic;
};
513C5CE5232571C2003D4054 = {
CreatedOnToolsVersion = 11.0;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
518B2ED12351B3DD00400001 = {
CreatedOnToolsVersion = 11.2;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
TestTargetID = 840D617B2029031C009BC708;
};
51C0513C24A77DF800194D5E = {
CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
51C0514324A77DF800194D5E = {
CreatedOnToolsVersion = 12.0;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
6581C73220CED60000F4AD34 = {
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
65ED3FA2235DEF6C0081F399 = {
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
65ED4090235DEF770081F399 = {
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
};
840D617B2029031C009BC708 = {
CreatedOnToolsVersion = 9.3;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.BackgroundModes = {
@ -4194,7 +4197,7 @@
};
849C645F1ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.HardenedRuntime = {
@ -4204,7 +4207,7 @@
};
849C64701ED37A5D003D8FC0 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = SHJK2V3AJG;
DevelopmentTeam = FQLBNX3GP7;
ProvisioningStyle = Automatic;
TestTargetID = 849C645F1ED37A5D003D8FC0;
};
@ -5137,6 +5140,7 @@
51E4996C24A8762D00B667CB /* ExtractedArticle.swift in Sources */,
51E4990824A808C300B667CB /* RSHTMLMetadata+Extension.swift in Sources */,
51919FF824AB8B7700541E64 /* TimelineView.swift in Sources */,
1717535624BADF33004498C6 /* MacPreferencesModel.swift in Sources */,
51E4992B24A8676300B667CB /* ArticleArray.swift in Sources */,
51B54AB324B5AC830014348B /* ArticleButtonState.swift in Sources */,
17D5F17224B0BC6700375168 /* SidebarToolbarModel.swift in Sources */,