diff options
| author | Patrick Storz <eduard.braun2@gmx.de> | 2019-07-21 01:07:14 +0000 |
|---|---|---|
| committer | Patrick Storz <eduard.braun2@gmx.de> | 2019-07-21 01:07:14 +0000 |
| commit | 9dfa379a29ad986254ffd966ed6e886ffb176543 (patch) | |
| tree | 14ea92afaa4a251a966e0381b2c561aeb2435227 /src | |
| parent | Simplify code for context menu items of Layers and Objects dialogs (diff) | |
| download | inkscape-9dfa379a29ad986254ffd966ed6e886ffb176543.tar.gz inkscape-9dfa379a29ad986254ffd966ed6e886ffb176543.zip | |
Make menu icon preference apply to Layers and Objects dialogs
Also fix "show-icons" attribute inheritance in menus.xml and make
it apply to canvas icons.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/contextmenu.cpp | 17 | ||||
| -rw-r--r-- | src/ui/desktop/menubar.cpp | 69 | ||||
| -rw-r--r-- | src/ui/dialog/layers.cpp | 4 | ||||
| -rw-r--r-- | src/ui/dialog/layers.h | 1 | ||||
| -rw-r--r-- | src/ui/dialog/objects.cpp | 5 | ||||
| -rw-r--r-- | src/ui/dialog/objects.h | 3 |
6 files changed, 61 insertions, 38 deletions
diff --git a/src/ui/contextmenu.cpp b/src/ui/contextmenu.cpp index 1424ba4ab..4286bc70e 100644 --- a/src/ui/contextmenu.cpp +++ b/src/ui/contextmenu.cpp @@ -68,18 +68,17 @@ ContextMenu::ContextMenu(SPDesktop *desktop, SPItem *item) : _desktop = desktop; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int show_icons_pref = prefs->getInt("/theme/menuIcons", 0); - bool show_icon = show_icons_pref >= 0 ? true : false; + bool show_icons = prefs->getInt("/theme/menuIcons_canvas", true); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_UNDO), show_icon); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_REDO), show_icon); + AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_UNDO), show_icons); + AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_REDO), show_icons); AddSeparator(); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_CUT), show_icon); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_COPY), show_icon); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_PASTE), show_icon); + AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_CUT), show_icons); + AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_COPY), show_icons); + AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_PASTE), show_icons); AddSeparator(); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DUPLICATE), show_icon); - AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DELETE), show_icon); + AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DUPLICATE), show_icons); + AppendItemFromVerb(Inkscape::Verb::get(SP_VERB_EDIT_DELETE), show_icons); positionOfLastDialog = 10; // 9 in front + 1 for the separator in the next if; used to position the dialog menu entries below each other /* Item menu */ diff --git a/src/ui/desktop/menubar.cpp b/src/ui/desktop/menubar.cpp index 04e97a933..d69783563 100644 --- a/src/ui/desktop/menubar.cpp +++ b/src/ui/desktop/menubar.cpp @@ -331,7 +331,7 @@ sp_recent_open(Gtk::RecentChooser* recentchooser) // =================== Main Menu ================ // Recursively build menu and submenus. void -build_menu(Gtk::MenuShell* menu, Inkscape::XML::Node* xml, Inkscape::UI::View::View* view) +build_menu(Gtk::MenuShell* menu, Inkscape::XML::Node* xml, Inkscape::UI::View::View* view, bool show_icons = true) { if (menu == nullptr) { std::cerr << "build_menu: menu is nullptr" << std::endl; @@ -343,41 +343,41 @@ build_menu(Gtk::MenuShell* menu, Inkscape::XML::Node* xml, Inkscape::UI::View::V return; } - // Do we want icons???? + // user preference for icons in menus (1: show all, -1: hide all; 0: theme chooses per icon) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int show_icon_pref = prefs->getInt("/theme/menuIcons", 0); - static bool show_icon = false; - if (show_icon_pref == 1) { - show_icon = true; - } else if ( show_icon_pref == -1) { - show_icon = false; - } + int show_icons_pref = prefs->getInt("/theme/menuIcons", 0); Gtk::RadioMenuItem::Group group; for (auto menu_ptr = xml; menu_ptr != nullptr; menu_ptr = menu_ptr->next()) { - if (show_icon_pref == 0) { - // We set according to file, value is inherited into sub-menus. - const char *str = menu_ptr->attribute("show-icons"); - if (str) { - Glib::ustring ustr = str; - if (ustr == "true") { - show_icon = true; - } else if (ustr == "false") { - show_icon = false; - } else { - std::cerr << "build_menu: invalid value for 'show-icon' (use 'true' or 'false')." - << ustr << std::endl; + if (menu_ptr->name()) { + + // show menu icons for current item? + bool show_icons_curr = show_icons; + if (show_icons_pref == 1) { // show all icons per global pref + show_icons_curr = true; + } else if (show_icons_pref == -1) { // hide all icons per global pref + show_icons_curr = false; + } else { // set according to 'show-icons' attribute in theme's XML file; value is fully inherited + const char *str = menu_ptr->attribute("show-icons"); + if (str) { + Glib::ustring ustr = str; + if (ustr == "true") { + show_icons_curr = true; + } else if (ustr == "false") { + show_icons_curr = false; + } else { + std::cerr << "build_menu: invalid value for 'show-icons' (use 'true' or 'false')." + << ustr << std::endl; + } } } - } - if (menu_ptr->name()) { Glib::ustring name = menu_ptr->name(); if (name == "inkscape") { - build_menu(menu, menu_ptr->firstChild(), view); + build_menu(menu, menu_ptr->firstChild(), view, show_icons_curr); continue; } @@ -389,7 +389,7 @@ build_menu(Gtk::MenuShell* menu, Inkscape::XML::Node* xml, Inkscape::UI::View::V menuitem = Gtk::manage(new Gtk::MenuItem( menu_ptr->attribute("name"), true)); } Gtk::Menu* submenu = Gtk::manage(new Gtk::Menu()); - build_menu(submenu, menu_ptr->firstChild(), view); + build_menu(submenu, menu_ptr->firstChild(), view, show_icons_curr); menuitem->set_submenu(*submenu); menu->append(*menuitem); @@ -398,6 +398,21 @@ build_menu(Gtk::MenuShell* menu, Inkscape::XML::Node* xml, Inkscape::UI::View::V continue; } + + if (name == "contextmenu") { + if (menu_ptr->attribute("id")) { + Glib::ustring id = menu_ptr->attribute("id"); + if (id == "canvas" || id == "layers" || id == "objects") { + Glib::ustring prefname = Glib::ustring::compose("/theme/menuIcons_%1", id); + prefs->setBool(prefname, show_icons_curr); + } else { + std::cerr << "build_menu: invalid contextmenu id: " << id << std::endl; + } + } else { + std::cerr << "build_menu: contextmenu element needs a valid id" << std::endl; + } + continue; + } if (name == "verb") { if (menu_ptr->attribute("verb-id") != nullptr) { @@ -417,7 +432,7 @@ build_menu(Gtk::MenuShell* menu, Inkscape::XML::Node* xml, Inkscape::UI::View::V } else if (menu_ptr->attribute("radio") != nullptr) { - Gtk::MenuItem* menuitem = build_menu_item_from_verb(action, show_icon, true, &group); + Gtk::MenuItem* menuitem = build_menu_item_from_verb(action, show_icons_curr, true, &group); if (menuitem) { if (menu_ptr->attribute("default") != nullptr) { auto radiomenuitem = dynamic_cast<Gtk::RadioMenuItem*>(menuitem); @@ -430,7 +445,7 @@ build_menu(Gtk::MenuShell* menu, Inkscape::XML::Node* xml, Inkscape::UI::View::V } else { - Gtk::MenuItem* menuitem = build_menu_item_from_verb(action, show_icon); + Gtk::MenuItem* menuitem = build_menu_item_from_verb(action, show_icons_curr); if (menuitem) { menu->append(*menuitem); } diff --git a/src/ui/dialog/layers.cpp b/src/ui/dialog/layers.cpp index 9f57bbe60..e2aa4e2c9 100644 --- a/src/ui/dialog/layers.cpp +++ b/src/ui/dialog/layers.cpp @@ -129,7 +129,7 @@ Gtk::MenuItem& LayersPanel::_addPopupItem( SPDesktop *desktop, unsigned int code Gtk::Label *label = Gtk::manage(new Gtk::Label(action->name, true)); label->set_xalign(0.0); - if (action->image) { + if (_show_contextmenu_icons && action->image) { item->set_name("ImageMenuItem"); // custom name to identify our "ImageMenuItems" Gtk::Image *icon = Gtk::manage(sp_get_icon_image(action->image, Gtk::ICON_SIZE_MENU)); @@ -870,6 +870,8 @@ LayersPanel::LayersPanel() : // ------------------------------------------------------- { + _show_contextmenu_icons = prefs->getBool("/theme/menuIcons_layers", true); + _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, (int)BUTTON_NEW ) ); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, (int)BUTTON_RENAME ) ); diff --git a/src/ui/dialog/layers.h b/src/ui/dialog/layers.h index e0b983faf..8a66eef15 100644 --- a/src/ui/dialog/layers.h +++ b/src/ui/dialog/layers.h @@ -107,6 +107,7 @@ private: SPItem* _dnd_source; SPItem* _dnd_target; GdkEvent* _toggleEvent; + bool _show_contextmenu_icons; Glib::RefPtr<Gtk::TreeStore> _store; std::vector<Gtk::Widget*> _watching; diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index 38fd2eba2..f0f99c219 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -257,7 +257,7 @@ Gtk::MenuItem& ObjectsPanel::_addPopupItem( SPDesktop *desktop, unsigned int cod Gtk::Label *label = Gtk::manage(new Gtk::Label(action->name, true)); label->set_xalign(0.0); - if (action->image) { + if (_show_contextmenu_icons && action->image) { item->set_name("ImageMenuItem"); // custom name to identify our "ImageMenuItems" Gtk::Image *icon = Gtk::manage(sp_get_icon_image(action->image, Gtk::ICON_SIZE_MENU)); @@ -1853,6 +1853,9 @@ ObjectsPanel::ObjectsPanel() : //Set up the pop-up menu // ------------------------------------------------------- { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + _show_contextmenu_icons = prefs->getBool("/theme/menuIcons_objects", true); + _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, (int)BUTTON_RENAME ) ); _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, (int)BUTTON_NEW ) ); diff --git a/src/ui/dialog/objects.h b/src/ui/dialog/objects.h index 04c0a02b3..9a8085098 100644 --- a/src/ui/dialog/objects.h +++ b/src/ui/dialog/objects.h @@ -121,6 +121,9 @@ private: //List of items to change the highlight on std::vector<SPItem*> _highlight_target; + //Show icons in the context menu + bool _show_contextmenu_icons; + //GUI Members: GdkEvent* _toggleEvent; |
