mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-13 13:05:37 +00:00
add a method to get the current states in the filter
This commit is contained in:
parent
29634505e4
commit
85c0725f83
@ -78,7 +78,9 @@ Deluge.ux.AddLabelWindow = Ext.extend(Ext.Window, {
|
|||||||
deluge.client.label.add(label, {
|
deluge.client.label.add(label, {
|
||||||
success: function() {
|
success: function() {
|
||||||
deluge.ui.update();
|
deluge.ui.update();
|
||||||
}
|
this.fireEvent('labeladded', label);
|
||||||
|
},
|
||||||
|
scope: this
|
||||||
});
|
});
|
||||||
this.hide();
|
this.hide();
|
||||||
},
|
},
|
||||||
@ -181,7 +183,39 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
|||||||
|
|
||||||
onEnable: function() {
|
onEnable: function() {
|
||||||
deluge.sidebar.on('filtercreate', this.onFilterCreate, this);
|
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.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'
|
||||||
|
});
|
||||||
|
|
||||||
|
this.torrentMenu = new Ext.menu.Menu({
|
||||||
|
items: [{
|
||||||
|
text: _('No Label'),
|
||||||
|
label: '',
|
||||||
|
handler: this.onTorrentMenuClick,
|
||||||
|
scope: this
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
deluge.menus.torrent.add({
|
||||||
|
text: _('Label'),
|
||||||
|
menu: this.torrentMenu
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
onFilterCreate: function(sidebar, filter) {
|
onFilterCreate: function(sidebar, filter) {
|
||||||
@ -193,10 +227,22 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onLabelAddClick: function() {
|
onLabelAddClick: function() {
|
||||||
if (!this.addWindow) this.addWindow = new Deluge.ux.AddLabelWindow();
|
if (!this.addWindow) {
|
||||||
|
this.addWindow = new Deluge.ux.AddLabelWindow();
|
||||||
|
this.addWindow.on('labeladded', this.onLabelAdded, this);
|
||||||
|
}
|
||||||
this.addWindow.show();
|
this.addWindow.show();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onLabelAdded: function(label) {
|
||||||
|
this.torrentMenu.addMenuItem({
|
||||||
|
text: label,
|
||||||
|
label: label,
|
||||||
|
handler: this.onTorrentMenuClick,
|
||||||
|
scope: this
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
onLabelContextMenu: function(dv, i, node, e) {
|
onLabelContextMenu: function(dv, i, node, e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!this.labelMenu) this.createMenu();
|
if (!this.labelMenu) this.createMenu();
|
||||||
@ -224,11 +270,22 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onLabelRemoveClick: function() {
|
onLabelRemoveClick: function() {
|
||||||
deluge.client.label.remove(this.filter.getFilter(), {
|
var state = this.filter.getFilter();
|
||||||
|
deluge.client.label.remove(state, {
|
||||||
success: function() {
|
success: function() {
|
||||||
deluge.ui.update();
|
deluge.ui.update();
|
||||||
}
|
this.torrentMenu.items.each(function(item) {
|
||||||
|
if (item.text != state) return;
|
||||||
|
this.torrentMenu.remove(item);
|
||||||
|
var i = item;
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
scope: this
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onTorrentMenuClick: function(item, e) {
|
||||||
|
alert(item.label);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Deluge.registerPlugin('Label', Deluge.plugins.LabelPlugin);
|
Deluge.registerPlugin('Label', Deluge.plugins.LabelPlugin);
|
||||||
|
@ -97,6 +97,17 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
|
|||||||
return filter.id;
|
return filter.id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current states in the filter
|
||||||
|
*/
|
||||||
|
getStates: function() {
|
||||||
|
var states = [];
|
||||||
|
this.list.getStore().each(function(r) {
|
||||||
|
states.push(r.get('filter'));
|
||||||
|
});
|
||||||
|
return states;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Store for the ListView of the FilterPanel
|
* Return the Store for the ListView of the FilterPanel
|
||||||
* @returns {Ext.data.Store} the ListView store
|
* @returns {Ext.data.Store} the ListView store
|
||||||
@ -130,7 +141,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
|
|||||||
count: s[1]
|
count: s[1]
|
||||||
});
|
});
|
||||||
record.id = s[0];
|
record.id = s[0];
|
||||||
store.insert(i, [record]);
|
store.insert(i, record);
|
||||||
}
|
}
|
||||||
record.beginEdit();
|
record.beginEdit();
|
||||||
record.set('filter', s[0]);
|
record.set('filter', s[0]);
|
||||||
|
@ -77,12 +77,14 @@ Deluge.Sidebar = Ext.extend(Ext.Panel, {
|
|||||||
panel.on('selectionchange', function(view, nodes) {
|
panel.on('selectionchange', function(view, nodes) {
|
||||||
deluge.ui.update();
|
deluge.ui.update();
|
||||||
});
|
});
|
||||||
panel.updateStates(states);
|
|
||||||
this.add(panel);
|
this.add(panel);
|
||||||
|
|
||||||
this.doLayout();
|
this.doLayout();
|
||||||
this.panels[filter] = panel;
|
this.panels[filter] = panel;
|
||||||
this.fireEvent('filtercreate', this, panel);
|
this.fireEvent('filtercreate', this, panel);
|
||||||
|
|
||||||
|
panel.updateStates(states);
|
||||||
|
this.fireEvent('afterfiltercreate', this, panel);
|
||||||
},
|
},
|
||||||
|
|
||||||
getFilters: function() {
|
getFilters: function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user