From f7ba2f2f99e102ae5e7312ab426960b1fb7e0ea8 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sun, 14 Apr 2019 16:19:56 -0400 Subject: [PATCH] error: Add helper confirm_unapplied_changes For the common dialog we use to confirm changes --- virtManager/details.py | 8 +------- virtManager/error.py | 12 ++++++++++++ virtManager/hostnets.py | 12 +----------- virtManager/snapshots.py | 8 +------- virtManager/storagelist.py | 12 +----------- 5 files changed, 16 insertions(+), 36 deletions(-) diff --git a/virtManager/details.py b/virtManager/details.py index ab55db638..1b0d5d029 100644 --- a/virtManager/details.py +++ b/virtManager/details.py @@ -1178,13 +1178,7 @@ class vmmDetails(vmmGObjectUI): if not self.widget("config-apply").get_sensitive(): return False - if not self.err.chkbox_helper( - self.config.get_confirm_unapplied, - self.config.set_confirm_unapplied, - text1=(_("There are unapplied changes. Would you like to apply " - "them now?")), - chktext=_("Don't warn me again."), - default=False): + if not self.err.confirm_unapplied_changes(): return False return not self.config_apply(row=row) diff --git a/virtManager/error.py b/virtManager/error.py index 27d5c71f4..c0d177d01 100644 --- a/virtManager/error.py +++ b/virtManager/error.py @@ -157,6 +157,18 @@ class vmmErrorDialog(vmmGObject): buttons = Gtk.ButtonsType.OK return self._simple_dialog(dtype, buttons, text1, text2, title) + def confirm_unapplied_changes(self): + """ + Helper function for confirming whether to apply unapplied changes + """ + return self.chkbox_helper( + self.config.get_confirm_unapplied, + self.config.set_confirm_unapplied, + text1=(_("There are unapplied changes. " + "Would you like to apply them now?")), + chktext=_("Don't warn me again."), + default=False) + ########################################## # One shot dialog with a checkbox prompt # diff --git a/virtManager/hostnets.py b/virtManager/hostnets.py index 48e0967b1..ddb15f10e 100644 --- a/virtManager/hostnets.py +++ b/virtManager/hostnets.py @@ -450,18 +450,8 @@ class vmmHostNets(vmmGObjectUI): self._active_edits.add(edittype) def _confirm_changes(self): - if not self._active_edits: - return True - - if self.err.chkbox_helper( - self.config.get_confirm_unapplied, - self.config.set_confirm_unapplied, - text1=(_("There are unapplied changes. " - "Would you like to apply them now?")), - chktext=_("Don't warn me again."), - default=False): + if self._active_edits and self.err.confirm_unapplied_changes(): self._net_apply() - self._active_edits = set() return True diff --git a/virtManager/snapshots.py b/virtManager/snapshots.py index fcd606489..49ec8b02b 100644 --- a/virtManager/snapshots.py +++ b/virtManager/snapshots.py @@ -358,13 +358,7 @@ class vmmSnapshotPage(vmmGObjectUI): if not self._unapplied_changes or not path_selected: return True - if self.err.chkbox_helper( - self.config.get_confirm_unapplied, - self.config.set_confirm_unapplied, - text1=(_("There are unapplied changes. " - "Would you like to apply them now?")), - chktext=_("Don't warn me again."), - default=False): + if self.err.confirm_unapplied_changes(): self._apply() return True diff --git a/virtManager/storagelist.py b/virtManager/storagelist.py index 4f85f9b6c..a73ebb6a1 100644 --- a/virtManager/storagelist.py +++ b/virtManager/storagelist.py @@ -584,18 +584,8 @@ class vmmStorageList(vmmGObjectUI): self.widget("pool-apply").set_sensitive(False) def _confirm_changes(self): - if not self._active_edits: - return True - - if self.err.chkbox_helper( - self.config.get_confirm_unapplied, - self.config.set_confirm_unapplied, - text1=(_("There are unapplied changes. " - "Would you like to apply them now?")), - chktext=_("Don't warn me again."), - default=False): + if self._active_edits and self.err.confirm_unapplied_changes(): self._pool_apply() - self._active_edits = set() return True