Module: deluge
Branch: master
Commit: 6e737518d8d85d27ce30a621d6142a9292df7688

Author: John Garland <[email protected]>
Date:   Mon Apr  5 20:21:05 2010 +1000

Fix splitting folders in add torrent dialog (fixes #1112)

---

 deluge/ui/gtkui/addtorrentdialog.py |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/deluge/ui/gtkui/addtorrentdialog.py 
b/deluge/ui/gtkui/addtorrentdialog.py
index be975e8..3a42fe8 100644
--- a/deluge/ui/gtkui/addtorrentdialog.py
+++ b/deluge/ui/gtkui/addtorrentdialog.py
@@ -785,6 +785,8 @@ class AddTorrentDialog(component.Component):
     def _on_filename_edited(self, renderer, path, new_text):
         index = self.files_treestore[path][3]
 
+        new_text = new_text.strip(os.path.sep)
+
         # Return if the text hasn't changed
         if new_text == self.files_treestore[path][1]:
             return
@@ -802,11 +804,9 @@ class AddTorrentDialog(component.Component):
         if index > -1:
             # We're renaming a file! Yay! That's easy!
             parent = self.files_treestore.iter_parent(itr)
-            file_path = self.get_file_path(parent)
-            file_path += new_text
-            file_path = file_path.replace(os.path.sep*2, os.path.sep)
+            file_path = os.path.join(self.get_file_path(parent), new_text)
 
-            if "/" in new_text:
+            if os.path.sep in new_text:
                 # There are folders in this path, so we need to create them
                 # and then move the file iter to top
                 split_text = new_text.split(os.path.sep)
@@ -843,30 +843,25 @@ class AddTorrentDialog(component.Component):
 
                     index = self.files_treestore[row][3]
 
-                    # Don't do anything if this is a folder
-                    if index == -1:
-                        return
-
-                    # Get the new full path for this file
-                    file_path = file_path_base + self.files_treestore[row][1]
+                    if index > -1:
+                        # Get the new full path for this file
+                        file_path = file_path_base + 
self.files_treestore[row][1]
 
-                    # Update the file path in the mapped_files dict
-                    self.options[torrent_id]["mapped_files"][index] = file_path
+                        # Update the file path in the mapped_files dict
+                        self.options[torrent_id]["mapped_files"][index] = 
file_path
 
                     # Get the next siblings iter
                     row = self.files_treestore.iter_next(row)
 
             # Update the treestore row first so that when walking the tree
             # we can construct the new proper paths
-            if len(new_text) == 0 or new_text[-1] != os.path.sep:
-                new_text += os.path.sep
 
             # We need to check if this folder has been split
-            split_text = new_text[:-1].split(os.path.sep)
-            if len(split_text) > 1:
+            if os.path.sep in new_text:
                 # It's been split, so we need to add new folders and then 
reparent
                 # itr.
                 parent = self.files_treestore.iter_parent(itr)
+                split_text = new_text.split(os.path.sep)
                 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
@@ -877,6 +872,7 @@ class AddTorrentDialog(component.Component):
 
                 # Now reparent itr to parent
                 common.reparent_iter(self.files_treestore, itr, parent)
+                itr = parent
 
                 # We need to re-expand the view because it might contracted
                 # if we change the root iter
@@ -884,7 +880,7 @@ class AddTorrentDialog(component.Component):
             else:
                 # This was a simple folder rename without any splits, so just
                 # change the path for itr
-                self.files_treestore[itr][1] = new_text
+                self.files_treestore[itr][1] = new_text + os.path.sep
 
             # Walk through the tree from 'itr' and add all the new file paths
             # to the 'mapped_files' option

-- 
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