Prevent the updating of row that is being edited

This commit is contained in:
Andrew Resch 2008-10-14 00:11:35 +00:00
parent ed0c7f1b9f
commit 08fd7a14f9
1 changed files with 18 additions and 0 deletions

View File

@ -105,6 +105,10 @@ class FilesTab(Tab):
# filename, size, progress string, progress value, priority, file index, icon id # filename, size, progress string, progress value, priority, file index, icon id
self.treestore = gtk.TreeStore(str, gobject.TYPE_UINT64, str, int, int, int, str) self.treestore = gtk.TreeStore(str, gobject.TYPE_UINT64, str, int, int, int, str)
# We need to store the row that's being edited to prevent updating it until
# it's been done editing
self._editing_index = None
# Filename column # Filename column
column = gtk.TreeViewColumn(_("Filename")) column = gtk.TreeViewColumn(_("Filename"))
render = gtk.CellRendererPixbuf() render = gtk.CellRendererPixbuf()
@ -113,6 +117,8 @@ class FilesTab(Tab):
render = gtk.CellRendererText() render = gtk.CellRendererText()
render.set_property("editable", True) render.set_property("editable", True)
render.connect("edited", self._on_filename_edited) render.connect("edited", self._on_filename_edited)
render.connect("editing-started", self._on_filename_editing_start)
render.connect("editing-canceled", self._on_filename_editing_canceled)
column.pack_start(render, True) column.pack_start(render, True)
column.add_attribute(render, "text", 0) column.add_attribute(render, "text", 0)
column.set_sort_column_id(0) column.set_sort_column_id(0)
@ -388,6 +394,11 @@ class FilesTab(Tab):
self.get_files_from_tree(self.treestore, files_list, 0) self.get_files_from_tree(self.treestore, files_list, 0)
files_list.sort() files_list.sort()
for index, row in files_list: for index, row in files_list:
# Do not update a row that is being edited
if self._editing_index is not None:
if self._editing_index == row[5]:
continue
progress_string = "%.2f%%" % (status["file_progress"][index] * 100) progress_string = "%.2f%%" % (status["file_progress"][index] * 100)
if row[2] != progress_string: if row[2] != progress_string:
row[2] = progress_string row[2] = progress_string
@ -466,6 +477,13 @@ class FilesTab(Tab):
def _on_filename_edited(self, renderer, path, new_text): def _on_filename_edited(self, renderer, path, new_text):
index = self.treestore[path][5] index = self.treestore[path][5]
client.rename_files(self.torrent_id, [(index, new_text)]) client.rename_files(self.torrent_id, [(index, new_text)])
self._editing_index = None
def _on_filename_editing_start(self, renderer, editable, path):
self._editing_index = self.treestore[path][5]
def _on_filename_editing_canceled(self, renderer):
self._editing_index = None
def _on_torrent_file_renamed_signal(self, torrent_id, index, name): def _on_torrent_file_renamed_signal(self, torrent_id, index, name):
log.debug("index: %s name: %s", index, name) log.debug("index: %s name: %s", index, name)