5196: When reordering items in a list, make sure selected item is always visible

svn: r18696
This commit is contained in:
Michiel Nauta 2012-01-03 21:00:13 +00:00
parent ac7660c0fd
commit 00ac7302d3
16 changed files with 86 additions and 23 deletions

View File

@ -30,6 +30,7 @@ Address List display tab.
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gobject
#-------------------------------------------------------------------------
#
@ -118,8 +119,10 @@ class AddrEmbedList(EmbeddedList):
"""
Called to update the screen when a new address is added
"""
self.get_data().append(name)
data = self.get_data()
data.append(name)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def edit_button_clicked(self, obj):
"""

View File

@ -26,6 +26,7 @@
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gobject
#-------------------------------------------------------------------------
#
@ -95,9 +96,11 @@ class AttrEmbedList(EmbeddedList):
pass
def add_callback(self, name):
self.get_data().append(name)
data = self.get_data()
data.append(name)
self.changed = True
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data)-1)
def edit_button_clicked(self, obj):
attr = self.get_selected()

View File

@ -35,6 +35,7 @@ LOG = logging.getLogger(".citation")
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gobject
#-------------------------------------------------------------------------
#
@ -144,10 +145,12 @@ class CitationEmbedList(EmbeddedList, DbGUIElement):
"""
Called to update the screen when a new citation is added
"""
self.get_data().append(value)
data = self.get_data()
data.append(value)
self.callman.register_handles({'citation': [value]})
self.changed = True
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def share_button_clicked(self, obj):
SelectCitation = SelectorFactory('Citation')

View File

@ -34,6 +34,7 @@ import cPickle as pickle
# GTK libraries
#
#-------------------------------------------------------------------------
import gobject
import gtk
import pango
@ -265,7 +266,6 @@ class EmbeddedList(ButtonTab):
def _handle_drag(self, row, obj):
self.get_data().insert(row, obj)
self.changed = True
self.rebuild()
def _move(self, row_from, row_to, obj):
dlist = self.get_data()
@ -276,7 +276,6 @@ class EmbeddedList(ButtonTab):
del dlist[row_from]
dlist.insert(row_to, obj)
self.changed = True
self.rebuild()
def _move_up(self, row_from, obj, selmethod=None):
"""
@ -294,6 +293,9 @@ class EmbeddedList(ButtonTab):
#select the row
path = '%d' % (row_from-1)
self.tree.get_selection().select_path(path)
# The height/location of gtk.treecells is calculated in an idle handler
# so use idle_add to scroll cell into view.
gobject.idle_add(self.tree.scroll_to_cell, path)
def _move_down(self, row_from, obj, selmethod=None):
"""
@ -311,6 +313,7 @@ class EmbeddedList(ButtonTab):
#select the row
path = '%d' % (row_from+1)
self.tree.get_selection().select_path(path)
gobject.idle_add(self.tree.scroll_to_cell, path)
def get_icon_name(self):
"""
@ -375,7 +378,6 @@ class EmbeddedList(ButtonTab):
"""
(model, node) = self.selection.get_selected()
if node:
obj = self.model.get_value(node, self._HANDLE_COL)
return model.get_value(node, self._HANDLE_COL)
return None
@ -463,6 +465,7 @@ class EmbeddedList(ButtonTab):
Rebuilds the data in the database by creating a new model,
using the build_model function passed at creation time.
"""
offset = self.tree.get_visible_rect()
#during rebuild, don't do _selection_changed
self.dirty_selection = True
(model, node) = self.selection.get_selected()
@ -490,6 +493,8 @@ class EmbeddedList(ButtonTab):
#model and tree are reset, allow _selection_changed again, and force it
self.dirty_selection = False
self._selection_changed()
if self.tree.flags() & gtk.REALIZED:
gobject.idle_add(self.tree.scroll_to_point, offset.x, offset.y)
self.post_rebuild(selectedpath)
def post_rebuild(self, prebuildpath):

View File

