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

This commit is contained in:
John Garland 2010-04-05 20:21:05 +10:00
commit 6e737518d8

View file

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