Fix #2036: new labels are not sorted on torrent right click
This commit is contained in:
parent
4bbf9e2ea6
commit
330019bb3d
|
@ -357,6 +357,13 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
||||||
|
|
||||||
name: 'Label',
|
name: 'Label',
|
||||||
|
|
||||||
|
noLabelItem: {
|
||||||
|
text: _('No Label'),
|
||||||
|
label: '',
|
||||||
|
handler: this.onTorrentMenuClick,
|
||||||
|
scope: this
|
||||||
|
},
|
||||||
|
|
||||||
createMenu: function() {
|
createMenu: function() {
|
||||||
this.labelMenu = new Ext.menu.Menu({
|
this.labelMenu = new Ext.menu.Menu({
|
||||||
items: [{
|
items: [{
|
||||||
|
@ -386,8 +393,8 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateTorrentMenu: function(filter) {
|
updateTorrentMenu: function(states) {
|
||||||
for (var state in filter.getStates()) {
|
for (var state in states) {
|
||||||
if (!state) continue;
|
if (!state) continue;
|
||||||
this.torrentMenu.addMenuItem({
|
this.torrentMenu.addMenuItem({
|
||||||
text: state,
|
text: state,
|
||||||
|
@ -409,12 +416,7 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
||||||
|
|
||||||
onEnable: function() {
|
onEnable: function() {
|
||||||
this.torrentMenu = new Ext.menu.Menu({
|
this.torrentMenu = new Ext.menu.Menu({
|
||||||
items: [{
|
items: [ this.noLabelItem ]
|
||||||
text: _('No Label'),
|
|
||||||
label: '',
|
|
||||||
handler: this.onTorrentMenuClick,
|
|
||||||
scope: this
|
|
||||||
}]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.tmSep = deluge.menus.torrent.add({
|
this.tmSep = deluge.menus.torrent.add({
|
||||||
|
@ -436,7 +438,7 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
||||||
var filter = deluge.sidebar.getFilter('label');
|
var filter = deluge.sidebar.getFilter('label');
|
||||||
filter.list.columns[0].tpl = new Ext.XTemplate(lbltpl);
|
filter.list.columns[0].tpl = new Ext.XTemplate(lbltpl);
|
||||||
this.setFilter(filter);
|
this.setFilter(filter);
|
||||||
this.updateTorrentMenu(filter);
|
this.updateTorrentMenu(filter.getStates());
|
||||||
filter.list.refresh();
|
filter.list.refresh();
|
||||||
} else {
|
} else {
|
||||||
deluge.sidebar.on('filtercreate', this.onFilterCreate, this);
|
deluge.sidebar.on('filtercreate', this.onFilterCreate, this);
|
||||||
|
@ -448,7 +450,7 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
||||||
|
|
||||||
onAfterFilterCreate: function(sidebar, filter) {
|
onAfterFilterCreate: function(sidebar, filter) {
|
||||||
if (filter.filter != 'label') return;
|
if (filter.filter != 'label') return;
|
||||||
this.updateTorrentMenu(filter);
|
this.updateTorrentMenu(filter.getStates());
|
||||||
},
|
},
|
||||||
|
|
||||||
onFilterCreate: function(sidebar, filter) {
|
onFilterCreate: function(sidebar, filter) {
|
||||||
|
@ -465,12 +467,34 @@ Deluge.plugins.LabelPlugin = Ext.extend(Deluge.Plugin, {
|
||||||
},
|
},
|
||||||
|
|
||||||
onLabelAdded: function(label) {
|
onLabelAdded: function(label) {
|
||||||
this.torrentMenu.addMenuItem({
|
var filter = deluge.sidebar.getFilter('label');
|
||||||
text: label,
|
var states = filter.getStates();
|
||||||
label: label,
|
var statesArray = [];
|
||||||
handler: this.onTorrentMenuClick,
|
|
||||||
scope: this
|
for (state in states) {
|
||||||
});
|
statesArray.push(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
var none = statesArray.shift();
|
||||||
|
var all = statesArray.shift();
|
||||||
|
|
||||||
|
this.torrentMenu.removeAll(true);
|
||||||
|
this.torrentMenu.addMenuItem(this.noLabelItem);
|
||||||
|
|
||||||
|
statesArray.push(label.toLowerCase());
|
||||||
|
statesArray.sort();
|
||||||
|
statesArray.unshift(all);
|
||||||
|
|
||||||
|
console.log(states);
|
||||||
|
console.log(statesArray);
|
||||||
|
|
||||||
|
states = {}
|
||||||
|
|
||||||
|
for (i = 0; i < statesArray.length; ++i) {
|
||||||
|
states[statesArray[i]] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateTorrentMenu(states);
|
||||||
},
|
},
|
||||||
|
|
||||||
onLabelContextMenu: function(dv, i, node, e) {
|
onLabelContextMenu: function(dv, i, node, e) {
|
||||||
|
|
Loading…
Reference in New Issue