[geary/mjog/email-templates: 2/7] Application.Controller: Allow creating composers with alt save folders
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/email-templates: 2/7] Application.Controller: Allow creating composers with alt save folders
- Date: Tue, 21 Apr 2020 13:37:16 +0000 (UTC)
commit 14f3dd0c36d4148441f7dfef0008628bcbce92d0
Author: Michael Gratton <mike vee net>
Date: Mon Apr 20 23:47:38 2020 +1000
Application.Controller: Allow creating composers with alt save folders
Allow a non-draft folder to be specified as the location to save
email being composed.
src/client/application/application-controller.vala | 88 ++++++++++++----------
src/client/composer/composer-widget.vala | 16 ++--
2 files changed, 59 insertions(+), 45 deletions(-)
---
diff --git a/src/client/application/application-controller.vala
b/src/client/application/application-controller.vala
index 825eebe1..c025c2fb 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -325,7 +325,8 @@ internal class Application.Controller : Geary.BaseObject {
/**
* Opens a composer for writing a new, blank message.
*/
- public async void compose_new_email(Geary.RFC822.MailboxAddress? to = null) {
+ public async Composer.Widget? compose_new_email(Geary.RFC822.MailboxAddress? to = null,
+ Geary.Folder? save_to = null) {
// If there's already an empty composer open, just use that
MainWindow main = this.application.get_active_main_window();
Composer.Widget existing = main.conversation_viewer.current_composer;
@@ -334,17 +335,19 @@ internal class Application.Controller : Geary.BaseObject {
existing.is_blank) {
existing.present();
existing.set_focus();
- return;
+ return existing;
}
var context = this.accounts.get(
this.application.get_active_main_window().selected_account.information
);
+ Composer.Widget? composer = null;
if (context != null) {
- var composer = new Composer.Widget(
+ composer = new Composer.Widget(
this.application,
context,
- this.accounts.values.read_only_view
+ this.accounts.values.read_only_view,
+ save_to
);
register_composer(composer);
show_composer(composer);
@@ -354,34 +357,7 @@ internal class Application.Controller : Geary.BaseObject {
report_problem(new Geary.ProblemReport(err));
}
}
- }
-
- /**
- * Opens a composer with the given `mailto:` URL.
- */
- public async void compose_mailto(string mailto) {
- MainWindow? window = this.application.last_active_main_window;
- if (window != null && window.selected_account != null) {
- var context = this.accounts.get(window.selected_account.information);
- if (context != null) {
- var composer = new Composer.Widget(
- this.application,
- context,
- this.accounts.values.read_only_view
- );
- register_composer(composer);
- show_composer(composer);
-
- try {
- yield composer.load_mailto(mailto);
- } catch (GLib.Error err) {
- report_problem(new Geary.ProblemReport(err));
- }
- }
- } else {
- // Schedule the send for after we have an account open.
- this.pending_mailtos.add(mailto);
- }
+ return composer;
}
/**
@@ -392,9 +368,10 @@ internal class Application.Controller : Geary.BaseObject {
* sending again. Otherwise the context is treated as the email to
* be replied to, etc.
*/
- public async void compose_with_context_email(Composer.Widget.ContextType type,
- Geary.Email context,
- string? quote) {
+ public async Composer.Widget? compose_with_context_email(Composer.Widget.ContextType type,
+ Geary.Email context,
+ string? quote,
+ Geary.Folder? save_to = null) {
MainWindow show_on = this.application.get_active_main_window();
if (type == EDIT) {
// Check all known composers since the context may be open
@@ -406,7 +383,7 @@ internal class Application.Controller : Geary.BaseObject {
composer.saved_id.equal_to(context.id)) {
composer.present();
composer.set_focus();
- return;
+ return composer;
}
}
} else {
@@ -422,7 +399,7 @@ internal class Application.Controller : Geary.BaseObject {
try {
existing.append_to_email(context, quote, type);
existing.present();
- return;
+ return existing;
} catch (Geary.EngineError error) {
report_problem(new Geary.ProblemReport(error));
}
@@ -434,18 +411,20 @@ internal class Application.Controller : Geary.BaseObject {
// so we need to ensure there are no composers open there
// first.
if (!show_on.close_composer(true)) {
- return;
+ return null;
}
}
var account = this.accounts.get(
this.application.get_active_main_window().selected_account.information
);
+ Composer.Widget? composer = null;
if (account != null) {
- var composer = new Composer.Widget(
+ composer = new Composer.Widget(
this.application,
account,
- this.accounts.values.read_only_view
+ this.accounts.values.read_only_view,
+ save_to
);
register_composer(composer);
show_composer(composer);
@@ -456,6 +435,35 @@ internal class Application.Controller : Geary.BaseObject {
report_problem(new Geary.ProblemReport(err));
}
}
+ return composer;
+ }
+
+ /**
+ * Opens a composer with the given `mailto:` URL.
+ */
+ public async void compose_mailto(string mailto) {
+ MainWindow? window = this.application.last_active_main_window;
+ if (window != null && window.selected_account != null) {
+ var context = this.accounts.get(window.selected_account.information);
+ if (context != null) {
+ var composer = new Composer.Widget(
+ this.application,
+ context,
+ this.accounts.values.read_only_view
+ );
+ register_composer(composer);
+ show_composer(composer);
+
+ try {
+ yield composer.load_mailto(mailto);
+ } catch (GLib.Error err) {
+ report_problem(new Geary.ProblemReport(err));
+ }
+ }
+ } else {
+ // Schedule the send for after we have an account open.
+ this.pending_mailtos.add(mailto);
+ }
}
/** Displays a problem report when an error has been encountered. */
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 9c013a6b..c340218b 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -29,7 +29,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
/// Translators: Title for an empty composer window
private const string DEFAULT_TITLE = _("New Message");
-
+
/**
* Determines the type of the context email passed to the composer
*
@@ -466,6 +466,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
private Gee.Map<string,Geary.Memory.Buffer> inline_files = new Gee.HashMap<string,Geary.Memory.Buffer>();
private Gee.Map<string,Geary.Memory.Buffer> cid_files = new Gee.HashMap<string,Geary.Memory.Buffer>();
+ private Geary.Folder? save_to;
private Geary.App.DraftManager? draft_manager = null;
private GLib.Cancellable? draft_manager_opening = null;
private Geary.TimeoutManager draft_timer;
@@ -503,12 +504,14 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
public Widget(Application.Client application,
Application.AccountContext initial_account,
- Gee.Collection<Application.AccountContext> all_accounts) {
+ Gee.Collection<Application.AccountContext> all_accounts,
+ Geary.Folder? save_to = null) {
components_reflow_box_get_type();
base_ref();
this.application = application;
this.sender_context = initial_account;
this.accounts = all_accounts;
+ this.save_to = save_to;
this.header = new Headerbar(application.config);
this.header.expand_composer.connect(on_expand_compact_headers);
@@ -1631,9 +1634,12 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
);
this.draft_manager_opening = internal_cancellable;
- Geary.Folder? target = yield this.sender_context.account.get_required_special_folder_async(
- DRAFTS, internal_cancellable
- );
+ Geary.Folder? target = this.save_to;
+ if (target == null) {
+ this.sender_context.account.get_required_special_folder_async(
+ DRAFTS, internal_cancellable
+ );
+ }
Geary.EmailFlags? flags = (
target.used_as == DRAFTS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]