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

GH-293 Add scroll to source button and some tooltips

This commit is contained in:
Tae Won Ha 2016-12-07 21:04:47 +01:00
parent ded0023f20
commit cfbce465fa
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 53 additions and 4 deletions

View File

@ -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))
}
}

View File

@ -22,6 +22,25 @@ extension URL {
return Array(targetPathComps[0..<myPathComps.count]) == myPathComps
}
func isContained(in url: URL) -> 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..<pathComps.endIndex]) == pathComps else {
return false
}
return true
}
var parent: URL {
if self.path == "/" {
return self
@ -29,7 +48,7 @@ extension URL {
return self.deletingLastPathComponent()
}
/// Wrapper function for NSURL.getResourceValue for Bool values.
/// Returns also `false` when
/// - there is no value for the given `key` or
@ -39,7 +58,7 @@ extension URL {
/// - key: The `key`-parameter of `NSURL.getResourceValue`.
func resourceValue(_ key: String) -> 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
}

View File

@ -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)

View File

@ -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)