Add move_up and move_down methods to ListModel
svn: r15918
This commit is contained in:
parent
54a35df4bc
commit
70abaea768
@ -284,28 +284,18 @@ class Bookmarks :
|
||||
def up_clicked(self, obj):
|
||||
"""Move the current selection up one row."""
|
||||
row = self.namemodel.get_selected_row()
|
||||
if not row or row == -1:
|
||||
return
|
||||
store, the_iter = self.namemodel.get_selected()
|
||||
data = self.namemodel.get_data(the_iter, range(self.namemodel_cols))
|
||||
self.namemodel.remove(the_iter)
|
||||
self.namemodel.insert(row-1, data, None, 1)
|
||||
handle = self.bookmarks.pop(row)
|
||||
self.bookmarks.insert(row-1, handle)
|
||||
self.modified = True
|
||||
if self.namemodel.move_up(row):
|
||||
handle = self.bookmarks.pop(row)
|
||||
self.bookmarks.insert(row-1, handle)
|
||||
self.modified = True
|
||||
|
||||
def down_clicked(self, obj):
|
||||
"""Move the current selection down one row."""
|
||||
row = self.namemodel.get_selected_row()
|
||||
if row + 1 >= self.namemodel.count or row == -1:
|
||||
return
|
||||
store, the_iter = self.namemodel.get_selected()
|
||||
data = self.namemodel.get_data(the_iter, range(self.namemodel_cols))
|
||||
self.namemodel.remove(the_iter)
|
||||
self.namemodel.insert(row+1, data, None, 1)
|
||||
handle = self.bookmarks.pop(row)
|
||||
self.bookmarks.insert(row+1, handle)
|
||||
self.modified = True
|
||||
if self.namemodel.move_down(row):
|
||||
handle = self.bookmarks.pop(row)
|
||||
self.bookmarks.insert(row+1, handle)
|
||||
self.modified = True
|
||||
|
||||
def help_clicked(self):
|
||||
"""Display the relevant portion of GRAMPS manual."""
|
||||
|
@ -446,3 +446,24 @@ class ListModel(object):
|
||||
node = self.idmap[str(info)]
|
||||
self.selection.select_iter(node)
|
||||
|
||||
def move_up(self, row):
|
||||
"""
|
||||
Move the given row up one position.
|
||||
"""
|
||||
if row < 1 or row == -1:
|
||||
return False
|
||||
this_row = self.model.get_iter((row, ))
|
||||
prev_row = self.model.get_iter((row - 1, ))
|
||||
self.model.move_before(this_row, prev_row)
|
||||
return True
|
||||
|
||||
def move_down(self, row):
|
||||
"""
|
||||
Move the given row down one position.
|
||||
"""
|
||||
if row >= self.count - 1 or row == -1:
|
||||
return False
|
||||
this_row = self.model.get_iter((row, ))
|
||||
next_row = self.model.get_iter((row + 1, ))
|
||||
self.model.move_after(this_row, next_row)
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user