mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 23:48:05 +03:00
Add RootView::openAsync
This commit is contained in:
parent
dc245184c1
commit
a1c39c9f38
@ -205,7 +205,7 @@ describe "RootView", ->
|
||||
rootView.trigger 'window:decrease-font-size'
|
||||
expect(config.get('editor.fontSize')).toBe 1
|
||||
|
||||
describe ".open(path, options)", ->
|
||||
describe ".open(filePath, options)", ->
|
||||
describe "when there is no active pane", ->
|
||||
beforeEach ->
|
||||
spyOn(Pane.prototype, 'focus')
|
||||
@ -279,6 +279,29 @@ describe "RootView", ->
|
||||
editSession = rootView.open('b', changeFocus: false)
|
||||
expect(activePane.focus).not.toHaveBeenCalled()
|
||||
|
||||
describe ".openAsync(filePath)", ->
|
||||
describe "when there is an active pane", ->
|
||||
[activePane] = []
|
||||
beforeEach ->
|
||||
activePane = rootView.getActivePane()
|
||||
spyOn(activePane, 'focus')
|
||||
|
||||
describe "when called with a path", ->
|
||||
describe "when the active pane does not have an edit session item for the path being opened", ->
|
||||
it "creates a new edit session for the given path in the active editor and returns a promise", ->
|
||||
openHandler = jasmine.createSpy("Open Handler")
|
||||
promise = rootView.openAsync('b', openHandler)
|
||||
expect(activePane.items.length).toBe 1
|
||||
expect(activePane.focus).not.toHaveBeenCalled()
|
||||
|
||||
waitsForPromise ->
|
||||
promise.then (editSession) ->
|
||||
expect(activePane.activeItem).toBe editSession
|
||||
|
||||
runs ->
|
||||
expect(activePane.items.length).toBe 2
|
||||
expect(activePane.focus).toHaveBeenCalled()
|
||||
|
||||
describe "window:toggle-invisibles event", ->
|
||||
it "shows/hides invisibles in all open and future editors", ->
|
||||
rootView.height(200)
|
||||
|
@ -1,5 +1,6 @@
|
||||
ipc = require 'ipc'
|
||||
path = require 'path'
|
||||
Q = require 'q'
|
||||
$ = require './jquery-extensions'
|
||||
{$$, View} = require './space-pen-extensions'
|
||||
fsUtils = require './fs-utils'
|
||||
@ -162,32 +163,61 @@ class RootView extends View
|
||||
confirmClose: ->
|
||||
@panes.confirmClose()
|
||||
|
||||
# Public: Opens a given a filepath in Atom.
|
||||
# Public: Asynchronously opens a given a filepath in Atom.
|
||||
#
|
||||
# * path: A file path
|
||||
# * filePath: A file path
|
||||
# * options
|
||||
# + initialLine:
|
||||
# The buffer line number to open to.
|
||||
# + initialLine: The buffer line number to open to.
|
||||
#
|
||||
# Returns the {EditSession} for the file URI.
|
||||
open: (path, options = {}) ->
|
||||
# Returns a promise that resolves to the {EditSession} for the file URI.
|
||||
openAsync: (filePath, options) ->
|
||||
deferred = Q.defer()
|
||||
|
||||
filePath = project.relativize(filePath)
|
||||
initialLine = options.initialLine
|
||||
if activePane = @getActivePane()
|
||||
if filePath
|
||||
if editSession = activePane.itemForUri(filePath)
|
||||
deferred.resolve(editSession)
|
||||
else
|
||||
editSession = project.open(filePath, {initialLine})
|
||||
deferred.resolve(editSession)
|
||||
else
|
||||
editSession = project.open()
|
||||
deferred.resolve(editSession)
|
||||
else
|
||||
editSession = project.open(filePath, {initialLine})
|
||||
deferred.resolve(editSession)
|
||||
deferred.promise.done (editSession) =>
|
||||
activePane = new Pane(editSession)
|
||||
@panes.setRoot(activePane)
|
||||
|
||||
deferred.promise.done (editSession) ->
|
||||
activePane.showItem(editSession)
|
||||
activePane.focus()
|
||||
|
||||
deferred.promise
|
||||
|
||||
# Private: DEPRECATED Synchronously Opens a given a filepath in Atom.
|
||||
open: (filePath, options = {}) ->
|
||||
changeFocus = options.changeFocus ? true
|
||||
initialLine = options.initialLine
|
||||
path = project.relativize(path)
|
||||
filePath = project.relativize(filePath)
|
||||
if activePane = @getActivePane()
|
||||
if path
|
||||
editSession = activePane.itemForUri(path) ? project.open(path, {initialLine})
|
||||
if filePath
|
||||
editSession = activePane.itemForUri(filePath) ? project.open(filePath, {initialLine})
|
||||
else
|
||||
editSession = project.open()
|
||||
activePane.showItem(editSession)
|
||||
else
|
||||
editSession = project.open(path, {initialLine})
|
||||
editSession = project.open(filePath, {initialLine})
|
||||
activePane = new Pane(editSession)
|
||||
@panes.setRoot(activePane)
|
||||
|
||||
activePane.focus() if changeFocus
|
||||
editSession
|
||||
|
||||
|
||||
# Public: Updates the application's title, based on whichever file is open.
|
||||
updateTitle: ->
|
||||
if projectPath = project.getPath()
|
||||
|
@ -24,7 +24,8 @@ class WindowEventHandler
|
||||
@subscribe $(window), 'blur', -> $("body").addClass('is-blurred')
|
||||
|
||||
@subscribe $(window), 'window:open-path', (event, {pathToOpen, initialLine}) ->
|
||||
atom.rootView?.open(pathToOpen, {initialLine}) unless fsUtils.isDirectorySync(pathToOpen)
|
||||
unless fsUtils.isDirectorySync(pathToOpen)
|
||||
atom.rootView?.openAsync(pathToOpen, initialLine)
|
||||
|
||||
@subscribe $(window), 'beforeunload', =>
|
||||
confirmed = atom.rootView?.confirmClose()
|
||||
|
Loading…
Reference in New Issue
Block a user