SF.net SVN: geany: [972] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Tue Nov 7 11:24:30 UTC 2006
Revision: 972
http://svn.sourceforge.net/geany/?rev=972&view=rev
Author: ntrel
Date: 2006-11-07 03:24:22 -0800 (Tue, 07 Nov 2006)
Log Message:
-----------
Don't close any tabs when quitting until all unsaved changes have
been accounted for; switch to each unsaved file before showing the
unsaved dialog.
Remove limit of ~256 chars for session filenames.
Make dialogs_show_unsaved_file() fail if the Save As dialog was
cancelled.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/dialogs.c
trunk/src/dialogs.h
trunk/src/keyfile.c
trunk/src/win32.c
trunk/src/win32.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-11-06 21:02:03 UTC (rev 971)
+++ trunk/ChangeLog 2006-11-07 11:24:22 UTC (rev 972)
@@ -1,3 +1,15 @@
+2006-11-07 Nick Treleaven <nick.treleaven at btinternet.com>
+
+ * src/win32.c, src/win32.h, src/callbacks.c, src/keyfile.c,
+ src/dialogs.c, src/dialogs.h:
+ Don't close any tabs when quitting until all unsaved changes have
+ been accounted for; switch to each unsaved file before showing the
+ unsaved dialog.
+ Remove limit of ~256 chars for session filenames.
+ Make dialogs_show_unsaved_file() fail if the Save As dialog was
+ cancelled.
+
+
2006-11-06 Enrico Tröger <enrico.troeger at uvena.de>
* data/filetypes.java, src/highlighting.c:
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2006-11-06 21:02:03 UTC (rev 971)
+++ trunk/src/callbacks.c 2006-11-07 11:24:22 UTC (rev 972)
@@ -84,79 +84,79 @@
}
-// wrapper function to abort exit process if cancel button is pressed
-gboolean
-on_exit_clicked (GtkWidget *widget, gpointer gdata)
+static gboolean check_no_unsaved()
{
- app->quitting = TRUE;
+ guint i;
- if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) > 0)
+ for (i = 0; i < doc_array->len; i++)
{
- guint i;
- gboolean has_dirty_editors = FALSE;
-
- for (i = 0; i < doc_array->len; i++)
+ if (doc_list[i].is_valid && doc_list[i].changed)
{
- if (doc_list[i].is_valid && doc_list[i].changed)
- {
- has_dirty_editors = TRUE;
- break;
- }
+ return FALSE;
}
- if (has_dirty_editors)
+ }
+ return TRUE; // no unsaved edits
+}
+
+
+static gboolean account_for_unsaved()
+{
+ gint p;
+
+ for (p = 0; p < gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); p++)
+ {
+ gint idx = document_get_n_idx(p);
+
+ if (doc_list[idx].changed)
{
- // there is the chance that the user cancel the exit process while closing open
- // files, so save the configuration(i.e. the list of open files) first
- configuration_save();
- if (on_close_all1_activate(NULL, NULL))
- {
- destroyapp(NULL, gdata);
- }
- else app->quitting = FALSE;
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook), p);
+ if (! dialogs_show_unsaved_file(idx))
+ return FALSE;
}
- else
- {
- if (app->pref_main_confirm_exit)
- {
- if (dialogs_show_question_full(GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
- _("Do you really want to quit?")) && on_close_all1_activate(NULL, NULL))
- {
- configuration_save();
- destroyapp(NULL, gdata);
- }
- else app->quitting = FALSE;
- }
- else
- {
- // there is the chance that the user cancel the exit process while closing open
- // files, so save the configuration(i.e. the list of open files) first
- configuration_save();
- if (on_close_all1_activate(NULL, NULL))
- {
- destroyapp(NULL, gdata);
- }
- else app->quitting = FALSE;
- }
- }
}
- else
+ return TRUE;
+}
+
+
+// should only be called from on_exit_clicked
+static void quit_app()
+{
+ guint i;
+
+ configuration_save();
+
+ // force close all tabs
+ for (i = 0; i < doc_array->len; i++)
{
- if (app->pref_main_confirm_exit)
+ if (doc_list[i].is_valid && doc_list[i].changed)
{
- if (dialogs_show_question_full(GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
- _("Do you really want to quit?")))
- {
- configuration_save();
- destroyapp(NULL, gdata);
- }
- else app->quitting = FALSE;
+ doc_list[i].changed = FALSE; // ignore changes (already asked user in on_exit_clicked)
}
- else
- {
- configuration_save();
- destroyapp(NULL, gdata);
- }
}
+ on_close_all1_activate(NULL, NULL);
+
+ destroyapp(NULL, NULL);
+}
+
+
+// wrapper function to abort exit process if cancel button is pressed
+gboolean
+on_exit_clicked (GtkWidget *widget, gpointer gdata)
+{
+ app->quitting = TRUE;
+
+ if (! check_no_unsaved())
+ {
+ if (account_for_unsaved())
+ quit_app();
+ }
+ else
+ if (! app->pref_main_confirm_exit ||
+ dialogs_show_question_full(GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
+ _("Do you really want to quit?")))
+ quit_app();
+
+ app->quitting = FALSE;
return TRUE;
}
Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c 2006-11-06 21:02:03 UTC (rev 971)
+++ trunk/src/dialogs.c 2006-11-07 11:24:22 UTC (rev 972)
@@ -246,13 +246,14 @@
#endif
-/* This shows the file selection dialog to save a file. */
-void dialogs_show_save_as()
+/* This shows the file selection dialog to save a file, returning TRUE if
+ * the file was saved. */
+gboolean dialogs_show_save_as()
{
#ifdef G_OS_WIN32
- win32_show_file_dialog(FALSE);
+ return win32_show_file_dialog(FALSE);
#else
- gint idx = document_get_cur_idx();
+ gint idx = document_get_cur_idx(), resp;
if (app->save_filesel == NULL)
{
@@ -299,7 +300,8 @@
}
// Run the dialog synchronously, pausing this function call
- gtk_dialog_run(GTK_DIALOG(app->save_filesel));
+ resp = gtk_dialog_run(GTK_DIALOG(app->save_filesel));
+ return (resp == GTK_RESPONSE_ACCEPT);
#endif
}
@@ -384,8 +386,7 @@
{
if (doc_list[idx].file_name == NULL)
{
- dialogs_show_save_as();
- ret = TRUE;
+ ret = dialogs_show_save_as();
}
else
// document_save_file() returns the status if the file could be saved
Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h 2006-11-06 21:02:03 UTC (rev 971)
+++ trunk/src/dialogs.h 2006-11-07 11:24:22 UTC (rev 972)
@@ -28,7 +28,7 @@
void dialogs_show_open_file();
/* This shows the file selection dialog to save a file. */
-void dialogs_show_save_as();
+gboolean dialogs_show_save_as();
gboolean dialogs_show_unsaved_file(gint idx);
Modified: trunk/src/keyfile.c
===================================================================
--- trunk/src/keyfile.c 2006-11-06 21:02:03 UTC (rev 971)
+++ trunk/src/keyfile.c 2006-11-07 11:24:22 UTC (rev 972)
@@ -58,7 +58,6 @@
gchar *configfile = g_strconcat(app->configdir, G_DIR_SEPARATOR_S, "geany.conf", NULL);
gchar *data, *tmp;
gchar *entry = g_malloc(14);
- gchar *fname = g_malloc0(256);
gchar **recent_files = g_new0(gchar*, app->mru_length + 1);
GtkTextBuffer *buffer;
GtkTextIter start, end;
@@ -212,10 +211,16 @@
idx = document_get_n_idx(i);
if (idx >= 0 && doc_list[idx].file_name)
{
+ gchar *fname;
+ filetype *ft = doc_list[idx].file_type;
+
+ if (ft == NULL) // can happen when saving a new file when quitting
+ ft = filetypes[GEANY_FILETYPES_ALL];
g_snprintf(entry, 13, "FILE_NAME_%d", j);
- g_snprintf(fname, 255, "%d:%d:%s", sci_get_current_position(doc_list[idx].sci),
- doc_list[idx].file_type->uid, doc_list[idx].file_name);
+ fname = g_strdup_printf("%d:%d:%s", sci_get_current_position(doc_list[idx].sci),
+ ft->uid, doc_list[idx].file_name);
g_key_file_set_string(config, "files", entry, fname);
+ g_free(fname);
j++;
}
}
@@ -247,7 +252,6 @@
g_key_file_free(config);
g_free(configfile);
g_free(entry);
- g_free(fname);
g_free(scribble_text);
}
Modified: trunk/src/win32.c
===================================================================
--- trunk/src/win32.c 2006-11-06 21:02:03 UTC (rev 971)
+++ trunk/src/win32.c 2006-11-07 11:24:22 UTC (rev 972)
@@ -83,7 +83,8 @@
}
-void win32_show_file_dialog(gboolean file_open)
+// return TRUE if the dialog was not cancelled.
+gboolean win32_show_file_dialog(gboolean file_open)
{
OPENFILENAME of;
gint retval;
@@ -134,7 +135,7 @@
win32_message_dialog(GTK_MESSAGE_ERROR, error);
}
g_free(fname);
- return;
+ return FALSE;
}
if (file_open)
@@ -169,6 +170,7 @@
document_save_file(idx, TRUE);
}
g_free(fname);
+ return (retval != 0);
}
Modified: trunk/src/win32.h
===================================================================
--- trunk/src/win32.h 2006-11-06 21:02:03 UTC (rev 971)
+++ trunk/src/win32.h 2006-11-07 11:24:22 UTC (rev 972)
@@ -26,7 +26,7 @@
void win32_show_pref_file_dialog(GtkEntry *item);
-void win32_show_file_dialog(gboolean file_open);
+gboolean win32_show_file_dialog(gboolean file_open);
void win32_show_font_dialog(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list