mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Implement scene specific storage for Sidebar expanded state
This commit is contained in:
48
Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift
Normal file
48
Multiplatform/Shared/Sidebar/SidebarExpandedContainers.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// SidebarExpandedContainers.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 6/30/20.
|
||||
// Copyright © 2020 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import Account
|
||||
|
||||
final class SidebarExpandedContainers: ObservableObject {
|
||||
|
||||
@Published var expandedTable = Set<ContainerIdentifier>()
|
||||
var objectDidChange = PassthroughSubject<Void, Never>()
|
||||
|
||||
var data: Data {
|
||||
get {
|
||||
let encoder = PropertyListEncoder()
|
||||
encoder.outputFormat = .binary
|
||||
return (try? encoder.encode(expandedTable)) ?? Data()
|
||||
}
|
||||
set {
|
||||
let decoder = PropertyListDecoder()
|
||||
expandedTable = (try? decoder.decode(Set<ContainerIdentifier>.self, from: newValue)) ?? Set<ContainerIdentifier>()
|
||||
}
|
||||
}
|
||||
|
||||
subscript(_ containerID: ContainerIdentifier) -> Bool {
|
||||
get {
|
||||
if expandedTable.contains(containerID) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
set(newValue) {
|
||||
if newValue {
|
||||
expandedTable.insert(containerID)
|
||||
} else {
|
||||
expandedTable.remove(containerID)
|
||||
}
|
||||
objectDidChange.send()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user