Add openSingletonSync() to rootView

This commit is contained in:
Ben Ogle
2013-10-29 18:39:44 -07:00
parent a212a7c259
commit 1be8d5e618
3 changed files with 99 additions and 18 deletions

View File

@@ -161,6 +161,12 @@ class PaneContainer extends View
getActiveView: ->
@getActivePane()?.activeView
paneForUri: (uri) ->
for pane in @getPanes()
view = pane.itemForUri(uri)
return pane if view?
null
adjustPaneDimensions: ->
if root = @getRoot()
root.css(width: '100%', height: '100%', top: 0, left: 0)

View File

@@ -194,23 +194,44 @@ class RootView extends View
editSession
# Private: Only used in specs
openSync: (filePath, options = {}) ->
changeFocus = options.changeFocus ? true
initialLine = options.initialLine
filePath = project.relativize(filePath)
if activePane = @getActivePane()
if filePath
editSession = activePane.itemForUri(filePath) ? project.openSync(filePath, {initialLine})
else
editSession = project.openSync()
activePane.showItem(editSession)
else
editSession = project.openSync(filePath, {initialLine})
activePane = new Pane(editSession)
@panes.setRoot(activePane)
openSync: (uri, {changeFocus, initialLine, pane, split}={}) ->
changeFocus ?= true
pane ?= @getActivePane()
uri = project.relativize(uri)
activePane.focus() if changeFocus
editSession
if pane
if uri
paneItem = pane.itemForUri(uri) ? project.openSync(uri, {initialLine})
else
paneItem = project.openSync()
if split
panes = @getPanes()
if panes.length == 1
pane = panes[0].splitRight()
else
pane = _.last(panes)
pane.showItem(paneItem)
else
paneItem = project.openSync(uri, {initialLine})
pane = new Pane(paneItem)
@panes.setRoot(pane)
pane.focus() if changeFocus
paneItem
openSingletonSync: (uri, {split}={}) ->
uri = project.relativize(uri)
pane = @panes.paneForUri(uri)
if pane
paneItem = pane.itemForUri(uri)
pane.showItem(paneItem)
pane.focus()
paneItem
else
@openSync(uri, {split})
# Public: Updates the application's title, based on whichever file is open.
updateTitle: ->