summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Valavanis <valavanisalex@gmail.com>2017-06-28 19:26:18 +0000
committerAlexander Valavanis <valavanisalex@gmail.com>2017-06-28 19:26:18 +0000
commit18c0d1f13449856f3c0914d07b645fd3e5da002f (patch)
treeb6f87c126e2d74dfe8110574f74a223e33f0b93f /src
parentRevert "menu-items: C++ify" (diff)
downloadinkscape-18c0d1f13449856f3c0914d07b645fd3e5da002f.tar.gz
inkscape-18c0d1f13449856f3c0914d07b645fd3e5da002f.zip
Add a show-icon attribute to menu XML
Diffstat (limited to 'src')
-rw-r--r--src/menus-skeleton.h28
-rw-r--r--src/ui/interface.cpp45
2 files changed, 48 insertions, 25 deletions
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h
index 7d00ffa86..65c497da4 100644
--- a/src/menus-skeleton.h
+++ b/src/menus-skeleton.h
@@ -237,20 +237,20 @@ static char const menus_skeleton[] =
" <verb verb-id=\"SelectionPixelArt\" />\n"
" <separator/>\n"
-" <verb verb-id=\"SelectionUnion\" />\n"
-" <verb verb-id=\"SelectionDiff\" />\n"
-" <verb verb-id=\"SelectionIntersect\" />\n"
-" <verb verb-id=\"SelectionSymDiff\" />\n"
-" <verb verb-id=\"SelectionDivide\" />\n"
-" <verb verb-id=\"SelectionCutPath\" />\n"
-" <separator/>\n"
-" <verb verb-id=\"SelectionCombine\" />\n"
-" <verb verb-id=\"SelectionBreakApart\" />\n"
-" <separator/>\n"
-" <verb verb-id=\"SelectionInset\" />\n"
-" <verb verb-id=\"SelectionOffset\" />\n"
-" <verb verb-id=\"SelectionDynOffset\" />\n"
-" <verb verb-id=\"SelectionLinkedOffset\" />\n"
+" <verb verb-id=\"SelectionUnion\" show-icon=\"yes\" />\n"
+" <verb verb-id=\"SelectionDiff\" show-icon=\"yes\" />\n"
+" <verb verb-id=\"SelectionIntersect\" show-icon=\"yes\" />\n"
+" <verb verb-id=\"SelectionSymDiff\" show-icon=\"yes\"/>\n"
+" <verb verb-id=\"SelectionDivide\" show-icon=\"yes\"/>\n"
+" <verb verb-id=\"SelectionCutPath\" show-icon=\"yes\"/>\n"
+" <separator/>\n"
+" <verb verb-id=\"SelectionCombine\" show-icon=\"yes\"/>\n"
+" <verb verb-id=\"SelectionBreakApart\" show-icon=\"yes\"/>\n"
+" <separator/>\n"
+" <verb verb-id=\"SelectionInset\" show-icon=\"yes\"/>\n"
+" <verb verb-id=\"SelectionOffset\" show-icon=\"yes\"/>\n"
+" <verb verb-id=\"SelectionDynOffset\" show-icon=\"yes\"/>\n"
+" <verb verb-id=\"SelectionLinkedOffset\" show-icon=\"yes\"/>\n"
" <separator/>\n"
" <verb verb-id=\"SelectionSimplify\" />\n"
" <verb verb-id=\"SelectionReverse\" />\n"
diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp
index c2ce9e568..d1da47867 100644
--- a/src/ui/interface.cpp
+++ b/src/ui/interface.cpp
@@ -437,8 +437,25 @@ sp_ui_dialog_title_string(Inkscape::Verb *verb, gchar *c)
* Appends a custom menu UI from a verb.
*
* @see ContextMenu::AppendItemFromVerb for a c++ified alternative. Consider dropping sp_ui_menu_append_item_from_verb when c++ifying interface.cpp.
+ *
+ * @param menu The menu to which the item will be appended
+ * @param verb The verb from which the item's label, action and icon (optionally) will be read
+ * @param view
+ * @param show_icon True if an icon should be displayed before the menu item's label
+ * @param radio True if a radio button should be displayed next to the menu item
+ * @param group The radio button group that the item should belong to
+ *
+ * @details The show_icon flag should be used very sparingly because menu icons are not recommended
+ * any longer under the GNOME HIG. Also, note that the text appears after the icon, and
+ * so will be indented relative to "normal" menu items. As such, menus will look best if
+ * all the items with icons are grouped together between a pair of separators.
*/
-static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb *verb, Inkscape::UI::View::View *view, bool radio = false, GSList *group = NULL)
+static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu,
+ Inkscape::Verb *verb,
+ Inkscape::UI::View::View *view,
+ bool show_icon = false,
+ bool radio = false,
+ GSList *group = NULL)
{
GtkWidget *item;
@@ -475,22 +492,20 @@ static GtkWidget *sp_ui_menu_append_item_from_verb(GtkMenu *menu, Inkscape::Verb
sp_shortcut_add_accelerator(item, sp_shortcut_get_primary(verb));
gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(label), item);
+ GtkWidget *icon;
+
// If there is an image associated with the action, then we can add it as an
// icon for the menu item. If not, give the label a bit more space
- if(action->image) {
- GtkWidget *icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU);
- gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0);
+ if(show_icon && action->image) {
+ icon = gtk_image_new_from_icon_name(action->image, GTK_ICON_SIZE_MENU);
}
else {
- GtkWidget *fake_icon = gtk_label_new("");
- gtk_widget_set_size_request(label, 16, 16);
- gtk_widget_set_hexpand(label, true);
- gtk_box_pack_start(GTK_BOX(box), fake_icon, FALSE, TRUE, 16);
+ icon = gtk_label_new(NULL); // A fake icon just to act as a placeholder
}
+ gtk_box_pack_start(GTK_BOX(box), icon, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
-
// Finally, pack all the widgets into the menu item
gtk_container_add(GTK_CONTAINER(item), box);
@@ -830,11 +845,19 @@ 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") != NULL) {
+ show_icon = true;
+ }
+
Inkscape::Verb *verb = Inkscape::Verb::getbyid(verb_name);
if (verb != NULL) {
if (menu_pntr->attribute("radio") != NULL) {
- GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, true, group);
+ GtkWidget *item = sp_ui_menu_append_item_from_verb (GTK_MENU(menu), verb, view, show_icon, true, group);
group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(item));
if (menu_pntr->attribute("default") != NULL) {
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
@@ -850,7 +873,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);
+ sp_ui_menu_append_item_from_verb(GTK_MENU(menu), verb, view, show_icon);
group = NULL;
}
} else {