From bc381189c7e4283b72b0b5928254d835a4353867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20G=C4=85sior?= Date: Sat, 21 Jul 2018 22:34:26 +0200 Subject: [PATCH] Use highlight dialog instead submenu in "View" menu. --- xed/resources/ui/xed-ui.xml | 5 +---- xed/xed-commands-view.c | 40 +++++++++++++++++++++++++++++++++++++ xed/xed-commands.h | 1 + xed/xed-settings.c | 18 +---------------- xed/xed-ui.h | 4 +++- xed/xed-window.c | 12 ----------- 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/xed/resources/ui/xed-ui.xml b/xed/resources/ui/xed-ui.xml index 91a01ba..1e2c875 100644 --- a/xed/resources/ui/xed-ui.xml +++ b/xed/resources/ui/xed-ui.xml @@ -60,10 +60,7 @@ - - - - + diff --git a/xed/xed-commands-view.c b/xed/xed-commands-view.c index f692e55..68ac5a5 100644 --- a/xed/xed-commands-view.c +++ b/xed/xed-commands-view.c @@ -42,6 +42,8 @@ #include "xed-window-private.h" #include "xed-paned.h" #include "xed-view-frame.h" +#include "xed-highlight-mode-dialog.h" +#include "xed-highlight-mode-selector.h" void _xed_cmd_view_show_toolbar (GtkAction *action, @@ -213,3 +215,41 @@ _xed_cmd_view_leave_fullscreen_mode (GtkAction *action, _xed_window_unfullscreen (window); g_signal_handlers_unblock_by_func (view_action, G_CALLBACK (_xed_cmd_view_toggle_fullscreen_mode), window); } + +static void +on_language_selected (XedHighlightModeSelector *sel, + GtkSourceLanguage *language, + XedWindow *window) +{ + XedDocument *doc; + + doc = xed_window_get_active_document (window); + if (doc) + { + xed_document_set_language (doc, language); + } +} + +void +_xed_cmd_view_change_highlight_mode (GtkAction *action, + XedWindow *window) +{ + GtkWidget *dlg; + XedHighlightModeSelector *sel; + XedDocument *doc; + + dlg = xed_highlight_mode_dialog_new (GTK_WINDOW (window)); + sel = xed_highlight_mode_dialog_get_selector (XED_HIGHLIGHT_MODE_DIALOG (dlg)); + + doc = xed_window_get_active_document (XED_WINDOW (window)); + if (doc) + { + xed_highlight_mode_selector_select_language (sel, + xed_document_get_language (doc)); + } + + g_signal_connect (sel, "language-selected", + G_CALLBACK (on_language_selected), window); + + gtk_widget_show (GTK_WIDGET (dlg)); +} diff --git a/xed/xed-commands.h b/xed/xed-commands.h index 005e64a..eb6c451 100644 --- a/xed/xed-commands.h +++ b/xed/xed-commands.h @@ -51,6 +51,7 @@ void _xed_cmd_view_toggle_overview_map (GtkAction *action, XedWindow *window); void _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action, XedWindow *window); void _xed_cmd_view_toggle_word_wrap (GtkAction *action, XedWindow *window); void _xed_cmd_view_leave_fullscreen_mode (GtkAction *action, XedWindow *window); +void _xed_cmd_view_change_highlight_mode (GtkAction *action, XedWindow *window); void _xed_cmd_search_find (GtkAction *action, XedWindow *window); diff --git a/xed/xed-settings.c b/xed/xed-settings.c index 6f9d5ff..ce9774f 100644 --- a/xed/xed-settings.c +++ b/xed/xed-settings.c @@ -287,7 +287,7 @@ on_syntax_highlighting_changed (GSettings *settings, const gchar *key, XedSettings *xs) { - GList *docs, *windows, *l; + GList *docs, *l; gboolean enable; enable = g_settings_get_boolean (settings, key); @@ -300,22 +300,6 @@ on_syntax_highlighting_changed (GSettings *settings, } g_list_free (docs); - - /* update the sensitivity of the Higlight Mode menu item */ - windows = xed_app_get_main_windows (XED_APP (g_application_get_default ())); - for (l = windows; l != NULL; l = g_list_next (l)) - { - GtkUIManager *ui; - GtkAction *a; - - ui = xed_window_get_ui_manager (XED_WINDOW (l->data)); - - a = gtk_ui_manager_get_action (ui, "/MenuBar/ViewMenu/ViewHighlightModeMenu"); - - gtk_action_set_sensitive (a, enable); - } - - g_list_free (windows); } static void diff --git a/xed/xed-ui.h b/xed/xed-ui.h index 5f32f9f..e98b06d 100644 --- a/xed/xed-ui.h +++ b/xed/xed-ui.h @@ -107,7 +107,9 @@ 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") }, + { "ViewHighlightMode", NULL, N_("_Highlight Mode"), NULL, + N_("Change syntax hightlight mode"), + G_CALLBACK (_xed_cmd_view_change_highlight_mode), TRUE }, /* Search menu */ { "SearchFind", "edit-find-symbolic", N_("_Find"), "F", diff --git a/xed/xed-window.c b/xed/xed-window.c index af2bb91..6989f97 100644 --- a/xed/xed-window.c +++ b/xed/xed-window.c @@ -1282,14 +1282,6 @@ create_menu_bar_and_toolbar (XedWindow *window, window); update_recent_files_menu (window); - /* languages menu */ - action_group = gtk_action_group_new ("LanguagesActions"); - gtk_action_group_set_translation_domain (action_group, NULL); - window->priv->languages_action_group = action_group; - gtk_ui_manager_insert_action_group (manager, action_group, 0); - g_object_unref (action_group); - create_languages_menu (window); - /* list of open documents menu */ action_group = gtk_action_group_new ("DocumentsListActions"); gtk_action_group_set_translation_domain (action_group, NULL); @@ -2254,9 +2246,6 @@ notebook_switch_page (GtkNotebook *book, g_free (action_name); - /* update the syntax menu */ - update_languages_menu (window); - view = xed_tab_get_view (tab); map_frame = xed_view_frame_get_map_frame (XED_VIEW_FRAME (_xed_tab_get_view_frame (tab))); @@ -2846,7 +2835,6 @@ sync_languages_menu (XedDocument *doc, GParamSpec *pspec, XedWindow *window) { - update_languages_menu (window); peas_extension_set_call (window->priv->extensions, "update_state"); }