From 4bb477999843f1c14d81672b83607c7394e740b5 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 1 Sep 2020 12:48:40 +0200 Subject: Keep a separate record of unit cell file There seems to be no way to get a clear answer from the GtkFileChooser about whether a file is actually set. Instead, it now keeps a separate record which is set to NULL when the "clear" button is pressed, and set to the filename from the GtkFileChooserButton on the "file-set" signal. --- src/crystfelindexingopts.c | 20 ++++++++++++++++---- src/crystfelindexingopts.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/crystfelindexingopts.c b/src/crystfelindexingopts.c index c2fde290..2f4344a7 100644 --- a/src/crystfelindexingopts.c +++ b/src/crystfelindexingopts.c @@ -228,6 +228,7 @@ static GtkWidget *make_indexing_methods(CrystFELIndexingOpts *io) static void cell_file_clear_sig(GtkButton *buton, CrystFELIndexingOpts *io) { + io->cell_file = NULL; gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(io->cell_chooser), "(none)"); } @@ -253,6 +254,16 @@ static void check_cell_toggle_sig(GtkToggleButton *togglebutton, } +static void cell_file_set_sig(GtkFileChooserButton *widget, + CrystFELIndexingOpts *io) +{ + gchar *filename; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); + g_free(io->cell_file); + io->cell_file = filename; +} + + static GtkWidget *indexing_parameters(CrystFELIndexingOpts *io) { GtkWidget *box; @@ -279,6 +290,8 @@ static GtkWidget *indexing_parameters(CrystFELIndexingOpts *io) TRUE); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(io->cell_chooser), FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(io->cell_chooser), "file-set", + G_CALLBACK(cell_file_set_sig), io); button = gtk_button_new_from_icon_name("edit-clear", GTK_ICON_SIZE_BUTTON); g_signal_connect(G_OBJECT(button), "clicked", @@ -420,6 +433,8 @@ GtkWidget *crystfel_indexing_opts_new() io = g_object_new(CRYSTFEL_TYPE_INDEXING_OPTS, NULL); + io->cell_file = NULL; + gtk_notebook_append_page(GTK_NOTEBOOK(io), indexing_parameters(io), gtk_label_new("Indexing")); @@ -435,10 +450,7 @@ GtkWidget *crystfel_indexing_opts_new() char *crystfel_indexing_opts_get_cell_file(CrystFELIndexingOpts *opts) { - gchar *filename; - - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(opts->cell_chooser)); - return filename; + return safe_strdup(opts->cell_file); } diff --git a/src/crystfelindexingopts.h b/src/crystfelindexingopts.h index 58ba39bf..197f8863 100644 --- a/src/crystfelindexingopts.h +++ b/src/crystfelindexingopts.h @@ -54,6 +54,7 @@ struct _crystfelindexingopts GtkNotebook parent_instance; /*< private >*/ + char *cell_file; GtkWidget *cell_chooser; GtkWidget *auto_indm; GtkWidget *indm_chooser; -- cgit v1.2.3