From 68c7f7c04a94d2843834715d2b9fc466953e2cf4 Mon Sep 17 00:00:00 2001 From: Cory Chaplin Date: Wed, 16 Jul 2014 20:05:24 +0200 Subject: [PATCH] Fix for #380, fallback to last open tab when closing tabs --- client/src/models/panel.js | 1 + client/src/views/application.js | 38 +++++++++++++++++++++++++++++++++ client/src/views/tabs.js | 26 ---------------------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/client/src/models/panel.js b/client/src/models/panel.js index 1f77ad0..c4b5a41 100644 --- a/client/src/models/panel.js +++ b/client/src/models/panel.js @@ -11,6 +11,7 @@ _kiwi.model.Panel = Backbone.Model.extend({ }, close: function () { + _kiwi.app.panels.trigger('close', this); _kiwi.global.events.emit('panel:close', {panel: this}); if (this.view) { diff --git a/client/src/views/application.js b/client/src/views/application.js index d3d4d31..fe9ef3c 100644 --- a/client/src/views/application.js +++ b/client/src/views/application.js @@ -54,6 +54,8 @@ _kiwi.view.Application = Backbone.View.extend({ this.favicon = new _kiwi.view.Favicon(); this.initSound(); + + this.monitorPanelFallback(); }, @@ -355,5 +357,41 @@ _kiwi.view.Application = Backbone.View.extend({ setTimeout(function() { (notification.cancel || notification.close).call(notification); }, 5000); + }, + + monitorPanelFallback: function() { + var panel_access = []; + + this.model.panels.on('active', function() { + var panel = _kiwi.app.panels().active, + panel_index; + + // If the panel is already open, remove it so we can put it back in first place + panel_index = _.indexOf(panel_access, panel.cid); + + if (panel_index > -1) { + panel_access.splice(panel_index, 1); + } + + //Make this panel the most recently accessed + panel_access.unshift(panel.cid); + }); + + this.model.panels.on('close', function(panel) { + // If closing the active panel, switch to the last-accessed panel + if (panel_access[0] === panel.cid) { + panel_access.shift(); + + //Get the last-accessed panel model now that we removed the closed one + var model = kiwi.connections.active_connection.panels.getByCid(panel_access[0]); + + if (model) { + model.view.show(); + } else { + // This is a workaround because PanelList does not contain applets + kiwi.panels()[0].view.show(); + } + } + }); } }); diff --git a/client/src/views/tabs.js b/client/src/views/tabs.js index 69eb308..0af7973 100644 --- a/client/src/views/tabs.js +++ b/client/src/views/tabs.js @@ -25,8 +25,6 @@ _kiwi.view.Tabs = Backbone.View.extend({ $('span', this.model.server.tab).text(new_val); }, this); } - - this.panel_access = new Array(); }, render: function () { @@ -83,9 +81,6 @@ _kiwi.view.Tabs = Backbone.View.extend({ panel.bind('change:title', this.updateTabTitle); panel.bind('change:name', this.updateTabTitle); - //Adding a panel - this.panel_access.unshift(panel.cid); - _kiwi.app.view.doLayout(); }, panelRemoved: function (panel) { @@ -93,26 +88,12 @@ _kiwi.view.Tabs = Backbone.View.extend({ panel.tab.remove(); - // If closing the active panel, switch to the last-accessed panel - if (this.panel_access[0] === _kiwi.app.panels().active.cid) { - this.panel_access.shift(); - - //Get the last-accessed panel model now that we removed the closed one - var model = connection.panels.getByCid(this.panel_access[0]); - - if (model) { - model.view.show(); - } - } - delete panel.tab; _kiwi.app.view.doLayout(); }, panelActive: function (panel, previously_active_panel) { - var panel_index = _.indexOf(this.panel_access, panel.cid); - // Remove any existing tabs or part images _kiwi.app.view.$el.find('.panellist .part').remove(); _kiwi.app.view.$el.find('.panellist .active').removeClass('active'); @@ -123,13 +104,6 @@ _kiwi.view.Tabs = Backbone.View.extend({ if (!panel.isServer()) { panel.tab.append(''); } - - if (panel_index > -1) { - this.panel_access.splice(panel_index, 1); - } - - //Make this panel the most recently accessed - this.panel_access.unshift(panel.cid); }, tabClick: function (e) { -- 2.25.1