From da53fa1ba3a2f083451120040f627d3bd34949fb Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Fri, 13 Apr 2012 10:47:45 -0600 Subject: [PATCH] Replace RootView.proto.addPane with Pane.proto.split method --- src/app/editor.coffee | 17 +++++++++-------- src/app/pane.coffee | 34 +++++++++++++++++++++++++++++++++- src/app/root-view.coffee | 19 +++++-------------- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 417460a9a..a553f9dc0 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -66,6 +66,9 @@ class Editor extends View @saveCurrentEditSession() { viewClass: "Editor", @editSessions, @activeEditSessionIndex, @isFocused } + copy: -> + new Editor(@serialize()) + bindKeys: -> @on 'save', => @save() @on 'move-right', => @moveCursorRight() @@ -491,21 +494,19 @@ class Editor extends View @setCursorBufferPosition(fold.start) splitLeft: -> - @split('row', 'before') + @pane().splitLeft(@copy()) splitRight: -> - @split('row', 'after') + @pane().splitRight(@copy()) splitUp: -> - @split('column', 'before') + @pane().splitUp(@copy()) splitDown: -> - @split('column', 'after') + @pane().splitDown(@copy()) - split: (axis, side) -> - return unless rootView = @rootView() - editor = new Editor(@serialize()) - rootView.addPane(editor, this.parent(), axis, side) + pane: -> + @parent('.pane').view() remove: (selector, keepData) -> return super if keepData diff --git a/src/app/pane.coffee b/src/app/pane.coffee index be5d8551c..4fb4109bf 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -1,4 +1,6 @@ {View} = require 'space-pen' +PaneRow = require 'pane-row' +PaneColumn = require 'pane-column' module.exports = class Pane extends View @@ -13,7 +15,7 @@ class Pane extends View viewClass: "Pane" wrappedView: @wrappedView.serialize() - adjustDimensions: -> + adjustDimensions: -> # do nothing horizontalGridUnits: -> 1 @@ -21,3 +23,33 @@ class Pane extends View verticalGridUnits: -> 1 + splitUp: (view) -> + @split(view, 'column', 'before') + + splitDown: (view) -> + @split(view, 'column', 'after') + + splitLeft: (view) -> + @split(view, 'row', 'before') + + splitRight: (view) -> + @split(view, 'row', 'after') + + split: (view, axis, side) -> + unless @parent().hasClass(axis) + @buildPaneAxis(axis) + .insertBefore(this) + .append(@detach()) + + pane = new Pane(view) + this[side](pane) + @rootView().adjustPaneDimensions() + view + + buildPaneAxis: (axis) -> + switch axis + when 'row' then new PaneRow + when 'column' then new PaneColumn + + rootView: -> + @parents('#root-view').view() diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 73e9c2473..d1ce1c1d5 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -53,7 +53,7 @@ class RootView extends View deserializePanes: (panesViewState) -> @panes.append @deserializeView(panesViewState) - @adjustSplitPanes() + @adjustPaneDimensions() deserializeView: (viewState) -> switch viewState.viewClass @@ -78,7 +78,7 @@ class RootView extends View @setTitle(editor.buffer.path) editorRemoved: (editor) -> - @adjustSplitPanes() + @adjustPaneDimensions() if @editors().length @editors()[0].focus() else @@ -105,18 +105,9 @@ class RootView extends View editor.focus() editor - addPane: (view, sibling, axis, side) -> - unless sibling.parent().hasClass(axis) - container = if axis == 'column' then new PaneColumn else new PaneRow - container.insertBefore(sibling).append(sibling.detach()) - pane = new Pane(view) - sibling[side](pane) - @adjustSplitPanes() - view - - adjustSplitPanes: -> - view = @panes.children().first().view() - view.adjustDimensions() if view + adjustPaneDimensions: -> + rootPane = @panes.children().first().view() + rootPane?.adjustDimensions() toggleFileFinder: -> return unless @project