1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 23:02:35 +03:00

Merge branch 'develop' into 383-html-preview-tool

Conflicts:
	VimR/MainWindow.swift
This commit is contained in:
Tae Won Ha 2017-04-10 21:58:17 +02:00
commit 85dce6a8c7
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
8 changed files with 101 additions and 14 deletions

View File

@ -7,7 +7,7 @@ import Cocoa
import PureLayout
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, WorkspaceDelegate {
@IBOutlet weak var window: NSWindow!
@ -29,7 +29,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
contentView.addSubview(workspace)
workspace.autoPinEdgesToSuperviewEdges()
workspace.append(tool: dummyTool(title: "Top-1", color: .yellow), location: .top)
// workspace.append(tool: dummyTool(title: "Top-1", color: .yellow), location: .top)
workspace.append(tool: dummyTool(title: "Right-1", color: .magenta), location: .right)
workspace.append(tool: dummyTool(title: "Right-2", color: .black), location: .right)
@ -52,6 +52,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
workspace.append(tool: dummyTool(title: "Bottom-2", color: .blue), location: .bottom)
tool.toggle()
// FIXME: GH-422
workspace.delegate = self
}
fileprivate func dummyTool(title: String,
@ -68,6 +71,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return WorkspaceTool(config)
}
func resizeWillStart(workspace: Workspace, tool: WorkspaceTool?) {
NSLog("\(#function)")
}
func resizeDidEnd(workspace: Workspace, tool: WorkspaceTool?) {
NSLog("\(#function)")
}
func toggled(tool: WorkspaceTool) {
NSLog("\(#function)")
}
func moved(tool: WorkspaceTool) {
NSLog("\(#function)")
}
}
class DummyView: NSView {

View File

@ -136,6 +136,9 @@
4BB409EE1DDA77E9005F39A2 /* ProxyWorkspaceBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB409ED1DDA77E9005F39A2 /* ProxyWorkspaceBar.swift */; };
4BB409EF1DDA77E9005F39A2 /* ProxyWorkspaceBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB409ED1DDA77E9005F39A2 /* ProxyWorkspaceBar.swift */; };
4BB489431D952CF6005BB0E8 /* WorkspaceToolButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB489411D952CF6005BB0E8 /* WorkspaceToolButton.swift */; };
4BB727131E97A6E5001571C1 /* DispatchUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE79141D16D2100012EDAA /* DispatchUtils.swift */; };
4BB727141E97A718001571C1 /* CocoaMarkdown.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B183E0D1E06E2940079E8A8 /* CocoaMarkdown.framework */; };
4BB727151E97A718001571C1 /* CocoaMarkdown.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4B183E0D1E06E2940079E8A8 /* CocoaMarkdown.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4BBFF8621E280E31008A3C1A /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BBFF8611E280E31008A3C1A /* Swifter.framework */; };
4BBFF8631E2810FE008A3C1A /* Swifter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4BBFF8611E280E31008A3C1A /* Swifter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4BCADE081D11ED12004DAD0F /* CocoaExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BCADE071D11ED12004DAD0F /* CocoaExtensions.swift */; };
@ -237,6 +240,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
4BB727151E97A718001571C1 /* CocoaMarkdown.framework in Embed Frameworks */,
4B6423AD1D8EFE9800FC78C8 /* PureLayout.framework in Embed Frameworks */,
4B91FFF41DEB772200447068 /* CocoaFontAwesome.framework in Embed Frameworks */,
);
@ -480,6 +484,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4BB727141E97A718001571C1 /* CocoaMarkdown.framework in Frameworks */,
4B6423AC1D8EFE9800FC78C8 /* PureLayout.framework in Frameworks */,
4B337FBC1DEB76F20020ADD2 /* CocoaFontAwesome.framework in Frameworks */,
);
@ -1280,6 +1285,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4BB727131E97A6E5001571C1 /* DispatchUtils.swift in Sources */,
4B280EFF1D945DA5003FE725 /* AppKitCommons.swift in Sources */,
4B3965371DEB21300082D3C1 /* InnterToolBar.swift in Sources */,
4B6423AF1D8EFEA800FC78C8 /* Workspace.swift in Sources */,

View File

