[geary/mjog/account-command-stacks: 12/27] Implement copying conversations as a command
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/account-command-stacks: 12/27] Implement copying conversations as a command
- Date: Sat, 26 Oct 2019 05:35:14 +0000 (UTC)
commit 75b41ab62f7272ce95ea356aa276d67c642d3c93
Author: Michael Gratton <mike vee net>
Date: Sun Oct 6 10:42:03 2019 +1100
Implement copying conversations as a command
Not yet undoable, since the engine doens't support it. :(
src/client/application/application-controller.vala | 91 ++++++++++++++++++++++
src/client/components/main-window.vala | 17 ++++
2 files changed, 108 insertions(+)
---
diff --git a/src/client/application/application-controller.vala
b/src/client/application/application-controller.vala
index a3f8c5c1..3be327f7 100644
--- a/src/client/application/application-controller.vala
+++ b/src/client/application/application-controller.vala
@@ -763,6 +763,39 @@ public class Application.Controller : Geary.BaseObject {
}
}
+ public async void copy_conversations(Geary.FolderSupport.Copy source,
+ Geary.Folder destination,
+ Gee.Collection<Geary.App.Conversation> conversations)
+ throws GLib.Error {
+ AccountContext? context = this.accounts.get(source.account.information);
+ if (context != null) {
+ yield this.commands.execute(
+ new CopyEmailCommand(
+ source,
+ destination,
+ to_in_folder_email_ids(conversations),
+ /// Translators: Label for in-app undo
+ /// notification. String substitution is the name
+ /// of the destination folder.
+ ngettext(
+ "Conversation labelled as %s",
+ "Conversations labelled as %s",
+ conversations.size
+ ).printf(destination.get_display_name()),
+ /// Translators: Label for in-app undo
+ /// notification. String substitution is the name
+ /// of the destination folder.
+ ngettext(
+ "Conversation un-labelled as %s",
+ "Conversations un-labelled as %s",
+ conversations.size
+ ).printf(destination.get_display_name())
+ ),
+ context.cancellable
+ );
+ }
+ }
+
/** Expunges removed accounts while the controller remains open. */
internal async void expunge_accounts() {
try {
@@ -2350,3 +2383,61 @@ private class Application.MoveEmailCommand : RevokableCommand {
}
+private class Application.CopyEmailCommand : Command {
+
+
+ public override bool can_undo {
+ // Engine doesn't yet support it :(
+ get { return false; }
+ }
+
+ private Geary.FolderSupport.Copy source;
+ private Gee.Collection<Geary.EmailIdentifier> source_messages;
+ private Geary.Folder destination;
+
+
+ public CopyEmailCommand(Geary.FolderSupport.Copy source,
+ Geary.Folder destination,
+ Gee.Collection<Geary.EmailIdentifier> messages,
+ string? executed_label = null,
+ string? undone_label = null) {
+ this.source = source;
+ this.source_messages = messages;
+ this.destination = destination;
+
+ this.executed_label = executed_label;
+ this.undone_label = undone_label;
+ }
+
+ public override async void execute(GLib.Cancellable? cancellable)
+ throws GLib.Error {
+ bool open = false;
+ try {
+ yield this.source.open_async(
+ Geary.Folder.OpenFlags.NO_DELAY, cancellable
+ );
+ open = true;
+ yield this.source.copy_email_async(
+ this.source_messages, this.destination.path, cancellable
+ );
+ } finally {
+ if (open) {
+ try {
+ yield this.source.close_async(null);
+ } catch (GLib.Error err) {
+ // ignored
+ }
+ }
+ }
+ }
+
+ public override async void undo(GLib.Cancellable? cancellable)
+ throws GLib.Error {
+ throw new Geary.EngineError.UNSUPPORTED(
+ "Cannot undo copy, not yet supported"
+ }
+ }
+
+}
+
+
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index eb441611..7acf5b74 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -1542,6 +1542,23 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
}
private void on_copy_conversation(Geary.Folder destination) {
+ Geary.FolderSupport.Copy source =
+ this.current_folder as Geary.FolderSupport.Copy;
+ if (source != null) {
+ this.application.controller.copy_conversations.begin(
+ source,
+ destination,
+ this.conversation_list_view.get_selected_conversations(),
+ (obj, res) => {
+ try {
+ this.application.controller.copy_conversations.end(res);
+ } catch (GLib.Error err) {
+ handle_error(source.account.information, err);
+ }
+ }
+ );
+
+ }
}
private void on_archive_conversation() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]