summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2018-11-03 19:10:56 +0000
committerPatrick Storz <eduard.braun2@gmx.de>2018-11-05 22:05:46 +0000
commit7edccc152c1f38ba9ee22c866abd0cfe155e41f6 (patch)
tree2db48998f1b424fb4264d3d1b4a6e6f43688d9c9
parentAdd a preference to force enable/disable menu icons (diff)
downloadinkscape-7edccc152c1f38ba9ee22c866abd0cfe155e41f6.tar.gz
inkscape-7edccc152c1f38ba9ee22c866abd0cfe155e41f6.zip
Fix sp_ui_menu_item_set_name to handle arbitrarily packed GtkBoxes
-rw-r--r--src/ui/interface.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp
index c5fc7ea5b..039db182a 100644
--- a/src/ui/interface.cpp
+++ b/src/ui/interface.cpp
@@ -1527,22 +1527,27 @@ sp_ui_menu_item_set_name(GtkWidget *data, Glib::ustring const &name)
{
if (data || GTK_IS_BIN (data)) {
void *child = gtk_bin_get_child (GTK_BIN (data));
- //child is either
- //- a GtkBox, whose first child is a label displaying name if the menu
- //item has an accel key
- //- a GtkLabel if the menu has no accel key
- if (child != nullptr){
+ // child is either
+ // - a GtkLabel (if the menu has no accel key or icon)
+ // - a GtkBox (if item has an accel key or image)
+ // in which case we need to find the GtkLabel in the box
+ // - something else we do not expect (yet)
+ if (child != nullptr) {
if (GTK_IS_LABEL(child)) {
gtk_label_set_markup_with_mnemonic(GTK_LABEL (child), name.c_str());
} else if (GTK_IS_BOX(child)) {
std::vector<Gtk::Widget*> children = Glib::wrap(GTK_CONTAINER(child))->get_children();
-
- // Label is second child in list
- Gtk::Label *label = dynamic_cast<Gtk::Label*>(children[1]);
- if(!label) return;
- label->set_markup_with_mnemonic(name);
- }//else sp_ui_menu_append_item_from_verb has been modified and can set
- //a menu item in yet another way...
+ for (auto child: children) {
+ Gtk::Label *label = dynamic_cast<Gtk::Label*>(child);
+ if (label) {
+ label->set_markup_with_mnemonic(name);
+ break;
+ }
+ }
+ } else {
+ // sp_ui_menu_append_item_from_verb might have learned to set a menu item in yet another way...
+ g_assert_not_reached();
+ }
}
}
}