From 4ea2ca6a2863cae3b836a1c49c15079b7ac659e9 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Thu, 4 May 2006 02:05:50 +0000 Subject: [PATCH] * src/PluginUtils/_Tool.py (BatchTool): Add class taking care of tools with batch transactions. (ActivePersonTool.pass): Remove method. * src/plugins/Check.py (Check): Derive from BatchTool. * src/plugins/ReorderIds.py (ReorderIds): Use batch transactions; derive from BatchTool. * src/plugins/ChangeTypes.py (ChangeTypes): Use batch transactions; derive from BatchTool. * src/plugins/ChangeNames.py (ChangeNames): Derive from BatchTool. * src/plugins/PatchNames.py (PatchNames): Use batch transactions; derive from BatchTool. * src/glade/gramps.glade: Make both buttons' lables in questiondialog use underline property. (ViewManager.import_data): Add undo warning for imports. svn: r6540 --- gramps2/ChangeLog | 14 +++++++++++ gramps2/src/PluginUtils/_Tool.py | 37 ++++++++++++++++++++++++++---- gramps2/src/ViewManager.py | 26 ++++++++++++++++----- gramps2/src/glade/gramps.glade | 1 + gramps2/src/plugins/ChangeNames.py | 6 +++-- gramps2/src/plugins/ChangeTypes.py | 8 ++++--- gramps2/src/plugins/Check.py | 6 +++-- gramps2/src/plugins/PatchNames.py | 8 ++++--- gramps2/src/plugins/ReorderIds.py | 8 ++++--- 9 files changed, 90 insertions(+), 24 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index b85fbb2c8..9b2e90294 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -2,6 +2,19 @@ * src/ViewManager.py: do a better job of building the buttons. 2006-05-03 Alex Roitman + * src/PluginUtils/_Tool.py (BatchTool): Add class taking care of + tools with batch transactions. + (ActivePersonTool.pass): Remove method. + * src/plugins/Check.py (Check): Derive from BatchTool. + * src/plugins/ReorderIds.py (ReorderIds): Use batch transactions; + derive from BatchTool. + * src/plugins/ChangeTypes.py (ChangeTypes): Use batch + transactions; derive from BatchTool. + * src/plugins/ChangeNames.py (ChangeNames): Derive from BatchTool. + * src/plugins/PatchNames.py (PatchNames): Use batch transactions; + derive from BatchTool. + * src/glade/gramps.glade: Make both buttons' lables in + questiondialog use underline property. * src/GrampsDb/_GrampsInMemDB.py (abort_changes): Remove method. * src/GrampsDb/_GrampsDbBase.py (abort_changes): Remove method. (GrampsDbBase.transaction_begin): No aborting after batch transaction. @@ -10,6 +23,7 @@ (abort_changes): Remove method. (GrampsBSDDB.transaction_begin): No aborting after batch transaction. * src/ViewManager.py (abort): Add method for abandoning changes. + (ViewManager.import_data): Add undo warning for imports. * configure.in: Set release to 0.SVN. * src/DataViews/_PersonView.py (define_actions): Change label. diff --git a/gramps2/src/PluginUtils/_Tool.py b/gramps2/src/PluginUtils/_Tool.py index 6d6bdd52f..2c925e2c5 100644 --- a/gramps2/src/PluginUtils/_Tool.py +++ b/gramps2/src/PluginUtils/_Tool.py @@ -75,7 +75,7 @@ tool_categories = { #------------------------------------------------------------------------- # -# Report +# Tool # #------------------------------------------------------------------------- class Tool: @@ -97,11 +97,39 @@ class Tool: pass +class BatchTool(Tool): + """ + Same as Tool, except the warning is displayed about the potential + loss of undo history. Should be used for tools using batch transactions. + + """ + + def __init__(self, dbstate, options_class, name): + from QuestionDialog import QuestionDialog2 + warn_dialog = QuestionDialog2( + _('Undo history warning'), + _('Proceeding with this tool will erase the undo history ' + 'for this session. In particular, you will not be able ' + 'to revert the changes made by this tool or any changes ' + 'made prior to it.\n\n' + 'If you think you may want to revert running this tool, ' + 'please stop here and backup your database.'), + _('_Proceed with the tool'), _('_Stop')) + if not warn_dialog.run(): + self.fail = True + return + + Tool.__init__(self, dbstate, options_class, name) + self.fail = False + + def run_tool(self): pass + + class ActivePersonTool(Tool): """ - The Tool base class. This is a base class for generating - customized tools. It cannot be used as is, but it can be easily - sub-classed to create a functional tool. + Same as Tool , except the existence of the active person is checked + and the tool is aborted if no active person exists. Should be used + for tools that depend on active person. """ def __init__(self, dbstate, options_class, name): @@ -118,7 +146,6 @@ class ActivePersonTool(Tool): Tool.__init__(self, dbstate, options_class, name) self.fail = False - #------------------------------------------------------------------------ # # Command-line tool diff --git a/gramps2/src/ViewManager.py b/gramps2/src/ViewManager.py index f87919548..8a21f7db9 100644 --- a/gramps2/src/ViewManager.py +++ b/gramps2/src/ViewManager.py @@ -1009,13 +1009,27 @@ class ViewManager: Exporter.Exporter(self.state, self.uistate) def import_data(self, obj): + # First thing first: import is a batch transaction + # so we will lose the undo history. Warn the user. + warn_dialog = QuestionDialog.QuestionDialog2( + _('Undo history warning'), + _('Proceeding with import will erase the undo history ' + 'for this session. In particular, you will not be able ' + 'to revert the import or any changes made prior to it.\n\n' + 'If you think you may want to revert the import, ' + 'please stop here and backup your database.'), + _('_Proceed with import'), _('_Stop'), + self.window) + if not warn_dialog.run(): + return False + choose = gtk.FileChooserDialog(_('GRAMPS: Import database'), - self.uistate.window, - gtk.FILE_CHOOSER_ACTION_OPEN, - (gtk.STOCK_CANCEL, - gtk.RESPONSE_CANCEL, - gtk.STOCK_OPEN, - gtk.RESPONSE_OK)) + self.uistate.window, + gtk.FILE_CHOOSER_ACTION_OPEN, + (gtk.STOCK_CANCEL, + gtk.RESPONSE_CANCEL, + gtk.STOCK_OPEN, + gtk.RESPONSE_OK)) choose.set_local_only(False) # Always add automatic (macth all files) filter add_all_files_filter(choose) diff --git a/gramps2/src/glade/gramps.glade b/gramps2/src/glade/gramps.glade index 024547cd2..701095042 100644 --- a/gramps2/src/glade/gramps.glade +++ b/gramps2/src/glade/gramps.glade @@ -7695,6 +7695,7 @@ Text Beside Icons True True gtk-cancel + True True GTK_RELIEF_NORMAL True diff --git a/gramps2/src/plugins/ChangeNames.py b/gramps2/src/plugins/ChangeNames.py index ee99e11b8..544ffcfb6 100644 --- a/gramps2/src/plugins/ChangeNames.py +++ b/gramps2/src/plugins/ChangeNames.py @@ -57,12 +57,14 @@ from PluginUtils import Tool, register_tool # ChangeNames # #------------------------------------------------------------------------- -class ChangeNames(Tool.Tool, ManagedWindow.ManagedWindow): +class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow): def __init__(self, dbstate, uistate, options_class, name, callback=None): self.label = _('Capitalization changes') - Tool.Tool.__init__(self, dbstate, options_class, name) + Tool.BatchTool.__init__(self, dbstate, options_class, name) + if self.fail: + return ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__) self.cb = callback diff --git a/gramps2/src/plugins/ChangeTypes.py b/gramps2/src/plugins/ChangeTypes.py index 5678be970..79792e492 100644 --- a/gramps2/src/plugins/ChangeTypes.py +++ b/gramps2/src/plugins/ChangeTypes.py @@ -56,11 +56,13 @@ from PluginUtils import Tool, register_tool # # #------------------------------------------------------------------------- -class ChangeTypes(Tool.Tool, ManagedWindow.ManagedWindow): +class ChangeTypes(Tool.BatchTool, ManagedWindow.ManagedWindow): def __init__(self, dbstate, uistate, options_class, name, callback=None): - Tool.Tool.__init__(self, dbstate, options_class, name) + Tool.BatchTool.__init__(self, dbstate, options_class, name) + if self.fail: + return if uistate: self.title = _('Change Event Types') @@ -110,7 +112,7 @@ class ChangeTypes(Tool.Tool, ManagedWindow.ManagedWindow): modified = 0 - self.trans = self.db.transaction_begin() + self.trans = self.db.transaction_begin("",batch=True) if not cli: progress = Utils.ProgressMeter(_('Analyzing events'),'') progress.set_pass('',self.db.get_number_of_people()) diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index c5822fc9d..11715097f 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -138,10 +138,12 @@ def _table_low_level(db,table): # runTool # #------------------------------------------------------------------------- -class Check(Tool.Tool): +class Check(Tool.BatchTool): def __init__(self, dbstate, uistate, options_class, name, callback=None): - Tool.Tool.__init__(self, dbstate, options_class, name) + Tool.BatchTool.__init__(self, dbstate, options_class, name) + if self.fail: + return cli = uistate == None diff --git a/gramps2/src/plugins/PatchNames.py b/gramps2/src/plugins/PatchNames.py index 07fbdcc0f..677ebb75d 100644 --- a/gramps2/src/plugins/PatchNames.py +++ b/gramps2/src/plugins/PatchNames.py @@ -85,16 +85,18 @@ _sn_prefix_re = re.compile("^\s*(%s)\s+(.*)" % '|'.join(prefix_list), # PatchNames # #------------------------------------------------------------------------- -class PatchNames(Tool.Tool, ManagedWindow.ManagedWindow): +class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow): def __init__(self, dbstate, uistate, options_class, name, callback=None): self.label = _('Name and title extraction tool') - Tool.Tool.__init__(self, dbstate, options_class, name) + Tool.BatchTool.__init__(self, dbstate, options_class, name) + if self.fail: + return ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__) self.cb = callback - self.trans = self.db.transaction_begin() + self.trans = self.db.transaction_begin("",batch=True) self.title_list = [] self.nick_list = [] self.prefix1_list = [] diff --git a/gramps2/src/plugins/ReorderIds.py b/gramps2/src/plugins/ReorderIds.py index 7f67c8526..51c4aa172 100644 --- a/gramps2/src/plugins/ReorderIds.py +++ b/gramps2/src/plugins/ReorderIds.py @@ -50,9 +50,11 @@ _findint = re.compile('^[^\d]*(\d+)[^\d]*') # Actual tool # #------------------------------------------------------------------------- -class ReorderIds(Tool.Tool): +class ReorderIds(Tool.BatchTool): def __init__(self,dbstate,uistate,options_class,name,callback=None): - Tool.Tool.__init__(self,dbstate,options_class,name) + Tool.BatchTool.__init__(self,dbstate,options_class,name) + if self.fail: + return db = dbstate.db self.uistate = uistate @@ -61,7 +63,7 @@ class ReorderIds(Tool.Tool): else: print "Reordering GRAMPS IDs..." - self.trans = db.transaction_begin() + self.trans = db.transaction_begin("",batch=True) if uistate: self.progress.set_pass(_('Reordering People IDs'),