mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 06:43:24 +03:00
GH-286 Respect minimum dimension of tools
This commit is contained in:
parent
6623c66eb5
commit
499e7431fc
@ -35,6 +35,11 @@
|
||||
4B029F1A1D45E349004EE0D3 /* PrefWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B029F1C1D45E349004EE0D3 /* PrefWindow.xib */; };
|
||||
4B0677371D99D9C3001A2588 /* FileBrowserComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B0677361D99D9C3001A2588 /* FileBrowserComponent.swift */; };
|
||||
4B06773C1D9DCF23001A2588 /* Component.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B39DA7AC4A9B62D7CD39 /* Component.swift */; };
|
||||
4B0677401DA170D5001A2588 /* AppKitCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6A70931D60E04200E12030 /* AppKitCommons.swift */; };
|
||||
4B0677411DA170D5001A2588 /* Workspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6423951D8EFD7100FC78C8 /* Workspace.swift */; };
|
||||
4B0677421DA170D5001A2588 /* WorkspaceBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6423971D8EFDE000FC78C8 /* WorkspaceBar.swift */; };
|
||||
4B0677431DA170D5001A2588 /* WorkspaceTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6423991D8EFE3000FC78C8 /* WorkspaceTool.swift */; };
|
||||
4B0677441DA170D5001A2588 /* WorkspaceToolButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB489411D952CF6005BB0E8 /* WorkspaceToolButton.swift */; };
|
||||
4B0BCC941D70320C00D3CE65 /* Logger.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0BCC931D70320C00D3CE65 /* Logger.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
4B0C905B1D5DED69007753A3 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */; };
|
||||
4B0E22581D5DEDC700C072E6 /* NeoVimBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0C90591D5DED69007753A3 /* NeoVimBuffer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@ -1046,6 +1051,11 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4B0677401DA170D5001A2588 /* AppKitCommons.swift in Sources */,
|
||||
4B0677411DA170D5001A2588 /* Workspace.swift in Sources */,
|
||||
4B0677421DA170D5001A2588 /* WorkspaceBar.swift in Sources */,
|
||||
4B0677431DA170D5001A2588 /* WorkspaceTool.swift in Sources */,
|
||||
4B0677441DA170D5001A2588 /* WorkspaceToolButton.swift in Sources */,
|
||||
4B06773C1D9DCF23001A2588 /* Component.swift in Sources */,
|
||||
4BF8EEDC1D85908400CAC08A /* PrefUtils.swift in Sources */,
|
||||
1929B43FBA7A31F39D294CD0 /* FileItem.swift in Sources */,
|
||||
|
@ -11,10 +11,6 @@ protocol Flow: class {
|
||||
var sink: Observable<Any> { get }
|
||||
}
|
||||
|
||||
protocol Store: Flow {}
|
||||
|
||||
protocol Component: Flow {}
|
||||
|
||||
class PublishingFlow: Flow {
|
||||
|
||||
var sink: Observable<Any> {
|
||||
@ -57,7 +53,7 @@ class StandardFlow: PublishingFlow {
|
||||
}
|
||||
}
|
||||
|
||||
class StandardComponent: NSObject, Component {
|
||||
class StandardComponent: NSObject, Flow {
|
||||
|
||||
var sink: Observable<Any> {
|
||||
return self.subject.asObservable()
|
||||
@ -92,7 +88,7 @@ class StandardComponent: NSObject, Component {
|
||||
}
|
||||
}
|
||||
|
||||
class ViewComponent: NSView, Component {
|
||||
class ViewComponent: NSView, Flow {
|
||||
|
||||
var view: NSView {
|
||||
preconditionFailure("Please override")
|
||||
@ -137,6 +133,19 @@ class ViewComponent: NSView, Component {
|
||||
}
|
||||
}
|
||||
|
||||
class WorkspaceToolComponent: WorkspaceTool, Flow {
|
||||
|
||||
let viewComponent: ViewComponent
|
||||
var sink: Observable<Any> {
|
||||
return self.viewComponent.sink
|
||||
}
|
||||
|
||||
init(title: String, viewComponent: ViewComponent, minimumDimension: CGFloat = 50) {
|
||||
self.viewComponent = viewComponent
|
||||
super.init(title: title, view: viewComponent, minimumDimension: minimumDimension)
|
||||
}
|
||||
}
|
||||
|
||||
class WindowComponent: StandardComponent {
|
||||
|
||||
let windowController: NSWindowController
|
||||
|
@ -33,9 +33,7 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, WorkspaceDelegate
|
||||
|
||||
fileprivate let workspace: Workspace
|
||||
fileprivate let neoVimView: NeoVimView
|
||||
fileprivate var tools = [Tool: WorkspaceTool]()
|
||||
|
||||
fileprivate var flows = [Flow]()
|
||||
fileprivate var tools = [Tool: WorkspaceToolComponent]()
|
||||
|
||||
// MARK: - API
|
||||
var uuid: String {
|
||||
@ -85,12 +83,10 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, WorkspaceDelegate
|
||||
self.workspace.delegate = self
|
||||
|
||||
let fileBrowser = FileBrowserComponent(source: self.sink, fileItemService: fileItemService)
|
||||
let fileBrowserTool = WorkspaceTool(title: "Files", view: fileBrowser)
|
||||
let fileBrowserTool = WorkspaceToolComponent(title: "Files", viewComponent: fileBrowser, minimumDimension: 100)
|
||||
self.tools[.fileBrowser] = fileBrowserTool
|
||||
self.workspace.append(tool: fileBrowserTool, location: .left)
|
||||
|
||||
self.flows.append(fileBrowser)
|
||||
|
||||
// FIXME: temporarily for dev
|
||||
fileBrowserTool.dimension = 200
|
||||
self.workspace.bars[.left]?.toggle(fileBrowserTool)
|
||||
@ -128,7 +124,7 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, WorkspaceDelegate
|
||||
|
||||
// MARK: - Private
|
||||
fileprivate func addReactions() {
|
||||
self.flows
|
||||
self.tools.values
|
||||
.map { $0.sink }
|
||||
.toMergedObservables()
|
||||
.subscribe(onNext: { [unowned self] action in
|
||||
|
@ -30,6 +30,8 @@ class WorkspaceBar: NSView, WorkspaceToolDelegate {
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
static let minimumDimension = CGFloat(50)
|
||||
|
||||
let location: WorkspaceBarLocation
|
||||
var isButtonVisible = true {
|
||||
didSet {
|
||||
@ -299,9 +301,11 @@ extension WorkspaceBar {
|
||||
}
|
||||
|
||||
fileprivate func set(dimension: CGFloat) {
|
||||
self.dimensionConstraint.constant = dimension
|
||||
let saneDimension = self.saneDimension(from: dimension)
|
||||
|
||||
let toolDimension = self.toolDimension(fromBarDimension: dimension)
|
||||
self.dimensionConstraint.constant = saneDimension
|
||||
|
||||
let toolDimension = self.toolDimension(fromBarDimension: saneDimension)
|
||||
if self.isOpen() {
|
||||
self.selectedTool?.dimension = toolDimension
|
||||
}
|
||||
@ -312,6 +316,18 @@ extension WorkspaceBar {
|
||||
self.window?.invalidateCursorRects(for: self)
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
fileprivate func saneDimension(from dimension: CGFloat) -> CGFloat {
|
||||
if dimension == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if self.isOpen() {
|
||||
return max(dimension, self.selectedTool!.minimumDimension, WorkspaceBar.minimumDimension)
|
||||
}
|
||||
|
||||
return max(dimension, self.barDimensionWithButtonsWithoutTool())
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Layout
|
||||
|
@ -34,12 +34,14 @@ class WorkspaceTool {
|
||||
|
||||
weak var delegate: WorkspaceToolDelegate?
|
||||
|
||||
let minimumDimension = CGFloat(30)
|
||||
var dimension = CGFloat(50)
|
||||
let minimumDimension: CGFloat
|
||||
var dimension: CGFloat
|
||||
|
||||
init(title: String, view: NSView) {
|
||||
init(title: String, view: NSView, minimumDimension: CGFloat = 50) {
|
||||
self.title = title
|
||||
self.view = view
|
||||
self.minimumDimension = minimumDimension
|
||||
self.dimension = minimumDimension
|
||||
self.button = WorkspaceToolButton(title: title)
|
||||
|
||||
self.button.tool = self
|
||||
|
Loading…
Reference in New Issue
Block a user