From 4c11667ff7e6c54fb08bfdff80dd88c70f74fc48 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Thu, 9 Jul 2020 07:15:47 +0800 Subject: [PATCH] Moves selection to SidebarModel --- .../Shared/Sidebar/SidebarModel.swift | 22 +++++++++++ .../Sidebar/SidebarSelectionModel.swift | 38 ------------------- .../Shared/Sidebar/SidebarView.swift | 10 ++--- NetNewsWire.xcodeproj/project.pbxproj | 6 --- 4 files changed, 26 insertions(+), 50 deletions(-) delete mode 100644 Multiplatform/Shared/Sidebar/SidebarSelectionModel.swift diff --git a/Multiplatform/Shared/Sidebar/SidebarModel.swift b/Multiplatform/Shared/Sidebar/SidebarModel.swift index dfa9844ee..09a9e1b6b 100644 --- a/Multiplatform/Shared/Sidebar/SidebarModel.swift +++ b/Multiplatform/Shared/Sidebar/SidebarModel.swift @@ -20,6 +20,28 @@ class SidebarModel: ObservableObject { @Published var sidebarItems = [SidebarItem]() + #if os(macOS) + @Published var selectedSidebarItems = Set() { + didSet { + print(selectedSidebarItems) + } + } + #endif + + private var items = Set() + + @Published var selectedSidebarItem: FeedIdentifier? = .none { + willSet { + #if os(macOS) + if newValue != nil { + items.insert(newValue!) + } else { + selectedSidebarItems = items + items.removeAll() + } + #endif + } + } init() { diff --git a/Multiplatform/Shared/Sidebar/SidebarSelectionModel.swift b/Multiplatform/Shared/Sidebar/SidebarSelectionModel.swift deleted file mode 100644 index 9bb3d531d..000000000 --- a/Multiplatform/Shared/Sidebar/SidebarSelectionModel.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// SidebarSelectionModel.swift -// NetNewsWire -// -// Created by Stuart Breckenridge on 8/7/20. -// Copyright © 2020 Ranchero Software. All rights reserved. -// - -import Foundation -import RSCore -import Account - - -class SidebarSelectionModel: ObservableObject { - - #if os(macOS) - @Published var selectedSidebarItems = Set() { - didSet { - print(selectedSidebarItems) - } - } - #endif - - private var items = Set() - - @Published var selectedSidebarItem: FeedIdentifier? = .none { - willSet { - #if os(macOS) - if newValue != nil { - items.insert(newValue!) - } else { - selectedSidebarItems = items - items.removeAll() - } - #endif - } - } -} diff --git a/Multiplatform/Shared/Sidebar/SidebarView.swift b/Multiplatform/Shared/Sidebar/SidebarView.swift index 76768f090..cd9a7e920 100644 --- a/Multiplatform/Shared/Sidebar/SidebarView.swift +++ b/Multiplatform/Shared/Sidebar/SidebarView.swift @@ -16,12 +16,10 @@ struct SidebarView: View { @StateObject private var expandedContainers = SidebarExpandedContainers() @EnvironmentObject private var sidebarModel: SidebarModel - @StateObject private var sidebarSelectionModel = SidebarSelectionModel() - @ViewBuilder var body: some View { #if os(macOS) - List(selection: $sidebarSelectionModel.selectedSidebarItems) { + List(selection: $sidebarModel.selectedSidebarItems) { containedList } #else @@ -49,7 +47,7 @@ struct SidebarView: View { SidebarItemView(sidebarItem: sidebarItem) NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)), tag: sidebarItem.feed!.feedID!, - selection: $sidebarSelectionModel.selectedSidebarItem) { + selection: $sidebarModel.selectedSidebarItem) { EmptyView() }.buttonStyle(PlainButtonStyle()) } @@ -59,7 +57,7 @@ struct SidebarView: View { SidebarItemView(sidebarItem: sidebarItem) NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)), tag: sidebarItem.feed!.feedID!, - selection: $sidebarSelectionModel.selectedSidebarItem) { + selection: $sidebarModel.selectedSidebarItem) { EmptyView() }.buttonStyle(PlainButtonStyle()) } @@ -69,7 +67,7 @@ struct SidebarView: View { SidebarItemView(sidebarItem: sidebarItem) NavigationLink(destination: (TimelineContainerView(feed: sidebarItem.feed)), tag: sidebarItem.feed!.feedID!, - selection: $sidebarSelectionModel.selectedSidebarItem) { + selection: $sidebarModel.selectedSidebarItem) { EmptyView() }.buttonStyle(PlainButtonStyle()) } diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 93fb1fde2..b18dc8502 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -17,8 +17,6 @@ 1729529B24AA1FD200D65E66 /* MacSearchField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1729529A24AA1FD200D65E66 /* MacSearchField.swift */; }; 175942AA24AD533200585066 /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */; }; 175942AB24AD533200585066 /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */; }; - 1770CAFA24B5CFEC007D398B /* SidebarSelectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1770CAF924B5CFEC007D398B /* SidebarSelectionModel.swift */; }; - 1770CAFB24B5CFEC007D398B /* SidebarSelectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1770CAF924B5CFEC007D398B /* SidebarSelectionModel.swift */; }; 1776E88E24AC5F8A00E78166 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */; }; 1776E88F24AC5F8A00E78166 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */; }; 17930ED424AF10EE00A9BA52 /* AddWebFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */; }; @@ -1776,7 +1774,6 @@ 1729529224AA1CAA00D65E66 /* GeneralPreferencesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralPreferencesView.swift; sourceTree = ""; }; 1729529624AA1CD000D65E66 /* MacPreferencesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacPreferencesView.swift; sourceTree = ""; }; 1729529A24AA1FD200D65E66 /* MacSearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacSearchField.swift; sourceTree = ""; }; - 1770CAF924B5CFEC007D398B /* SidebarSelectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarSelectionModel.swift; sourceTree = ""; }; 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDefaults.swift; sourceTree = ""; }; 17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedView.swift; sourceTree = ""; }; 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsNewsBlurWindowController.swift; sourceTree = ""; }; @@ -3104,7 +3101,6 @@ 17D5F17024B0BC6700375168 /* SidebarToolbarModel.swift */, 172199F024AB716900A31D04 /* SidebarToolbarModifier.swift */, 51919FA524AA64B000541E64 /* SidebarView.swift */, - 1770CAF924B5CFEC007D398B /* SidebarSelectionModel.swift */, 51919FAB24AA8CCA00541E64 /* UnreadCountView.swift */, ); path = Sidebar; @@ -5010,7 +5006,6 @@ 51E4991B24A8091000B667CB /* IconImage.swift in Sources */, 51E4995424A8734D00B667CB /* ExtensionPointIdentifer.swift in Sources */, 51E4996924A8760C00B667CB /* ArticleStylesManager.swift in Sources */, - 1770CAFA24B5CFEC007D398B /* SidebarSelectionModel.swift in Sources */, 5177471E24B387E100EB0F74 /* ImageTransition.swift in Sources */, 51E498F324A8085D00B667CB /* PseudoFeed.swift in Sources */, 65ACE48424B4779B003AE06A /* SettingsAddAccountView.swift in Sources */, @@ -5127,7 +5122,6 @@ 51E4990524A808C300B667CB /* FeaturedImageDownloader.swift in Sources */, 5181C5AE24AF89B1002E0F70 /* PreferredColorSchemeModifier.swift in Sources */, 51E4991624A8090300B667CB /* ArticleUtilities.swift in Sources */, - 1770CAFB24B5CFEC007D398B /* SidebarSelectionModel.swift in Sources */, 51919FF224AB864A00541E64 /* TimelineModel.swift in Sources */, 51E4991A24A8090F00B667CB /* IconImage.swift in Sources */, 51E4992724A80AAB00B667CB /* AppAssets.swift in Sources */,