diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala index d8d88015..23fb8edc 100644 --- a/src/client/composer/composer-window.vala +++ b/src/client/composer/composer-window.vala @@ -38,6 +38,7 @@ public class ComposerWindow : Gtk.Window { private const string ACTION_COLOR = "color"; private const string ACTION_INSERT_LINK = "insertlink"; private const string ACTION_COMPOSE_AS_HTML = "compose as html"; + private const string ACTION_CLOSE = "close"; private const string URI_LIST_MIME_TYPE = "text/uri-list"; private const string FILE_URI_PREFIX = "file://"; @@ -275,11 +276,15 @@ public class ComposerWindow : Gtk.Window { actions.get_action(ACTION_COLOR).activate.connect(on_select_color); actions.get_action(ACTION_INSERT_LINK).activate.connect(on_insert_link); + actions.get_action(ACTION_CLOSE).activate.connect(on_close); + ui = new Gtk.UIManager(); ui.insert_action_group(actions, 0); add_accel_group(ui.get_accel_group()); GearyApplication.instance.load_ui_file_for_manager(ui, "composer_accelerators.ui"); + add_extra_accelerators(); + from = account.information.get_from().to_rfc822_string(); update_from_field(); from_multiple.changed.connect(on_from_changed); @@ -489,6 +494,12 @@ public class ComposerWindow : Gtk.Window { update_actions(); } + // Glade only allows one accelerator per-action. This method adds extra accelerators not defined + // in the Glade file. + private void add_extra_accelerators() { + GtkUtil.add_accelerator(ui, actions, "Escape", ACTION_CLOSE); + } + private void setup_drag_destination(Gtk.Widget destination) { const Gtk.TargetEntry[] target_entries = { { URI_LIST_MIME_TYPE, 0, 0 } }; Gtk.drag_dest_set(destination, Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT, @@ -630,6 +641,12 @@ public class ComposerWindow : Gtk.Window { destroy(); } + private void on_close() { + // Accelerator w was pressed to close the composer window. Do the same as + // when clicking the Discard button, at least for now. + on_discard(); + } + private bool should_send() { bool has_subject = !Geary.String.is_empty(subject.strip()); bool has_body_or_attachment = !Geary.String.is_empty(get_html()) || attachment_files.size > 0; @@ -1176,13 +1193,6 @@ public class ComposerWindow : Gtk.Window { return true; } break; - - case "Escape": - if (should_close()) { - destroy(); - return true; - } - break; } return base.key_press_event(event); diff --git a/src/client/geary-controller.vala b/src/client/geary-controller.vala index 5e373a22..7c77ae18 100644 --- a/src/client/geary-controller.vala +++ b/src/client/geary-controller.vala @@ -151,21 +151,8 @@ public class GearyController { } private void add_accelerator(string accelerator, string action) { - // Parse the accelerator. - uint key = 0; - Gdk.ModifierType modifiers = 0; - Gtk.accelerator_parse(accelerator, out key, out modifiers); - if (key == 0) { - debug("Failed to parse accelerator '%s'", accelerator); - return; - } - - // Connect the accelerator to the action. - GearyApplication.instance.ui_manager.get_accel_group().connect(key, modifiers, - Gtk.AccelFlags.VISIBLE, (group, obj, key, modifiers) => { - GearyApplication.instance.actions.get_action(action).activate(); - return false; - }); + GtkUtil.add_accelerator(GearyApplication.instance.ui_manager, GearyApplication.instance.actions, + accelerator, action); } private Gtk.ActionEntry[] create_actions() { diff --git a/src/client/util/util-gtk.vala b/src/client/util/util-gtk.vala index ab6c469d..f1beb991 100644 --- a/src/client/util/util-gtk.vala +++ b/src/client/util/util-gtk.vala @@ -192,5 +192,24 @@ public void add_proxy_menu(Gtk.ToolItem tool_item, string label, Gtk.Menu proxy_ }); } +public void add_accelerator(Gtk.UIManager ui_manager, Gtk.ActionGroup action_group, + string accelerator, string action) { + // Parse the accelerator. + uint key = 0; + Gdk.ModifierType modifiers = 0; + Gtk.accelerator_parse(accelerator, out key, out modifiers); + if (key == 0) { + debug("Failed to parse accelerator '%s'", accelerator); + return; + } + + // Connect the accelerator to the action. + ui_manager.get_accel_group().connect(key, modifiers, Gtk.AccelFlags.VISIBLE, + (group, obj, key, modifiers) => { + action_group.get_action(action).activate(); + return false; + }); +} + } diff --git a/ui/composer.glade b/ui/composer.glade index 1d17666f..728d7e30 100644 --- a/ui/composer.glade +++ b/ui/composer.glade @@ -149,6 +149,10 @@ Rich Text + + + + True diff --git a/ui/composer_accelerators.ui b/ui/composer_accelerators.ui index ea6b90bb..3503c5f9 100644 --- a/ui/composer_accelerators.ui +++ b/ui/composer_accelerators.ui @@ -27,4 +27,6 @@ + +