From 90bcb8a34f4fcfc52b21da7c82430f06524318b8 Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Tue, 22 Mar 2011 14:30:47 -0400 Subject: [PATCH] Added theme switching to auth plugin. Tries to do it live, but some windows may need resizing to redraw using the new theme's metrics. --- contrib/gilbert/media/gilbert/lib/app.js | 24 ++++---- contrib/gilbert/media/gilbert/plugins/auth.js | 60 +++++++++++++------ .../gilbert/media/gilbert/plugins/models.js | 2 +- contrib/gilbert/plugins/auth.py | 2 +- 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/contrib/gilbert/media/gilbert/lib/app.js b/contrib/gilbert/media/gilbert/lib/app.js index 2c3f59c..d68e10c 100644 --- a/contrib/gilbert/media/gilbert/lib/app.js +++ b/contrib/gilbert/media/gilbert/lib/app.js @@ -204,21 +204,25 @@ Gilbert.lib.app.Application = Ext.extend(Ext.util.Observable, { }); Gilbert.api.plugins.auth.get_preference('gilbert.theme', function (theme) { if (theme) { - var link_element = document.getElementById('gilbert.theme.' + theme); - if (link_element) { - Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) { - if (theme_element != link_element) { - theme_element.disabled = true; - } else { - theme_element.disabled = false; - } - }); - } + outer._set_theme(theme); } outer.init(); }); }, + _set_theme: function(theme) { + var link_element = document.getElementById('gilbert.theme.' + theme); + if (link_element) { + Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) { + if (theme_element != link_element) { + theme_element.disabled = true; + } else { + theme_element.disabled = false; + } + }); + } + }, + init: function () { Ext.QuickTips.init(); diff --git a/contrib/gilbert/media/gilbert/plugins/auth.js b/contrib/gilbert/media/gilbert/plugins/auth.js index e31d6fd..6983748 100644 --- a/contrib/gilbert/media/gilbert/plugins/auth.js +++ b/contrib/gilbert/media/gilbert/plugins/auth.js @@ -1,23 +1,12 @@ Ext.ns('Gilbert.lib.plugins.auth'); -Gilbert.lib.plugins.auth.PreferencesWindow = Ext.extend(Ext.Window, { - constructor: function (config, application) { - Gilbert.lib.plugins.auth.PreferencesWindow.superclass.constructor.call(this, Ext.applyIf(config||{},{ - width: 320, - height: 200, - title: 'Preferences', - })); - } -}); - - Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { init: function (application) { Gilbert.lib.plugins.auth.Plugin.superclass.init.call(this, application); - var preferences_window = new Gilbert.lib.plugins.auth.PreferencesWindow({}, application); + var outer = this; Gilbert.api.plugins.auth.whoami(function (whoami) { application.mainmenu.add({ @@ -29,11 +18,9 @@ Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { iconCls: 'icon-user-silhouette', text: '' + whoami + '', menu: [{ - text: 'Preferences...', - iconCls: 'icon-switch', - handler: function (button, event) { - preferences_window.show(); - }, + text: 'Theme', + iconCls: 'icon-mask', + menu: outer.build_theme_menu(), },{ xtype: 'menuseparator', },{ @@ -102,7 +89,44 @@ Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { application.do_layout(); }); }, - + + build_theme_menu: function () { + var application = this.application; + + var theme_switcher = function (menuitem) { + var theme_name = menuitem.theme_name; + Gilbert.api.plugins.auth.set_preference('gilbert.theme', theme_name, function () { + application._set_theme(theme_name); + application.do_layout(); + application.windows.each(function (win) { + win.doLayout(); + }); + }); + }; + + var menu = []; + + Ext.each(document.getElementsByClassName('gilbert.theme'), function (theme_element) { + var theme_id = theme_element.id; + var theme_name = theme_id.match(/gilbert.theme.(.*)/)[1]; + var current_theme = false; + if (!theme_element.disabled) { + current_theme = true; + } + + + menu.push({ + text: theme_name.capfirst(), + checked: current_theme, + group: 'theme', + theme_name: theme_name, + handler: theme_switcher, + }); + }); + + return menu; + }, + }); diff --git a/contrib/gilbert/media/gilbert/plugins/models.js b/contrib/gilbert/media/gilbert/plugins/models.js index afe2a10..61fa7fb 100644 --- a/contrib/gilbert/media/gilbert/plugins/models.js +++ b/contrib/gilbert/media/gilbert/plugins/models.js @@ -231,7 +231,7 @@ Gilbert.lib.plugins.models.ui.ModelPanel = Ext.extend(Ext.Panel, { '->', { xtype: 'button', - text: 'Yes', + text: 'Delete', handler: function () { consequences_win.close(); store.remove(records); diff --git a/contrib/gilbert/plugins/auth.py b/contrib/gilbert/plugins/auth.py index e964559..0daaf85 100644 --- a/contrib/gilbert/plugins/auth.py +++ b/contrib/gilbert/plugins/auth.py @@ -18,7 +18,7 @@ class Auth(Plugin): def icon_names(self): return super(Auth, self).icon_names + [ 'user-silhouette', - 'switch', + 'mask', 'key--pencil', 'door-open-out', ] -- 2.20.1