[geary/wip/3.32-ux: 313/314] Move common widow action definitions to GearyApplication



commit e6f39db127b95adde1bdcb91f2a77f3417aea53a
Author: Michael Gratton <mike vee net>
Date:   Sun Feb 24 20:26:11 2019 +1100

    Move common widow action definitions to GearyApplication
    
    We want to ensure that things like close, undo, etc all have the same
    action name, and hence use the same definition.

 src/client/accounts/accounts-editor-list-pane.vala |  4 ++--
 src/client/accounts/accounts-editor.vala           |  8 +++----
 src/client/application/geary-application.vala      | 14 +++++++++++
 src/client/application/geary-controller.vala       | 12 +++++-----
 src/client/composer/composer-widget.vala           | 27 ++++++++--------------
 5 files changed, 36 insertions(+), 29 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-list-pane.vala 
b/src/client/accounts/accounts-editor-list-pane.vala
index 3cc59888..eca2b02c 100644
--- a/src/client/accounts/accounts-editor-list-pane.vala
+++ b/src/client/accounts/accounts-editor-list-pane.vala
@@ -240,7 +240,7 @@ internal class Accounts.EditorListPane : Gtk.Grid, EditorPane, CommandPane {
     private void on_execute(Application.Command command) {
         if (command.executed_label != null) {
             InAppNotification ian = new InAppNotification(command.executed_label);
-            ian.set_button(_("Undo"), "win." + GearyController.ACTION_UNDO);
+            ian.set_button(_("Undo"), "win." + GearyApplication.ACTION_UNDO);
             this.editor.add_notification(ian);
         }
     }
@@ -248,7 +248,7 @@ internal class Accounts.EditorListPane : Gtk.Grid, EditorPane, CommandPane {
     private void on_undo(Application.Command command) {
         if (command.undone_label != null) {
             InAppNotification ian = new InAppNotification(command.undone_label);
-            ian.set_button(_("Redo"), "win." + GearyController.ACTION_REDO);
+            ian.set_button(_("Redo"), "win." + GearyApplication.ACTION_REDO);
             this.editor.add_notification(ian);
         }
     }
diff --git a/src/client/accounts/accounts-editor.vala b/src/client/accounts/accounts-editor.vala
index 24f3297f..3da9df8c 100644
--- a/src/client/accounts/accounts-editor.vala
+++ b/src/client/accounts/accounts-editor.vala
@@ -19,8 +19,8 @@ public class Accounts.Editor : Gtk.Dialog {
 
 
     private const ActionEntry[] ACTION_ENTRIES = {
-        { GearyController.ACTION_REDO, on_redo },
-        { GearyController.ACTION_UNDO, on_undo },
+        { GearyApplication.ACTION_REDO, on_redo },
+        { GearyApplication.ACTION_UNDO, on_undo },
     };
 
 
@@ -226,8 +226,8 @@ public class Accounts.Editor : Gtk.Dialog {
             can_redo = pane.commands.can_redo;
         }
 
-        get_action(GearyController.ACTION_UNDO).set_enabled(can_undo);
-        get_action(GearyController.ACTION_REDO).set_enabled(can_redo);
+        get_action(GearyApplication.ACTION_UNDO).set_enabled(can_undo);
+        get_action(GearyApplication.ACTION_REDO).set_enabled(can_redo);
     }
 
     private inline EditorPane? get_current_pane() {
diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala
index 79740282..69bd59f3 100644
--- a/src/client/application/geary-application.vala
+++ b/src/client/application/geary-application.vala
@@ -16,6 +16,7 @@ extern const string GETTEXT_PACKAGE;
  * The interface between Geary and the desktop environment.
  */
 public class GearyApplication : Gtk.Application {
+
     public const string NAME = "Geary";
     public const string PRGNAME = "geary";
     public const string APP_ID = "org.gnome.Geary";
@@ -43,6 +44,13 @@ public class GearyApplication : Gtk.Application {
         null
     };
 
+    // Common window actions
+    public const string ACTION_CLOSE = "close";
+    public const string ACTION_COPY = "copy";
+    public const string ACTION_REDO = "redo";
+    public const string ACTION_UNDO = "undo";
+
+    // App-wide actions
     private const string ACTION_ABOUT = "about";
     private const string ACTION_ACCOUNTS = "accounts";
     private const string ACTION_COMPOSE = "compose";
@@ -237,7 +245,13 @@ public class GearyApplication : Gtk.Application {
             exec_dir.get_path(), is_installed().to_string());
 
         config = new Configuration(APP_ID);
+
+        add_window_accelerators(ACTION_CLOSE, { "<Ctrl>W" });
+        add_window_accelerators(ACTION_COPY, { "<Ctrl>C" });
+        add_window_accelerators(ACTION_REDO, { "<Ctrl><Shift>Z" });
+        add_window_accelerators(ACTION_UNDO, { "<Ctrl>Z" });
         ComposerWidget.add_window_accelerators(this);
+
         yield controller.open_async(null);
 
         release();
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index dda2a490..7f88e5a8 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -22,8 +22,6 @@ public class GearyController : Geary.BaseObject {
     public const string ACTION_DELETE_CONVERSATION = "delete-conv";
     public const string ACTION_EMPTY_SPAM = "empty-spam";
     public const string ACTION_EMPTY_TRASH = "empty-trash";
-    public const string ACTION_UNDO = "undo";
-    public const string ACTION_REDO = "redo";
     public const string ACTION_FIND_IN_CONVERSATION = "conv-find";
     public const string ACTION_ZOOM = "zoom";
     public const string ACTION_SHOW_MARK_MENU = "mark-message-menu";
@@ -168,7 +166,7 @@ public class GearyController : Geary.BaseObject {
         {ACTION_SEARCH,                on_search_activated             },
         {ACTION_EMPTY_SPAM,            on_empty_spam                   },
         {ACTION_EMPTY_TRASH,           on_empty_trash                  },
-        {ACTION_UNDO,                  on_revoke                       },
+        {GearyApplication.ACTION_UNDO, on_revoke                       },
         // Message actions
         {ACTION_REPLY_TO_MESSAGE,      on_reply_to_message_action   },
         {ACTION_REPLY_ALL_MESSAGE,     on_reply_all_message_action  },
@@ -613,8 +611,6 @@ public class GearyController : Geary.BaseObject {
         add_window_accelerators(ACTION_ARCHIVE_CONVERSATION, { "A" });
         add_window_accelerators(ACTION_TRASH_CONVERSATION, { "Delete", "BackSpace" });
         add_window_accelerators(ACTION_DELETE_CONVERSATION, { "<Shift>Delete", "<Shift>BackSpace" });
-        add_window_accelerators(ACTION_UNDO, { "<Ctrl>Z" });
-        add_window_accelerators(ACTION_REDO, { "<Ctrl><Shift>Z" });
         add_window_accelerators(ACTION_ZOOM+("('in')"), { "<Ctrl>equal", "equal" });
         add_window_accelerators(ACTION_ZOOM+("('out')"), { "<Ctrl>minus", "minus" });
         add_window_accelerators(ACTION_ZOOM+("('normal')"), { "<Ctrl>0", "0" });
@@ -2525,7 +2521,11 @@ public class GearyController : Geary.BaseObject {
     }
 
     private void update_revokable_action() {
-        get_window_action(ACTION_UNDO).set_enabled(this.revokable != null && this.revokable.valid && 
!this.revokable.in_process);
+        get_window_action(GearyApplication.ACTION_UNDO).set_enabled(
+            this.revokable != null &&
+            this.revokable.valid &&
+            !this.revokable.in_process
+        );
     }
 
     private void on_revokable_valid_changed() {
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 8d06bc65..24365816 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -47,10 +47,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
         }
     }
 
-    private const string ACTION_UNDO = "undo";
-    private const string ACTION_REDO = "redo";
     private const string ACTION_CUT = "cut";
-    private const string ACTION_COPY = "copy";
     private const string ACTION_COPY_LINK = "copy-link";
     private const string ACTION_PASTE = "paste";
     private const string ACTION_PASTE_WITHOUT_FORMATTING = "paste-without-formatting";
@@ -72,7 +69,6 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     private const string ACTION_INSERT_LINK = "insert-link";
     private const string ACTION_COMPOSE_AS_HTML = "compose-as-html";
     private const string ACTION_SHOW_EXTENDED = "show-extended";
-    private const string ACTION_CLOSE = "close";
     private const string ACTION_CLOSE_AND_SAVE = "close-and-save";
     private const string ACTION_CLOSE_AND_DISCARD = "close-and-discard";
     private const string ACTION_DETACH = "detach";
@@ -92,10 +88,10 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     };
 
     private const ActionEntry[] editor_action_entries = {
-        {ACTION_UNDO,                     on_undo                                       },
-        {ACTION_REDO,                     on_redo                                       },
+        {GearyApplication.ACTION_UNDO,    on_undo                                       },
+        {GearyApplication.ACTION_REDO,    on_redo                                       },
+        {GearyApplication.ACTION_COPY,    on_copy                                       },
         {ACTION_CUT,                      on_cut                                        },
-        {ACTION_COPY,                     on_copy                                       },
         {ACTION_COPY_LINK,                on_copy_link                                  },
         {ACTION_PASTE,                    on_paste                                      },
         {ACTION_PASTE_WITHOUT_FORMATTING, on_paste_without_formatting                   },
@@ -119,9 +115,9 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     };
 
     private const ActionEntry[] composer_action_entries = {
+        {GearyApplication.ACTION_CLOSE,   on_close                                                         },
         {ACTION_ADD_ATTACHMENT,           on_add_attachment                                                  
  },
         {ACTION_ADD_ORIGINAL_ATTACHMENTS, on_pending_attachments                                             
  },
-        {ACTION_CLOSE,                    on_close                                                           
  },
         {ACTION_CLOSE_AND_DISCARD,        on_close_and_discard                                               
  },
         {ACTION_CLOSE_AND_SAVE,           on_close_and_save                                                  
  },
         {ACTION_COMPOSE_AS_HTML,          on_toggle_action,        null,   "true",  
on_compose_as_html_toggled },
@@ -134,10 +130,8 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     public static Gee.MultiMap<string, string> action_accelerators = new Gee.HashMultiMap<string, string>();
 
     public static void add_window_accelerators(GearyApplication application) {
-        application.add_window_accelerators(ACTION_UNDO, { "<Ctrl>z" } );
-        application.add_window_accelerators(ACTION_REDO, { "<Ctrl><Shift>z" } );
+        application.add_window_accelerators(GearyApplication.ACTION_CLOSE, { "Escape" } );
         application.add_window_accelerators(ACTION_CUT, { "<Ctrl>x" } );
-        application.add_window_accelerators(ACTION_COPY, { "<Ctrl>c" } );
         application.add_window_accelerators(ACTION_PASTE, { "<Ctrl>v" } );
         application.add_window_accelerators(ACTION_PASTE_WITHOUT_FORMATTING, { "<Ctrl><Shift>v" } );
         application.add_window_accelerators(ACTION_INSERT_IMAGE, { "<Ctrl>g" } );
@@ -149,7 +143,6 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
         application.add_window_accelerators(ACTION_ITALIC, { "<Ctrl>i" } );
         application.add_window_accelerators(ACTION_UNDERLINE, { "<Ctrl>u" } );
         application.add_window_accelerators(ACTION_STRIKETHROUGH, { "<Ctrl>k" } );
-        application.add_window_accelerators(ACTION_CLOSE, { "Escape" } );
         application.add_window_accelerators(ACTION_ADD_ATTACHMENT, { "<Ctrl>t" } );
         application.add_window_accelerators(ACTION_DETACH, { "<Ctrl>d" } );
     }
@@ -841,8 +834,8 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
         );
 
         get_action(ACTION_CLOSE_AND_SAVE).set_enabled(false);
-        get_action(ACTION_UNDO).set_enabled(false);
-        get_action(ACTION_REDO).set_enabled(false);
+        get_action(GearyApplication.ACTION_UNDO).set_enabled(false);
+        get_action(GearyApplication.ACTION_REDO).set_enabled(false);
 
         update_cursor_actions();
     }
@@ -850,7 +843,7 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     private void update_cursor_actions() {
         bool has_selection = this.editor.has_selection;
         get_action(ACTION_CUT).set_enabled(has_selection);
-        get_action(ACTION_COPY).set_enabled(has_selection);
+        get_action(GearyApplication.ACTION_COPY).set_enabled(has_selection);
 
         get_action(ACTION_INSERT_LINK).set_enabled(
             this.editor.is_rich_text && (has_selection || this.cursor_url != null)
@@ -2223,8 +2216,8 @@ public class ComposerWidget : Gtk.EventBox, Geary.BaseInterface {
     }
 
     private void on_command_state_changed(bool can_undo, bool can_redo) {
-        get_action(ACTION_UNDO).set_enabled(can_undo);
-        get_action(ACTION_REDO).set_enabled(can_redo);
+        get_action(GearyApplication.ACTION_UNDO).set_enabled(can_undo);
+        get_action(GearyApplication.ACTION_REDO).set_enabled(can_redo);
     }
 
     private void on_draft_id_changed() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]