@ -28,6 +28,7 @@
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gtk
import gobject
#-------------------------------------------------------------------------
#
@ -270,10 +271,13 @@ class EventEmbedList(DbGUIElement, GroupEmbeddedList):
def object_added(self, reference, primary):
reference.ref = primary.handle
self.get_data()[self._WORKGROUP].append(reference)
data = self.get_data()[self._WORKGROUP]
data.append(reference)
self.callman.register_handles({'event': [primary.handle]})
self.changed = True
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell,
(self._WORKGROUP, len(data) - 1))
def object_edited(self, ref, event):
"""

View File

@ -279,10 +279,18 @@ class GalleryTab(ButtonTab, DbGUIElement):
def add_callback(self, media_ref, media):
media_ref.ref = media.handle
self.get_data().append(media_ref)
data = self.get_data()
data.append(media_ref)
self.callman.register_handles({'media': [media.handle]})
self.changed = True
self.rebuild()
model = self.iconlist.get_model()
if model:
itr_last = model.iter_nth_child(None, len(data) - 1)
if itr_last:
path = model.get_path(itr_last)
gobject.idle_add(self.iconlist.scroll_to_path, path, False,
0.0, 0.0)
def __blocked_text(self):
"""
@ -517,7 +525,6 @@ class GalleryTab(ButtonTab, DbGUIElement):
def _handle_drag(self, row, obj):
self.get_data().insert(row, obj)
self.changed = True
self.rebuild()
def _move(self, row_from, row_to, obj):
dlist = self.get_data()
@ -528,7 +535,6 @@ class GalleryTab(ButtonTab, DbGUIElement):
del dlist[row_from]
dlist.insert(row_to, obj)
self.changed = True
self.rebuild()
def find_index(self, obj):
"""

View File

@ -35,6 +35,7 @@ import cPickle as pickle
#-------------------------------------------------------------------------
import gtk
import pango
import gobject
#-------------------------------------------------------------------------
#
@ -237,7 +238,6 @@ class GroupEmbeddedList(EmbeddedList):
if row[0] == self._WORKGROUP:
self.get_data()[self._WORKGROUP].insert(row[1], obj)
self.changed = True
self.rebuild()
else:
self.dropnotworkgroup(row, obj)
@ -260,7 +260,6 @@ class GroupEmbeddedList(EmbeddedList):
del dlist[row_from[1]]
dlist.insert(row_to[1], obj)
self.changed = True
self.rebuild()
elif row_from[0] == self._WORKGROUP:
self.move_away_work(row_from, row_to, obj)
elif row_to[0] == self._WORKGROUP:
@ -295,8 +294,9 @@ class GroupEmbeddedList(EmbeddedList):
self.changed = True
self.rebuild()
#select the row
self.tree.get_selection().select_path((self._WORKGROUP,
row_from[1]-1))
path = (self._WORKGROUP, row_from[1]-1)
self.tree.get_selection().select_path(path)
gobject.idle_add(self.tree.scroll_to_cell, path)
else:
self._move_up_notwork(row_from, obj, selmethod)
@ -327,8 +327,9 @@ class GroupEmbeddedList(EmbeddedList):
self.changed = True
self.rebuild()
#select the row
self.tree.get_selection().select_path((self._WORKGROUP,
row_from[1]+1))
path = (self._WORKGROUP, row_from[1]+1)
self.tree.get_selection().select_path(path)
gobject.idle_add(self.tree.scroll_to_cell, path)
else:
self._move_down_notwork(row_from, obj, selmethod)

View File

@ -26,6 +26,7 @@
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gobject
#-------------------------------------------------------------------------
#
@ -91,8 +92,10 @@ class LdsEmbedList(EmbeddedList):
pass
def add_callback(self, name):
self.get_data().append(name)
data = self.get_data()
data.append(name)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def edit_button_clicked(self, obj):
lds = self.get_selected()

View File

@ -26,6 +26,7 @@
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gobject
#-------------------------------------------------------------------------
#
@ -81,8 +82,10 @@ class LocationEmbedList(EmbeddedList):
pass
def add_callback(self, name):
self.get_data().append(name)
data = self.get_data()
data.append(name)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def edit_button_clicked(self, obj):
loc = self.get_selected()

View File

@ -27,6 +27,7 @@
#
#-------------------------------------------------------------------------
import gtk
import gobject
#-------------------------------------------------------------------------
#
@ -163,8 +164,11 @@ class NameEmbedList(GroupEmbeddedList):
pass
def add_callback(self, name):
self.get_data()[self._WORKGROUP].append(name)
data = self.get_data()[self._WORKGROUP]
data.append(name)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell,
(self._WORKGROUP, len(data) - 1))
def edit_button_clicked(self, obj):
name = self.get_selected()

View File

@ -32,6 +32,7 @@ from gen.ggettext import gettext as _
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gobject
#-------------------------------------------------------------------------
#
@ -141,10 +142,12 @@ class NoteTab(EmbeddedList, DbGUIElement):
"""
Called to update the screen when a new note is added
"""
self.get_data().append(name)
data = self.get_data()
data.append(name)
self.callman.register_handles({'note': [name]})
self.changed = True
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def edit_button_clicked(self, obj):
"""

