Move WorkspaceView::openSync to the Workspace model

This commit is contained in:
Nathan Sobo
2014-01-13 21:30:42 -07:00
parent 7199cda549
commit c8e4535e8b
2 changed files with 35 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
{remove} = require 'underscore-plus'
{remove, last} = require 'underscore-plus'
{Model} = require 'theorist'
Q = require 'q'
Serializable = require 'serializable'
@@ -12,6 +12,7 @@ class Workspace extends Model
Serializable.includeInto(this)
@delegatesProperty 'activePane', toProperty: 'paneContainer'
@delegatesMethod 'getPanes', toProperty: 'paneContainer'
@properties
paneContainer: -> new PaneContainer
@@ -60,6 +61,38 @@ class Workspace extends Model
.catch (error) ->
console.error(error.stack ? error)
# Private: Only used in specs
openSync: (uri, {changeFocus, initialLine, pane, split}={}) ->
changeFocus ?= true
pane ?= @activePane
uri = atom.project.relativize(uri)
if pane
if uri
paneItem = pane.itemForUri(uri) ? atom.project.openSync(uri, {initialLine})
else
paneItem = atom.project.openSync()
if split == 'right'
panes = @getPanes()
if panes.length == 1
pane = panes[0].splitRight()
else
pane = last(panes)
else if split == 'left'
pane = @getPanes()[0]
pane.activateItem(paneItem)
else
paneItem = atom.project.openSync(uri, {initialLine})
pane = new Pane(items: [paneItem])
@paneContainer.root = pane
@itemOpened(paneItem)
pane.activate() if changeFocus
paneItem
# Private: Removes the item's uri from the list of potential items to reopen.
itemOpened: (item) ->
if uri = item.getUri?()