aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-15 05:33:25 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-09-17 21:03:09 -0400
commitd3bf8af7fe2d862b2b4188332776f86cde00cbe6 (patch)
tree8922cdd54ec3f9914054267d847883978dcc4a0c
parent65d9d488452c6d13d8db7812dfd09be0e985876d (diff)
downloadsubsurface-d3bf8af7fe2d862b2b4188332776f86cde00cbe6.tar.gz
File Open now closes the previous file, first
This is a pretty significant semantic change - Open used to act more like Import; you added more dives to the divelist. With this change it instead acts more like the traditional File->Open in that it closes the previous file, first. The diff hides the minimalistic nature of the change - it seemed cleaner to move the file_open function around than to do a forward declaration of file_close. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--gtk-gui.c97
1 files changed, 50 insertions, 47 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index e5bdac9f2..5153ab21d 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -126,53 +126,6 @@ void report_error(GError* error)
}
}
-static void file_open(GtkWidget *w, gpointer data)
-{
- GtkWidget *dialog;
- GtkFileFilter *filter;
-
- dialog = gtk_file_chooser_dialog_new("Open File",
- GTK_WINDOW(main_window),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
-
- filter = gtk_file_filter_new();
- gtk_file_filter_add_pattern(filter, "*.xml");
- gtk_file_filter_add_pattern(filter, "*.XML");
- gtk_file_filter_add_pattern(filter, "*.sda");
- gtk_file_filter_add_pattern(filter, "*.SDA");
- gtk_file_filter_add_mime_type(filter, "text/xml");
- gtk_file_filter_set_name(filter, "XML file");
- gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
-
- if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
- GSList *filenames, *fn_glist;
- char *filename;
- filenames = fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
-
- GError *error = NULL;
- while(filenames != NULL) {
- filename = filenames->data;
- parse_file(filename, &error);
- if (error != NULL)
- {
- report_error(error);
- g_error_free(error);
- error = NULL;
- }
-
- g_free(filename);
- filenames = g_slist_next(filenames);
- }
- g_slist_free(fn_glist);
- report_dives(FALSE);
- }
- gtk_widget_destroy(dialog);
-}
-
static void file_save_as(GtkWidget *w, gpointer data)
{
GtkWidget *dialog;
@@ -307,6 +260,56 @@ static void file_close(GtkWidget *w, gpointer data)
show_dive_info(NULL);
}
+static void file_open(GtkWidget *w, gpointer data)
+{
+ GtkWidget *dialog;
+ GtkFileFilter *filter;
+
+ /* first, close the existing file, if any */
+ file_close(w, data);
+
+ dialog = gtk_file_chooser_dialog_new("Open File",
+ GTK_WINDOW(main_window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_add_pattern(filter, "*.xml");
+ gtk_file_filter_add_pattern(filter, "*.XML");
+ gtk_file_filter_add_pattern(filter, "*.sda");
+ gtk_file_filter_add_pattern(filter, "*.SDA");
+ gtk_file_filter_add_mime_type(filter, "text/xml");
+ gtk_file_filter_set_name(filter, "XML file");
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+ GSList *filenames, *fn_glist;
+ char *filename;
+ filenames = fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
+
+ GError *error = NULL;
+ while(filenames != NULL) {
+ filename = filenames->data;
+ parse_file(filename, &error);
+ if (error != NULL)
+ {
+ report_error(error);
+ g_error_free(error);
+ error = NULL;
+ }
+
+ g_free(filename);
+ filenames = g_slist_next(filenames);
+ }
+ g_slist_free(fn_glist);
+ report_dives(FALSE);
+ }
+ gtk_widget_destroy(dialog);
+}
+
static gboolean on_delete(GtkWidget* w, gpointer data)
{
/* Make sure to flush any modified dive data */