From: Darren Date: Tue, 4 Sep 2012 17:40:02 +0000 (+0100) Subject: Tab view cleanup +tab switching hotkeys X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8b2a103d99cf0464a784d810f2217de08e44d344;p=KiwiIRC.git Tab view cleanup +tab switching hotkeys --- diff --git a/client_backbone/dev/model_panellist.js b/client_backbone/dev/model_panellist.js index 28217f3..d563ef3 100644 --- a/client_backbone/dev/model_panellist.js +++ b/client_backbone/dev/model_panellist.js @@ -11,10 +11,10 @@ kiwi.model.PanelList = Backbone.Collection.extend({ this.view = new kiwi.view.Tabs({"el": $('#toolbar .panellist')[0], "model": this}); // Automatically create a server tab - this.server = new kiwi.model.Server({'name': kiwi.gateway.get('name')}); - kiwi.gateway.on('change:name', this.view.render, this.view); - this.add(this.server); + this.add(new kiwi.model.Server({'name': kiwi.gateway.get('name')})); + this.server = this.getByName(kiwi.gateway.get('name')); + // Keep a tab on the active panel this.bind('active', function (active_panel) { this.active = active_panel; }, this); diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index 679139a..7340b0c 100644 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -300,24 +300,31 @@ kiwi.view.Tabs = Backbone.View.extend({ this.model.on("add", this.panelAdded, this); this.model.on("remove", this.panelRemoved, this); this.model.on("reset", this.render, this); + + this.model.on('active', this.panelActive, this); + + kiwi.gateway.on('change:name', function (gateway, new_val) { + $('span', this.model.server.tab).text(new_val); + }, this); }, render: function () { var that = this; - $this = $(this.el); - $this.empty(); + + this.$el.empty(); // Add the server tab first - $('
  • ' + kiwi.gateway.get('name') + '
  • ') + this.model.server.tab .data('panel_id', this.model.server.cid) - .appendTo($this); + .appendTo(this.$el); + // Go through each panel adding its tab this.model.forEach(function (panel) { // If this is the server panel, ignore as it's already added if (panel == that.model.server) return; - $('
  • ' + panel.get("name") + '
  • ') + panel.tab .data('panel_id', panel.cid) - .appendTo($this); + .appendTo(this.$el); }); }, @@ -326,8 +333,6 @@ kiwi.view.Tabs = Backbone.View.extend({ panel.tab = $('
  • ' + panel.get("name") + '
  • '); panel.tab.data('panel_id', panel.cid) .appendTo(this.$el); - - panel.view.on('active', this.panelActive, this); }, panelRemoved: function (panel) { panel.tab.remove(); @@ -344,7 +349,9 @@ kiwi.view.Tabs = Backbone.View.extend({ }, tabClick: function (e) { - var panel = this.model.getByCid($(e.currentTarget).data('panel_id')); + var tab = $(e.currentTarget); + + var panel = this.model.getByCid(tab.data('panel_id')); if (!panel) { // A panel wasn't found for this tab... wadda fuck return; @@ -354,7 +361,8 @@ kiwi.view.Tabs = Backbone.View.extend({ }, partClick: function (e) { - var panel = this.model.getByCid($(e.currentTarget).parent().data('panel_id')); + var tab = $(e.currentTarget).parent(); + var panel = this.model.getByCid(tab.data('panel_id')); // Only need to part if it's a channel if (panel.isChannel()) { @@ -362,6 +370,19 @@ kiwi.view.Tabs = Backbone.View.extend({ } else { panel.close(); } + }, + + next: function () { + var next = kiwi.app.panels.active.tab.next(); + if (!next.length) next = $('li:first', this.$el); + + next.click(); + }, + prev: function () { + var prev = kiwi.app.panels.active.tab.prev(); + if (!prev.length) prev = $('li:last', this.$el); + + prev.click(); } }); @@ -418,8 +439,15 @@ kiwi.view.ControlBox = Backbone.View.extend({ process: function (ev) { var inp = $(ev.currentTarget), - inp_val = inp.val(); + inp_val = inp.val(), + meta; + if (navigator.appVersion.indexOf("Mac") !== -1) { + meta = ev.ctrlKey; + } else { + meta = ev.altKey; + } + switch (true) { case (ev.keyCode === 13): // return inp_val = inp_val.trim(); @@ -447,6 +475,17 @@ kiwi.view.ControlBox = Backbone.View.extend({ this.buffer_pos++; inp.val(this.buffer[this.buffer_pos]); } + break; + + case (ev.keyCode === 37 && meta): // left + kiwi.app.panels.view.prev(); + return false; + break; + + case (ev.keyCode === 39 && meta): // right + kiwi.app.panels.view.next(); + return false; + break; } },