Add support for 'spli...
Content-type: text/plain

Author: andar

Revision: 5427

Log:
        Move reparent_iter to common
Add support for 'spliting' folders in the add torrent dialog

Diff:
Modified: trunk/deluge/ui/gtkui/addtorrentdialog.py
===================================================================
--- trunk/deluge/ui/gtkui/addtorrentdialog.py   2009-06-27 22:49:01 UTC (rev 
5426)
+++ trunk/deluge/ui/gtkui/addtorrentdialog.py   2009-06-28 00:56:36 UTC (rev 
5427)
@@ -52,6 +52,7 @@
 import deluge.common
 import deluge.ui.common
 import dialogs
+import common
 
 class AddTorrentDialog(component.Component):
     def __init__(self):
@@ -859,8 +860,32 @@
             # 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
             walk_tree(itr)

Modified: trunk/deluge/ui/gtkui/common.py
===================================================================
--- trunk/deluge/ui/gtkui/common.py     2009-06-27 22:49:01 UTC (rev 5426)
+++ trunk/deluge/ui/gtkui/common.py     2009-06-28 00:56:36 UTC (rev 5427)
@@ -181,3 +181,29 @@
 
     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)

Modified: trunk/deluge/ui/gtkui/files_tab.py
===================================================================
--- trunk/deluge/ui/gtkui/files_tab.py  2009-06-27 22:49:01 UTC (rev 5426)
+++ trunk/deluge/ui/gtkui/files_tab.py  2009-06-28 00:56:36 UTC (rev 5427)
@@ -46,6 +46,7 @@
 import deluge.configmanager
 import deluge.component as component
 import deluge.common
+import common
 
 from deluge.log import LOG as log
 
@@ -673,29 +674,6 @@
 
         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 @@
                 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



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to