Tab view cleanup +tab switching hotkeys
authorDarren <darren@darrenwhitlen.com>
Tue, 4 Sep 2012 17:40:02 +0000 (18:40 +0100)
committerDarren <darren@darrenwhitlen.com>
Tue, 4 Sep 2012 17:40:02 +0000 (18:40 +0100)
client_backbone/dev/model_panellist.js
client_backbone/dev/view.js

index 28217f3aeb013bc8e94e0377bdceb787ef33afc7..d563ef3f77b3726f8023abe05dab4dc63af2309d 100644 (file)
@@ -11,10 +11,10 @@ kiwi.model.PanelList = Backbone.Collection.extend({
         this.view = new kiwi.view.Tabs({"el": $('#toolbar .panellist')[0], "model": this});\r
 \r
         // Automatically create a server tab\r
-        this.server = new kiwi.model.Server({'name': kiwi.gateway.get('name')});\r
-        kiwi.gateway.on('change:name', this.view.render, this.view);\r
-        this.add(this.server);\r
+        this.add(new kiwi.model.Server({'name': kiwi.gateway.get('name')}));\r
+        this.server = this.getByName(kiwi.gateway.get('name'));\r
 \r
+        // Keep a tab on the active panel\r
         this.bind('active', function (active_panel) {\r
             this.active = active_panel;\r
         }, this);\r
index 679139ae5a4bfc5424c2c2ec7003694bc7812a7e..7340b0c2f4b70870ff8f86411cd11108b39cc7fe 100644 (file)
@@ -300,24 +300,31 @@ kiwi.view.Tabs = Backbone.View.extend({
         this.model.on("add", this.panelAdded, this);\r
         this.model.on("remove", this.panelRemoved, this);\r
         this.model.on("reset", this.render, this);\r
+\r
+        this.model.on('active', this.panelActive, this);\r
+\r
+        kiwi.gateway.on('change:name', function (gateway, new_val) {\r
+            $('span', this.model.server.tab).text(new_val);\r
+        }, this);\r
     },\r
     render: function () {\r
         var that = this;\r
-        $this = $(this.el);\r
-        $this.empty();\r
+\r
+        this.$el.empty();\r
         \r
         // Add the server tab first\r
-        $('<li><span>' + kiwi.gateway.get('name') + '</span></li>')\r
+        this.model.server.tab\r
             .data('panel_id', this.model.server.cid)\r
-            .appendTo($this);\r
+            .appendTo(this.$el);\r
 \r
+        // Go through each panel adding its tab\r
         this.model.forEach(function (panel) {\r
             // If this is the server panel, ignore as it's already added\r
             if (panel == that.model.server) return;\r
 \r
-            $('<li><span>' + panel.get("name") + '</span></li>')\r
+            panel.tab\r
                 .data('panel_id', panel.cid)\r
-                .appendTo($this);\r
+                .appendTo(this.$el);\r
         });\r
     },\r
 \r
@@ -326,8 +333,6 @@ kiwi.view.Tabs = Backbone.View.extend({
         panel.tab = $('<li><span>' + panel.get("name") + '</span></li>');\r
         panel.tab.data('panel_id', panel.cid)\r
             .appendTo(this.$el);\r
-\r
-        panel.view.on('active', this.panelActive, this);\r
     },\r
     panelRemoved: function (panel) {\r
         panel.tab.remove();\r
@@ -344,7 +349,9 @@ kiwi.view.Tabs = Backbone.View.extend({
     },\r
 \r
     tabClick: function (e) {\r
-        var panel = this.model.getByCid($(e.currentTarget).data('panel_id'));\r
+        var tab = $(e.currentTarget);\r
+\r
+        var panel = this.model.getByCid(tab.data('panel_id'));\r
         if (!panel) {\r
             // A panel wasn't found for this tab... wadda fuck\r
             return;\r
@@ -354,7 +361,8 @@ kiwi.view.Tabs = Backbone.View.extend({
     },\r
 \r
     partClick: function (e) {\r
-        var panel = this.model.getByCid($(e.currentTarget).parent().data('panel_id'));\r
+        var tab = $(e.currentTarget).parent();\r
+        var panel = this.model.getByCid(tab.data('panel_id'));\r
 \r
         // Only need to part if it's a channel\r
         if (panel.isChannel()) {\r
@@ -362,6 +370,19 @@ kiwi.view.Tabs = Backbone.View.extend({
         } else {\r
             panel.close();\r
         }\r
+    },\r
+\r
+    next: function () {\r
+        var next = kiwi.app.panels.active.tab.next();\r
+        if (!next.length) next = $('li:first', this.$el);\r
+\r
+        next.click();\r
+    },\r
+    prev: function () {\r
+        var prev = kiwi.app.panels.active.tab.prev();\r
+        if (!prev.length) prev = $('li:last', this.$el);\r
+\r
+        prev.click();\r
     }\r
 });\r
 \r
@@ -418,8 +439,15 @@ kiwi.view.ControlBox = Backbone.View.extend({
 \r
     process: function (ev) {\r
         var inp = $(ev.currentTarget),\r
-            inp_val = inp.val();\r
+            inp_val = inp.val(),\r
+            meta;\r
 \r
+        if (navigator.appVersion.indexOf("Mac") !== -1) {\r
+            meta = ev.ctrlKey;\r
+        } else {\r
+            meta = ev.altKey;\r
+        }\r
+        \r
         switch (true) {\r
         case (ev.keyCode === 13):              // return\r
             inp_val = inp_val.trim();\r
@@ -447,6 +475,17 @@ kiwi.view.ControlBox = Backbone.View.extend({
                 this.buffer_pos++;\r
                 inp.val(this.buffer[this.buffer_pos]);\r
             }\r
+            break;\r
+\r
+        case (ev.keyCode === 37 && meta):            // left\r
+            kiwi.app.panels.view.prev();\r
+            return false;\r
+            break;\r
+\r
+        case (ev.keyCode === 39 && meta):            // right\r
+            kiwi.app.panels.view.next();\r
+            return false;\r
+            break;\r
         }\r
     },\r
 \r