1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 11:35:35 +03:00

GH-293 Store show hidden flag

This commit is contained in:
Tae Won Ha 2016-12-04 22:03:40 +01:00
parent 39316136e7
commit ea06e9f42a
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
5 changed files with 90 additions and 13 deletions

View File

@ -173,6 +173,14 @@ class WorkspaceToolComponent: WorkspaceTool, Flow {
return self.viewComponent.sink
}
var toolDataDict: [String: Any] {
guard let toolDataHolder = self.viewComponent as? ToolDataHolder else {
return [:]
}
return toolDataHolder.toolDataDict
}
init(toolIdentifier: ToolIdentifier, config: WorkspaceTool.Config) {
guard let viewComponent = config.view as? ViewComponent else {
preconditionFailure("ERROR view must be a ViewComponent!")

View File

@ -18,7 +18,34 @@ enum FileBrowserAction {
case setAsWorkingDirectory(url: URL)
}
class FileBrowserComponent: ViewComponent {
struct FileBrowserData: StandardPrefData {
fileprivate static let isShowHidden = "is-show-hidden"
static let `default` = FileBrowserData(isShowHidden: false)
var isShowHidden: Bool
init(isShowHidden: Bool) {
self.isShowHidden = isShowHidden
}
init?(dict: [String: Any]) {
guard let isShowHidden = PrefUtils.bool(from: dict, for: FileBrowserData.isShowHidden) else {
return nil
}
self.init(isShowHidden: isShowHidden)
}
func dict() -> [String: Any] {
return [
FileBrowserData.isShowHidden: self.isShowHidden
]
}
}
class FileBrowserComponent: ViewComponent, ToolDataHolder {
fileprivate let fileView: FileOutlineView
fileprivate let fileItemService: FileItemService
@ -33,6 +60,8 @@ class FileBrowserComponent: ViewComponent {
}
}
fileprivate var isShowHidden = false
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@ -78,11 +107,16 @@ class FileBrowserComponent: ViewComponent {
return self.fileView.isFirstResponder
}
var toolDataDict: [String: Any] {
return FileBrowserData(isShowHidden: self.isShowHidden).dict()
}
let innerCustomToolbar = InnerCustomToolbar()
init(source: Observable<Any>, fileItemService: FileItemService) {
init(source: Observable<Any>, fileItemService: FileItemService, initialData: FileBrowserData) {
self.fileItemService = fileItemService
self.fileView = FileOutlineView(source: source, fileItemService: fileItemService)
self.isShowHidden = initialData.isShowHidden
super.init(source: source)

View File

@ -167,9 +167,17 @@ class MainWindowComponent: WindowComponent,
}
fileprivate func setupTools(with mainWindowData: MainWindowPrefData) {
// By default the tool buttons are shown and only the file browser tool is shown.
let fileBrowserToolData = mainWindowData.toolPrefData(for: .fileBrowser)
let bufferListToolData = mainWindowData.toolPrefData(for: .bufferList)
let fileBrowserData = FileBrowserData(dict: fileBrowserToolData.toolData) ?? FileBrowserData.default
// FIXME: We do not use [self.sink, source].toMergedObservables. If we do so, then self.sink seems to live as long
// as source, i.e. forever. Thus, self (MainWindowComponent) does not get deallocated. Not nice...
let fileBrowser = FileBrowserComponent(source: self.sink, fileItemService: self.fileItemService)
let fileBrowser = FileBrowserComponent(source: self.sink,
fileItemService: self.fileItemService,
initialData: fileBrowserData)
let fileBrowserConfig = WorkspaceTool.Config(title: "Files",
view: fileBrowser,
minimumDimension: 100,
@ -186,10 +194,6 @@ class MainWindowComponent: WindowComponent,
let bufferListTool = WorkspaceToolComponent(toolIdentifier: .bufferList, config: bufferListConfig)
self.tools[.bufferList] = bufferListTool
// By default the tool buttons are shown and no tools are shown.
let fileBrowserToolData = mainWindowData.toolPrefData(for: .fileBrowser)
let bufferListToolData = mainWindowData.toolPrefData(for: .bufferList)
self.workspace.append(tool: fileBrowserTool, location: fileBrowserToolData.location)
self.workspace.append(tool: bufferListTool, location: bufferListToolData.location)
@ -506,7 +510,8 @@ extension MainWindowComponent {
let fileBrowserData = ToolPrefData(identifier: .fileBrowser,
location: fileBrowser.location,
isVisible: fileBrowser.isSelected,
dimension: fileBrowser.dimension)
dimension: fileBrowser.dimension,
toolData: fileBrowser.toolDataDict)
let bufferList = self.tools[.bufferList]!
let bufferListData = ToolPrefData(identifier: .bufferList,

View File

@ -43,6 +43,10 @@ class PrefUtils {
return dict[key] as? T ?? defaultValue
}
static func dict(from dict: [String: Any], for key: String) -> [String: Any]? {
return dict[key] as? [String: Any]
}
static func float(from dict: [String: Any], for key: String, default defaultValue: Float) -> Float {
return (dict[key] as? NSNumber)?.floatValue ?? defaultValue
}

View File

@ -13,28 +13,48 @@ enum ToolIdentifier: String {
static let all = [ fileBrowser, bufferList ]
}
protocol ToolDataHolder: class {
var toolDataDict: [String: Any] { get }
}
struct ToolPrefData: StandardPrefData {
fileprivate static let identifier = "identifier"
fileprivate static let location = "location"
fileprivate static let isVisible = "is-visible"
fileprivate static let dimension = "dimension"
fileprivate static let toolData = "tool-data"
static let defaults: [ToolIdentifier: ToolPrefData] = [
.fileBrowser: ToolPrefData(identifier: .fileBrowser, location: .left, isVisible: true, dimension: 200),
.bufferList: ToolPrefData(identifier: .bufferList, location: .left, isVisible: true, dimension: 200),
.fileBrowser: ToolPrefData(identifier: .fileBrowser,
location: .left,
isVisible: true,
dimension: 200,
toolData: FileBrowserData.default.dict()),
.bufferList: ToolPrefData(identifier: .bufferList,
location: .left,
isVisible: true,
dimension: 200),
]
var identifier: ToolIdentifier
var location: WorkspaceBarLocation
var isVisible: Bool
var dimension: CGFloat
var toolData: [String: Any]
init(identifier: ToolIdentifier, location: WorkspaceBarLocation, isVisible: Bool, dimension: CGFloat) {
init(identifier: ToolIdentifier,
location: WorkspaceBarLocation,
isVisible: Bool,
dimension: CGFloat,
toolData: [String: Any] = [:])
{
self.identifier = identifier
self.location = location
self.isVisible = isVisible
self.dimension = dimension
self.toolData = toolData
}
func dict() -> [String: Any] {
@ -43,6 +63,7 @@ struct ToolPrefData: StandardPrefData {
ToolPrefData.location: PrefUtils.locationAsString(for: self.location),
ToolPrefData.isVisible: self.isVisible,
ToolPrefData.dimension: Float(self.dimension),
ToolPrefData.toolData: self.toolData
]
}
@ -50,7 +71,8 @@ struct ToolPrefData: StandardPrefData {
guard let identifierRawValue = dict[ToolPrefData.identifier] as? String,
let locationRawValue = dict[ToolPrefData.location] as? String,
let isVisible = PrefUtils.bool(from: dict, for: ToolPrefData.isVisible),
let fDimension = PrefUtils.float(from: dict, for: ToolPrefData.dimension)
let fDimension = PrefUtils.float(from: dict, for: ToolPrefData.dimension),
let toolData = PrefUtils.dict(from: dict, for: ToolPrefData.toolData)
else {
return nil
}
@ -61,6 +83,10 @@ struct ToolPrefData: StandardPrefData {
return nil
}
self.init(identifier: identifier, location: location, isVisible: isVisible, dimension: CGFloat(fDimension))
self.init(identifier: identifier,
location: location,
isVisible: isVisible,
dimension: CGFloat(fDimension),
toolData: toolData)
}
}