]> git.street.me.uk Git - andy/viking.git/commitdiff
Enable copying the centre location of the viewport via Ctrl+h
authorRob Norris <rw_norris@hotmail.com>
Thu, 15 May 2014 20:22:53 +0000 (21:22 +0100)
committerRob Norris <rw_norris@hotmail.com>
Thu, 15 May 2014 20:25:09 +0000 (21:25 +0100)
help/C/viking.xml
src/menu.xml.h
src/vikwindow.c

index 51f2cb2c1816637051d8b8a1d045202a4c346a18..a9793a3e56e33fcd11738429952c05f3e5a5f97d 100644 (file)
@@ -3043,6 +3043,9 @@ Accept: */*
          <listitem>
            <para>window_menubar=true</para>
          </listitem>
+         <listitem>
+           <para>window_copy_centre_full_format=false</para>
+         </listitem>
          <listitem>
            <para>version_check_period_days=14</para>
          </listitem>
index 0086a8fe49018484ce7a5d6ba32de5bb861341af..ef30bb7a1d776c41aa595c697aba80a3578f424d 100644 (file)
@@ -50,6 +50,7 @@ static const char *menu_xml =
        "      <menuitem action='Delete'/>"
        "      <menuitem action='DeleteAll'/>"
        "      <separator/>"
+       "      <menuitem action='CopyCentre'/>"
        "      <menuitem action='MapCacheFlush'/>"
        "      <menuitem action='SetDefaultLocation'/>"
        "      <menuitem action='Preferences'/>"
index b8fdc8b78095bfe7e566d347311d2f1fe7e2be45..5d0be89aae8ee38b405aa7769448d356f47e4c4f 100644 (file)
@@ -693,6 +693,7 @@ static void drag_data_received_cb ( GtkWidget *widget,
 #define VIK_SETTINGS_WIN_SAVE_IMAGE_WIDTH "window_save_image_width"
 #define VIK_SETTINGS_WIN_SAVE_IMAGE_HEIGHT "window_save_image_height"
 #define VIK_SETTINGS_WIN_SAVE_IMAGE_PNG "window_save_image_as_png"
+#define VIK_SETTINGS_WIN_COPY_CENTRE_FULL_FORMAT "window_copy_centre_full_format"
 
 static void vik_window_init ( VikWindow *vw )
 {
@@ -1157,11 +1158,34 @@ static void vik_window_pan_move (VikWindow *vw, GdkEventMotion *event)
   }
 }
 
+/**
+ * get_location_strings:
+ *
+ * Utility function to get positional strings for the given location
+ * lat and lon strings will get allocated and so need to be freed after use
+ */
+static void get_location_strings ( VikWindow *vw, struct UTM utm, gchar **lat, gchar **lon )
+{
+  if ( vik_viewport_get_drawmode ( vw->viking_vvp ) == VIK_VIEWPORT_DRAWMODE_UTM ) {
+    // Reuse lat for the first part (Zone + N or S, and lon for the second part (easting and northing) of a UTM format:
+    //  ZONE[N|S] EASTING NORTHING
+    *lat = g_malloc(4*sizeof(gchar));
+    // NB zone is stored in a char but is an actual number
+    g_snprintf (*lat, 4, "%d%c", utm.zone, utm.letter);
+    *lon = g_malloc(16*sizeof(gchar));
+    g_snprintf (*lon, 16, "%d %d", (gint)utm.easting, (gint)utm.northing);
+  }
+  else {
+    struct LatLon ll;
+    a_coords_utm_to_latlon ( &utm, &ll );
+    a_coords_latlon_to_string ( &ll, lat, lon );
+  }
+}
+
 static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
 {
   static VikCoord coord;
   static struct UTM utm;
-  static struct LatLon ll;
   #define BUFFER_SIZE 50
   static char pointer_buf[BUFFER_SIZE];
   gchar *lat = NULL, *lon = NULL;
@@ -1181,19 +1205,7 @@ static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
   vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
   vik_coord_to_utm ( &coord, &utm );
 
-  if ( vik_viewport_get_drawmode ( vw->viking_vvp ) == VIK_VIEWPORT_DRAWMODE_UTM ) {
-    // Reuse lat for the first part (Zone + N or S, and lon for the second part (easting and northing) of a UTM format:
-    //  ZONE[N|S] EASTING NORTHING
-    lat = g_malloc(4*sizeof(gchar));
-    // NB zone is stored in a char but is an actual number
-    g_snprintf (lat, 4, "%d%c", utm.zone, utm.letter);
-    lon = g_malloc(16*sizeof(gchar));
-    g_snprintf (lon, 16, "%d %d", (gint)utm.easting, (gint)utm.northing);
-  }
-  else {
-    a_coords_utm_to_latlon ( &utm, &ll );
-    a_coords_latlon_to_string ( &ll, &lat, &lon );
-  }
+  get_location_strings ( vw, utm, &lat, &lon );
 
   /* Change interpolate method according to scale */
   zoom = vik_viewport_get_zoom(vw->viking_vvp);
@@ -3239,6 +3251,38 @@ static void mapcache_flush_cb ( GtkAction *a, VikWindow *vw )
   a_mapcache_flush();
 }
 
