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
This commit is contained in:
Michael Webster 2018-12-09 00:07:15 -05:00
parent dc1104c93b
commit b868ebde1c
3 changed files with 33 additions and 1 deletions

View File

@ -60,6 +60,13 @@ on_language_selected (XedHighlightModeSelector *sel,
gtk_widget_destroy (GTK_WIDGET (dlg)); gtk_widget_destroy (GTK_WIDGET (dlg));
} }
static void
on_dialog_cancelled (XedHighlightModeSelector *sel,
XedHighlightModeDialog *dlg)
{
gtk_widget_destroy (GTK_WIDGET (dlg));
}
static void static void
xed_highlight_mode_dialog_class_init (XedHighlightModeDialogClass *klass) 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", dlg->on_language_selected_id = g_signal_connect (dlg->selector, "language-selected",
G_CALLBACK (on_language_selected), dlg); G_CALLBACK (on_language_selected), dlg);
g_signal_connect (dlg->selector, "cancelled",
G_CALLBACK (on_dialog_cancelled), dlg);
} }
GtkWidget * GtkWidget *

View File

@ -46,6 +46,7 @@ struct _XedHighlightModeSelector
enum enum
{ {
LANGUAGE_SELECTED, LANGUAGE_SELECTED,
CANCELLED,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -74,6 +75,13 @@ xed_highlight_mode_selector_class_init (XedHighlightModeSelectorClass *klass)
1, 1,
GTK_SOURCE_TYPE_LANGUAGE); 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 */ /* Bind class to template */
gtk_widget_class_set_template_from_resource (widget_class, gtk_widget_class_set_template_from_resource (widget_class,
"/org/x/editor/ui/xed-highlight-mode-selector.ui"); "/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); 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; return FALSE;
} }
static void
on_entry_realized (GtkWidget *entry,
XedHighlightModeSelector *selector)
{
gtk_widget_grab_focus (entry);
}
static void static void
on_row_activated (GtkTreeView *tree_view, on_row_activated (GtkTreeView *tree_view,
GtkTreePath *path, GtkTreePath *path,
@ -259,6 +279,8 @@ xed_highlight_mode_selector_init (XedHighlightModeSelector *selector)
G_CALLBACK (on_entry_changed), selector); G_CALLBACK (on_entry_changed), selector);
g_signal_connect (selector->entry, "key-press-event", g_signal_connect (selector->entry, "key-press-event",
G_CALLBACK (on_entry_key_press_event), selector); 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_signal_connect (selector->treeview, "row-activated",
G_CALLBACK (on_row_activated), selector); G_CALLBACK (on_row_activated), selector);

View File

@ -104,7 +104,7 @@ static const GtkActionEntry xed_menu_entries[] =
N_("Select the entire document"), G_CALLBACK (_xed_cmd_edit_select_all) }, N_("Select the entire document"), G_CALLBACK (_xed_cmd_edit_select_all) },
/* View menu */ /* View menu */
{ "ViewHighlightMode", NULL, N_("_Highlight Mode"), NULL, { "ViewHighlightMode", NULL, N_("_Highlight Mode"), "<shift><control>H",
N_("Change syntax hightlight mode"), N_("Change syntax hightlight mode"),
G_CALLBACK (_xed_cmd_view_change_highlight_mode) }, G_CALLBACK (_xed_cmd_view_change_highlight_mode) },