From 3cf5f982d9a66a05e7fafbcd3fd4ff6f4f3c9740 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 3 Nov 2018 20:07:45 +0100 Subject: Add a preference to force enable/disable menu icons By default the theme decides whether it wants to display icons or not by using the "show-icons" attribute in the menus.xml file. This attribute is properly inherited an can therefore be used to selectively enable and disable icons globally (by setting it on the root element), in certain submenus, or individually per menu item. --- src/ui/dialog/inkscape-preferences.cpp | 7 +++++ src/ui/dialog/inkscape-preferences.h | 1 + src/ui/interface.cpp | 56 ++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 419567474..9b0190d13 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -889,6 +889,13 @@ void InkscapePreferences::initPageUI() _page_theme.add_line(false, _("Secondary toolbar icon size:"), _misc_small_secondary, "", _("Set the size for the icons in secondary toolbars to use (requires restart)"), false); } + { + Glib::ustring menu_icons_labels[] = {_("Yes"), _("No"), _("Theme decides")}; + int menu_icons_values[] = {1, -1, 0}; + _menu_icons.init("/theme/menuIcons", menu_icons_labels, menu_icons_values, G_N_ELEMENTS(menu_icons_labels), 0); + _page_theme.add_line(false, _("Show icons in menus:"), _menu_icons, "", + _("You can either enable or disable all icons in menus. By default the theme determines which icons to display by using the 'show-icons' attribute in its 'menus.xml' file."), false); + } _apply_theme.set_label(_("Reload icons")); _apply_theme.set_tooltip_text(_("Apply icon changes (may take a few seconds)")); _page_theme.add_line(false, "", _apply_theme, "Reloading icons will close all windows and open them again. No data will be lost.", "", false); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index dd67cd2bf..fbdb8748e 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -247,6 +247,7 @@ protected: UI::Widget::PrefCombo _misc_small_toolbar; UI::Widget::PrefCombo _misc_small_secondary; UI::Widget::PrefCombo _misc_small_tools; + UI::Widget::PrefCombo _menu_icons; Gtk::Button _apply_theme; UI::Widget::PrefRadioButton _win_dockable; diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index fc8b4032e..c5fc7ea5b 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -897,19 +897,45 @@ private: * the verb that is missing, and display that. The menu item is also made * insensitive. * - * @param menus This is the XML that defines the menu - * @param menu Menu to be added to - * @param view The View that this menu is being built for + * @param menus This is the XML that defines the menu + * @param menu Menu to be added to + * @param view The View that this menu is being built for + * @param show_icons Whether to show icons (can be overridden by the current XML::Node and preferences) */ -static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, Inkscape::UI::View::View *view) +static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, Inkscape::UI::View::View *view, + bool show_icons = true) { if (menus == nullptr) return; if (menu == nullptr) return; Gtk::RadioMenuItem::Group group; - for (Inkscape::XML::Node *menu_pntr = menus; - menu_pntr != nullptr; - menu_pntr = menu_pntr->next()) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int show_icons_pref = prefs->getInt("/theme/menuIcons", 0); + + for (Inkscape::XML::Node *menu_pntr = menus; menu_pntr != nullptr; menu_pntr = menu_pntr->next()) { + + // Check if the "show-icons" attribute is set, and set the flag here accordingly + bool show_icons_curr = show_icons; + if (show_icons_pref == 1) { // enable all icons + show_icons_curr = true; + } else if (show_icons_pref == -1) { // disable all icons + show_icons_curr = false; + } else { // read from XML file or inherit (=keep) previous value if unset + const char *str = menu_pntr->attribute("show-icons"); + if (str) { + if (!g_ascii_strcasecmp(str, "yes") || !g_ascii_strcasecmp(str, "true") || !g_ascii_strcasecmp(str, "1")) { + show_icons_curr = true; + } else if (!g_ascii_strcasecmp(str, "no") || !g_ascii_strcasecmp(str, "false") || !g_ascii_strcasecmp(str, "0")) { + show_icons_curr = false; + } else { + g_warning("Invalid value for attribute 'show-icons': '%s'", str); + } + } + } + + if (!strcmp(menu_pntr->name(), "inkscape")) { + sp_ui_build_dyn_menus(menu_pntr->firstChild(), menu, view, show_icons_curr); + } if (!strcmp(menu_pntr->name(), "submenu")) { GtkWidget *mitem; if (menu_pntr->attribute("_name") != nullptr) { @@ -918,7 +944,7 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I mitem = gtk_menu_item_new_with_mnemonic(menu_pntr->attribute("name")); } GtkWidget *submenu = gtk_menu_new(); - sp_ui_build_dyn_menus(menu_pntr->firstChild(), submenu, view); + sp_ui_build_dyn_menus(menu_pntr->firstChild(), submenu, view, show_icons_curr); gtk_menu_item_set_submenu(GTK_MENU_ITEM(mitem), GTK_WIDGET(submenu)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mitem); g_signal_connect(submenu, "map", G_CALLBACK(shift_icons), NULL); @@ -926,19 +952,11 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I } if (!strcmp(menu_pntr->name(), "verb")) { gchar const *verb_name = menu_pntr->attribute("verb-id"); - - // Check if the "show-icon" attribute is set, and set the flag here accordingly - bool show_icon = false; - - if(menu_pntr->attribute("show-icon") != nullptr) { - show_icon = true; - } - Inkscape::Verb *verb = Inkscape::Verb::getbyid(verb_name); if (verb != nullptr) { if (menu_pntr->attribute("radio") != nullptr) { - GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, show_icon, true, &group); + GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, false, true, &group); if (menu_pntr->attribute("default") != nullptr) { gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE); } @@ -953,7 +971,7 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I checkitem_toggled, checkitem_update, verb); } } else { - sp_ui_menu_append_item_from_verb(GTK_MENU(menu), verb, view, show_icon); + sp_ui_menu_append_item_from_verb(GTK_MENU(menu), verb, view, show_icons_curr); Gtk::RadioMenuItem::Group group2; group = group2; } @@ -1017,7 +1035,7 @@ static void sp_ui_build_dyn_menus(Inkscape::XML::Node *menus, GtkWidget *menu, I GtkWidget *sp_ui_main_menubar(Inkscape::UI::View::View *view) { GtkWidget *mbar = gtk_menu_bar_new(); - sp_ui_build_dyn_menus(INKSCAPE.get_menus(), mbar, view); + sp_ui_build_dyn_menus(INKSCAPE.get_menus()->parent(), mbar, view); return mbar; } -- cgit v1.2.3