From: Rob Norris Date: Fri, 17 Mar 2017 20:26:15 +0000 (+0000) Subject: Make each tool contain it's own icon definition. X-Git-Url: https://git.street.me.uk/andy/viking.git/commitdiff_plain/95de0de7c2604fa3e7a8606e545a2e72c243b26f Make each tool contain it's own icon definition. Instead of having it all in vikwindow.c, each tool can now have it's own icon definition which is then registered as a 'stock icon' prior to the tool being added into the GUI definition. --- diff --git a/src/globals.h b/src/globals.h index b666fbc7..485d50ad 100644 --- a/src/globals.h +++ b/src/globals.h @@ -228,6 +228,9 @@ gint a_vik_get_recent_number_files ( ); #define VIKING_PREFERENCES_STARTUP_GROUP_KEY "viking.startup" #define VIKING_PREFERENCES_STARTUP_NAMESPACE "viking.startup." +// Additions to 'Stock Icons' +#define VIK_ICON_SHOW_PICTURE "vik-icon-Show Picture" + G_END_DECLS #endif diff --git a/src/vikdemlayer.c b/src/vikdemlayer.c index 12d52145..e14e7ad5 100644 --- a/src/vikdemlayer.c +++ b/src/vikdemlayer.c @@ -132,7 +132,8 @@ static gboolean dem_layer_download_release ( VikDEMLayer *vdl, GdkEventButton *e static gboolean dem_layer_download_click ( VikDEMLayer *vdl, GdkEventButton *event, VikViewport *vvp ); static VikToolInterface dem_tools[] = { - { { "DEMDownload", "vik-icon-DEM Download", N_("_DEM Download"), NULL, N_("DEM Download"), 0 }, + { &demdl_18_pixbuf, + { "DEMDownload", "vik-icon-DEM Download", N_("_DEM Download"), NULL, N_("DEM Download"), 0 }, (VikToolConstructorFunc) dem_layer_download_create, NULL, NULL, NULL, (VikToolMouseFunc) dem_layer_download_click, NULL, (VikToolMouseFunc) dem_layer_download_release, (VikToolKeyFunc) NULL, diff --git a/src/vikgeoreflayer.c b/src/vikgeoreflayer.c index fbd9f68d..32081dac 100644 --- a/src/vikgeoreflayer.c +++ b/src/vikgeoreflayer.c @@ -93,14 +93,16 @@ static gboolean georef_layer_zoom_press ( VikGeorefLayer *vgl, GdkEventButton *e // See comment in viktrwlayer.c for advice on values used static VikToolInterface georef_tools[] = { - { { "GeorefMoveMap", "vik-icon-Georef Move Map", N_("_Georef Move Map"), NULL, N_("Georef Move Map"), 0 }, + { &geomove_18_pixbuf, + { "GeorefMoveMap", "vik-icon-Georef Move Map", N_("_Georef Move Map"), NULL, N_("Georef Move Map"), 0 }, (VikToolConstructorFunc) georef_layer_move_create, NULL, NULL, NULL, (VikToolMouseFunc) georef_layer_move_press, NULL, (VikToolMouseFunc) georef_layer_move_release, (VikToolKeyFunc) NULL, FALSE, GDK_CURSOR_IS_PIXMAP, &cursor_geomove_pixbuf, NULL }, - { { "GeorefZoomTool", "vik-icon-Georef Zoom Tool", N_("Georef Z_oom Tool"), NULL, N_("Georef Zoom Tool"), 0 }, + { &geozoom_18_pixbuf, + { "GeorefZoomTool", "vik-icon-Georef Zoom Tool", N_("Georef Z_oom Tool"), NULL, N_("Georef Zoom Tool"), 0 }, (VikToolConstructorFunc) georef_layer_zoom_create, NULL, NULL, NULL, (VikToolMouseFunc) georef_layer_zoom_press, NULL, NULL, (VikToolKeyFunc) NULL, diff --git a/src/viklayer.h b/src/viklayer.h index 8abb37ea..8ade4190 100644 --- a/src/viklayer.h +++ b/src/viklayer.h @@ -91,6 +91,7 @@ typedef gboolean (*VikToolKeyFunc) (VikLayer *, GdkEventKey *, gpointer); typedef struct _VikToolInterface VikToolInterface; struct _VikToolInterface { + const GdkPixdata *icon; GtkRadioActionEntry radioActionEntry; VikToolConstructorFunc create; VikToolDestructorFunc destroy; diff --git a/src/vikmapniklayer.c b/src/vikmapniklayer.c index 924a43c0..dc8c5558 100644 --- a/src/vikmapniklayer.c +++ b/src/vikmapniklayer.c @@ -118,7 +118,8 @@ static gboolean mapnik_feature_release ( VikMapnikLayer *vml, GdkEventButton *ev static VikToolInterface mapnik_tools[] = { // Layer Info // Zoom All? - { { "MapnikFeatures", GTK_STOCK_INFO, N_("_Mapnik Features"), NULL, N_("Mapnik Features"), 0 }, + { NULL, + { "MapnikFeatures", GTK_STOCK_INFO, N_("_Mapnik Features"), NULL, N_("Mapnik Features"), 0 }, (VikToolConstructorFunc) mapnik_feature_create, NULL, NULL, diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c index c0f8310f..3e789c3d 100644 --- a/src/vikmapslayer.c +++ b/src/vikmapslayer.c @@ -193,7 +193,8 @@ void maps_layer_set_cache_default ( VikMapsCacheLayout layout ) } static VikToolInterface maps_tools[] = { - { { "MapsDownload", "vik-icon-Maps Download", N_("_Maps Download"), NULL, N_("Maps Download"), 0 }, + { &mapdl_18_pixbuf, + { "MapsDownload", "vik-icon-Maps Download", N_("_Maps Download"), NULL, N_("Maps Download"), 0 }, (VikToolConstructorFunc) maps_layer_download_create, NULL, NULL, diff --git a/src/viktrwlayer.c b/src/viktrwlayer.c index 720ff8ff..97a4a5f7 100644 --- a/src/viktrwlayer.c +++ b/src/viktrwlayer.c @@ -415,13 +415,15 @@ static void highest_wp_number_remove_wp(VikTrwLayer *vtl, const gchar *old_wp_na // the second N_ text value is used for the button tooltip (i.e. generally don't want an underscore here) // the value is always set to 0 and the tool loader in VikWindow will set the actual appropriate value used static VikToolInterface trw_layer_tools[] = { - { { "CreateWaypoint", "vik-icon-Create Waypoint", N_("Create _Waypoint"), "W", N_("Create Waypoint"), 0 }, + { &addwp_18_pixbuf, + { "CreateWaypoint", "vik-icon-Create Waypoint", N_("Create _Waypoint"), "W", N_("Create Waypoint"), 0 }, (VikToolConstructorFunc) tool_new_waypoint_create, NULL, NULL, NULL, (VikToolMouseFunc) tool_new_waypoint_click, NULL, NULL, (VikToolKeyFunc) NULL, FALSE, GDK_CURSOR_IS_PIXMAP, &cursor_addwp_pixbuf, NULL }, - { { "CreateTrack", "vik-icon-Create Track", N_("Create _Track"), "T", N_("Create Track"), 0 }, + { &addtr_18_pixbuf, + { "CreateTrack", "vik-icon-Create Track", N_("Create _Track"), "T", N_("Create Track"), 0 }, (VikToolConstructorFunc) tool_new_track_create, NULL, NULL, NULL, (VikToolMouseFunc) tool_new_track_click, (VikToolMouseMoveFunc) tool_new_track_move, @@ -430,7 +432,8 @@ static VikToolInterface trw_layer_tools[] = { TRUE, // Still need to handle clicks when in PAN mode to disable the potential trackpoint drawing GDK_CURSOR_IS_PIXMAP, &cursor_addtr_pixbuf, NULL }, - { { "CreateRoute", "vik-icon-Create Route", N_("Create _Route"), "B", N_("Create Route"), 0 }, + { &vik_new_route_18_pixbuf, + { "CreateRoute", "vik-icon-Create Route", N_("Create _Route"), "B", N_("Create Route"), 0 }, (VikToolConstructorFunc) tool_new_route_create, NULL, NULL, NULL, (VikToolMouseFunc) tool_new_route_click, (VikToolMouseMoveFunc) tool_new_track_move, // -\# @@ -439,7 +442,8 @@ static VikToolInterface trw_layer_tools[] = { TRUE, // Still need to handle clicks when in PAN mode to disable the potential trackpoint drawing GDK_CURSOR_IS_PIXMAP, &cursor_new_route_pixbuf, NULL }, - { { "ExtendedRouteFinder", "vik-icon-Route Finder", N_("Route _Finder"), "F", N_("Route Finder"), 0 }, + { &route_finder_18_pixbuf, + { "ExtendedRouteFinder", "vik-icon-Route Finder", N_("Route _Finder"), "F", N_("Route Finder"), 0 }, (VikToolConstructorFunc) tool_extended_route_finder_create, NULL, NULL, NULL, (VikToolMouseFunc) tool_extended_route_finder_click, (VikToolMouseMoveFunc) tool_new_track_move, // -\# @@ -448,7 +452,8 @@ static VikToolInterface trw_layer_tools[] = { TRUE, // Still need to handle clicks when in PAN mode to disable the potential trackpoint drawing GDK_CURSOR_IS_PIXMAP, &cursor_route_finder_pixbuf, NULL }, - { { "EditWaypoint", "vik-icon-Edit Waypoint", N_("_Edit Waypoint"), "E", N_("Edit Waypoint"), 0 }, + { &edwp_18_pixbuf, + { "EditWaypoint", "vik-icon-Edit Waypoint", N_("_Edit Waypoint"), "E", N_("Edit Waypoint"), 0 }, (VikToolConstructorFunc) tool_edit_waypoint_create, (VikToolDestructorFunc) tool_edit_waypoint_destroy, NULL, NULL, @@ -458,7 +463,8 @@ static VikToolInterface trw_layer_tools[] = { FALSE, GDK_CURSOR_IS_PIXMAP, &cursor_edwp_pixbuf, NULL }, - { { "EditTrackpoint", "vik-icon-Edit Trackpoint", N_("Edit Trac_kpoint"), "K", N_("Edit Trackpoint"), 0 }, + { &edtr_18_pixbuf, + { "EditTrackpoint", "vik-icon-Edit Trackpoint", N_("Edit Trac_kpoint"), "K", N_("Edit Trackpoint"), 0 }, (VikToolConstructorFunc) tool_edit_trackpoint_create, (VikToolDestructorFunc) tool_edit_trackpoint_destroy, NULL, NULL, @@ -468,7 +474,8 @@ static VikToolInterface trw_layer_tools[] = { FALSE, GDK_CURSOR_IS_PIXMAP, &cursor_edtr_pixbuf, NULL }, - { { "ShowPicture", "vik-icon-Show Picture", N_("Show P_icture"), "I", N_("Show Picture"), 0 }, + { NULL, // a pixbuf for this one is already made globally available + { "ShowPicture", VIK_ICON_SHOW_PICTURE, N_("Show P_icture"), "I", N_("Show Picture"), 0 }, (VikToolConstructorFunc) tool_show_picture_create, NULL, NULL, NULL, (VikToolMouseFunc) tool_show_picture_click, NULL, NULL, (VikToolKeyFunc) NULL, FALSE, diff --git a/src/vikwindow.c b/src/vikwindow.c index cc988b4e..8b9efa43 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -1764,7 +1764,8 @@ static gboolean ruler_key_press (VikLayer *vl, GdkEventKey *event, ruler_tool_st static VikToolInterface ruler_tool = // NB Ctrl+Shift+R is used for Refresh (deemed more important), so use 'U' instead - { { "Ruler", "vik-icon-ruler", N_("_Ruler"), "U", N_("Ruler Tool"), 2 }, + { &ruler_18_pixbuf, + { "Ruler", "vik-icon-ruler", N_("_Ruler"), "U", N_("Ruler Tool"), 2 }, (VikToolConstructorFunc) ruler_create, (VikToolDestructorFunc) ruler_destroy, (VikToolActivationFunc) NULL, @@ -2037,7 +2038,8 @@ static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *ev } static VikToolInterface zoom_tool = - { { "Zoom", "vik-icon-zoom", N_("_Zoom"), "Z", N_("Zoom Tool"), 1 }, + { &zoom_18_pixbuf, + { "Zoom", "vik-icon-zoom", N_("_Zoom"), "Z", N_("Zoom Tool"), 1 }, (VikToolConstructorFunc) zoomtool_create, (VikToolDestructorFunc) zoomtool_destroy, (VikToolActivationFunc) NULL, @@ -2102,7 +2104,8 @@ static VikLayerToolFuncStatus pantool_release (VikLayer *vl, GdkEventButton *eve } static VikToolInterface pan_tool = - { { "Pan", "vik-icon-pan", N_("_Pan"), "P", N_("Pan Tool"), 0 }, + { &mover_22_pixbuf, + { "Pan", "vik-icon-pan", N_("_Pan"), "P", N_("Pan Tool"), 0 }, (VikToolConstructorFunc) pantool_create, (VikToolDestructorFunc) NULL, (VikToolActivationFunc) NULL, @@ -2254,7 +2257,8 @@ static VikLayerToolFuncStatus selecttool_release (VikLayer *vl, GdkEventButton * } static VikToolInterface select_tool = - { { "Select", "vik-icon-select", N_("_Select"), "S", N_("Select Tool"), 3 }, + { &select_18_pixbuf, + { "Select", "vik-icon-select", N_("_Select"), "S", N_("Select Tool"), 3 }, (VikToolConstructorFunc) selecttool_create, (VikToolDestructorFunc) selecttool_destroy, (VikToolActivationFunc) NULL, @@ -4453,6 +4457,20 @@ static void set_highlight_color ( GtkAction *a, VikWindow *vw ) /*********************************************************************************************** ** GUI Creation ***********************************************************************************************/ +typedef struct { + const GdkPixdata *data; + const gchar *name; +} icon_definition_t; + +static void +a_register_icon ( GtkIconFactory *icon_factory, icon_definition_t icon ) +{ + if ( !icon.data ) return; + GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata ( icon.data, FALSE, NULL )); + gtk_icon_factory_add ( icon_factory, icon.name, icon_set ); + gtk_icon_set_unref ( icon_set ); +} + static GtkActionEntry entries[] = { { "File", NULL, N_("_File"), 0, 0, 0 }, @@ -4590,7 +4608,6 @@ static void window_create_ui( VikWindow *window ) GError *error; guint i, j, mid; GtkIconFactory *icon_factory; - GtkIconSet *icon_set; GtkRadioActionEntry *tools = NULL, *radio; guint ntools; @@ -4693,12 +4710,12 @@ static void window_create_ui( VikWindow *window ) vik_layer_get_interface(i)->fixed_layer_name, GTK_UI_MANAGER_MENUITEM, FALSE); - icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata (vik_layer_get_interface(i)->icon, FALSE, NULL )); - gtk_icon_factory_add (icon_factory, vik_layer_get_interface(i)->name, icon_set); - gtk_icon_set_unref (icon_set); + icon_definition_t icon = { vik_layer_get_interface(i)->icon, + vik_layer_get_interface(i)->fixed_layer_name }; + a_register_icon ( icon_factory, icon ); action.name = vik_layer_get_interface(i)->fixed_layer_name; - action.stock_id = vik_layer_get_interface(i)->name; + action.stock_id = vik_layer_get_interface(i)->fixed_layer_name; action.label = g_strdup_printf( _("New _%s Layer"), _(vik_layer_get_interface(i)->name)); action.accelerator = vik_layer_get_interface(i)->accelerator; action.tooltip = NULL; @@ -4719,7 +4736,11 @@ static void window_create_ui( VikWindow *window ) tools = g_renew(GtkRadioActionEntry, tools, ntools+1); radio = &tools[ntools]; ntools++; - + + icon_definition_t icon = { vik_layer_get_interface(i)->tools[j].icon, + vik_layer_get_interface(i)->tools[j].radioActionEntry.stock_id }; + a_register_icon ( icon_factory, icon ); + gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools", vik_layer_get_interface(i)->tools[j].radioActionEntry.label, vik_layer_get_interface(i)->tools[j].radioActionEntry.name, @@ -4744,7 +4765,7 @@ static void window_create_ui( VikWindow *window ) // For default layers use action names of the form 'Layer' // This is to avoid clashing with just the layer name used above for the tool actions action_dl.name = g_strconcat("Layer", vik_layer_get_interface(i)->fixed_layer_name, NULL); - action_dl.stock_id = NULL; + action_dl.stock_id = vik_layer_get_interface(i)->fixed_layer_name; action_dl.label = g_strconcat(_(vik_layer_get_interface(i)->name), _("..."), NULL); action_dl.accelerator = NULL; action_dl.tooltip = NULL; @@ -4788,43 +4809,21 @@ static void window_create_ui( VikWindow *window ) } } - -// TODO - add method to add tool icons defined from outside this file -// and remove the reverse dependency on icon definition from this file -static struct { - const GdkPixdata *data; - gchar *stock_id; -} stock_icons[] = { +static icon_definition_t vik_icons[] = { + // Vikwindow specific icons: { &mover_22_pixbuf, "vik-icon-pan" }, { &zoom_18_pixbuf, "vik-icon-zoom" }, { &ruler_18_pixbuf, "vik-icon-ruler" }, { &select_18_pixbuf, "vik-icon-select" }, - { &vik_new_route_18_pixbuf, "vik-icon-Create Route" }, - { &route_finder_18_pixbuf, "vik-icon-Route Finder" }, - { &demdl_18_pixbuf, "vik-icon-DEM Download" }, - { &showpic_18_pixbuf, "vik-icon-Show Picture" }, - { &addtr_18_pixbuf, "vik-icon-Create Track" }, - { &edtr_18_pixbuf, "vik-icon-Edit Trackpoint" }, - { &addwp_18_pixbuf, "vik-icon-Create Waypoint" }, - { &edwp_18_pixbuf, "vik-icon-Edit Waypoint" }, - { &geozoom_18_pixbuf, "vik-icon-Georef Zoom Tool" }, - { &geomove_18_pixbuf, "vik-icon-Georef Move Map" }, - { &mapdl_18_pixbuf, "vik-icon-Maps Download" }, + // Generic icons for use anywhere: + { &showpic_18_pixbuf, VIK_ICON_SHOW_PICTURE }, }; - -static gint n_stock_icons = G_N_ELEMENTS (stock_icons); static void -register_vik_icons (GtkIconFactory *icon_factory) +register_vik_icons ( GtkIconFactory *icon_factory ) { - GtkIconSet *icon_set; - gint i; - - for (i = 0; i < n_stock_icons; i++) { - icon_set = gtk_icon_set_new_from_pixbuf (gdk_pixbuf_from_pixdata ( - stock_icons[i].data, FALSE, NULL )); - gtk_icon_factory_add (icon_factory, stock_icons[i].stock_id, icon_set); - gtk_icon_set_unref (icon_set); + for (guint i = 0; i < G_N_ELEMENTS(vik_icons); i++) { + a_register_icon ( icon_factory, vik_icons[i] ); } }