Fix for #380, fallback to last open tab when closing tabs
authorCory Chaplin <cory.chaplin@laposte.net>
Wed, 16 Jul 2014 18:05:24 +0000 (20:05 +0200)
committerCory Chaplin <cory.chaplin@laposte.net>
Wed, 16 Jul 2014 18:05:24 +0000 (20:05 +0200)
client/src/models/panel.js
client/src/views/application.js
client/src/views/tabs.js

index 1f77ad072e3b0c442a980af22ee38fbcc408cb02..c4b5a410ccf72454633113d1f2cde7cdf96ff63b 100644 (file)
@@ -11,6 +11,7 @@ _kiwi.model.Panel = Backbone.Model.extend({
     },\r
 \r
     close: function () {\r
+        _kiwi.app.panels.trigger('close', this);\r
         _kiwi.global.events.emit('panel:close', {panel: this});\r
 \r
         if (this.view) {\r
index d3d4d3172f69226a2dc3449a863d162741ce69c0..fe9ef3c65b446c8e67cfa5622124f062cf2ed2a7 100644 (file)
@@ -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();
+                }
+            }
+        });
     }
 });
index 69eb30854b627b458798173b16144e9df432fa9b..0af7973a883618f62d9425f3501c60fa08bb579a 100644 (file)
@@ -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('<span class="part fa fa-nonexistant"></span>');
         }
-
-        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) {