Module: deluge
Branch: master
Commit: a47f9bc8ddd9cb5cde9ebe36283a10f72667c490

Author: Damien Churchill <[email protected]>
Date:   Mon Apr 26 00:51:17 2010 +0100

make enabling the plugin more robust

---

 deluge/plugins/label/label/data/label.js |   66 +++++++++++++++++++----------
 1 files changed, 43 insertions(+), 23 deletions(-)

diff --git a/deluge/plugins/label/label/data/label.js 
b/deluge/plugins/label/label/data/label.js
index 4e3a358..9132ba0 100644
--- a/deluge/plugins/label/label/data/label.js
+++ b/deluge/plugins/label/label/data/label.js
@@ -176,19 +176,46 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
                        }]
                });
        },
+
+       setFilter: function(filter) {
+               filter.show_zero = true;
+               filter.list.on('contextmenu', this.onLabelContextMenu, this);
+               filter.header.on('contextmenu', this.onLabelHeaderContextMenu, 
this);
+               this.filter = filter;
+       },
+
+       updateTorrentMenu: function(filter) {
+               Ext.each(filter.getStates(), function(state) {
+                       if (!state) return;
+                       this.torrentMenu.addMenuItem({
+                               text: state,
+                               label: state,
+                               handler: this.onTorrentMenuClick,
+                               scope: this
+                       });
+               }, this);
+       },
        
        onDisable: function() {
-           
+               deluge.sidebar.un('filtercreate', this.onFilterCreate);
+               deluge.sidebar.un('afterfiltercreate', 
this.onAfterFilterCreate);
+               delete Deluge.FilterPanel.templates.label;
+           this.deregisterTorrentStatus('label');
+               deluge.menus.torrent.remove(this.tmSep);
+               deluge.menus.torrent.remove(this.tm);
        },
        
        onEnable: function() {
-               deluge.sidebar.on('filtercreate', this.onFilterCreate, this);
-               deluge.sidebar.on('afterfiltercreate', 
this.onAfterFilterCreate, this);
-               Deluge.FilterPanel.templates.label = '<div 
class="x-deluge-filter x-deluge-{filter:lowercase}"><tpl 
if="filter">{filter}</tpl><tpl if="!filter">no label</tpl> ({count})</div>';
-
-               deluge.menus.torrent.add({
-                       xtype: 'menuseparator'
-               });
+               if (deluge.sidebar.hasFilter('label')) {
+                       var filter = deluge.sidebar.getFilter('label');
+                       this.setFilter(filter);
+                       this.updateTorrentMenu(filter);
+               } else {
+                       deluge.sidebar.on('filtercreate', this.onFilterCreate, 
this);
+                       deluge.sidebar.on('afterfiltercreate', 
this.onAfterFilterCreate, this);
+                       Deluge.FilterPanel.templates.label = '<div 
class="x-deluge-filter x-deluge-{filter:lowercase}"><tpl 
if="filter">{filter}</tpl><tpl if="!filter">no label</tpl> ({count})</div>';
+               }
+               this.registerTorrentStatus('label', _('Label'));
 
                this.torrentMenu = new Ext.menu.Menu({
                        items: [{
@@ -198,7 +225,12 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
                                scope: this
                        }]
                });
-               deluge.menus.torrent.add({
+
+               this.tmSep = deluge.menus.torrent.add({
+                       xtype: 'menuseparator'
+               });
+
+               this.tm = deluge.menus.torrent.add({
                        text: _('Label'),
                        menu: this.torrentMenu
                })
@@ -206,24 +238,12 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
 
        onAfterFilterCreate: function(sidebar, filter) {
                if (filter.filter != 'label') return;
-
-               Ext.each(filter.getStates(), function(state) {
-                       if (!state) return;
-                       this.torrentMenu.addMenuItem({
-                               text: state,
-                               label: state,
-                               handler: this.onTorrentMenuClick,
-                               scope: this
-                       });
-               }, this);
+               this.updateTorrentMenu(filter);
        },
 
        onFilterCreate: function(sidebar, filter) {
                if (filter.filter != 'label') return;
-               filter.show_zero = true;
-               filter.list.on('contextmenu', this.onLabelContextMenu, this);
-               filter.header.on('contextmenu', this.onLabelHeaderContextMenu, 
this);
-               this.filter = filter;
+               this.setFilter(filter);
        },
 
        onLabelAddClick: function() {

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to