[geary/wip/713739-inline: 12/37] Make ComposerWidget.should_close() return enum describing state
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/713739-inline: 12/37] Make ComposerWidget.should_close() return enum describing state
- Date: Tue, 20 May 2014 20:16:40 +0000 (UTC)
commit 0b352e8d635bb7d902ab5c9f96d6c501f150b445
Author: Robert Schroll <rschroll gmail com>
Date: Tue May 13 11:12:01 2014 -0700
Make ComposerWidget.should_close() return enum describing state
src/client/application/geary-controller.vala | 30 +++++++++++--------------
src/client/composer/composer-embed.vala | 2 +-
src/client/composer/composer-widget.vala | 25 +++++++++++----------
src/client/composer/composer-window.vala | 2 +-
4 files changed, 28 insertions(+), 31 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 416d102..e95ca16 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1767,24 +1767,20 @@ public class GearyController : Geary.BaseObject {
// If there's composer windows open, give the user a chance to save or cancel.
foreach(ComposerWidget cw in composer_widgets) {
// Check if we should close the window immediately, or if we need to wait.
- if (!cw.should_close()) {
- if (cw.delayed_close) {
- // Window is currently busy saving.
- waiting_to_close.add(cw);
-
- continue;
- } else {
- // User cancelled operation.
- quit_cancelled = true;
-
- break;
- }
+ ComposerWidget.CloseStatus status = cw.should_close();
+ if (status == ComposerWidget.CloseStatus.PENDING_CLOSE) {
+ // Window is currently busy saving.
+ waiting_to_close.add(cw);
+ } else if (status == ComposerWidget.CloseStatus.CANCEL_CLOSE) {
+ // User cancelled operation.
+ quit_cancelled = true;
+ break;
+ } else if (status == ComposerWidget.CloseStatus.DO_CLOSE) {
+ // Hide any existing composer windows for the moment; actually deleting the windows
+ // will result in their removal from composer_windows, which could crash this loop.
+ composers_to_destroy.add(cw);
+ cw.hide();
}
-
- // Hide any existing composer windows for the moment; actually deleting the windows
- // will result in their removal from composer_windows, which could crash this loop.
- composers_to_destroy.add(cw);
- cw.hide();
}
// Safely destroy windows.
diff --git a/src/client/composer/composer-embed.vala b/src/client/composer/composer-embed.vala
index 2062867..0ecc53b 100644
--- a/src/client/composer/composer-embed.vala
+++ b/src/client/composer/composer-embed.vala
@@ -109,7 +109,7 @@ public class ComposerEmbed : Gtk.Box, ComposerContainer {
}
private void on_close() {
- if (composer.should_close())
+ if (composer.should_close() == ComposerWidget.CloseStatus.DO_CLOSE)
close();
}
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index eeaa86a..3c09fbd 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -13,6 +13,12 @@ public class ComposerWidget : Gtk.EventBox {
FORWARD
}
+ public enum CloseStatus {
+ DO_CLOSE,
+ PENDING_CLOSE,
+ CANCEL_CLOSE
+ }
+
public const string ACTION_UNDO = "undo";
public const string ACTION_REDO = "redo";
public const string ACTION_CUT = "cut";
@@ -130,9 +136,6 @@ public class ComposerWidget : Gtk.EventBox {
public ComposeType compose_type { get; private set; default = ComposeType.NEW_MESSAGE; }
- // True if composer can't close immediately (i.e. it's saving a draft)
- public bool delayed_close { get; private set; default = false; }
-
private ContactListStore? contact_list_store = null;
private string? body_html = null;
@@ -674,7 +677,7 @@ public class ComposerWidget : Gtk.EventBox {
&& !drafts_folder.properties.create_never_returns_id && editor.can_undo());
}
- public bool should_close() {
+ public CloseStatus should_close() {
bool try_to_save = can_save();
container.present();
@@ -694,26 +697,26 @@ public class ComposerWidget : Gtk.EventBox {
Gtk.ResponseType response = dialog.run();
if (response == Gtk.ResponseType.CANCEL || response == Gtk.ResponseType.DELETE_EVENT) {
- return false; // Cancel
+ return CloseStatus.CANCEL_CLOSE; // Cancel
} else if (response == Gtk.ResponseType.OK) {
if (try_to_save) {
save_and_exit.begin(); // Save
- return false;
+ return CloseStatus.PENDING_CLOSE;
} else {
- return true;
+ return CloseStatus.DO_CLOSE;
}
} else {
delete_and_exit.begin(); // Discard
- return false;
+ return CloseStatus.PENDING_CLOSE;
}
}
public override bool delete_event(Gdk.EventAny event) {
- return !should_close();
+ return !(should_close() == CloseStatus.DO_CLOSE);
}
private void on_close() {
- if (should_close())
+ if (should_close() == CloseStatus.DO_CLOSE)
destroy();
}
@@ -899,7 +902,6 @@ public class ComposerWidget : Gtk.EventBox {
}
private async void save_and_exit() {
- delayed_close = true;
make_gui_insensitive();
// Do the save.
@@ -909,7 +911,6 @@ public class ComposerWidget : Gtk.EventBox {
}
private async void delete_and_exit() {
- delayed_close = true;
make_gui_insensitive();
// Do the delete.
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index d25d22d..6f9a8c0 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -34,7 +34,7 @@ public class ComposerWindow : Gtk.Window, ComposerContainer {
}
public override bool delete_event(Gdk.EventAny event) {
- return !((ComposerWidget) get_child()).should_close();
+ return !(((ComposerWidget) get_child()).should_close() == ComposerWidget.CloseStatus.DO_CLOSE);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]