diff --git a/VimR/FileBrowserComponent.swift b/VimR/FileBrowserComponent.swift index 0a4c2b90..86d4f8bb 100644 --- a/VimR/FileBrowserComponent.swift +++ b/VimR/FileBrowserComponent.swift @@ -16,6 +16,7 @@ enum FileBrowserAction { case openInHorizontalSplit(url: URL) case openInVerticalSplit(url: URL) case setAsWorkingDirectory(url: URL) + case scrollToSource(cwd: URL) } struct FileBrowserData: StandardPrefData { @@ -79,6 +80,7 @@ class FileBrowserComponent: ViewComponent, ToolDataHolder { fileprivate var fileBrowser: FileBrowserComponent? { didSet { self.goToParentButton.target = self.fileBrowser + self.scrollToSourceButton.target = self.fileBrowser } } @@ -87,6 +89,7 @@ class FileBrowserComponent: ViewComponent, ToolDataHolder { } let goToParentButton = NSButton(forAutoLayout:()) + let scrollToSourceButton = NSButton(forAutoLayout:()) init() { super.init(frame: .zero) @@ -101,13 +104,25 @@ class FileBrowserComponent: ViewComponent, ToolDataHolder { dimension: InnerToolBar.iconDimension) let goToParent = self.goToParentButton + goToParent.toolTip = "Set parent as working directory" InnerToolBar.configureToStandardIconButton(button: goToParent, image: goToParentIcon) goToParent.action = #selector(FileBrowserComponent.goToParentAction) + let scrollToSourceIcon = NSImage.fontAwesomeIcon(name: .bullseye, + textColor: InnerToolBar.iconColor, + dimension: InnerToolBar.iconDimension) + let scrollToSource = self.scrollToSourceButton + scrollToSource.toolTip = "Navigate to the current buffer" + InnerToolBar.configureToStandardIconButton(button: scrollToSource, image: scrollToSourceIcon) + scrollToSource.action = #selector(FileBrowserComponent.scrollToSourceAction) + self.addSubview(goToParent) + self.addSubview(scrollToSource) goToParent.autoPinEdge(toSuperviewEdge: .top) goToParent.autoPinEdge(toSuperviewEdge: .right) + scrollToSource.autoPinEdge(toSuperviewEdge: .top) + scrollToSource.autoPinEdge(.right, to: .left, of: goToParent) } } @@ -222,4 +237,8 @@ extension FileBrowserComponent { func goToParentAction(_ sender: Any?) { self.publish(event: FileBrowserAction.setAsWorkingDirectory(url: self.cwd.parent)) } + + func scrollToSourceAction(_ sender: Any?) { + self.publish(event: FileBrowserAction.scrollToSource(cwd: self.cwd)) + } } diff --git a/VimR/FoundationCommons.swift b/VimR/FoundationCommons.swift index 1aee401e..4358dafb 100644 --- a/VimR/FoundationCommons.swift +++ b/VimR/FoundationCommons.swift @@ -22,6 +22,25 @@ extension URL { return Array(targetPathComps[0.. Bool { + if url == self || url.isParent(of: self) { + return false + } + + let pathComps = self.pathComponents + let targetPathComps = url.pathComponents + + guard targetPathComps.count > pathComps.count else { + return false + } + + guard Array(targetPathComps[0.. Bool { var rsrc: AnyObject? - + do { try (self as NSURL).getResourceValue(&rsrc, forKey: URLResourceKey(rawValue: key)) } catch let error as NSError { @@ -47,11 +66,11 @@ extension URL { print("\(#function): \(self) -> ERROR while getting \(key): \(error)") return false } - + if let result = rsrc as? NSNumber { return result.boolValue } - + return false } diff --git a/VimR/MainWindowComponent.swift b/VimR/MainWindowComponent.swift index 542ec82d..05fc7150 100644 --- a/VimR/MainWindowComponent.swift +++ b/VimR/MainWindowComponent.swift @@ -261,6 +261,12 @@ class MainWindowComponent: WindowComponent, case let FileBrowserAction.setAsWorkingDirectory(url: url): self.neoVimView.cwd = url + case let FileBrowserAction.scrollToSource(cwd: cwd): + guard self.neoVimView.currentBuffer()?.url?.isContained(in: cwd) == true else { + return + } + + case let BufferListAction.open(buffer: buffer): self.neoVimView.select(buffer: buffer) diff --git a/VimR/Workspace/InnterToolBar.swift b/VimR/Workspace/InnterToolBar.swift index 29534553..d4e7ac7e 100644 --- a/VimR/Workspace/InnterToolBar.swift +++ b/VimR/Workspace/InnterToolBar.swift @@ -56,6 +56,10 @@ class InnerToolBar: NSView, NSUserInterfaceValidations { var tool: WorkspaceTool? { didSet { self.titleField.stringValue = self.tool?.title ?? "" + + let toolTitle = self.tool?.title ?? "Tool" + self.closeButton.toolTip = "Close \(toolTitle)" + self.cogButton.toolTip = "\(toolTitle) Settings" } } @@ -110,6 +114,7 @@ class InnerToolBar: NSView, NSUserInterfaceValidations { textColor: InnerToolBar.iconColor, dimension: InnerToolBar.iconDimension) InnerToolBar.configureToStandardIconButton(button: close, image: closeIcon) + close.target = self close.action = #selector(InnerToolBar.closeAction)