]> git.street.me.uk Git - andy/viking.git/blob - src/viktrwlayer_waypointlist.c
added save previous user input string and input label options to datasource search...
[andy/viking.git] / src / viktrwlayer_waypointlist.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4  *
5  * Copyright (C) 2013, Rob Norris <rw_norris@hotmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 #include <math.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <glib.h>
27 #include <glib/gstdio.h>
28 #include <glib/gi18n.h>
29
30 #include "viking.h"
31 #include "viktrwlayer_waypointlist.h"
32 #include "viktrwlayer_wpwin.h"
33
34 // Long formatted date+basic time - listing this way ensures the string comparison sort works - so no local type format %x or %c here!
35 #define WAYPOINT_LIST_DATE_FORMAT "%Y-%m-%d %H:%M"
36
37 /**
38  * waypoint_close_cb:
39  *
40  */
41 static void waypoint_close_cb ( GtkWidget *dialog, gint resp, GList *data )
42 {
43         g_list_foreach ( data, (GFunc) g_free, NULL );
44         g_list_free ( data );
45
46         gtk_widget_destroy (dialog);
47 }
48
49 /**
50  * format_1f_cell_data_func:
51  *
52  * General purpose column double formatting
53  *
54 static void format_1f_cell_data_func ( GtkTreeViewColumn *col,
55                                        GtkCellRenderer   *renderer,
56                                        GtkTreeModel      *model,
57                                        GtkTreeIter       *iter,
58                                        gpointer           user_data )
59 {
60         gdouble value;
61         gchar buf[20];
62         gint column = GPOINTER_TO_INT (user_data);
63         gtk_tree_model_get ( model, iter, column, &value, -1 );
64         g_snprintf ( buf, sizeof(buf), "%.1f", value );
65         g_object_set ( renderer, "text", buf, NULL );
66 }
67  */
68
69 #define WPT_LIST_COLS 9
70 #define WPT_COL_NUM WPT_LIST_COLS-1
71 #define TRW_COL_NUM WPT_COL_NUM-1
72
73 /*
74  * trw_layer_waypoint_tooltip_cb:
75  *
76  * Show a tooltip when the mouse is over a waypoint list entry.
77  * The tooltip contains the description.
78  */
79 static gboolean trw_layer_waypoint_tooltip_cb ( GtkWidget  *widget,
80                                                 gint        x,
81                                                 gint        y,
82                                                 gboolean    keyboard_tip,
83                                                 GtkTooltip *tooltip,
84                                                 gpointer    data )
85 {
86         GtkTreeIter iter;
87         GtkTreePath *path = NULL;
88         GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
89         GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
90
91         if ( !gtk_tree_view_get_tooltip_context ( tree_view, &x, &y,
92                                                   keyboard_tip,
93                                                   &model, &path, &iter ) )
94                 return FALSE;
95
96         VikWaypoint *wpt;
97         gtk_tree_model_get ( model, &iter, WPT_COL_NUM, &wpt, -1 );
98         if ( !wpt ) return FALSE;
99
100         gboolean tooltip_set = TRUE;
101         if ( wpt->description )
102                 gtk_tooltip_set_text ( tooltip, wpt->description );
103         else
104                 tooltip_set = FALSE;
105
106         if ( tooltip_set )
107                 gtk_tree_view_set_tooltip_row ( tree_view, tooltip, path );
108
109         gtk_tree_path_free ( path );
110
111         return tooltip_set;
112 }
113
114 /*
115 static void trw_layer_waypoint_select_cb ( GtkTreeSelection *selection, gpointer data )
116 {
117         GtkTreeIter iter;
118         if ( !gtk_tree_selection_get_selected (selection, NULL, &iter) )
119                 return;
120
121         GtkTreeView *tree_view = GTK_TREE_VIEW ( data );
122         GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
123
124         VikWaypoint *wpt;
125         gtk_tree_model_get ( model, &iter, WPT_COL_NUM, &wpt, -1 );
126         if ( !wpt ) return;
127
128         VikTrwLayer *vtl;
129         gtk_tree_model_get ( model, &iter, TRW_COL_NUM, &vtl, -1 );
130         if ( !IS_VIK_TRW_LAYER(vtl) ) return;
131
132         //vik_treeview_select_iter ( VIK_LAYER(vtl)->vt, g_hash_table_lookup ( vtl->waypoint_iters, uuid ), TRUE );
133 }
134 */
135
136 // A slightly better way of defining the menu callback information
137 // This should be much easier to extend/rework compared to the current trw_layer menus
138 typedef enum {
139   MA_VTL = 0,
140   MA_WPT,
141   MA_WPT_UUID,
142   MA_VVP,
143   MA_TREEVIEW,
144   MA_WPTS_LIST,
145   MA_LAST
146 } menu_array_index;
147
148 typedef gpointer menu_array_values[MA_LAST];
149
150 // Instead of hooking automatically on treeview item selection
151 // This is performed on demand via the specific menu request
152 static void trw_layer_waypoint_select ( menu_array_values values )
153 {
154         VikTrwLayer *vtl = VIK_TRW_LAYER(values[MA_VTL]);
155
156         if ( values[MA_WPT_UUID] ) {
157                 GtkTreeIter *iter = NULL;
158                 iter = g_hash_table_lookup ( vik_trw_layer_get_waypoints_iters(vtl), values[MA_WPT_UUID] );
159
160                 if ( iter )
161                         vik_treeview_select_iter ( VIK_LAYER(vtl)->vt, iter, TRUE );
162         }
163 }
164
165 static void trw_layer_waypoint_properties ( menu_array_values values )
166 {
167         VikTrwLayer *vtl = VIK_TRW_LAYER(values[MA_VTL]);
168         VikWaypoint *wpt = VIK_WAYPOINT(values[MA_WPT]);
169
170         if ( wpt && wpt->name ) {
171                 // Kill off this dialog to allow interaction with properties window
172                 //  since the properties also allows waypoint manipulations it won't cause conflicts here.
173                 GtkWidget *gw = gtk_widget_get_toplevel ( values[MA_TREEVIEW] );
174                 waypoint_close_cb ( gw, 0, values[MA_WPTS_LIST] );
175
176                 gboolean updated = FALSE;
177                 gchar *new_name = a_dialog_waypoint ( VIK_GTK_WINDOW_FROM_LAYER(vtl), wpt->name, vtl, wpt, vik_trw_layer_get_coord_mode(vtl), FALSE, &updated );
178                 if ( new_name )
179                         trw_layer_waypoint_rename ( vtl, wpt, new_name );
180
181                 if ( updated )
182                         trw_layer_waypoint_reset_icon ( vtl, wpt );
183
184                 if ( updated && VIK_LAYER(vtl)->visible )
185                         vik_layer_emit_update ( VIK_LAYER(vtl) );
186         }
187 }
188
189 static void trw_layer_waypoint_view ( menu_array_values values )
190 {
191         VikTrwLayer *vtl = VIK_TRW_LAYER(values[MA_VTL]);
192         VikWaypoint *wpt = VIK_WAYPOINT(values[MA_WPT]);
193         VikViewport *vvp = VIK_VIEWPORT(values[MA_VVP]);
194
195         vik_viewport_set_center_coord ( vvp, &(wpt->coord), TRUE );
196
197         trw_layer_waypoint_select (values);
198
199         vik_layer_emit_update ( VIK_LAYER(vtl) );
200 }
201
202 static void trw_layer_show_picture ( menu_array_values values )
203 {
204         VikWaypoint *wpt = VIK_WAYPOINT(values[MA_WPT]);
205 #ifdef WINDOWS
206         ShellExecute(NULL, "open", wpt->image, NULL, NULL, SW_SHOWNORMAL);
207 #else
208         VikTrwLayer *vtl = VIK_TRW_LAYER(values[MA_VTL]);
209         GError *err = NULL;
210         gchar *quoted_file = g_shell_quote ( wpt->image );
211         gchar *cmd = g_strdup_printf ( "%s %s", a_vik_get_image_viewer(), quoted_file );
212         g_free ( quoted_file );
213         if ( ! g_spawn_command_line_async ( cmd, &err ) ) {
214                 a_dialog_error_msg_extra ( VIK_GTK_WINDOW_FROM_LAYER(vtl), _("Could not launch %s to open file."), a_vik_get_image_viewer() );
215                 g_error_free ( err );
216         }
217         g_free ( cmd );
218 #endif
219 }
220
221
222 static gboolean add_menu_items ( GtkMenu *menu, VikTrwLayer *vtl, VikWaypoint *wpt, gpointer wpt_uuid, VikViewport *vvp, GtkWidget *tree_view, gpointer data )
223 {
224         static menu_array_values values;
225         GtkWidget *item;
226
227         values[MA_VTL]       = vtl;
228         values[MA_WPT]       = wpt;
229         values[MA_WPT_UUID]  = wpt_uuid;
230         values[MA_VVP]       = vvp;
231         values[MA_TREEVIEW]  = tree_view;
232         values[MA_WPTS_LIST] = data;
233
234         /*
235         item = gtk_image_menu_item_new_with_mnemonic ( _("_Select") );
236         gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_MENU) );
237         g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_waypoint_select), values );
238         gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
239         gtk_widget_show ( item );
240         */
241
242         // AUTO SELECT NOT TRUE YET...
243         // ATM view auto selects, so don't bother with separate select menu entry
244         item = gtk_image_menu_item_new_with_mnemonic ( _("_View") );
245         gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock (GTK_STOCK_ZOOM_FIT, GTK_ICON_SIZE_MENU) );
246         g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_waypoint_view), values );
247         gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
248         gtk_widget_show ( item );
249
250         item = gtk_image_menu_item_new_from_stock ( GTK_STOCK_PROPERTIES, NULL );
251         g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_waypoint_properties), values );
252         gtk_menu_shell_append ( GTK_MENU_SHELL(menu), item );
253         gtk_widget_show ( item );
254
255         item = gtk_image_menu_item_new_with_mnemonic ( _("_Show Picture...") );
256         gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock ("vik-icon-Show Picture", GTK_ICON_SIZE_MENU) ); // Own icon - see stock_icons in vikwindow.c
257         g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_show_picture), values );
258         gtk_menu_shell_append ( GTK_MENU_SHELL(menu), item );
259         gtk_widget_show ( item );
260         gtk_widget_set_sensitive ( item, GPOINTER_TO_INT(wpt->image) );
261
262         return TRUE;
263 }
264
265 static gboolean trw_layer_waypoint_menu_popup ( GtkWidget *tree_view,
266                                                 GdkEventButton *event,
267                                                 gpointer data )
268 {
269         static GtkTreeIter iter;
270
271         // Use selected item to get a single iterator ref
272         // This relies on an row being selected as part of the right click
273         GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(tree_view) );
274         if ( gtk_tree_selection_count_selected_rows (selection) != 1 )
275                 return FALSE;
276
277         GtkTreePath *path;
278         GtkTreeModel *model = gtk_tree_view_get_model ( GTK_TREE_VIEW(tree_view) );
279
280         // All this just to get the iter
281         if ( gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW(tree_view),
282                                              (gint) event->x,
283                                              (gint) event->y,
284                                              &path, NULL, NULL, NULL)) {
285                 gtk_tree_model_get_iter_from_string ( model, &iter, gtk_tree_path_to_string (path) );
286                 gtk_tree_path_free ( path );
287         }
288         else
289                 return FALSE;
290
291         VikWaypoint *wpt;
292         gtk_tree_model_get ( model, &iter, WPT_COL_NUM, &wpt, -1 );
293         if ( !wpt ) return FALSE;
294
295         VikTrwLayer *vtl;
296         gtk_tree_model_get ( model, &iter, TRW_COL_NUM, &vtl, -1 );
297         if ( !IS_VIK_TRW_LAYER(vtl) ) return FALSE;
298
299         wpu_udata udataU;
300         udataU.wp   = wpt;
301         udataU.uuid = NULL;
302
303         gpointer *wptf;
304         wptf = g_hash_table_find ( vik_trw_layer_get_waypoints(vtl), (GHRFunc) trw_layer_waypoint_find_uuid, &udataU );
305
306         if ( wptf && udataU.uuid ) {
307                 VikViewport *vvp = vik_window_viewport((VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(vtl)));
308
309                 GtkWidget *menu = gtk_menu_new();
310
311                 // Originally started to reuse the trw_layer menu items
312                 //  however these offer too many ways to edit the waypoint data
313                 //  so without an easy way to distinguish read only operations,
314                 //  create a very minimal new set of operations
315                 add_menu_items ( GTK_MENU(menu),
316                                  vtl,
317                                  wpt,
318                                  udataU.uuid,
319                                  vvp,
320                                  tree_view,
321                                  data );
322
323                 gtk_menu_popup ( GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, gtk_get_current_event_time() );
324                 return TRUE;
325         }
326         return FALSE;
327 }
328
329 static gboolean trw_layer_waypoint_button_pressed ( GtkWidget *tree_view,
330                                                     GdkEventButton *event,
331                                                     gpointer data )
332 {
333         // Only on right clicks...
334         if ( ! (event->type == GDK_BUTTON_PRESS && event->button == 3) )
335                 return FALSE;
336
337         // ATM Force a selection...
338         GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW(tree_view) );
339         if ( gtk_tree_selection_count_selected_rows (selection) <= 1 ) {
340                 GtkTreePath *path;
341                 /* Get tree path for row that was clicked */
342                 if ( gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW(tree_view),
343                                                      (gint) event->x,
344                                                     (gint) event->y,
345                                                      &path, NULL, NULL, NULL)) {
346                         gtk_tree_selection_unselect_all ( selection );
347                         gtk_tree_selection_select_path ( selection, path );
348                         gtk_tree_path_free ( path );
349                 }
350         }
351         return trw_layer_waypoint_menu_popup ( tree_view, event, data );
352 }
353
354 /*
355  * Foreach entry we copy the various individual waypoint properties into the tree store
356  *  formatting & converting the internal values into something for display
357  */
358 static void trw_layer_waypoint_list_add ( vik_trw_waypoint_list_t *vtdl,
359                                           GtkTreeStore *store,
360                                           vik_units_height_t height_units )
361 {
362         GtkTreeIter t_iter;
363         VikWaypoint *wpt = vtdl->wpt;
364         VikTrwLayer *vtl = vtdl->vtl;
365
366         // Get start date
367         gchar time_buf[32];
368         time_buf[0] = '\0';
369         if ( wpt->has_timestamp ) {
370
371 #if GLIB_CHECK_VERSION(2,26,0)
372                 GDateTime* gdt = g_date_time_new_from_unix_utc ( wpt->timestamp );
373                 gchar *time = g_date_time_format ( gdt, WAYPOINT_LIST_DATE_FORMAT );
374                 strncpy ( time_buf, time, sizeof(time_buf) );
375                 g_free ( time );
376                 g_date_time_unref ( gdt);
377 #else
378                 GDate* gdate_start = g_date_new ();
379                 g_date_set_time_t ( gdate_start, wpt->timestamp );
380                 g_date_strftime ( time_buf, sizeof(time_buf), WAYPOINT_LIST_DATE_FORMAT, gdate_start );
381                 g_date_free ( gdate_start );
382 #endif
383         }
384
385         // NB: doesn't include aggegrate visibility
386         gboolean visible = VIK_LAYER(vtl)->visible && wpt->visible;
387         visible = visible && vik_trw_layer_get_waypoints_visibility(vtl);
388
389         gdouble alt = wpt->altitude;
390         switch (height_units) {
391         case VIK_UNITS_HEIGHT_FEET: alt = VIK_METERS_TO_FEET(alt); break;
392         default:
393                 // VIK_UNITS_HEIGHT_METRES: no need to convert
394                 break;
395         }
396
397         gtk_tree_store_append ( store, &t_iter, NULL );
398         gtk_tree_store_set ( store, &t_iter,
399                              0, VIK_LAYER(vtl)->name,
400                              1, wpt->name,
401                              2, time_buf,
402                              3, visible,
403                              4, wpt->comment,
404                              5, (gint)round(alt),
405                              6, get_wp_sym_small (wpt->symbol),
406                              TRW_COL_NUM, vtl,
407                              WPT_COL_NUM, wpt,
408                              -1 );
409 }
410
411 /*
412  * Instead of comparing the pixbufs,
413  *  look at the waypoint data and compare the symbol (as text).
414  */
415 gint sort_pixbuf_compare_func ( GtkTreeModel *model,
416                                 GtkTreeIter  *a,
417                                 GtkTreeIter  *b,
418                                 gpointer      userdata )
419 {
420         VikWaypoint *wpt1, *wpt2;
421         gtk_tree_model_get ( model, a, WPT_COL_NUM, &wpt1, -1 );
422         if ( !wpt1 ) return 0;
423         gtk_tree_model_get ( model, b, WPT_COL_NUM, &wpt2, -1 );
424         if ( !wpt2 ) return 0;
425
426         return g_strcmp0 ( wpt1->symbol, wpt2->symbol );
427 }
428
429 static GtkTreeViewColumn *my_new_column_text ( const gchar *title, GtkCellRenderer *renderer, GtkWidget *view, gint column_runner )
430 {
431         GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ( title, renderer, "text", column_runner, NULL );
432         gtk_tree_view_column_set_sort_column_id ( column, column_runner );
433         gtk_tree_view_append_column ( GTK_TREE_VIEW(view), column );
434         gtk_tree_view_column_set_reorderable ( column, TRUE );
435         gtk_tree_view_column_set_resizable ( column, TRUE );
436         return column;
437 }
438
439 /**
440  * vik_trw_layer_waypoint_list_internal:
441  * @dialog:            The dialog to create the widgets in
442  * @waypoints_and_layers: The list of waypoints (and it's layer) to be shown
443  * @show_layer_names:  Show the layer names that each waypoint belongs to
444  *
445  * Create a table of waypoints with corresponding waypoint information
446  * This table does not support being actively updated
447  */
448 static void vik_trw_layer_waypoint_list_internal ( GtkWidget *dialog,
449                                                    GList *waypoints_and_layers,
450                                                    gboolean show_layer_names )
451 {
452         if ( !waypoints_and_layers )
453                 return;
454
455         // It's simple storing the gdouble values in the tree store as the sort works automatically
456         // Then apply specific cell data formatting (rather default double is to 6 decimal places!)
457         // However not storing any doubles for waypoints ATM
458         // TODO: Consider adding the waypoint icon into this store for display in the list
459         GtkTreeStore *store = gtk_tree_store_new ( WPT_LIST_COLS,
460                                                    G_TYPE_STRING,    // 0: Layer Name
461                                                    G_TYPE_STRING,    // 1: Waypoint Name
462                                                    G_TYPE_STRING,    // 2: Date
463                                                    G_TYPE_BOOLEAN,   // 3: Visible
464                                                    G_TYPE_STRING,    // 4: Comment
465                                                    G_TYPE_INT,       // 5: Height
466                                                    GDK_TYPE_PIXBUF,  // 6: Symbol Icon
467                                                    G_TYPE_POINTER,   // 7: TrackWaypoint Layer pointer
468                                                    G_TYPE_POINTER ); // 8: Waypoint pointer
469
470         //gtk_tree_selection_set_select_function ( gtk_tree_view_get_selection (GTK_TREE_VIEW(vt)), vik_treeview_selection_filter, vt, NULL );
471
472         vik_units_height_t height_units = a_vik_get_units_height ();
473
474         //GList *gl = get_waypoints_and_layers_cb ( vl, user_data );
475         //g_list_foreach ( waypoints_and_layers, (GFunc) trw_layer_waypoint_list_add, store );
476         GList *gl = waypoints_and_layers;
477         while ( gl ) {
478                 trw_layer_waypoint_list_add ( (vik_trw_waypoint_list_t*)gl->data, store, height_units );
479                 gl = g_list_next ( gl );
480         }
481
482         GtkWidget *view = gtk_tree_view_new();
483         GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
484         g_object_set (G_OBJECT (renderer), "xalign", 0.0, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
485         GtkTreeViewColumn *column;
486         GtkTreeViewColumn *sort_by_column;
487
488         gint column_runner = 0;
489         if ( show_layer_names ) {
490                 // Insert column for the layer name when viewing multi layers
491                 column = my_new_column_text ( _("Layer"), renderer, view, column_runner++ );
492                 g_object_set (G_OBJECT (renderer), "xalign", 0.0, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
493                 gtk_tree_view_column_set_expand ( column, TRUE );
494                 // remember the layer column so we can sort by it later
495                 sort_by_column = column;
496         }
497         else
498                 column_runner++;
499
500         column = my_new_column_text ( _("Name"), renderer, view, column_runner++ );
501         gtk_tree_view_column_set_expand ( column, TRUE );
502         if ( !show_layer_names )
503                 // remember the name column so we can sort by it later
504                 sort_by_column = column;
505
506         column = my_new_column_text ( _("Date"), renderer, view, column_runner++ );
507         gtk_tree_view_column_set_resizable ( column, TRUE );
508
509         GtkCellRenderer *renderer_toggle = gtk_cell_renderer_toggle_new ();
510         column = gtk_tree_view_column_new_with_attributes ( _("Visible"), renderer_toggle, "active", column_runner, NULL );
511         gtk_tree_view_column_set_sort_column_id ( column, column_runner );
512         gtk_tree_view_append_column ( GTK_TREE_VIEW(view), column );
513         column_runner++;
514
515         column = my_new_column_text ( _("Comment"), renderer, view, column_runner++ );
516         gtk_tree_view_column_set_expand ( column, TRUE );
517
518         if ( height_units == VIK_UNITS_HEIGHT_FEET )
519                 column = my_new_column_text ( _("Max Height\n(Feet)"), renderer, view, column_runner++ );
520         else
521                 column = my_new_column_text ( _("Max Height\n(Metres)"), renderer, view, column_runner++ );
522
523         GtkCellRenderer *renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
524         g_object_set (G_OBJECT (renderer_pixbuf), "xalign", 0.5, NULL);
525         column = gtk_tree_view_column_new_with_attributes ( _("Symbol"), renderer_pixbuf, "pixbuf", column_runner++, NULL );
526         // Special sort required for pixbufs
527         gtk_tree_sortable_set_sort_func ( GTK_TREE_SORTABLE(store), column_runner, sort_pixbuf_compare_func, NULL, NULL );
528         gtk_tree_view_column_set_sort_column_id ( column, column_runner );
529         gtk_tree_view_append_column ( GTK_TREE_VIEW(view), column );
530
531         gtk_tree_view_set_model ( GTK_TREE_VIEW(view), GTK_TREE_MODEL(store) );
532         gtk_tree_selection_set_mode ( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), GTK_SELECTION_BROWSE ); // GTK_SELECTION_MULTIPLE
533         gtk_tree_view_set_rules_hint ( GTK_TREE_VIEW(view), TRUE );
534
535         g_object_unref(store);
536
537         GtkWidget *scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
538         gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
539         gtk_container_add ( GTK_CONTAINER(scrolledwindow), view );
540
541         g_object_set ( view, "has-tooltip", TRUE, NULL);
542
543         g_signal_connect ( view, "query-tooltip", G_CALLBACK (trw_layer_waypoint_tooltip_cb), NULL );
544         //g_signal_connect ( gtk_tree_view_get_selection (GTK_TREE_VIEW(view)), "changed", G_CALLBACK(trw_layer_waypoint_select_cb), view );
545
546         g_signal_connect ( view, "popup-menu", G_CALLBACK(trw_layer_waypoint_menu_popup), waypoints_and_layers );
547         g_signal_connect ( view, "button-press-event", G_CALLBACK(trw_layer_waypoint_button_pressed), waypoints_and_layers );
548
549         gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwindow, TRUE, TRUE, 0);
550
551         // Set ordering of the initial view by one of the name columns
552         gtk_tree_view_column_clicked ( sort_by_column );
553
554         // Ensure a reasonable number of items are shown
555         //  TODO: may be save window size, column order, sorted by between invocations.
556         gtk_window_set_default_size ( GTK_WINDOW(dialog), show_layer_names ? 700 : 500, 400 );
557 }
558
559
560 /**
561  * vik_trw_layer_waypoint_list_show_dialog:
562  * @title:                    The title for the dialog
563  * @vl:                       The #VikLayer passed on into get_waypoints_and_layers_cb()
564  * @user_data:                Data passed on into get_waypoints_and_layers_cb()
565  * @get_waypoints_and_layers_cb: The function to call to construct items to be analysed
566  * @show_layer_names:         Normally only set when called from an aggregate level
567  *
568  * Common method for showing a list of waypoints with extended information
569  *
570  */
571 void vik_trw_layer_waypoint_list_show_dialog ( gchar *title,
572                                                VikLayer *vl,
573                                                gpointer user_data,
574                                                VikTrwlayerGetWaypointsAndLayersFunc get_waypoints_and_layers_cb,
575                                                gboolean show_layer_names )
576 {
577         GtkWidget *dialog = gtk_dialog_new_with_buttons ( title,
578                                                           VIK_GTK_WINDOW_FROM_LAYER(vl),
579                                                           GTK_DIALOG_DESTROY_WITH_PARENT,
580                                                           GTK_STOCK_CLOSE,
581                                                           GTK_RESPONSE_CLOSE,
582                                                           NULL );
583
584         GList *gl = get_waypoints_and_layers_cb ( vl, user_data );
585
586         vik_trw_layer_waypoint_list_internal ( dialog, gl, show_layer_names );
587
588         // Use response to close the dialog with tidy up
589         g_signal_connect ( G_OBJECT(dialog), "response", G_CALLBACK(waypoint_close_cb), gl );
590
591         gtk_widget_show_all ( dialog );
592         // Yes - set the size *AGAIN* - this time widgets are expanded nicely
593         gtk_window_resize ( GTK_WINDOW(dialog), show_layer_names ? 800 : 600, 400 );
594
595         // ATM lock out on dialog run - to prevent list contents being manipulated in other parts of the GUI whilst shown here.
596         gtk_dialog_run (GTK_DIALOG (dialog));
597         // Unfortunately seems subsequently opening the Waypoint Properties we can't interact with it until this dialog is closed
598         // Thus this dialog is then forcibly closed when opening the properties.
599
600         // Occassionally the 'View' doesn't update the viewport properly
601         //  viewport center + zoom is changed but the viewport isn't updated
602         // not sure why yet..
603 }