View File

@ -27,6 +27,7 @@
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gobject
#-------------------------------------------------------------------------
#
@ -149,6 +150,11 @@ class PersonEventEmbedList(EventEmbedList):
flist.insert(index-1, handle)
self.changed = True
self.rebuild()
# select the row
# New index is index-1 but for path, add another 1 for person events.
path = (index,)
self.tree.get_selection().select_path(path)
gobject.idle_add(self.tree.scroll_to_cell, path)
def _move_down_group(self, groupindex):
"""
@ -172,3 +178,8 @@ class PersonEventEmbedList(EventEmbedList):
flist.insert(index+1, handle)
self.changed = True
self.rebuild()
# select the row
# New index is index+1 but for path, add another 1 for person events.
path = (index + 2,)
self.tree.get_selection().select_path(path)
gobject.idle_add(self.tree.scroll_to_cell, path)

View File

@ -26,6 +26,7 @@
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gobject
#-------------------------------------------------------------------------
#
@ -92,8 +93,10 @@ class PersonRefEmbedList(EmbeddedList):
pass
def add_callback(self, obj):
self.get_data().append(obj)
data = self.get_data()
data.append(obj)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def edit_button_clicked(self, obj):
from gui.editors import EditPersonRef

View File

@ -26,6 +26,7 @@
#
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gobject
#-------------------------------------------------------------------------
#
@ -145,10 +146,12 @@ class RepoEmbedList(EmbeddedList, DbGUIElement):
def add_callback(self, value):
value[0].ref = value[1].handle
self.get_data().append(value[0])
data = self.get_data()
data.append(value[0])
self.callman.register_handles({'repository': [value[1].handle]})
self.changed = True
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def edit_button_clicked(self, obj):
ref = self.get_selected()

View File

@ -27,6 +27,7 @@
#-------------------------------------------------------------------------
from gen.ggettext import gettext as _
import gtk
import gobject
#-------------------------------------------------------------------------
#
@ -90,8 +91,10 @@ class WebEmbedList(EmbeddedList):
pass
def add_callback(self, url):
self.get_data().append(url)
data = self.get_data()
data.append(url)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell, len(data) - 1)
def edit_button_clicked(self, obj):
from gui.editors import EditUrl

View File

@ -53,6 +53,7 @@ from DdTargets import DdTargets
import gtk
from gtk import gdk
import pango
import gobject
#-------------------------------------------------------------------------
#
@ -192,6 +193,8 @@ class ChildEmbedList(EmbeddedList):
ref.ref = person.get_handle()
self.family.add_child_ref(ref)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell,
len(self.family.get_child_ref_list()) - 1)
self.call_edit_childref(ref)
def child_ref_edited(self, person):
@ -212,6 +215,8 @@ class ChildEmbedList(EmbeddedList):
ref.ref = person.get_handle()
self.family.add_child_ref(ref)
self.rebuild()
gobject.idle_add(self.tree.scroll_to_cell,
len(self.family.get_child_ref_list()) - 1)
self.call_edit_childref(ref)
def run(self, skip):