2006-05-06 03:25:01 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modiy
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2008-01-22 14:47:46 +05:30
|
|
|
# $Id$
|
2006-05-06 03:25:01 +05:30
|
|
|
|
|
|
|
# Written by Alex Roitman
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import time
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
2008-01-22 03:33:43 +05:30
|
|
|
import gobject
|
2006-05-06 03:25:01 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from QuestionDialog import QuestionDialog
|
|
|
|
import ManagedWindow
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# UndoHistory class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class UndoHistory(ManagedWindow.ManagedWindow):
|
|
|
|
"""
|
|
|
|
The UndoHistory provides a list view with all the editing
|
|
|
|
steps available for undo/redo. Selecting a line in the list
|
|
|
|
will revert/advance to the appropriate step in editing history.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, dbstate, uistate):
|
|
|
|
|
|
|
|
self.title = _("Undo History")
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
|
|
|
self.db = dbstate.db
|
2009-09-01 00:12:29 +05:30
|
|
|
self.undodb = self.db.undodb
|
2006-05-07 10:52:44 +05:30
|
|
|
self.dbstate = dbstate
|
|
|
|
|
|
|
|
window = gtk.Dialog("",uistate.window,
|
|
|
|
gtk.DIALOG_DESTROY_WITH_PARENT,None)
|
|
|
|
|
|
|
|
self.undo_button = window.add_button(gtk.STOCK_UNDO,
|
|
|
|
gtk.RESPONSE_REJECT)
|
|
|
|
self.redo_button = window.add_button(gtk.STOCK_REDO,
|
|
|
|
gtk.RESPONSE_ACCEPT)
|
|
|
|
self.clear_button = window.add_button(gtk.STOCK_CLEAR,
|
|
|
|
gtk.RESPONSE_APPLY)
|
|
|
|
self.close_button = window.add_button(gtk.STOCK_CLOSE,
|
|
|
|
gtk.RESPONSE_CLOSE)
|
|
|
|
|
|
|
|
self.set_window(window, None, self.title)
|
|
|
|
self.window.set_size_request(400,200)
|
2006-05-06 03:25:01 +05:30
|
|
|
self.window.connect('response', self._response)
|
|
|
|
|
|
|
|
scrolled_window = gtk.ScrolledWindow()
|
|
|
|
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
2006-05-09 04:48:16 +05:30
|
|
|
self.tree = gtk.TreeView()
|
2008-01-22 03:33:43 +05:30
|
|
|
self.model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING, gobject.TYPE_STRING)
|
2006-05-09 04:48:16 +05:30
|
|
|
self.selection = self.tree.get_selection()
|
2006-05-06 03:25:01 +05:30
|
|
|
|
2006-05-12 02:34:46 +05:30
|
|
|
self.renderer = gtk.CellRendererText()
|
2006-05-09 04:48:16 +05:30
|
|
|
self.tree.set_model(self.model)
|
|
|
|
self.tree.set_rules_hint(True)
|
|
|
|
self.tree.append_column(
|
2006-05-12 02:34:46 +05:30
|
|
|
gtk.TreeViewColumn(_('Original time'), self.renderer,
|
|
|
|
text=0,foreground=2,background=3))
|
2006-05-09 04:48:16 +05:30
|
|
|
self.tree.append_column(
|
2006-05-12 02:34:46 +05:30
|
|
|
gtk.TreeViewColumn(_('Action'), self.renderer,
|
|
|
|
text=1,foreground=2,background=3))
|
2006-05-06 03:25:01 +05:30
|
|
|
|
2006-05-09 04:48:16 +05:30
|
|
|
scrolled_window.add(self.tree)
|
2006-05-06 03:25:01 +05:30
|
|
|
self.window.vbox.add(scrolled_window)
|
|
|
|
self.window.show_all()
|
|
|
|
|
|
|
|
self._build_model()
|
2006-05-07 10:52:44 +05:30
|
|
|
self._update_ui()
|
|
|
|
|
|
|
|
self.selection.connect('changed',self._selection_changed)
|
|
|
|
self.show()
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def _selection_changed(self, obj):
|
|
|
|
(model, node) = self.selection.get_selected()
|
2006-05-12 02:34:46 +05:30
|
|
|
if not node:
|
|
|
|
return
|
|
|
|
path = self.model.get_path(node)
|
2009-09-01 00:12:29 +05:30
|
|
|
|
|
|
|
start = min(path[0],self.undodb.undoindex+1)
|
|
|
|
end = max(path[0],self.undodb.undoindex+1)
|
2006-05-12 02:34:46 +05:30
|
|
|
|
|
|
|
self._paint_rows(0,len(self.model)-1,False)
|
|
|
|
self._paint_rows(start,end,True)
|
2006-05-06 03:25:01 +05:30
|
|
|
|
2009-09-01 00:12:29 +05:30
|
|
|
if path[0] < self.undodb.undoindex+1:
|
2006-05-12 06:31:10 +05:30
|
|
|
self.redo_button.set_sensitive(False)
|
2009-09-01 00:12:29 +05:30
|
|
|
self.undo_button.set_sensitive(self.undodb.undo_available())
|
|
|
|
if path[0] > self.undodb.undoindex+1:
|
2006-05-12 06:31:10 +05:30
|
|
|
self.undo_button.set_sensitive(False)
|
2009-09-01 00:12:29 +05:30
|
|
|
self.redo_button.set_sensitive(self.undodb.redo_available())
|
|
|
|
if path[0] == self.undodb.undoindex+1:
|
|
|
|
self.undo_button.set_sensitive(self.undodb.undo_available())
|
|
|
|
self.redo_button.set_sensitive(self.undodb.redo_available())
|
2006-05-12 06:31:10 +05:30
|
|
|
|
2006-05-12 02:34:46 +05:30
|
|
|
def _paint_rows(self,start,end,selected=False):
|
|
|
|
if selected:
|
|
|
|
(fg,bg) = get_colors(self.tree,gtk.STATE_SELECTED)
|
|
|
|
else:
|
|
|
|
fg = bg = None
|
|
|
|
|
|
|
|
for idx in range(start,end+1):
|
|
|
|
the_iter = self.model.get_iter( (idx,) )
|
|
|
|
self.model.set(the_iter,2,fg)
|
|
|
|
self.model.set(the_iter,3,bg)
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def _response(self, obj,response_id):
|
2006-05-06 03:25:01 +05:30
|
|
|
if response_id == gtk.RESPONSE_CLOSE:
|
2006-06-20 20:31:27 +05:30
|
|
|
self.close(obj)
|
2006-05-06 03:25:01 +05:30
|
|
|
elif response_id == gtk.RESPONSE_REJECT:
|
2008-02-24 19:25:55 +05:30
|
|
|
(model, node) = self.selection.get_selected()
|
2006-05-12 02:34:46 +05:30
|
|
|
if not node:
|
|
|
|
return
|
|
|
|
path = self.model.get_path(node)
|
2009-09-01 00:12:29 +05:30
|
|
|
nsteps = path[0]-self.undodb.undoindex-1
|
2006-05-12 02:34:46 +05:30
|
|
|
if nsteps == 0:
|
|
|
|
self._move(-1)
|
|
|
|
else:
|
|
|
|
self._move(nsteps)
|
2006-05-06 03:25:01 +05:30
|
|
|
elif response_id == gtk.RESPONSE_ACCEPT:
|
2008-02-24 19:25:55 +05:30
|
|
|
(model, node) = self.selection.get_selected()
|
2006-05-12 02:34:46 +05:30
|
|
|
if not node:
|
|
|
|
return
|
|
|
|
path = self.model.get_path(node)
|
2009-09-01 00:12:29 +05:30
|
|
|
nsteps = path[0]-self.undodb.undoindex-1
|
2006-05-12 02:34:46 +05:30
|
|
|
if nsteps == 0:
|
|
|
|
self._move(1)
|
|
|
|
else:
|
|
|
|
self._move(nsteps)
|
2006-05-06 03:25:01 +05:30
|
|
|
elif response_id == gtk.RESPONSE_APPLY:
|
|
|
|
self._clear_clicked()
|
2008-01-06 01:40:26 +05:30
|
|
|
elif response_id == gtk.RESPONSE_DELETE_EVENT:
|
2006-06-20 20:31:27 +05:30
|
|
|
self.close(obj)
|
2006-05-06 03:25:01 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2006-05-06 03:25:01 +05:30
|
|
|
return (self.title,None)
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def _clear_clicked(self, obj=None):
|
2006-05-06 03:25:01 +05:30
|
|
|
QuestionDialog(_("Delete confirmation"),
|
|
|
|
_("Are you sure you want to clear the Undo history?"),
|
|
|
|
_("Clear"),
|
|
|
|
self.clear,
|
|
|
|
self.window)
|
|
|
|
|
|
|
|
def clear(self):
|
2009-09-01 00:12:29 +05:30
|
|
|
self.undodb.clear()
|
|
|
|
self.undodb.abort_possible = False
|
2006-05-06 03:25:01 +05:30
|
|
|
self.update()
|
|
|
|
if self.db.undo_callback:
|
|
|
|
self.db.undo_callback(None)
|
|
|
|
if self.db.redo_callback:
|
|
|
|
self.db.redo_callback(None)
|
|
|
|
|
2006-05-07 10:52:44 +05:30
|
|
|
def _move(self,steps=-1):
|
|
|
|
if steps == 0 :
|
|
|
|
return
|
|
|
|
elif steps < 0:
|
|
|
|
func = self.db.undo
|
|
|
|
elif steps > 0:
|
|
|
|
func = self.db.redo
|
|
|
|
|
|
|
|
for step in range(abs(steps)):
|
|
|
|
func(False)
|
|
|
|
self.update()
|
2006-05-06 03:25:01 +05:30
|
|
|
|
|
|
|
def _update_ui(self):
|
2006-05-12 02:34:46 +05:30
|
|
|
self._paint_rows(0,len(self.model)-1,False)
|
2009-09-01 00:12:29 +05:30
|
|
|
self.undo_button.set_sensitive(self.undodb.undo_available())
|
|
|
|
self.redo_button.set_sensitive(self.undodb.redo_available())
|
2006-05-07 10:52:44 +05:30
|
|
|
self.clear_button.set_sensitive(
|
2009-09-01 00:12:29 +05:30
|
|
|
self.undodb.undo_available() or self.undodb.redo_available() )
|
2006-05-06 03:25:01 +05:30
|
|
|
|
|
|
|
def _build_model(self):
|
|
|
|
self.model.clear()
|
2006-05-12 02:34:46 +05:30
|
|
|
fg = bg = None
|
2006-08-01 07:54:49 +05:30
|
|
|
|
2009-09-01 00:12:29 +05:30
|
|
|
if self.undodb.undo_history_timestamp:
|
2006-08-01 07:54:49 +05:30
|
|
|
if self.db.abort_possible:
|
|
|
|
mod_text = _('Database opened')
|
|
|
|
else:
|
|
|
|
mod_text = _('History cleared')
|
2009-09-01 00:12:29 +05:30
|
|
|
time_text = time.ctime(self.undodb.undo_history_timestamp)
|
2006-08-01 07:54:49 +05:30
|
|
|
self.model.append(row=[time_text,mod_text,fg,bg])
|
2006-05-07 10:52:44 +05:30
|
|
|
|
2006-05-06 03:25:01 +05:30
|
|
|
# Get the not-None portion of transaction list
|
2009-09-01 00:12:29 +05:30
|
|
|
translist = [item for item in self.undodb.translist if item]
|
2006-05-06 03:25:01 +05:30
|
|
|
for transaction in translist:
|
|
|
|
time_text = time.ctime(transaction.timestamp)
|
|
|
|
mod_text = transaction.get_description()
|
2006-05-12 02:34:46 +05:30
|
|
|
self.model.append(row=[time_text,mod_text,fg,bg])
|
2009-09-01 00:12:29 +05:30
|
|
|
path = (self.undodb.undoindex+1,)
|
2006-05-07 10:52:44 +05:30
|
|
|
self.selection.select_path(path)
|
|
|
|
|
2006-05-06 03:25:01 +05:30
|
|
|
def update(self):
|
|
|
|
self._build_model()
|
|
|
|
self._update_ui()
|
2006-05-12 02:34:46 +05:30
|
|
|
|
|
|
|
def gtk_color_to_str(color):
|
2006-05-13 00:16:26 +05:30
|
|
|
color_str = u"#%02x%02x%02x" % (color.red/256,
|
|
|
|
color.green/256,
|
|
|
|
color.blue/256)
|
2006-05-12 02:34:46 +05:30
|
|
|
return color_str
|
|
|
|
|
|
|
|
def get_colors(obj,state):
|
|
|
|
fg_color = obj.style.fg[state]
|
|
|
|
bg_color = obj.style.bg[state]
|
|
|
|
|
|
|
|
fg_color_str = gtk_color_to_str(fg_color)
|
|
|
|
bg_color_str = gtk_color_to_str(bg_color)
|
|
|
|
|
|
|
|
return (fg_color_str,bg_color_str)
|