Change behavior for the existing filename

Previously we always picked the last file that was openend as the file
name to save to. That seems counterintuitive when importing files or when
opening multiple files. Especially if Subsurface was executed without a
file on the command line and we are using the default file.

Now we only remember a file name if it was the first one to ever be
openend or if it was used in save-as.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-09-10 12:27:00 -07:00
parent b73f29fea3
commit 78c5aa9f07
4 changed files with 9 additions and 10 deletions

2
dive.h
View file

@ -379,7 +379,7 @@ static inline struct dive *get_dive(unsigned int nr)
extern void parse_xml_init(void);
extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error);
extern void set_filename(const char *filename);
extern void set_filename(const char *filename, gboolean force);
extern void parse_file(const char *filename, GError **error);

View file

@ -233,7 +233,7 @@ static void file_save_as(GtkWidget *w, gpointer data)
if (filename){
save_dives(filename);
set_filename(filename);
set_filename(filename, TRUE);
g_free(filename);
mark_divelist_changed(FALSE);
}
@ -1419,11 +1419,11 @@ void update_progressbar_text(progressbar_t *progress, const char *text)
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), text);
}
void set_filename(const char *filename)
void set_filename(const char *filename, gboolean force)
{
if (existing_filename)
free(existing_filename);
existing_filename = NULL;
if (!force && existing_filename)
return;
free(existing_filename);
if (filename)
existing_filename = strdup(filename);
}

2
main.c
View file

@ -243,7 +243,7 @@ int main(int argc, char **argv)
parse_file(filename, &error);
/* don't report errors - this file may not exist, but make
sure we remember this as the filename in use */
set_filename(filename);
set_filename(filename, FALSE);
}
report_dives(imported);

View file

@ -1475,9 +1475,8 @@ void parse_xml_buffer(const char *url, const char *buffer, int size, GError **er
}
return;
}
/* we assume that the last (or only) filename passed as argument is a
* great filename to use as default when saving the dives */
set_filename(url);
/* remember, if necessary, that this is the filename to store to */
set_filename(url, FALSE);
reset_all();
dive_start();
#ifdef XSLT