+static void menu_copy_centre_cb ( GtkAction *a, VikWindow *vw )
+{
+  const VikCoord* coord;
+  struct UTM utm;
+  gchar *lat = NULL, *lon = NULL;
+
+  coord = vik_viewport_get_center ( vw->viking_vvp );
+  vik_coord_to_utm ( coord, &utm );
+
+  gboolean full_format = FALSE;
+  a_settings_get_boolean ( VIK_SETTINGS_WIN_COPY_CENTRE_FULL_FORMAT, &full_format );
+
+  if ( full_format )
+    // Bells & Whistles - may include degrees, minutes and second symbols
+    get_location_strings ( vw, utm, &lat, &lon );
+  else {
+    // Simple x.xx y.yy format
+    struct LatLon ll;
+    a_coords_utm_to_latlon ( &utm, &ll );
+    lat = g_strdup_printf ( "%.6f", ll.lat );
+    lon = g_strdup_printf ( "%.6f", ll.lon );
+  }
+
+  gchar *msg = g_strdup_printf ( "%s %s", lat, lon );
+  g_free (lat);
+  g_free (lon);
+
+  a_clipboard_copy ( VIK_CLIPBOARD_DATA_TEXT, 0, 0, 0, msg, NULL );
+
+  g_free ( msg );
+}
+
 static void layer_defaults_cb ( GtkAction *a, VikWindow *vw )
 {
   gchar **texts = g_strsplit ( gtk_action_get_name(a), "Layer", 0 );
@@ -3977,6 +4021,7 @@ static GtkActionEntry entries[] = {
   { "Paste",     GTK_STOCK_PASTE,        N_("_Paste"),                        NULL,         NULL,                                           (GCallback)menu_paste_layer_cb   },
   { "Delete",    GTK_STOCK_DELETE,       N_("_Delete"),                       NULL,         NULL,                                           (GCallback)menu_delete_layer_cb  },
   { "DeleteAll", NULL,                   N_("Delete All"),                    NULL,         NULL,                                           (GCallback)clear_cb              },
+  { "CopyCentre",NULL,                   N_("Copy Centre _Location"),     "<control>h",     NULL,                                           (GCallback)menu_copy_centre_cb   },
   { "MapCacheFlush",NULL,                N_("_Flush Map Cache"),              NULL,         NULL,                                           (GCallback)mapcache_flush_cb     },
   { "SetDefaultLocation", GTK_STOCK_GO_FORWARD, N_("_Set the Default Location"), NULL, N_("Set the Default Location to the current position"),(GCallback)default_location_cb },
   { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences"),                  NULL,         NULL,                                           (GCallback)preferences_cb              },