Implement scene specific storage for Sidebar expanded state

This commit is contained in:
Maurice Parker
2020-06-30 20:23:22 -05:00
parent e593f67429
commit 53a26f89fe
4 changed files with 94 additions and 13 deletions

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