5598: implement User() class for tools
change BatchTool to take user instead of uistate BatchTool now uses user.prompt, properly prompting the user in CLI scenario as well, unless "--yes" flag is given svn: r23071
This commit is contained in:
parent
a4ae95f260
commit
be8c13ef4f
@ -1051,7 +1051,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, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
if not self.fail:
|
||||
ToolManagedWindowBase.__init__(self, dbstate, uistate,
|
||||
options_class, name, callback)
|
||||
|
@ -100,16 +100,13 @@ class Tool(object):
|
||||
|
||||
class BatchTool(Tool):
|
||||
"""
|
||||
Same as Tool, except the warning is displayed about the potential
|
||||
loss of undo history when GUI is available.
|
||||
Same as Tool, except the warning is given about the potential
|
||||
loss of undo history.
|
||||
Should be used for tools using batch transactions.
|
||||
"""
|
||||
|
||||
def __init__(self, dbstate, uistate, options_class, name):
|
||||
if uistate:
|
||||
# TODO: should we replace this with a callback?
|
||||
from ..dialog import QuestionDialog2
|
||||
warn_dialog = QuestionDialog2(
|
||||
def __init__(self, dbstate, user, options_class, name):
|
||||
if not user.prompt(
|
||||
_('Undo history warning'),
|
||||
_('Proceeding with this tool will erase the undo history '
|
||||
'for this session. In particular, you will not be able '
|
||||
@ -117,10 +114,9 @@ class BatchTool(Tool):
|
||||
'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
|
||||
_('_Proceed with the tool'), _('_Stop')):
|
||||
self.fail = True
|
||||
return
|
||||
|
||||
Tool.__init__(self, dbstate, options_class, name)
|
||||
self.fail = False
|
||||
|
@ -80,7 +80,7 @@ class ChangeNames(tool.BatchTool, ManagedWindow):
|
||||
ManagedWindow.__init__(self,uistate,[],self.__class__)
|
||||
self.set_window(Gtk.Window(),Gtk.Label(),'')
|
||||
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
if self.fail:
|
||||
return
|
||||
|
||||
|
@ -57,7 +57,7 @@ class ChangeTypes(tool.BatchTool, ManagedWindow):
|
||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||
uistate = user.uistate
|
||||
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
if self.fail:
|
||||
return
|
||||
|
||||
|
@ -138,7 +138,7 @@ class Check(tool.BatchTool):
|
||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||
uistate = user.uistate
|
||||
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
if self.fail:
|
||||
return
|
||||
|
||||
|
@ -70,7 +70,7 @@ class EventNames(tool.BatchTool, ManagedWindow):
|
||||
|
||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||
uistate = user.uistate
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
|
||||
if not self.fail:
|
||||
uistate.set_busy_cursor(True)
|
||||
|
@ -420,7 +420,7 @@ class ExtractCity(tool.BatchTool, ManagedWindow):
|
||||
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
|
||||
if not self.fail:
|
||||
uistate.set_busy_cursor(True)
|
||||
|
@ -99,7 +99,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow):
|
||||
self.dbstate = dbstate
|
||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
|
||||
if not self.fail:
|
||||
uistate.set_busy_cursor(True)
|
||||
|
@ -109,7 +109,7 @@ class PatchNames(tool.BatchTool, ManagedWindow):
|
||||
ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||
self.set_window(Gtk.Window(), Gtk.Label(), '')
|
||||
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
if self.fail:
|
||||
return
|
||||
|
||||
|
@ -61,7 +61,7 @@ _parseformat = re.compile('.*%(\d+)[^\d]+')
|
||||
class ReorderIds(tool.BatchTool):
|
||||
def __init__(self, dbstate, user, options_class, name, callback=None):
|
||||
uistate = user.uistate
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
if self.fail:
|
||||
return
|
||||
|
||||
|
@ -122,7 +122,7 @@ class TestcaseGenerator(tool.BatchTool):
|
||||
if dbstate.db.readonly:
|
||||
return
|
||||
|
||||
tool.BatchTool.__init__(self, dbstate, uistate, options_class, name)
|
||||
tool.BatchTool.__init__(self, dbstate, user, options_class, name)
|
||||
|
||||
if self.fail:
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user