[geary/wip/747627-drafts-not-saved-0.11: 1/4] Fix Close and Save not saving drafts. Bug 747627.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/747627-drafts-not-saved-0.11: 1/4] Fix Close and Save not saving drafts. Bug 747627.
- Date: Thu, 15 Dec 2016 00:19:44 +0000 (UTC)
commit abfc9971697fbe062a51e8f8b17d60f612c7396c
Author: Michael James Gratton <mike vee net>
Date: Tue Sep 20 11:11:20 2016 +1000
Fix Close and Save not saving drafts. Bug 747627.
* src/client/composer/composer-widget.vala (ComposerWidget): Simplify
code paths that lead to the draft manager being opened, so we can
ensure it is always opened when constructing a new draft.
src/client/composer/composer-widget.vala | 74 +++++++++++++++---------------
1 files changed, 37 insertions(+), 37 deletions(-)
---
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 950f491..3363fd0 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -264,7 +264,6 @@ public class ComposerWidget : Gtk.EventBox {
private string? last_quote = null;
private Geary.App.DraftManager? draft_manager = null;
- private Geary.EmailIdentifier? editing_draft_id = null;
private Geary.EmailFlags draft_flags = new Geary.EmailFlags.with(Geary.EmailFlags.DRAFT);
private uint draft_save_timeout_id = 0;
private bool is_closing = false;
@@ -374,8 +373,14 @@ public class ComposerWidget : Gtk.EventBox {
bind_property("state", header, "state", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
// Listen to account signals to update from menu.
- Geary.Engine.instance.account_available.connect(update_from_field);
- Geary.Engine.instance.account_unavailable.connect(update_from_field);
+ Geary.Engine.instance.account_available.connect(() => {
+ update_from_field();
+ });
+ Geary.Engine.instance.account_unavailable.connect(() => {
+ if (update_from_field()) {
+ on_from_changed();
+ }
+ });
// TODO: also listen for account updates to allow adding identities while writing an email
Gtk.ScrolledWindow scroll = new Gtk.ScrolledWindow(null, null);
@@ -456,6 +461,7 @@ public class ComposerWidget : Gtk.EventBox {
add_extra_accelerators();
from = account.information.get_primary_from();
+ Geary.EmailIdentifier? editing_draft_id = null;
if (referred != null) {
if (compose_type != ComposeType.NEW_MESSAGE) {
@@ -521,6 +527,7 @@ public class ComposerWidget : Gtk.EventBox {
}
update_from_field();
+ open_draft_manager_async.begin(editing_draft_id);
// only add signature if the option is actually set and if this is not a draft
if (account.information.use_email_signature && !is_referred_draft)
@@ -607,12 +614,7 @@ public class ComposerWidget : Gtk.EventBox {
chain.append(composer_toolbar);
chain.append(attachments_box);
box.set_focus_chain(chain);
-
- // If there's only one From option, open the drafts manager. If there's more than one,
- // the drafts manager will be opened by on_from_changed().
- if (!from_multiple.visible)
- open_draft_manager_async.begin(null);
-
+
// Remind the conversation viewer of draft ids when it reloads
ConversationViewer conversation_viewer =
GearyApplication.instance.controller.main_window.conversation_viewer;
@@ -1369,7 +1371,11 @@ public class ComposerWidget : Gtk.EventBox {
}
// Returns the drafts folder for the current From account.
- private async void open_draft_manager_async(Cancellable? cancellable) throws Error {
+ private async void open_draft_manager_async(
+ Geary.EmailIdentifier? editing_draft_id = null,
+ Cancellable? cancellable = null)
+ throws Error {
+ this.draft_save_text = "";
yield close_draft_manager_async(cancellable);
if (!account.information.save_drafts)
@@ -1377,7 +1383,7 @@ public class ComposerWidget : Gtk.EventBox {
draft_manager = new Geary.App.DraftManager(account);
try {
- yield draft_manager.open_async(editing_draft_id, cancellable);
+ yield this.draft_manager.open_async(editing_draft_id, cancellable);
} catch (Error err) {
debug("Unable to open draft manager %s: %s", draft_manager.to_string(), err.message);
@@ -1385,20 +1391,11 @@ public class ComposerWidget : Gtk.EventBox {
throw err;
}
-
- // clear now, as it was only needed to open draft manager
- editing_draft_id = null;
-
connect_to_draft_manager();
}
private async void close_draft_manager_async(Cancellable? cancellable) throws Error {
- // clear status text
- draft_save_text = "";
-
- // only clear editing_draft_id if associated with prior draft_manager, not due to this
- // widget being initialized with it
- if (draft_manager == null)
+ if (this.draft_manager == null)
return;
disconnect_from_draft_manager();
@@ -1407,8 +1404,7 @@ public class ComposerWidget : Gtk.EventBox {
try {
yield draft_manager.close_async(cancellable);
} finally {
- draft_manager = null;
- editing_draft_id = null;
+ this.draft_manager = null;
}
}
@@ -2343,8 +2339,10 @@ public class ComposerWidget : Gtk.EventBox {
}
return set_active;
}
-
- private void update_from_field() {
+
+ // Updates from combobox contents and visibility, returns true if
+ // the from address had to be set
+ private bool update_from_field() {
from_multiple.changed.disconnect(on_from_changed);
from_single.visible = from_multiple.visible = from_label.visible = false;
@@ -2353,20 +2351,20 @@ public class ComposerWidget : Gtk.EventBox {
accounts = Geary.Engine.instance.get_accounts();
} catch (Error e) {
debug("Could not fetch account info: %s", e.message);
-
- return;
+
+ return false;
}
-
+
// Don't show in inline, compact, or paned modes.
if (state == ComposerState.INLINE || state == ComposerState.INLINE_COMPACT ||
state == ComposerState.PANED)
- return;
-
+ return false;
+
// If there's only one account, show nothing. (From fields are hidden above.)
if (accounts.size < 1 || (accounts.size == 1 && Geary.traverse<Geary.AccountInformation>(
accounts.values).first().alternate_mailboxes == null))
- return;
-
+ return false;
+
from_label.visible = true;
from_label.set_use_underline(true);
@@ -2378,7 +2376,9 @@ public class ComposerWidget : Gtk.EventBox {
from_multiple.visible = true;
from_multiple.remove_all();
from_list = new Gee.ArrayList<FromAddressMap>();
-
+
+ // This is set to true if the current message's from address
+ // has been selected in the ComboBox
bool set_active = false;
if (compose_type == ComposeType.NEW_MESSAGE) {
set_active = add_account_emails_to_from_list(account);
@@ -2399,12 +2399,12 @@ public class ComposerWidget : Gtk.EventBox {
// The identity or account that was active before has been removed
// use the best we can get now (primary address of the account or any other)
from_multiple.set_active(0);
- on_from_changed();
}
-
+
from_multiple.changed.connect(on_from_changed);
+ return !set_active;
}
-
+
private void on_from_changed() {
bool changed = false;
try {
@@ -2419,7 +2419,7 @@ public class ComposerWidget : Gtk.EventBox {
if (!changed && draft_manager != null)
return;
- open_draft_manager_async.begin(null);
+ open_draft_manager_async.begin();
reset_draft_timer();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]