fix updating the file tree in the file details tab

This commit is contained in:
Damien Churchill 2010-05-02 23:00:05 +01:00
parent e86d2ad4e2
commit d49e1eda79
1 changed files with 66 additions and 52 deletions

View File

@ -86,26 +86,48 @@
Deluge.details.FilesTab.superclass.initComponent.call(this); Deluge.details.FilesTab.superclass.initComponent.call(this);
}, },
onRender: function(ct, position) {
Deluge.details.FilesTab.superclass.onRender.call(this, ct, position);
deluge.menus.filePriorities.on('itemclick', this.onItemClick, this);
this.on('contextmenu', this.onContextMenu, this);
this.sorter = new Ext.tree.TreeSorter(this, {
folderSort: true
});
},
clear: function() { clear: function() {
var root = this.getRootNode(); var root = this.getRootNode();
if (!root.hasChildNodes()) return; if (!root.hasChildNodes()) return;
root.cascade(function(node) { root.cascade(function(node) {
var parent = node.parentNode; var parentNode = node.parentNode;
if (!parent) return; if (!parentNode) return;
if (!parent.ownerTree) return; if (!parentNode.ownerTree) return;
parent.removeChild(node); parentNode.removeChild(node);
}); });
}, },
createFileTree: function(files) {
function walk(files, parentNode) {
for (var file in files.contents) {
var item = files.contents[file];
if (item.type == 'dir') {
walk(item, parentNode.appendChild(new Ext.tree.TreeNode({
text: file,
filename: file,
size: item.size,
progress: item.progress,
priority: item.priority
})));
} else {
parentNode.appendChild(new Ext.tree.TreeNode({
filename: file,
fileIndex: item.index,
size: item.size,
progress: item.progress,
priority: item.priority,
leaf: true,
iconCls: 'x-deluge-file',
uiProvider: Ext.ux.tree.TreeGridNodeUI
}));
}
}
}
var root = this.getRootNode();
walk(files, root);
root.firstChild.expand();
},
update: function(torrentId) { update: function(torrentId) {
if (this.torrentId != torrentId) { if (this.torrentId != torrentId) {
this.clear(); this.clear();
@ -119,6 +141,32 @@
}); });
}, },
updateFileTree: function(files) {
function walk(files, parentNode) {
for (var file in files.contents) {
var item = files.contents[file];
var node = parentNode.findChild('filename', file);
node.attributes.size = item.size;
node.attributes.progress = item.progress;
node.attributes.priority = item.priority;
node.ui.updateColumns();
if (item.type == 'dir') {
walk(item, node);
}
}
}
walk(files, this.getRootNode());
},
onRender: function(ct, position) {
Deluge.details.FilesTab.superclass.onRender.call(this, ct, position);
deluge.menus.filePriorities.on('itemclick', this.onItemClick, this);
this.on('contextmenu', this.onContextMenu, this);
this.sorter = new Ext.tree.TreeSorter(this, {
folderSort: true
});
},
onContextMenu: function(node, e) { onContextMenu: function(node, e) {
e.stopEvent(); e.stopEvent();
var selModel = this.getSelectionModel(); var selModel = this.getSelectionModel();
@ -174,45 +222,11 @@
}, },
onRequestComplete: function(files, options) { onRequestComplete: function(files, options) {
function walk(files, parent) { if (!this.getRootNode().hasChildNodes()) {
for (var file in files.contents) { this.createFileTree(files);
var item = files.contents[file]; } else {
var child = parent.findChild('id', file); this.updateFileTree(files);
if (item.type == 'dir') {
if (!child) {
child = new Ext.tree.TreeNode({
id: file,
text: file,
filename: file,
size: item.size,
progress: item.progress,
priority: item.priority
});
parent.appendChild(child);
}
walk(item, child);
} else {
if (!child) {
child = new Ext.tree.TreeNode({
id: file,
filename: file,
text: file, // this needs to be here for sorting
fileIndex: item.index,
size: item.size,
progress: item.progress,
priority: item.priority,
leaf: true,
iconCls: 'x-deluge-file',
uiProvider: Ext.ux.tree.TreeGridNodeUI
});
parent.appendChild(child);
}
}
}
} }
var root = this.getRootNode();
walk(files, root);
root.firstChild.expand();
} }
}); });
})(); })();