From: Linus Torvalds Date: Fri, 17 Aug 2012 17:28:19 +0000 (-0700) Subject: Merge branch 'change_quit2' of http://ambre.pingoured.fr/cgit/subsurface X-Git-Url: http://git.tdb.fi/?p=ext%2Fsubsurface.git;a=commitdiff_plain;h=589589c707262920a4c9ffc258704e30fa62b8fa;hp=9cb36850303f8ce6c031926512aad3fc2d800889 Merge branch 'change_quit2' of http://ambre.pingoured.fr/cgit/subsurface Pull patches to change behavior on exit from Pierre-Yves Chibon. Pierry-Yves explains: "When someone opens a file, change something in it and try to quit, the program asked whether the data should be saved. If 'Ok' then it shows the save-window and the user can choose to save the file or rename it. My habits in such case would be that since I opened a specific file, I want to save to that specific file, therefore, when I press 'Ok', I want it to save automatically to the file I opened. So I have been working on changes that do: - When a file has been opened by the user, save to this same file if the user is 'Ok' while closing. - Add a 'Cancel' option to the pop-up window that offers to save the file while closing. - Add a 'Save As' entry in the file menu." * 'change_quit2' of http://ambre.pingoured.fr/cgit/subsurface: Add a 'Save As' entry in the menu. Allow to cancel while trying to quit and the data was changed. When the file has been opened rely on it to save. --- diff --git a/info.c b/info.c index 846d51e..0ee4014 100644 --- a/info.c +++ b/info.c @@ -43,7 +43,7 @@ static int text_changed(const char *old, const char *new) (!old && strcmp("",new)); } -static char *skip_space(char *str) +static const char *skip_space(const char *str) { if (str) { while (isspace(*str)) @@ -60,13 +60,14 @@ static char *skip_space(char *str) * The "master" string is the string of the current dive - we only consider it * changed if the old string is either empty, or matches that master string. */ -static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp, char *master) +static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp, const char *master) { char *old = *textp; + const char *old_text; const gchar *new; GtkEntry *entry; - old = skip_space(old); + old_text = skip_space(old); master = skip_space(master); /* @@ -75,14 +76,17 @@ static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp, * we're editing another dive's info that already had a * valid value). */ - if (master && old) - if (strcmp(master, old)) + if (master && old_text) + if (strcmp(master, old_text)) return NULL; entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box))); new = gtk_entry_get_text(entry); while (isspace(*new)) new++; + /* If the master string didn't change, don't change other dives either! */ + if (!text_changed(master,new)) + return NULL; if (!text_changed(old,new)) return NULL; free(old);