1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-26 23:36:08 +03:00

GH-293 Add show hidden menu

This commit is contained in:
Tae Won Ha 2016-12-05 18:19:46 +01:00
parent f4a2912f61
commit 7798885af8
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 40 additions and 5 deletions

View File

@ -60,7 +60,15 @@ class FileBrowserComponent: ViewComponent, ToolDataHolder {
}
}
fileprivate var isShowHidden = false
fileprivate var isShowHidden: Bool {
get {
return self.fileView.isShowHidden
}
set {
self.fileView.isShowHidden = newValue
}
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
@ -112,15 +120,26 @@ class FileBrowserComponent: ViewComponent, ToolDataHolder {
}
let innerCustomToolbar = InnerCustomToolbar()
let menuItems: [NSMenuItem]
init(source: Observable<Any>, fileItemService: FileItemService, initialData: FileBrowserData) {
self.fileItemService = fileItemService
self.fileView = FileOutlineView(source: source, fileItemService: fileItemService)
self.isShowHidden = initialData.isShowHidden
self.fileView.isShowHidden = initialData.isShowHidden
let showHiddenMenuItem = NSMenuItem(title: "Show Hidden Files",
action: #selector(FileBrowserComponent.showHiddenAction),
keyEquivalent: "")
showHiddenMenuItem.state = initialData.isShowHidden ? NSOnState : NSOffState
self.menuItems = [
showHiddenMenuItem,
]
super.init(source: source)
self.innerCustomToolbar.fileBrowser = self
showHiddenMenuItem.target = self
self.addReactions()
}
@ -193,6 +212,13 @@ class FileBrowserComponent: ViewComponent, ToolDataHolder {
// MARK: - Actions
extension FileBrowserComponent {
func showHiddenAction(_ sender: Any?) {
self.isShowHidden = !self.isShowHidden
if let menuItem = sender as? NSMenuItem {
menuItem.state = self.isShowHidden ? NSOnState : NSOffState
}
}
func goToParentAction(_ sender: Any?) {
self.publish(event: FileBrowserAction.setAsWorkingDirectory(url: self.cwd.parent))
}

View File

@ -68,6 +68,15 @@ class FileOutlineView: NSOutlineView, Flow, NSOutlineViewDataSource, NSOutlineVi
}
var cwd: URL = FileUtils.userHomeUrl
var isShowHidden = false {
didSet {
if oldValue == self.isShowHidden {
return
}
self.reloadItem(nil)
}
}
init(source: Observable<Any>, fileItemService: FileItemService) {
self.flow = EmbeddableComponent(source: source)
@ -188,8 +197,7 @@ class FileOutlineView: NSOutlineView, Flow, NSOutlineViewDataSource, NSOutlineVi
extension FileOutlineView {
fileprivate func prepare(_ children: [FileBrowserItem]) -> [FileBrowserItem] {
// return children.filter { !$0.fileItem.isHidden }
return children
return self.isShowHidden ? children : children.filter { !$0.fileItem.isHidden }
}
func outlineView(_: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {

View File

@ -182,7 +182,8 @@ class MainWindowComponent: WindowComponent,
view: fileBrowser,
minimumDimension: 100,
withInnerToolbar: true,
customToolbar: fileBrowser.innerCustomToolbar)
customToolbar: fileBrowser.innerCustomToolbar,
customMenuItems: fileBrowser.menuItems)
let fileBrowserTool = WorkspaceToolComponent(toolIdentifier: .fileBrowser, config: fileBrowserConfig)
self.tools[.fileBrowser] = fileBrowserTool