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 );
}
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 );
}
GtkWidget *file_selector;
GtkFileChooserAction action;
gint filter_type;
+ VikFileEntryFunc on_finish;
+ gpointer user_data;
};
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 );
}
}
- 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 );
}
-
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 );
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 );
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;