From f93565708ba63783c16cb76475aec66548d906ab Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 13 Nov 2015 10:54:43 +0100 Subject: [PATCH 1/3] Close empty active window when Close command is given --- spec/workspace-spec.coffee | 16 ++++++++++------ src/register-default-commands.coffee | 2 +- src/workspace.coffee | 12 +++++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 5d7343540..124b0917c 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -1438,11 +1438,11 @@ describe "Workspace", -> save = -> atom.workspace.saveActivePaneItem() expect(save).toThrow() - describe "::destroyActivePaneItemOrEmptyPane", -> + describe "::closeActivePaneItemOrEmptyPaneOrWindow", -> beforeEach -> waitsForPromise -> atom.workspace.open() - it "closes the active pane item until all that remains is a single empty pane", -> + it "closes the active pane item, or the active pane if it is empty, or the current window if there is only the empty root pane", -> atom.config.set('core.destroyEmptyPanes', false) pane1 = atom.workspace.getActivePane() @@ -1450,19 +1450,23 @@ describe "Workspace", -> expect(atom.workspace.getPanes().length).toBe 2 expect(pane2.getItems().length).toBe 1 - atom.workspace.destroyActivePaneItemOrEmptyPane() + atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow() expect(atom.workspace.getPanes().length).toBe 2 expect(pane2.getItems().length).toBe 0 - atom.workspace.destroyActivePaneItemOrEmptyPane() + atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow() expect(atom.workspace.getPanes().length).toBe 1 expect(pane1.getItems().length).toBe 1 - atom.workspace.destroyActivePaneItemOrEmptyPane() + atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow() expect(atom.workspace.getPanes().length).toBe 1 expect(pane1.getItems().length).toBe 0 - atom.workspace.destroyActivePaneItemOrEmptyPane() + atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow() expect(atom.workspace.getPanes().length).toBe 1 + + spyOn(atom, 'close') + atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow() + expect(atom.close).toHaveBeenCalled() diff --git a/src/register-default-commands.coffee b/src/register-default-commands.coffee index 6c838b8c0..159ea1abc 100644 --- a/src/register-default-commands.coffee +++ b/src/register-default-commands.coffee @@ -55,7 +55,7 @@ module.exports = ({commandRegistry, commandInstaller, config}) -> 'window:log-deprecation-warnings': -> Grim.logDeprecations() 'window:toggle-auto-indent': -> config.set("editor.autoIndent", not config.get("editor.autoIndent")) 'pane:reopen-closed-item': -> @getModel().reopenItem() - 'core:close': -> @getModel().destroyActivePaneItemOrEmptyPane() + 'core:close': -> @getModel().closeActivePaneItemOrEmptyPaneOrWindow() 'core:save': -> @getModel().saveActivePaneItem() 'core:save-as': -> @getModel().saveActivePaneItemAs() diff --git a/src/workspace.coffee b/src/workspace.coffee index 396008201..bfa013018 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -675,9 +675,15 @@ class Workspace extends Model destroyActivePane: -> @getActivePane()?.destroy() - # Destroy the active pane item or the active pane if it is empty. - destroyActivePaneItemOrEmptyPane: -> - if @getActivePaneItem()? then @destroyActivePaneItem() else @destroyActivePane() + # Close the active pane item, or the active pane if it is empty, + # or the current window if there is only the empty root pane. + closeActivePaneItemOrEmptyPaneOrWindow: -> + if @getActivePaneItem()? + @destroyActivePaneItem() + else if @getPanes().length > 1 + @destroyActivePane() + else + atom.close() # Increase the editor font size by 1px. increaseFontSize: -> From a7809d67728932499130a30cf9ee4e3e6edf08a9 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 20 Nov 2015 16:40:55 +0100 Subject: [PATCH 2/3] Add 'Close Empty Windows' option.' --- src/config-schema.coffee | 8 ++++++-- src/workspace.coffee | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/config-schema.coffee b/src/config-schema.coffee index 08956d470..d9c0c1d21 100644 --- a/src/config-schema.coffee +++ b/src/config-schema.coffee @@ -21,7 +21,6 @@ module.exports = followSymlinks: type: 'boolean' default: true - title: 'Follow symlinks' description: 'Follow symbolic links when searching files and when opening files with the fuzzy finder.' disabledPackages: type: 'array' @@ -54,7 +53,12 @@ module.exports = destroyEmptyPanes: type: 'boolean' default: true - description: 'When the last item of a pane is removed, remove that pane as well.' + title: 'Remove Empty Panes' + description: 'When the last tab of a pane is closed, remove that pane as well.' + closeEmptyWindows: + type: 'boolean' + default: true + description: 'When a window with no open tabs or panes is given the \'Close Tab\' command, close that window.' fileEncoding: description: 'Default character set encoding to use when reading and writing files.' type: 'string' diff --git a/src/workspace.coffee b/src/workspace.coffee index bfa013018..704b0e8a4 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -682,7 +682,7 @@ class Workspace extends Model @destroyActivePaneItem() else if @getPanes().length > 1 @destroyActivePane() - else + else if @config.get('core.closeEmptyWindows') atom.close() # Increase the editor font size by 1px. From 704da43800b1d91a6fad983e4f190487e1465a92 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 20 Nov 2015 10:34:05 -0700 Subject: [PATCH 3/3] Prevent spec from closing window --- spec/workspace-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 124b0917c..1a28eea45 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -1440,6 +1440,7 @@ describe "Workspace", -> describe "::closeActivePaneItemOrEmptyPaneOrWindow", -> beforeEach -> + spyOn(atom, 'close') waitsForPromise -> atom.workspace.open() it "closes the active pane item, or the active pane if it is empty, or the current window if there is only the empty root pane", -> @@ -1467,6 +1468,5 @@ describe "Workspace", -> atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow() expect(atom.workspace.getPanes().length).toBe 1 - spyOn(atom, 'close') atom.workspace.closeActivePaneItemOrEmptyPaneOrWindow() expect(atom.close).toHaveBeenCalled()