Fix Delete dialogs to all canceling multiple deletes more easily

Fixes #10796
This commit is contained in:
prculley 2018-10-05 11:58:37 -05:00 committed by Nick Hall
parent a592f7b2fd
commit 2e17c65a2c
3 changed files with 79 additions and 10 deletions

View File

@ -168,6 +168,52 @@ class QuestionDialog2:
self.parent.set_modal(True) self.parent.set_modal(True)
return (response == Gtk.ResponseType.ACCEPT) return (response == Gtk.ResponseType.ACCEPT)
class QuestionDialog3:
""" Like QuestionDialog2, but includes cancel button,
returns: 1 (okbutton, label_msg1)
0 (no button label_msg2)
-1 (cancel button)
"""
def __init__(self, msg1, msg2, label_msg1, label_msg2, parent=None):
self.xml = Glade(toplevel='questiondialog')
self.top = self.xml.toplevel
self.top.set_icon(ICON)
self.top.set_title("%s - Gramps" % msg1)
label1 = self.xml.get_object('qd_label1')
label1.set_text('<span weight="bold" size="larger">%s</span>' %
html.escape(msg1))
label1.set_use_markup(True)
label2 = self.xml.get_object('qd_label2')
# see https://github.com/emesene/emesene/issues/723
label2.connect('activate-link', on_activate_link)
label2.set_text(msg2)
label2.set_use_markup(True)
self.xml.get_object('okbutton').set_label(label_msg1)
self.xml.get_object('okbutton').set_use_underline(True)
self.xml.get_object('no').set_label(label_msg2)
self.xml.get_object('no').set_use_underline(True)
self.xml.get_object('cancelbutton').show()
self.parent = parent
if parent:
self.top.set_transient_for(parent)
self.parent_modal = parent.get_modal()
if self.parent_modal:
parent.set_modal(False)
self.top.show()
def run(self):
response = self.top.run()
self.top.destroy()
if self.parent and self.parent_modal:
self.parent.set_modal(True)
return (-1 if response == Gtk.ResponseType.DELETE_EVENT
else response == Gtk.ResponseType.ACCEPT)
class OptionDialog: class OptionDialog:
def __init__(self, msg1, msg2, btnmsg1, task1, btnmsg2, task2, parent=None): def __init__(self, msg1, msg2, btnmsg1, task1, btnmsg2, task2, parent=None):
self.xml = Glade(toplevel='optiondialog') self.xml = Glade(toplevel='optiondialog')

View File

@ -696,6 +696,19 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="layout_style">end</property> <property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancelbutton">
<property name="label" translatable="yes">Cancel</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child> <child>
<object class="GtkButton" id="no"> <object class="GtkButton" id="no">
<property name="label" translatable="yes">_Cancel</property> <property name="label" translatable="yes">_Cancel</property>
@ -708,7 +721,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">0</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -722,7 +735,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>
@ -805,6 +818,7 @@
</object> </object>
</child> </child>
<action-widgets> <action-widgets>
<action-widget response="-4">cancelbutton</action-widget>
<action-widget response="-6">no</action-widget> <action-widget response="-6">no</action-widget>
<action-widget response="-3">okbutton</action-widget> <action-widget response="-3">okbutton</action-widget>
</action-widgets> </action-widgets>

View File

@ -66,7 +66,7 @@ from gramps.gen.const import CUSTOM_FILTERS
from gramps.gen.utils.debug import profile from gramps.gen.utils.debug import profile
from gramps.gen.utils.string import data_recover_msg from gramps.gen.utils.string import data_recover_msg
from gramps.gen.plug import CATEGORY_QR_PERSON from gramps.gen.plug import CATEGORY_QR_PERSON
from ..dialog import QuestionDialog, QuestionDialog2, ErrorDialog from ..dialog import QuestionDialog, QuestionDialog3, ErrorDialog
from ..editors import FilterEditor from ..editors import FilterEditor
from ..ddtargets import DdTargets from ..ddtargets import DdTargets
from ..plug.quick import create_quickreport_menu, create_web_connect_menu from ..plug.quick import create_quickreport_menu, create_web_connect_menu
@ -543,14 +543,18 @@ class ListView(NavigationView):
""" """
prompt = True prompt = True
if len(self.selected_handles()) > 1: if len(self.selected_handles()) > 1:
q = QuestionDialog2( ques = QuestionDialog3(
_("Multiple Selection Delete"), _("Multiple Selection Delete"),
_("More than one item has been selected for deletion. " _("More than one item has been selected for deletion. "
"Select the option indicating how to delete the items:"), "Select the option indicating how to delete the items:"),
_("Delete All"), _("Delete All"),
_("Confirm Each Delete"), _("Confirm Each Delete"),
parent=self.uistate.window) parent=self.uistate.window)
prompt = not q.run() res = ques.run()
if res == -1: # Cancel
return
else:
prompt = not res # we prompt on 'Confirm Each Delete'
if not prompt: if not prompt:
self.uistate.set_busy_cursor(True) self.uistate.set_busy_cursor(True)
@ -569,11 +573,16 @@ class ListView(NavigationView):
#descr = object.get_description() #descr = object.get_description()
#if descr == "": #if descr == "":
descr = object.get_gramps_id() descr = object.get_gramps_id()
self.uistate.set_busy_cursor(True) ques = QuestionDialog3(_('Delete %s?') % descr, msg,
QuestionDialog(_('Delete %s?') % descr, msg, _('_Yes'), _('_No'),
_('_Delete Item'), query.query_response, parent=self.uistate.window)
parent=self.uistate.window) res = ques.run()
self.uistate.set_busy_cursor(False) if res == -1: # Cancel
return
elif res: # If true, perfom the delete
self.uistate.set_busy_cursor(True)
query.query_response()
self.uistate.set_busy_cursor(False)
else: else:
query.query_response() query.query_response()