Revision: 2526 http://geany.svn.sourceforge.net/geany/?rev=2526&view=rev Author: ntrel Date: 2008-04-24 07:33:12 -0700 (Thu, 24 Apr 2008)
Log Message: ----------- Move Close All functions to document.c. Add document_account_for_unsaved().
Modified Paths: -------------- trunk/ChangeLog trunk/src/callbacks.c trunk/src/document.c trunk/src/document.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-04-24 14:17:11 UTC (rev 2525) +++ trunk/ChangeLog 2008-04-24 14:33:12 UTC (rev 2526) @@ -11,6 +11,11 @@ * src/utils.c: Make utils_get_file_list() use a case-insensitive search so that the file browser lists files and directories in a more intuitive order. + * src/project.c: + Fix build because of wrong document_close_all() usage - oops. + * src/callbacks.c, src/document.c, src/document.h: + Move Close All functions to document.c. + Add document_account_for_unsaved().
2008-04-23 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2008-04-24 14:17:11 UTC (rev 2525) +++ trunk/src/callbacks.c 2008-04-24 14:33:12 UTC (rev 2526) @@ -105,25 +105,6 @@ }
-/* @return TRUE if all files were saved or had their changes discarded. */ -static gboolean account_for_unsaved(void) -{ - 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) - { - if (! dialogs_show_unsaved_file(idx)) - return FALSE; - } - } - return TRUE; -} - - /* set editor_info.click_pos to the current cursor position if insert_callback_from_menu is TRUE * to prevent invalid cursor positions which can cause segfaults */ static void verify_click_pos(gint idx) @@ -136,29 +117,6 @@ }
-static void force_close_all() -{ - guint i, len = doc_array->len; - - main_status.closing_all = TRUE; - - /* all documents should be accounted for, so ignore any changes */ - for (i = 0; i < len; i++) - { - if (doc_list[i].is_valid && doc_list[i].changed) - { - doc_list[i].changed = FALSE; - } - } - while (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) > 0) - { - document_remove(0); - } - - main_status.closing_all = FALSE; -} - - /* should only be called from on_exit_clicked */ static void quit_app(void) { @@ -167,7 +125,7 @@ if (app->project != NULL) project_close(FALSE); /* save project session files */
- force_close_all(); + document_close_all();
main_quit(); } @@ -181,7 +139,7 @@
if (! check_no_unsaved()) { - if (account_for_unsaved()) + if (document_account_for_unsaved()) { quit_app(); return FALSE; @@ -267,23 +225,11 @@ }
-static gboolean close_all(void) -{ - if (! account_for_unsaved()) - return FALSE; - - force_close_all(); - - tm_workspace_update(TM_WORK_OBJECT(app->tm_workspace), TRUE, TRUE, FALSE); - return TRUE; -} - - void on_close_all1_activate (GtkMenuItem *menuitem, gpointer user_data) { - close_all(); + document_close_all(); }
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2008-04-24 14:17:11 UTC (rev 2525) +++ trunk/src/document.c 2008-04-24 14:33:12 UTC (rev 2526) @@ -516,14 +516,6 @@ }
-void document_close_all() -{ - /* the code is in callbacks.c because when quitting, checking for changes - * has to be done before saving the session */ - on_close_all1_activate(NULL, NULL); -} - - /** * Remove the given notebook tab at @a page_num and clear all related information * in the document list. @@ -2724,3 +2716,68 @@ }
+/* @note If successful, this should always be followed up with a call to + * document_close_all(). + * @return TRUE if all files were saved or had their changes discarded. */ +gboolean document_account_for_unsaved(void) +{ + gint p; + guint i, len = doc_array->len; + + 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) + { + if (! dialogs_show_unsaved_file(idx)) + return FALSE; + } + } + /* all documents should now be accounted for, so ignore any changes */ + for (i = 0; i < len; i++) + { + if (doc_list[i].is_valid && doc_list[i].changed) + { + doc_list[i].changed = FALSE; + } + } + return TRUE; +} + + +static void force_close_all(void) +{ + guint i, len = doc_array->len; + + /* check all documents have been accounted for */ + for (i = 0; i < len; i++) + { + if (doc_list[i].is_valid) + { + g_return_if_fail(!doc_list[i].changed); + } + } + main_status.closing_all = TRUE; + + while (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) > 0) + { + document_remove(0); + } + + main_status.closing_all = FALSE; +} + + +gboolean document_close_all(void) +{ + if (! document_account_for_unsaved()) + return FALSE; + + force_close_all(); + + tm_workspace_update(TM_WORK_OBJECT(app->tm_workspace), TRUE, TRUE, FALSE); + return TRUE; +} + +
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2008-04-24 14:17:11 UTC (rev 2525) +++ trunk/src/document.h 2008-04-24 14:33:12 UTC (rev 2526) @@ -151,11 +151,13 @@ void document_apply_update_prefs(gint idx);
-void document_close_all(); - gboolean document_remove(guint page_num);
+gboolean document_account_for_unsaved(void);
+gboolean document_close_all(void); + + gint document_new_file_if_non_open();
gint document_new_file(const gchar *filename, filetype *ft, const gchar *text);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.