Replace RootView.proto.addPane with Pane.proto.split method

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-13 10:47:45 -06:00
parent 4e43f0e596
commit da53fa1ba3
3 changed files with 47 additions and 23 deletions

View File

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

View File

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

View File

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