Moves selection to SidebarModel

This commit is contained in:
Stuart Breckenridge 2020-07-09 07:15:47 +08:00
parent 91bc4a0c30
commit 4c11667ff7
No known key found for this signature in database
GPG Key ID: 79BD673276AE83CE
4 changed files with 26 additions and 50 deletions

View File

@ -20,6 +20,28 @@ class SidebarModel: ObservableObject {
@Published var sidebarItems = [SidebarItem]()
#if os(macOS)
@Published var selectedSidebarItems = Set<FeedIdentifier>() {
didSet {
print(selectedSidebarItems)
}
}
#endif
private var items = Set<FeedIdentifier>()
@Published var selectedSidebarItem: FeedIdentifier? = .none {
willSet {
#if os(macOS)
if newValue != nil {
items.insert(newValue!)
} else {
selectedSidebarItems = items
items.removeAll()
}
#endif
}
}
init() {

View File

@ -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<FeedIdentifier>() {
didSet {
print(selectedSidebarItems)
}
}
#endif
private var items = Set<FeedIdentifier>()
@Published var selectedSidebarItem: FeedIdentifier? = .none {
willSet {
#if os(macOS)
if newValue != nil {
items.insert(newValue!)
} else {
selectedSidebarItems = items
items.removeAll()
}
#endif
}
}
}

View File

@ -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())
}

View File

@ -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 = "<group>"; };
1729529624AA1CD000D65E66 /* MacPreferencesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacPreferencesView.swift; sourceTree = "<group>"; };
1729529A24AA1FD200D65E66 /* MacSearchField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacSearchField.swift; sourceTree = "<group>"; };
1770CAF924B5CFEC007D398B /* SidebarSelectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarSelectionModel.swift; sourceTree = "<group>"; };
1776E88D24AC5F8A00E78166 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDefaults.swift; sourceTree = "<group>"; };
17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedView.swift; sourceTree = "<group>"; };
179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsNewsBlurWindowController.swift; sourceTree = "<group>"; };
@ -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 */,