]> git.street.me.uk Git - andy/viking.git/commitdiff
Make each tool contain it's own icon definition.
authorRob Norris <rw_norris@hotmail.com>
Fri, 17 Mar 2017 20:26:15 +0000 (20:26 +0000)
committerRob Norris <rw_norris@hotmail.com>
Tue, 4 Apr 2017 22:17:27 +0000 (23:17 +0100)
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.

src/globals.h
src/vikdemlayer.c
src/vikgeoreflayer.c
src/viklayer.h
src/vikmapniklayer.c
src/vikmapslayer.c
src/viktrwlayer.c
src/vikwindow.c

index b666fbc7c80156860f2f22b5416515ba21a219db..485d50ad4bc568c60478ea1da712c7c809be4aa8 100644 (file)
@@ -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
index 12d52145c8490b7aa82c551477ed0631fbd4bceb..e14e7ad58ecd933b4c8879f371cd7b425ea10a61 100644 (file)
@@ -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,
index fbd9f68d2b8e3415bf3e8a7475913faf05bdc99e..32081dacb523fac15a631b018d66d5e3e7bf3fa7 100644 (file)
@@ -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,
index 8abb37ea3d04b6b7e245ca2315c3eccbe50c57a1..8ade4190b4371f24fd9e8c22ccadc82d836d61a9 100644 (file)
@@ -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;
index 924a43c01ff725c24d3f15d118c34b463a996695..dc8c555897034d0d3046695f925eb19a1114abcd 100644 (file)
@@ -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,
index c0f8310f510e936e2733db9ee33a23e25f4e5ae8..3e789c3db95ec3a71a02b257f1a8735e85725465 100644 (file)
@@ -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,
index 720ff8fff62ae667b6bef371d5849484509f4d40..97a4a5f712617079121fae4047e917fcd1d60da5 100644 (file)
@@ -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"), "<control><shift>W", N_("Create Waypoint"), 0 },
+  { &addwp_18_pixbuf,
+    { "CreateWaypoint", "vik-icon-Create Waypoint", N_("Create _Waypoint"), "<control><shift>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"), "<control><shift>T", N_("Create Track"), 0 },
+  { &addtr_18_pixbuf,
+    { "CreateTrack", "vik-icon-Create Track", N_("Create _Track"), "<control><shift>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"), "<control><shift>B", N_("Create Route"), 0 },
+  { &vik_new_route_18_pixbuf,
+    { "CreateRoute", "vik-icon-Create Route", N_("Create _Route"), "<control><shift>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"), "<control><shift>F", N_("Route Finder"), 0 },
+  { &route_finder_18_pixbuf,
+    { "ExtendedRouteFinder", "vik-icon-Route Finder", N_("Route _Finder"), "<control><shift>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"), "<control><shift>E", N_("Edit Waypoint"), 0 },
+  { &edwp_18_pixbuf,
+    { "EditWaypoint", "vik-icon-Edit Waypoint", N_("_Edit Waypoint"), "<control><shift>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"), "<control><shift>K", N_("Edit Trackpoint"), 0 },
+  { &edtr_18_pixbuf,
+    { "EditTrackpoint", "vik-icon-Edit Trackpoint", N_("Edit Trac_kpoint"), "<control><shift>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"), "<control><shift>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"), "<control><shift>I", N_("Show Picture"), 0 },
     (VikToolConstructorFunc) tool_show_picture_create,    NULL, NULL, NULL,
     (VikToolMouseFunc) tool_show_picture_click,    NULL, NULL, (VikToolKeyFunc) NULL,
     FALSE,
index cc988b4ea6ae6dd8e221634ba36243629948f9f1..8b9efa437dc58c854c09b0dda4d5f44faebb75f1 100644 (file)
@@ -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"), "<control><shift>U", N_("Ruler Tool"), 2 },
+  { &ruler_18_pixbuf,
+    { "Ruler", "vik-icon-ruler", N_("_Ruler"), "<control><shift>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"), "<control><shift>Z", N_("Zoom Tool"), 1 },
+  { &zoom_18_pixbuf,
+    { "Zoom", "vik-icon-zoom", N_("_Zoom"), "<control><shift>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"), "<control><shift>P", N_("Pan Tool"), 0 },
+  { &mover_22_pixbuf,
+    { "Pan", "vik-icon-pan", N_("_Pan"), "<control><shift>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"), "<control><shift>S", N_("Select Tool"), 3 },
+  { &select_18_pixbuf,
+    { "Select", "vik-icon-select", N_("_Select"), "<control><shift>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<LayerName>'
     // 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] );
   }
 }