aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crystfel_gui.c49
-rw-r--r--src/gui_peaksearch.c3
-rw-r--r--src/gui_project.c1
-rw-r--r--src/gui_project.h2
4 files changed, 53 insertions, 2 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index 9718e9f5..62337004 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -63,9 +63,37 @@ static void show_help(const char *s)
);
}
+static int confirm_exit(struct crystfelproject *proj)
+{
+ int r;
+ GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(proj->window),
+ 0,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ "Do you want to save the session?");
+ gtk_dialog_add_buttons(GTK_DIALOG(dialog),
+ "Save", GTK_RESPONSE_YES,
+ "Don't save", GTK_RESPONSE_NO,
+ "Cancel", GTK_RESPONSE_CANCEL,
+ NULL);
+ r = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ if ( r == GTK_RESPONSE_YES ) {
+ save_project(proj);
+ return 1;
+ }
+ if ( r == GTK_RESPONSE_NO ) return 1;
+ return 0;
+}
+
-static gboolean destroy_sig(GtkWidget *da, struct crystfelproject *proj)
+/* Main window destroyed */
+static gboolean delete_event_sig(GtkWidget *da, GdkEvent *event,
+ struct crystfelproject *proj)
{
+ if ( proj->unsaved ) {
+ if ( !confirm_exit(proj) ) return TRUE;
+ }
gtk_main_quit();
return FALSE;
}
@@ -180,6 +208,7 @@ static void finddata_response_sig(GtkWidget *dialog, gint resp,
type_id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(proj->type_combo));
add_files(proj, top, decode_matchtype(type_id));
+ proj->unsaved = 1;
proj->cur_frame = 0;
update_imageview(proj);
@@ -272,13 +301,24 @@ static gint finddata_sig(GtkWidget *widget, struct crystfelproject *proj)
}
+/* File->Quit */
static gint quit_sig(GtkWidget *widget, struct crystfelproject *proj)
{
+ if ( proj->unsaved ) {
+ if ( !confirm_exit(proj) ) return TRUE;
+ }
gtk_main_quit();
return FALSE;
}
+static gint save_sig(GtkWidget *widget, struct crystfelproject *proj)
+{
+ save_project(proj);
+ return FALSE;
+}
+
+
static gint first_frame_sig(GtkWidget *widget, struct crystfelproject *proj)
{
proj->cur_frame = 0;
@@ -362,6 +402,7 @@ static void add_menu_bar(struct crystfelproject *proj, GtkWidget *vbox)
const char *ui = "<ui> <menubar name=\"mainwindow\">"
"<menu name=\"file\" action=\"FileAction\">"
+ " <menuitem name=\"save\" action=\"SaveAction\" />"
" <menuitem name=\"quit\" action=\"QuitAction\" />"
"</menu>"
"<menu name=\"view\" action=\"ViewAction\" >"
@@ -377,6 +418,8 @@ static void add_menu_bar(struct crystfelproject *proj, GtkWidget *vbox)
GtkActionEntry entries[] = {
{ "FileAction", NULL, "_File", NULL, NULL, NULL },
+ { "SaveAction", GTK_STOCK_SAVE, "_Save", NULL, NULL,
+ G_CALLBACK(save_sig) },
{ "QuitAction", GTK_STOCK_QUIT, "_Quit", NULL, NULL,
G_CALLBACK(quit_sig) },
@@ -531,6 +574,7 @@ int main(int argc, char *argv[])
gtk_init(&argc, &argv);
+ proj.unsaved = 0;
proj.file_chooser = NULL;
proj.geom_chooser = NULL;
proj.geom_filename = NULL;
@@ -567,7 +611,8 @@ int main(int argc, char *argv[])
proj.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(proj.window), "CrystFEL");
- g_signal_connect(G_OBJECT(proj.window), "destroy", G_CALLBACK(destroy_sig),
+ g_signal_connect(G_OBJECT(proj.window), "delete-event",
+ G_CALLBACK(delete_event_sig),
&proj);
vbox = gtk_vbox_new(FALSE, 0.0);
diff --git a/src/gui_peaksearch.c b/src/gui_peaksearch.c
index 0fdea92d..5d4903cd 100644
--- a/src/gui_peaksearch.c
+++ b/src/gui_peaksearch.c
@@ -150,6 +150,7 @@ static void int_param_callback(GtkWidget *entry,
}
*(cbvals->pival) = val;
+ cbvals->proj->unsaved = 1;
update_peaks(cbvals->proj);
}
@@ -167,6 +168,7 @@ static void float_param_callback(GtkWidget *entry,
}
*(cbvals->pfval) = val;
+ cbvals->proj->unsaved = 1;
update_peaks(cbvals->proj);
}
@@ -356,6 +358,7 @@ static void peaksearch_algo_changed(GtkWidget *combo,
/* FIXME: Radii */
gtk_widget_show_all(proj->peak_vbox);
+ proj->unsaved = 1;
update_peaks(proj);
}
diff --git a/src/gui_project.c b/src/gui_project.c
index f201d591..65c06032 100644
--- a/src/gui_project.c
+++ b/src/gui_project.c
@@ -382,5 +382,6 @@ int save_project(struct crystfelproject *proj)
}
}
+ proj->unsaved = 0;
return 0;
}
diff --git a/src/gui_project.h b/src/gui_project.h
index 37b38e29..d7366f5f 100644
--- a/src/gui_project.h
+++ b/src/gui_project.h
@@ -75,6 +75,8 @@ struct crystfelproject {
GtkWidget *main_vbox;
GtkWidget *image_info;
+ int unsaved;
+
int cur_frame;
char *geom_filename;