From 80cd20193a0eaa8bd920a67270267ba3be5fc9cc Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 2 Mar 2015 18:38:25 -0800 Subject: [PATCH] Move the logic for opening empty initial buffer to renderer --- spec/atom-spec.coffee | 43 ++++++++++++++++++++++++++++++++++ src/atom.coffee | 6 +++++ src/browser/atom-window.coffee | 3 ++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index 12d094428..27040bcfb 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -152,3 +152,46 @@ describe "the `atom` global", -> loadSettings.initialPaths = [dir2, dir1] atom2 = Atom.loadOrCreate("editor") expect(atom2.state.stuff).toBe("cool") + + describe "openInitialEmptyEditorIfNecessary", -> + describe "when there are no paths set", -> + oldPaths = null + + beforeEach -> + oldPaths = atom.project.getPaths() + atom.project.setPaths([]) + + afterEach -> + atom.project.setPaths(oldPaths) + + it "opens an empty buffer", -> + spyOn(atom.workspace, 'open') + atom.openInitialEmptyEditorIfNecessary() + expect(atom.workspace.open).toHaveBeenCalledWith(null, {isInitialEmptyEditor: true}) + + describe "when there is already a buffer open", -> + beforeEach -> + waitsForPromise -> atom.workspace.open() + + it "does not open an empty buffer", -> + spyOn(atom.workspace, 'open') + atom.openInitialEmptyEditorIfNecessary() + expect(atom.workspace.open).not.toHaveBeenCalled() + + describe "when the project has a path", -> + beforeEach -> + spyOn(atom.workspace, 'open') + + it "does not open an empty buffer", -> + atom.openInitialEmptyEditorIfNecessary() + expect(atom.workspace.open).not.toHaveBeenCalled() + + describe "when there is already a buffer open", -> + beforeEach -> + waitsForPromise -> + atom.workspace.open() + + it "does not open an empty buffer", -> + spyOn(atom.workspace, 'open') + atom.openInitialEmptyEditorIfNecessary() + expect(atom.workspace.open).not.toHaveBeenCalled() diff --git a/src/atom.coffee b/src/atom.coffee index 303b0cfe7..a08a4b983 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -605,6 +605,8 @@ class Atom extends Model @setAutoHideMenuBar(newValue) @setAutoHideMenuBar(true) if @config.get('core.autoHideMenuBar') + @openInitialEmptyEditorIfNecessary() + maximize = dimensions?.maximized and process.platform isnt 'darwin' @displayWindow({maximize}) @@ -629,6 +631,10 @@ class Atom extends Model @windowEventHandler?.unsubscribe() + openInitialEmptyEditorIfNecessary: -> + if @project.getPaths().length is 0 and @workspace.getPaneItems().length is 0 + @workspace.open(null, {isInitialEmptyEditor: true}) + ### Section: Messaging the User ### diff --git a/src/browser/atom-window.coffee b/src/browser/atom-window.coffee index 77888fed4..785c11147 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -73,7 +73,8 @@ class AtomWindow @browserWindow.loadUrl @getUrl(loadSettings) @browserWindow.focusOnWebView() if @isSpec - @openLocations(locationsToOpen) unless @isSpecWindow() + hasPathToOpen = not (locationsToOpen.length is 1 and not locationsToOpen[0].pathToOpen?) + @openLocations(locationsToOpen) if hasPathToOpen and not @isSpecWindow() getUrl: (loadSettingsObj) -> # Ignore the windowState when passing loadSettings via URL, since it could