@ -37,6 +37,7 @@ class MainWindow: NSObject,
case toggleAllTools(Bool)
case toggleToolButtons(Bool)
case setState(for: Tools, with: WorkspaceTool)
case setToolsState([(Tools, WorkspaceTool)])
case close
}
@ -82,11 +83,12 @@ class MainWindow: NSObject,
config: NeoVimView.Config(useInteractiveZsh: state.useInteractiveZsh))
self.neoVimView.configureForAutoLayout()
self.workspace = Workspace(mainView: self.neoVimView)
self.htmlPreview = HtmlPreviewTool(source: source, emitter: emitter, state: state)
let workspace = Workspace(mainView: self.neoVimView)
self.workspace = workspace
self.preview = PreviewTool(source: source, emitter: emitter, state: state)
self.fileBrowser = FileBrowser(source: source, emitter: emitter, state: state)
self.openedFileList = OpenedFileList(source: source, emitter: emitter, state: state)
self.htmlPreview = HtmlPreviewTool(source: source, emitter: emitter, state: state)
if !state.isToolButtonsVisible {
self.workspace.toggleToolButtons()
@ -117,18 +119,22 @@ class MainWindow: NSObject,
self.openedFileListContainer = WorkspaceTool(openedFileListConfig)
self.openedFileListContainer.dimension = state.tools[.openedFilesList]?.dimension ?? 200
self.workspace.append(tool: previewContainer, location: state.tools[.preview]?.location ?? .right)
self.workspace.append(tool: htmlPreviewContainer, location: state.tools[.htmlPreview]?.location ?? .right)
self.workspace.append(tool: fileBrowserContainer, location: state.tools[.fileBrowser]?.location ?? .left)
self.workspace.append(tool: openedFileListContainer, location: state.tools[.openedFilesList]?.location ?? .left)
self.tools = [
let tools: [Tools: WorkspaceTool] = [
.fileBrowser: self.fileBrowserContainer,
.openedFilesList: self.openedFileListContainer,
.preview: self.previewContainer,
.htmlPreview: htmlPreviewContainer,
]
self.tools = tools
state.orderedTools.forEach { toolId in
guard let tool = tools[toolId] else {
return
}
workspace.append(tool: tool, location: state.tools[toolId]?.location ?? .left)
}
super.init()
self.tools.forEach { (toolId, toolContainer) in
@ -573,9 +579,17 @@ extension MainWindow {
}
func moved(tool: WorkspaceTool) {
if let toolIdentifier = self.toolIdentifier(for: tool) {
self.emitter.emit(self.uuidAction(for: .setState(for: toolIdentifier, with: tool)))
let tools = self.workspace.orderedTools.flatMap { (tool: WorkspaceTool) -> (Tools, WorkspaceTool)? in
guard let toolId = self.toolIdentifier(for: tool) else {
return nil
}
return (toolId, tool)
}
NSLog("\(tools)")
self.emitter.emit(self.uuidAction(for: .setToolsState(tools)))
}
fileprivate func toolIdentifier(for tool: WorkspaceTool) -> Tools? {

View File

@ -59,6 +59,28 @@ class MainWindowReducer: Reducer {
.forEach { state.tools[$0.0]?.open = false }
}
case let .setToolsState(tools):
state.orderedTools = []
tools.forEach { toolPair in
let toolId = toolPair.0
let tool = toolPair.1
state.tools[toolId] = WorkspaceToolState(location: tool.location,
dimension: tool.dimension,
open: tool.isSelected)
if tool.isSelected {
state.tools
.filter { $0 != toolId && $1.location == tool.location }
.forEach { state.tools[$0.0]?.open = false }
}
state.orderedTools.append(toolId)
NSLog("\(state.orderedTools)")
}
case let .toggleAllTools(value):
state.isAllToolsVisible = value

View File

@ -152,6 +152,7 @@ class Keys {
static let allToolsVisible = "is-all-tools-visible"
static let toolButtonsVisible = "is-tool-buttons-visible"
static let orderedTools = "ordered-tools"
static let isShowHidden = "is-show-hidden"
}

View File

@ -195,6 +195,7 @@ extension MainWindow {
var lastFileSystemUpdate = Marked(FileItem(URL(fileURLWithPath: "/", isDirectory: true)))
var tools = WorkspaceToolState.default
var orderedTools = WorkspaceToolState.orderedDefault
var preview = PreviewState.default
var htmlPreview = HtmlPreviewState.default
@ -229,6 +230,7 @@ extension MainWindow {
init?(dict: [String: Any]) {
guard let isAllToolsVisible = PrefUtils.bool(from: dict, for: Keys.MainWindow.allToolsVisible),
let isToolButtonsVisible = PrefUtils.bool(from: dict, for: Keys.MainWindow.toolButtonsVisible),
let orderedToolsAsString = dict[Keys.MainWindow.orderedTools] as? [String],
let isShowHidden = PrefUtils.bool(from: dict, for: Keys.MainWindow.isShowHidden)
else {
return nil
@ -240,6 +242,13 @@ extension MainWindow {
let appearanceDict = dict[Keys.Appearance.key] as? [String: Any] ?? [:]
self.appearance = AppearanceState(dict: appearanceDict) ?? AppearanceState.default
self.orderedTools = orderedToolsAsString.flatMap { MainWindow.Tools(rawValue: $0) }
guard self.orderedTools.count == MainWindow.Tools.all.count
&& Set(self.orderedTools) == MainWindow.Tools.all
else {
return nil
}
let workspaceToolsDict = dict[Keys.WorkspaceTool.key] as? [String: [String: Any]] ?? [:]
let toolKeys = workspaceToolsDict.keys.flatMap { MainWindow.Tools(rawValue: $0) }
if MainWindow.Tools.all == Set(toolKeys) {
@ -263,6 +272,8 @@ extension MainWindow {
Keys.WorkspaceTool.key: Array(self.tools.keys.map { $0.rawValue })
.toDict { self.tools[MainWindow.Tools(rawValue: $0)!]!.dict() },
Keys.MainWindow.orderedTools: self.orderedTools.map { $0.rawValue },
Keys.PreviewTool.key: self.previewTool.dict(),
Keys.MainWindow.isShowHidden: self.fileBrowserShowHidden,
@ -280,6 +291,12 @@ struct WorkspaceToolState: SerializableState {
MainWindow.Tools.htmlPreview: WorkspaceToolState(location: .right, dimension: 500, open: true),
]
static let `orderedDefault` = [
MainWindow.Tools.fileBrowser,
MainWindow.Tools.openedFilesList,
MainWindow.Tools.preview,
]
var location = WorkspaceBarLocation.left
var dimension = CGFloat(200)
var open = false

View File

@ -44,6 +44,9 @@ class Workspace: NSView, WorkspaceBarDelegate {
}
fileprivate var tools = [WorkspaceTool]()
var orderedTools: [WorkspaceTool] {
return self.bars.values.reduce([]) { [$0, $1.tools].flatMap { $0 } }
}
fileprivate var isDragOngoing = false
fileprivate var draggedOnBarLocation: WorkspaceBarLocation?
@ -206,7 +209,7 @@ extension Workspace {
}
func moved(tool: WorkspaceTool) {
self.delegate?.moved(tool: tool)
}
}

View File

@ -12,6 +12,7 @@ protocol WorkspaceBarDelegate: class {
func resizeDidEnd(workspaceBar: WorkspaceBar, tool: WorkspaceTool?)
func toggle(tool: WorkspaceTool)
func moved(tool: WorkspaceTool)
}
/**
@ -45,7 +46,7 @@ class WorkspaceBar: NSView, WorkspaceToolDelegate {
static fileprivate let separatorColor = NSColor.controlShadowColor
static fileprivate let separatorThickness = CGFloat(1)
fileprivate var tools = [WorkspaceTool]()
fileprivate(set) var tools = [WorkspaceTool]()
fileprivate weak var selectedTool: WorkspaceTool?
fileprivate var isMouseDownOngoing = false
@ -308,6 +309,7 @@ extension ProxyBar {
// 3.
tool.bar?.remove(tool: tool)
self.container!.append(tool: tool)
self.container?.delegate?.moved(tool: tool)
return true
}
@ -320,6 +322,7 @@ extension ProxyBar {
{
self.container!.tools.remove(at: toolIdx)
self.container!.tools.append(tool)
self.container?.delegate?.moved(tool: tool)
return true
}
@ -336,6 +339,7 @@ extension ProxyBar {
// 1.
tool.bar?.remove(tool: tool)
self.container!.insert(tool: tool, at: draggedOnToolIdx)
self.container?.delegate?.moved(tool: tool)
return true
}
@ -347,6 +351,7 @@ extension ProxyBar {
self.container!.tools.remove(at: toolIdx)
self.container!.tools.insert(tool, at: draggedOnToolIdx)
}
self.container?.delegate?.moved(tool: tool)
return true
}