diff --git a/src/Bookmarks.py b/src/Bookmarks.py index e71edd9e7..c7954262f 100644 --- a/src/Bookmarks.py +++ b/src/Bookmarks.py @@ -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.""" diff --git a/src/ListModel.py b/src/ListModel.py index 6c5866b45..9980a4c18 100644 --- a/src/ListModel.py +++ b/src/ListModel.py @@ -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