Closes #6755 Ctrl-W to close composer window.
This commit is contained in:
parent
0a03877964
commit
0ddcfb3512
5 changed files with 44 additions and 22 deletions
|
|
@ -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 <Primary>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);
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,10 @@
|
|||
<property name="label" translatable="yes">Rich Text</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="close"/>
|
||||
<accelerator key="w" modifiers="GDK_CONTROL_MASK"/>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="composer">
|
||||
<property name="visible">True</property>
|
||||
|
|
|
|||
|
|
@ -27,4 +27,6 @@
|
|||
<accelerator action="font" />
|
||||
<accelerator action="color" />
|
||||
<accelerator action="insertlink" />
|
||||
|
||||
<accelerator action="close" />
|
||||
</ui>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue