implement setting the file priority via the context menu

This commit is contained in:
Damien Churchill 2009-04-01 21:31:36 +00:00
parent 8b76cd8a2a
commit 4087dd38cb
3 changed files with 50 additions and 13 deletions

View File

@ -205,6 +205,7 @@ Deluge.Details.Files = {
new Ext.tree.TreeSorter(this.panel, {
folderSort: true
});
Deluge.Menus.FilePriorities.on('itemclick', this.onItemClick.bindWithEvent(this));
},
onContextMenu: function(node, e) {
@ -213,8 +214,38 @@ Deluge.Details.Files = {
Deluge.Menus.FilePriorities.showAt(e.getPoint());
},
onItemClick: function(baseItem, e) {
switch (baseItem.id) {
case 'expandAll':
this.panel.expandAll();
break;
default:
var indexes = new Hash();
function walk(node) {
if (!node.attributes.fileIndex) return;
indexes[node.attributes.fileIndex] = node.attributes.priority;
}
this.panel.getRootNode().cascade(walk);
var node = this.panel.getSelectionModel().getSelectedNode();
indexes[node.attributes.fileIndex] = baseItem.filePriority;
priorities = new Array(indexes.getLength());
indexes.each(function(priority, index) {
priorities[index] = priority;
});
Deluge.Client.core.set_torrent_file_priorities(this.torrentId, priorities, {
onSuccess: function() {
this.update(this.torrentId);
}
});
break;
}
},
onRequestComplete: function(files, torrentId) {
if (this.torrentId != torrentId) {
if (this.torrentId != torrentId) {
this.clear();
this.torrentId = torrentId;
}
@ -236,18 +267,19 @@ Deluge.Details.Files = {
id: file,
filename: file,
text: file, // this needs to be here for sorting
size: item[0],
progress: item[1],
priority: item[2],
fileIndex: item[0],
size: item[1],
progress: item[2],
priority: item[3],
leaf: true,
iconCls: 'x-deluge-file',
uiProvider: Ext.tree.ColumnNodeUI
});
parent.appendChild(child);
}
child.setColumnValue(1, item[0]);
child.setColumnValue(2, item[1]);
child.setColumnValue(3, item[2]);
child.setColumnValue(1, item[1]);
child.setColumnValue(2, item[2]);
child.setColumnValue(3, item[3]);
}
});
}

View File

@ -383,19 +383,23 @@ Deluge.Menus.FilePriorities = new Ext.menu.Menu({
}, '-', {
id: 'no_download',
text: _('Do Not Download'),
icon: '/icons/no_download.png'
icon: '/icons/no_download.png',
filePriority: 0
}, {
id: 'normal',
text: _('Normal Priority'),
icon: '/icons/normal.png'
icon: '/icons/normal.png',
filePriority: 1
}, {
id: 'high',
text: _('High Priority'),
icon: '/icons/high.png'
icon: '/icons/high.png',
filePriority: 2
}, {
id: 'highest',
text: _('Highest Priority'),
icon: '/icons/highest.png'
icon: '/icons/highest.png',
filePriority: 5
}]
});

View File

@ -341,13 +341,14 @@ class WebApi(JSONComponent):
paths.append(path)
torrent_file["progress"] = file_progress[index]
torrent_file["priority"] = file_priorities[index]
torrent_file["index"] = index
info[path] = torrent_file
def walk(path, item):
if type(item) is dict:
return item
return [info[path]["size"], info[path]["progress"],
info[path]["priority"]]
return [info[path]["index"], info[path]["size"],
info[path]["progress"], info[path]["priority"]]
file_tree = uicommon.FileTree(paths)
file_tree.walk(walk)