diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index c3d535284..12cf50694 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -52,6 +52,7 @@ from deluge.log import LOG as log import deluge.common import deluge.ui.common import dialogs +import common class AddTorrentDialog(component.Component): def __init__(self): @@ -859,7 +860,31 @@ class AddTorrentDialog(component.Component): # we can construct the new proper paths if len(new_text) == 0 or new_text[-1] != "/": new_text += "/" - self.files_treestore[itr][1] = new_text + + # We need to check if this folder has been split + split_text = new_text[:-1].split("/") + if len(split_text) > 1: + # It's been split, so we need to add new folders and then reparent + # itr. + parent = self.files_treestore.iter_parent(itr) + for s in split_text[:-1]: + # We don't iterate over the last item because we'll just use + # the existing itr and change the text + parent = self.files_treestore.append(parent, + [True, s, 0, -1, False, gtk.STOCK_DIRECTORY]) + + self.files_treestore[itr][1] = split_text[-1] + + # Now reparent itr to parent + common.reparent_iter(self.files_treestore, itr, parent) + + # We need to re-expand the view because it might contracted + # if we change the root iter + self.listview_files.expand_row("0", False) + else: + # This was a simple folder rename without any splits, so just + # change the path for itr + self.files_treestore[itr][1] = new_text # Walk through the tree from 'itr' and add all the new file paths # to the 'mapped_files' option diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py index a27fe823a..dce080757 100644 --- a/deluge/ui/gtkui/common.py +++ b/deluge/ui/gtkui/common.py @@ -181,3 +181,29 @@ def show_other_dialog(header, type_str, image_stockid=None, image_filename=None, dialog.destroy() return value + +def reparent_iter(treestore, itr, parent, move_siblings=False): + """ + This effectively moves itr plus it's children to be a child of parent in treestore + + :param treestore: gtkTreeStore, the treestore + :param itr: gtkTreeIter, the iter to move + :param parent: gtkTreeIter, the new parent for itr + :param move_siblings: bool. if True, it will move all itr's siblings to parent + """ + src = itr + def move_children(i, dest): + while i: + n = treestore.append(dest, treestore.get(i, *xrange(treestore.get_n_columns()))) + to_remove = i + if treestore.iter_children(i): + move_children(treestore.iter_children(i), n) + if i != src: + i = treestore.iter_next(i) + else: + # This is the source iter, we don't want other iters in it's level + if not move_siblings: + i = None + treestore.remove(to_remove) + + move_children(itr, parent) diff --git a/deluge/ui/gtkui/files_tab.py b/deluge/ui/gtkui/files_tab.py index 81be4945e..a0fae7939 100644 --- a/deluge/ui/gtkui/files_tab.py +++ b/deluge/ui/gtkui/files_tab.py @@ -46,6 +46,7 @@ from deluge.configmanager import ConfigManager import deluge.configmanager import deluge.component as component import deluge.common +import common from deluge.log import LOG as log @@ -673,29 +674,6 @@ class FilesTab(Tab): return path_iter - def reparent_iter(self, itr, parent, move_siblings=False): - """ - This effectively moves itr plus it's children to be a child of parent - - If move_siblings is True, it will move all itr's siblings to parent - """ - src = itr - def move_children(i, dest): - while i: - n = self.treestore.append(dest, self.treestore.get(i, *xrange(self.treestore.get_n_columns()))) - to_remove = i - if self.treestore.iter_children(i): - move_children(self.treestore.iter_children(i), n) - if i != src: - i = self.treestore.iter_next(i) - else: - # This is the source iter, we don't want other iters in it's level - if not move_siblings: - i = None - self.treestore.remove(to_remove) - - move_children(itr, parent) - def remove_childless_folders(self, itr): """ Goes up the tree removing childless itrs starting at itr @@ -745,14 +723,14 @@ class FilesTab(Tab): return if new_folder_iter: # This means that a folder by this name already exists - self.reparent_iter(self.treestore.iter_children(old_folder_iter), new_folder_iter) + common.reparent_iter(self.treestore, self.treestore.iter_children(old_folder_iter), new_folder_iter) else: parent = old_folder_iter_parent for ns in new_split[:-1]: parent = self.treestore.append(parent, [ns + "/", 0, "", 0, 0, -1, gtk.STOCK_DIRECTORY]) self.treestore[old_folder_iter][0] = new_split[-1] + "/" - self.reparent_iter(old_folder_iter, parent) + common.reparent_iter(self.treestore, old_folder_iter, parent) # We need to check if the old_folder_iter_parent no longer has children # and if so, we delete it