]> git.street.me.uk Git - andy/viking.git/commitdiff
Extend file entry to enable running a callback on entry accepted.
authorRob Norris <rw_norris@hotmail.com>
Wed, 5 Nov 2014 00:36:09 +0000 (00:36 +0000)
committerRob Norris <rw_norris@hotmail.com>
Wed, 5 Nov 2014 00:36:09 +0000 (00:36 +0000)
src/uibuilder.c
src/vikfileentry.c
src/vikfileentry.h
src/vikgeoreflayer.c
src/viktrwlayer_wpwin.c

index b7c4ff817341a7e797436fb9c4f57eb50d8a868f..d79ca43531c8fb1565cecb173bf262dc9257485c 100644 (file)
@@ -188,7 +188,7 @@ GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data
     case VIK_LAYER_WIDGET_FILEENTRY:
       if ( param->type == VIK_LAYER_PARAM_STRING )
       {
-        rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, GPOINTER_TO_INT(param->widget_data));
+        rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, GPOINTER_TO_INT(param->widget_data), NULL, NULL);
         if ( vlpd.s )
           vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), vlpd.s );
       }
@@ -196,7 +196,7 @@ GtkWidget *a_uibuilder_new_widget ( VikLayerParam *param, VikLayerParamData data
     case VIK_LAYER_WIDGET_FOLDERENTRY:
       if ( param->type == VIK_LAYER_PARAM_STRING )
       {
-        rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, VF_FILTER_NONE);
+        rv = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, VF_FILTER_NONE, NULL, NULL);
         if ( vlpd.s )
           vik_file_entry_set_filename ( VIK_FILE_ENTRY(rv), vlpd.s );
       }
index 40097c4baf679e903721146acc99e257017bc089..e96e5ff00fc1ff08d878df19c0f36d630c06ad3c 100644 (file)
@@ -36,6 +36,8 @@ struct _VikFileEntry {
   GtkWidget *file_selector;
   GtkFileChooserAction action;
   gint filter_type;
+  VikFileEntryFunc on_finish;
+  gpointer user_data;
 };
 
 GType vik_file_entry_get_type (void)
@@ -63,14 +65,16 @@ GType vik_file_entry_get_type (void)
 }
 
 /**
- * Create a file entry with an optional file filter
+ * Create a file entry with an optional file filter and an optional callback on completion
  */
-GtkWidget *vik_file_entry_new (GtkFileChooserAction action, vf_filter_type filter_type)
+GtkWidget *vik_file_entry_new (GtkFileChooserAction action, vf_filter_type filter_type, VikFileEntryFunc cb, gpointer user_data )
 {
   VikFileEntry *vfe = VIK_FILE_ENTRY ( g_object_new ( VIK_FILE_ENTRY_TYPE, NULL ) );
   vfe->entry = gtk_entry_new ();
   vfe->button = gtk_button_new_with_label ( _("Browse...") );
   vfe->action = action;
+  vfe->on_finish = cb;
+  vfe->user_data = user_data;
   g_signal_connect_swapped ( G_OBJECT(vfe->button), "clicked", G_CALLBACK(choose_file), vfe );
 
   gtk_box_pack_start ( GTK_BOX(vfe), vfe->entry, TRUE, TRUE, 3 );
@@ -146,8 +150,11 @@ static void choose_file ( VikFileEntry *vfe )
     }
   }
 
-  if ( gtk_dialog_run ( GTK_DIALOG(vfe->file_selector) ) == GTK_RESPONSE_ACCEPT )
+  if ( gtk_dialog_run ( GTK_DIALOG(vfe->file_selector) ) == GTK_RESPONSE_ACCEPT ) {
     gtk_entry_set_text ( GTK_ENTRY (vfe->entry), gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER(vfe->file_selector) ) );
+    // Ideally this should only be called if the entry has changed, but ATM it's any time OK is selected.
+    if ( vfe->on_finish )
+      vfe->on_finish(vfe, vfe->user_data);
+  }
   gtk_widget_hide ( vfe->file_selector );
 }
-
index f069c66bdb26412857145bf6db5ae17ab39b3679..f4f40f64b31dea8502470bccdf1b1277f9389e4c 100644 (file)
@@ -51,7 +51,9 @@ typedef enum {
   VF_FILTER_LAST
 } vf_filter_type;
 
-GtkWidget *vik_file_entry_new (GtkFileChooserAction action, vf_filter_type filter_type);
+typedef void (*VikFileEntryFunc) (VikFileEntry *, gpointer);
+
+GtkWidget *vik_file_entry_new (GtkFileChooserAction action, vf_filter_type filter_type, VikFileEntryFunc cb, gpointer user_data);
 const gchar *vik_file_entry_get_filename ( VikFileEntry *vfe );
 void vik_file_entry_set_filename ( VikFileEntry *vfe, const gchar *filename );
 
index 5cb72f0f1a52375e26423d859b7713f60460a750..01a2e99fc7d49481c832297cde17c32062447b4a 100644 (file)
@@ -544,7 +544,7 @@ static gboolean georef_layer_dialog ( VikGeorefLayer *vgl, gpointer vp, GtkWindo
   gtk_widget_set_tooltip_text ( GTK_WIDGET(yspin), _("the scale of the map in the Y direction (meters per pixel)") );
 
   imagelabel = gtk_label_new ( _("Map Image:") );
-  imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE);
+  imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE, NULL, NULL);
 
   gtk_spin_button_set_value ( GTK_SPIN_BUTTON(ce_spin), vgl->corner.easting );
   gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cn_spin), vgl->corner.northing );
index f5e661348c68ef40cfdc5b2f7e82ecf513ec93d2..0e182850d8771fd96f0d742719548623eadb4438 100644 (file)
@@ -165,7 +165,7 @@ gchar *a_dialog_waypoint ( GtkWindow *parent, gchar *default_name, VikTrwLayer *
   descriptionentry = gtk_entry_new ();
 
   imagelabel = gtk_label_new (_("Image:"));
-  imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE);
+  imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE, NULL, NULL);
 
   {
     GtkCellRenderer *r;