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:
parent
f4a2912f61
commit
7798885af8
@ -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))
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user