[geary/wip/728002-webkit2: 11/13] Tidy up ComposerWidget::should_close().
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/728002-webkit2: 11/13] Tidy up ComposerWidget::should_close().
- Date: Mon, 16 Jan 2017 04:57:00 +0000 (UTC)
commit 15fe80dd814f51a9ae95f52a15769eba76cb92cd
Author: Michael James Gratton <mike vee net>
Date: Mon Jan 16 14:03:44 2017 +1100
Tidy up ComposerWidget::should_close().
* src/client/composer/composer-widget.vala (ComposerWidget): Add
`can_save` property that defined what the composer's reqwuirements for
being able to save a draft.
(ComposerWidget::should_close): Use can_save rather than should_save to
determine which confirmation dialog to show. When keeping, only save if
we need to. Split up handling responses from 2 and 3 button dialogs so
it's more clear what is going on in each case.
src/client/composer/composer-widget.vala | 56 +++++++++++++++++------------
1 files changed, 33 insertions(+), 23 deletions(-)
---
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index ab3ec8f..c880d45 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -215,12 +215,15 @@ public class ComposerWidget : Gtk.EventBox {
}
}
+ /** Determines if the composer can currently save a draft. */
+ private bool can_save {
+ get { return this.draft_manager != null; }
+ }
+
/** Determines if current message should be saved as draft. */
private bool should_save {
get {
- return this.draft_manager != null
- && this.draft_manager.is_open
- && this.account.information.save_drafts
+ return this.can_save
&& !this.is_draft_saved
&& !this.is_blank;
}
@@ -1051,33 +1054,40 @@ public class ComposerWidget : Gtk.EventBox {
if (this.is_blank)
return CloseStatus.DO_CLOSE;
- bool try_to_save = this.should_save;
-
this.container.present();
- AlertDialog dialog;
- if (try_to_save) {
- dialog = new TernaryConfirmationDialog(container.top_window,
+
+ CloseStatus status = CloseStatus.PENDING_CLOSE;
+ if (this.can_save) {
+ AlertDialog dialog = new TernaryConfirmationDialog(container.top_window,
_("Do you want to discard this message?"), null, Stock._KEEP, Stock._DISCARD,
Gtk.ResponseType.CLOSE, "suggested-action");
+ Gtk.ResponseType response = dialog.run();
+ if (response == Gtk.ResponseType.CANCEL ||
+ response == Gtk.ResponseType.DELETE_EVENT) {
+ status = CloseStatus.CANCEL_CLOSE;
+ } else if (response == Gtk.ResponseType.OK) {
+ // Keep
+ if (!this.is_draft_saved) {
+ save_and_exit_async.begin();
+ } else {
+ status = CloseStatus.DO_CLOSE;
+ }
+ } else {
+ // Discard
+ discard_and_exit_async.begin();
+ }
} else {
- dialog = new ConfirmationDialog(container.top_window,
+ AlertDialog dialog = new ConfirmationDialog(container.top_window,
_("Do you want to discard this message?"), null, Stock._DISCARD, "destructive-action");
- }
-
- Gtk.ResponseType response = dialog.run();
- if (response == Gtk.ResponseType.CANCEL || response == Gtk.ResponseType.DELETE_EVENT) {
- return CloseStatus.CANCEL_CLOSE; // Cancel
- } else if (response == Gtk.ResponseType.OK) {
- if (try_to_save) {
- save_and_exit_async.begin(); // Save
- return CloseStatus.PENDING_CLOSE;
+ Gtk.ResponseType response = dialog.run();
+ if (response == Gtk.ResponseType.OK) {
+ discard_and_exit_async.begin();
} else {
- return CloseStatus.DO_CLOSE;
+ status = CloseStatus.CANCEL_CLOSE;
}
- } else {
- discard_and_exit_async.begin(); // Discard
- return CloseStatus.PENDING_CLOSE;
}
+
+ return status;
}
private void on_close(SimpleAction action, Variant? param) {
@@ -1089,7 +1099,7 @@ public class ComposerWidget : Gtk.EventBox {
if (this.should_save)
save_and_exit_async.begin();
else
- on_close(action, param);
+ this.container.close_container();
}
private void on_close_and_discard(SimpleAction action, Variant? param) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]