diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index c89266d88..048e3ba28 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -45,7 +45,7 @@ class WorkspaceView extends View Delegator.includeInto(this) @delegatesProperty 'fullScreen', 'destroyedItemUris', toProperty: 'model' - @delegatesMethods 'itemOpened', toProperty: 'model' + @delegatesMethods 'open', 'itemOpened', toProperty: 'model' @version: 4 @@ -75,6 +75,8 @@ class WorkspaceView extends View @panes.replaceWith(panes) @panes = panes + @subscribe @model, 'uri-opened', => @trigger 'uri-opened' + @updateTitle() @on 'focus', (e) => @handleFocus(e) @@ -151,36 +153,6 @@ class WorkspaceView extends View confirmClose: -> @panes.confirmClose() - # Public: Asynchronously opens a given a filepath in Atom. - # - # * filePath: A file path - # * options - # + initialLine: The buffer line number to open to. - # - # Returns a promise that resolves to the {Editor} for the file URI. - open: (filePath, options={}) -> - changeFocus = options.changeFocus ? true - filePath = atom.project.resolve(filePath) - initialLine = options.initialLine - activePane = @getActivePane() - - editor = activePane.itemForUri(atom.project.relativize(filePath)) if activePane and filePath - promise = atom.project.open(filePath, {initialLine}) if not editor - - Q(editor ? promise) - .then (editor) => - if not activePane - activePane = new PaneView(editor) - @panes.setRoot(activePane) - - @itemOpened(editor) - activePane.activateItem(editor) - activePane.activate() if changeFocus - @trigger "uri-opened" - editor - .catch (error) -> - console.error(error.stack ? error) - # Private: Only used in specs openSync: (uri, {changeFocus, initialLine, pane, split}={}) -> changeFocus ?= true diff --git a/src/workspace.coffee b/src/workspace.coffee index 657f35d0e..2709008f7 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -1,13 +1,18 @@ {remove} = require 'underscore-plus' {Model} = require 'theorist' +Q = require 'q' Serializable = require 'serializable' +Delegator = require 'delegato' PaneContainer = require './pane-container' +Pane = require './pane' module.exports = class Workspace extends Model atom.deserializers.add(this) Serializable.includeInto(this) + @delegatesProperty 'activePane', toProperty: 'paneContainer' + @properties paneContainer: -> new PaneContainer fullScreen: false @@ -25,6 +30,36 @@ class Workspace extends Model paneContainer: @paneContainer.serialize() fullScreen: atom.isFullScreen() + # Public: Asynchronously opens a given a filepath in Atom. + # + # * filePath: A file path + # * options + # + initialLine: The buffer line number to open to. + # + # Returns a promise that resolves to the {Editor} for the file URI. + open: (filePath, options={}) -> + changeFocus = options.changeFocus ? true + filePath = atom.project.resolve(filePath) + initialLine = options.initialLine + activePane = @activePane + + editor = activePane.itemForUri(atom.project.relativize(filePath)) if activePane and filePath + promise = atom.project.open(filePath, {initialLine}) if not editor + + Q(editor ? promise) + .then (editor) => + if not activePane + activePane = new Pane(items: [editor]) + @paneContainer.root = activePane + + @itemOpened(editor) + activePane.activateItem(editor) + activePane.activate() if changeFocus + @emit "uri-opened" + editor + .catch (error) -> + console.error(error.stack ? error) + # Private: Removes the item's uri from the list of potential items to reopen. itemOpened: (item) -> if uri = item.getUri?()