From ef3fc1d27857092b4d9728883e004e2a5faadd2b Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 13 Sep 2011 16:44:30 -0700 Subject: [PATCH] Tab tells editor to close file. Tab is then notified about closer. This is in prep for reopening files on app relaunch. --- plugins/tabs/tabs.coffee | 19 +++++++++++++------ src/editor.coffee | 4 ++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/plugins/tabs/tabs.coffee b/plugins/tabs/tabs.coffee index 3d2639105..ac4230522 100644 --- a/plugins/tabs/tabs.coffee +++ b/plugins/tabs/tabs.coffee @@ -34,6 +34,9 @@ class Tabs extends Pane # Only care about files, not directories return if File.isDirectory(filename) @addTab filename + + @editor.ace.on 'close', ({filename}) => + @removeTab filename tab = this # click tab @@ -53,14 +56,18 @@ class Tabs extends Pane """ $('#tabs ul li:last').addClass 'active' + removeTab: (path) -> + tab = $("#tabs li[data-path='#{path}']") + if tab.hasClass("active") + nextTab = tab.next() + nextTab = tab.prev() if nextTab.length == 0 + @switchToTab nextTab if nextTab.length != 0 + + tab.remove() + closeActiveTab: -> activeTab = $('#tabs ul .active') - nextTab = activeTab.next() - nextTab = activeTab.prev() if nextTab.length == 0 - - @editor.deleteSession activeTab.data 'path' - activeTab.remove() - @switchToTab nextTab if nextTab.length != 0 + @editor.close(activeTab.data 'path') hideTabs: -> $('#tabs').parents('.pane').remove() diff --git a/src/editor.coffee b/src/editor.coffee index 559d156ec..1f92ca09e 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -82,6 +82,10 @@ class Editor extends Pane activeWindow.setDirty false @ace._emit 'open', { @filename } + close: (path) -> + @deleteSession path + @ace._emit 'close', { filename : path } + saveAs: -> if file = App.savePanel() @filename = file