+ view = gtk_tree_view_new();
+ renderer = gtk_cell_renderer_text_new();
+ column_runner = 0;
+ GtkTreeViewColumn *column;
+ // NB could allow columns to be shifted around by doing this after each new
+ // gtk_tree_view_column_set_reorderable ( column, TRUE );
+ // However I don't think is that useful, so I haven't put it in
+ column = gtk_tree_view_column_new_with_attributes( _("Name"), renderer, "text", column_runner, NULL);
+ gtk_tree_view_column_set_sort_column_id (column, column_runner);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
+
+ column_runner++;
+ column = gtk_tree_view_column_new_with_attributes( _("Feature"), renderer, "text", column_runner, NULL);
+ gtk_tree_view_column_set_sort_column_id (column, column_runner);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
+
+ column_runner++;
+ column = gtk_tree_view_column_new_with_attributes( _("Lat/Lon"), renderer, "text", column_runner, NULL);
+ gtk_tree_view_column_set_sort_column_id (column, column_runner);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
+
+ gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));
+ gtk_tree_selection_set_mode( gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
+ multiple_selection_allowed ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_BROWSE );
+ g_object_unref(store);
+
+ GtkWidget *scrolledwindow = gtk_scrolled_window_new ( NULL, NULL );
+ gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolledwindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
+ gtk_container_add ( GTK_CONTAINER(scrolledwindow), view );
+
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwindow, TRUE, TRUE, 0);
+
+ // Ensure a reasonable number of items are shown, but let the width be automatically sized
+ gtk_widget_set_size_request ( dialog, -1, 400) ;
+ gtk_widget_show_all ( dialog );
+
+ if ( response_w )
+ gtk_widget_grab_focus ( response_w );
+
+ while ( gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT )
+ {
+ GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+ GList *selected_geonames = NULL;
+
+ // Possibily not the fastest method but we don't have thousands of entries to process...
+ if ( gtk_tree_model_get_iter_first( GTK_TREE_MODEL(store), &iter) ) {
+ do {
+ if ( gtk_tree_selection_iter_is_selected ( selection, &iter ) ) {
+ // For every selected item,
+ // compare the name from the displayed view to every geoname entry to find the geoname this selection represents
+ gchar* name;
+ gtk_tree_model_get (GTK_TREE_MODEL(store), &iter, 0, &name, -1 );
+ // I believe the name of these items to be always unique
+ geoname_runner = geonames;
+ while ( geoname_runner ) {
+ if ( !strcmp ( ((found_geoname*)geoname_runner->data)->name, name ) ) {
+ found_geoname *copied = copy_found_geoname(geoname_runner->data);
+ selected_geonames = g_list_prepend(selected_geonames, copied);
+ break;
+ }
+ geoname_runner = g_list_next(geoname_runner);
+ }
+ }
+ }
+ while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL(store), &iter ) );
+ }
+
+ if (selected_geonames)
+ {
+ gtk_widget_destroy ( dialog );
+ return selected_geonames;
+ }
+ a_dialog_error_msg(parent, _("Nothing was selected"));
+ }
+ gtk_widget_destroy ( dialog );
+ return NULL;