From baae86787c6cd07e211690db36154b15b458c65b Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Wed, 21 Aug 2013 14:41:12 +0000 Subject: [PATCH] 6953: remove "undo history warning" under CLI To remove the meaningless "undo history warning" when a BatchTool is run from cli (e.g., "check"), we add to BatchTool constructor an extra argument to get the uistate, and only produce the GUI warning if there is GUI. svn: r22894 --- src/gui/plug/_windows.py | 2 +- src/gui/plug/tool.py | 34 ++++++++++++++------------- src/plugins/tool/ChangeNames.py | 2 +- src/plugins/tool/ChangeTypes.py | 2 +- src/plugins/tool/Check.py | 2 +- src/plugins/tool/EventNames.py | 2 +- src/plugins/tool/ExtractCity.py | 2 +- src/plugins/tool/MergeCitations.py | 2 +- src/plugins/tool/PatchNames.py | 2 +- src/plugins/tool/ReorderIds.py | 2 +- src/plugins/tool/TestcaseGenerator.py | 2 +- 11 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/gui/plug/_windows.py b/src/gui/plug/_windows.py index c8d9b5d9a..99ca84de5 100644 --- a/src/gui/plug/_windows.py +++ b/src/gui/plug/_windows.py @@ -1029,7 +1029,7 @@ class ToolManagedWindowBatch(tool.BatchTool, ToolManagedWindowBase): # This constructor will ask a question, set self.fail: self.dbstate = dbstate self.uistate = uistate - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if not self.fail: ToolManagedWindowBase.__init__(self, dbstate, uistate, options_class, name, callback) diff --git a/src/gui/plug/tool.py b/src/gui/plug/tool.py index bb295415b..f9f1c9e25 100644 --- a/src/gui/plug/tool.py +++ b/src/gui/plug/tool.py @@ -99,25 +99,27 @@ class Tool(object): 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. + loss of undo history when GUI is available. + Should be used for tools using batch transactions. """ - def __init__(self, dbstate, options_class, name): - # TODO: should we replace this with a callback? - 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 + def __init__(self, dbstate, uistate, options_class, name): + if uistate: + # TODO: should we replace this with a callback? + 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 diff --git a/src/plugins/tool/ChangeNames.py b/src/plugins/tool/ChangeNames.py index 083aaa3a4..b0b3689ac 100644 --- a/src/plugins/tool/ChangeNames.py +++ b/src/plugins/tool/ChangeNames.py @@ -78,7 +78,7 @@ class ChangeNames(tool.BatchTool, ManagedWindow.ManagedWindow): ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__) self.set_window(gtk.Window(),gtk.Label(),'') - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return diff --git a/src/plugins/tool/ChangeTypes.py b/src/plugins/tool/ChangeTypes.py index 704831ad5..568530fb4 100644 --- a/src/plugins/tool/ChangeTypes.py +++ b/src/plugins/tool/ChangeTypes.py @@ -56,7 +56,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow.ManagedWindow): def __init__(self, dbstate, uistate, options_class, name, callback=None): - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return diff --git a/src/plugins/tool/Check.py b/src/plugins/tool/Check.py index 1b2df4ca1..34ae1d135 100644 --- a/src/plugins/tool/Check.py +++ b/src/plugins/tool/Check.py @@ -123,7 +123,7 @@ def cross_table_duplicates(db): class Check(tool.BatchTool): def __init__(self, dbstate, uistate, options_class, name, callback=None): - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return diff --git a/src/plugins/tool/EventNames.py b/src/plugins/tool/EventNames.py index 9727c955a..ff88a8524 100644 --- a/src/plugins/tool/EventNames.py +++ b/src/plugins/tool/EventNames.py @@ -68,7 +68,7 @@ class EventNames(tool.BatchTool, ManagedWindow.ManagedWindow): """ def __init__(self, dbstate, uistate, options_class, name, callback=None): - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if not self.fail: uistate.set_busy_cursor(True) diff --git a/src/plugins/tool/ExtractCity.py b/src/plugins/tool/ExtractCity.py index da32d3aec..a96322026 100644 --- a/src/plugins/tool/ExtractCity.py +++ b/src/plugins/tool/ExtractCity.py @@ -417,7 +417,7 @@ class ExtractCity(tool.BatchTool, ManagedWindow.ManagedWindow): ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__) self.set_window(gtk.Window(), gtk.Label(), '') - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if not self.fail: uistate.set_busy_cursor(True) diff --git a/src/plugins/tool/MergeCitations.py b/src/plugins/tool/MergeCitations.py index 589eabb39..94ed3dc2a 100644 --- a/src/plugins/tool/MergeCitations.py +++ b/src/plugins/tool/MergeCitations.py @@ -94,7 +94,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow.ManagedWindow): self.dbstate = dbstate self.set_window(gtk.Window(), gtk.Label(), '') - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if not self.fail: uistate.set_busy_cursor(True) diff --git a/src/plugins/tool/PatchNames.py b/src/plugins/tool/PatchNames.py index 0603e1784..945197129 100644 --- a/src/plugins/tool/PatchNames.py +++ b/src/plugins/tool/PatchNames.py @@ -107,7 +107,7 @@ class PatchNames(tool.BatchTool, ManagedWindow.ManagedWindow): ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__) self.set_window(gtk.Window(), gtk.Label(), '') - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return diff --git a/src/plugins/tool/ReorderIds.py b/src/plugins/tool/ReorderIds.py index 59e2c5e93..3cb635df5 100644 --- a/src/plugins/tool/ReorderIds.py +++ b/src/plugins/tool/ReorderIds.py @@ -57,7 +57,7 @@ _parseformat = re.compile('.*%(\d+)[^\d]+') #------------------------------------------------------------------------- class ReorderIds(tool.BatchTool): def __init__(self, dbstate, uistate, options_class, name, callback=None): - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return diff --git a/src/plugins/tool/TestcaseGenerator.py b/src/plugins/tool/TestcaseGenerator.py index a7bd48705..5199c72ce 100644 --- a/src/plugins/tool/TestcaseGenerator.py +++ b/src/plugins/tool/TestcaseGenerator.py @@ -110,7 +110,7 @@ class TestcaseGenerator(tool.BatchTool): if dbstate.db.readonly: return - tool.BatchTool.__init__(self, dbstate, options_class, name) + tool.BatchTool.__init__(self, dbstate, uistate, options_class, name) if self.fail: return