From b868ebde1cd1dbd2295cfb1a8aeadac2765d1daf Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Sun, 9 Dec 2018 00:07:15 -0500 Subject: [PATCH] highlight mode window: Make activatable via shortcut (ctrl-shift-H), focus the search entry by default, and allow Escape to cancel the dialog from the search entry. Fixes linuxmint/mint-19.1-beta#18 Fixes linuxmint/mint-19.1-beta#19 Fixes linuxmint/mint-19.1-beta#20 --- xed/xed-highlight-mode-dialog.c | 10 ++++++++++ xed/xed-highlight-mode-selector.c | 22 ++++++++++++++++++++++ xed/xed-ui.h | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/xed/xed-highlight-mode-dialog.c b/xed/xed-highlight-mode-dialog.c index 38644df..245c863 100644 --- a/xed/xed-highlight-mode-dialog.c +++ b/xed/xed-highlight-mode-dialog.c @@ -60,6 +60,13 @@ on_language_selected (XedHighlightModeSelector *sel, gtk_widget_destroy (GTK_WIDGET (dlg)); } +static void +on_dialog_cancelled (XedHighlightModeSelector *sel, + XedHighlightModeDialog *dlg) +{ + gtk_widget_destroy (GTK_WIDGET (dlg)); +} + static void xed_highlight_mode_dialog_class_init (XedHighlightModeDialogClass *klass) { @@ -82,6 +89,9 @@ xed_highlight_mode_dialog_init (XedHighlightModeDialog *dlg) dlg->on_language_selected_id = g_signal_connect (dlg->selector, "language-selected", G_CALLBACK (on_language_selected), dlg); + + g_signal_connect (dlg->selector, "cancelled", + G_CALLBACK (on_dialog_cancelled), dlg); } GtkWidget * diff --git a/xed/xed-highlight-mode-selector.c b/xed/xed-highlight-mode-selector.c index 8639bef..f0ccd1b 100644 --- a/xed/xed-highlight-mode-selector.c +++ b/xed/xed-highlight-mode-selector.c @@ -46,6 +46,7 @@ struct _XedHighlightModeSelector enum { LANGUAGE_SELECTED, + CANCELLED, LAST_SIGNAL }; @@ -74,6 +75,13 @@ xed_highlight_mode_selector_class_init (XedHighlightModeSelectorClass *klass) 1, GTK_SOURCE_TYPE_LANGUAGE); + signals[CANCELLED] = + g_signal_new_class_handler ("cancelled", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + NULL, NULL, NULL, NULL, + G_TYPE_NONE, 0); + /* Bind class to template */ gtk_widget_class_set_template_from_resource (widget_class, "/org/x/editor/ui/xed-highlight-mode-selector.ui"); @@ -223,10 +231,22 @@ on_entry_key_press_event (GtkWidget *entry, { return move_selection (selector, -5); } + else if (event->keyval == GDK_KEY_Escape) + { + g_signal_emit (G_OBJECT (selector), signals[CANCELLED], 0); + return FALSE; + } return FALSE; } +static void +on_entry_realized (GtkWidget *entry, + XedHighlightModeSelector *selector) +{ + gtk_widget_grab_focus (entry); +} + static void on_row_activated (GtkTreeView *tree_view, GtkTreePath *path, @@ -259,6 +279,8 @@ xed_highlight_mode_selector_init (XedHighlightModeSelector *selector) G_CALLBACK (on_entry_changed), selector); g_signal_connect (selector->entry, "key-press-event", G_CALLBACK (on_entry_key_press_event), selector); + g_signal_connect (selector->entry, "realize", + G_CALLBACK (on_entry_realized), selector); g_signal_connect (selector->treeview, "row-activated", G_CALLBACK (on_row_activated), selector); diff --git a/xed/xed-ui.h b/xed/xed-ui.h index 59b733a..20ec7e8 100644 --- a/xed/xed-ui.h +++ b/xed/xed-ui.h @@ -104,7 +104,7 @@ static const GtkActionEntry xed_menu_entries[] = N_("Select the entire document"), G_CALLBACK (_xed_cmd_edit_select_all) }, /* View menu */ - { "ViewHighlightMode", NULL, N_("_Highlight Mode"), NULL, + { "ViewHighlightMode", NULL, N_("_Highlight Mode"), "H", N_("Change syntax hightlight mode"), G_CALLBACK (_xed_cmd_view_change_highlight_mode) },