SF.net SVN: geany:[4483] branches/sm
ntrel at users.sourceforge.net
ntrel at xxxxx
Tue Dec 8 16:26:11 UTC 2009
Revision: 4483
http://geany.svn.sourceforge.net/geany/?rev=4483&view=rev
Author: ntrel
Date: 2009-12-08 16:26:11 +0000 (Tue, 08 Dec 2009)
Log Message:
-----------
Refactor quitting code into main_save() and main_finalize() (patch by
Eugene Arshinov, thanks).
Modified Paths:
--------------
branches/sm/ChangeLog
branches/sm/src/callbacks.c
branches/sm/src/document.c
branches/sm/src/document.h
branches/sm/src/main.c
branches/sm/src/main.h
branches/sm/src/project.c
branches/sm/src/project.h
Modified: branches/sm/ChangeLog
===================================================================
--- branches/sm/ChangeLog 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/ChangeLog 2009-12-08 16:26:11 UTC (rev 4483)
@@ -1,8 +1,12 @@
2009-12-08 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/Makefile.am, configure.in, wscript:
- Apply patch from Eugene Arshinov to detect libSM (X session management
- library, thanks).
+ Detect libSM X session management library (patch by Eugene Arshinov,
+ thanks).
+ * src/project.c, src/project.h, src/callbacks.c, src/document.c,
+ src/document.h, src/main.c, src/main.h:
+ Refactor quitting code into main_save() and main_finalize() (patch by
+ Eugene Arshinov, thanks).
2009-12-08 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: branches/sm/src/callbacks.c
===================================================================
--- branches/sm/src/callbacks.c 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/src/callbacks.c 2009-12-08 16:26:11 UTC (rev 4483)
@@ -90,21 +90,6 @@
/*static gboolean switch_tv_notebook_page = FALSE; */
-static gboolean check_no_unsaved(void)
-{
- guint i;
-
- for (i = 0; i < documents_array->len; i++)
- {
- if (documents[i]->is_valid && documents[i]->changed)
- {
- return FALSE;
- }
- }
- return TRUE; /* no unsaved edits */
-}
-
-
/* 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(GeanyDocument *doc)
@@ -117,42 +102,26 @@
}
-/* should only be called from on_exit_clicked */
-static void quit_app(void)
-{
- configuration_save();
-
- if (app->project != NULL)
- project_close(FALSE); /* save project session files */
-
- document_close_all();
-
- main_status.quitting = TRUE;
-
- main_quit();
-}
-
-
/* wrapper function to abort exit process if cancel button is pressed */
gboolean
on_exit_clicked (GtkWidget *widget, gpointer gdata)
{
+ gboolean quit = TRUE;
+
main_status.quitting = TRUE;
- if (! check_no_unsaved())
+ if (!document_any_unsaved() && prefs.confirm_exit)
{
- if (document_account_for_unsaved())
- {
- quit_app();
- return FALSE;
- }
- }
- else
- if (! prefs.confirm_exit ||
- dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
+ /* Ask for confirmation only if there are no unsaved documents.
+ * If any documents are unsaved, user will be asked in main_save(). */
+ if (!dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL,
_("Do you really want to quit?")))
+ quit = FALSE;
+ }
+
+ if (quit && main_save(TRUE))
{
- quit_app();
+ main_finalize();
return FALSE;
}
@@ -239,7 +208,7 @@
on_close_all1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- document_close_all();
+ document_close_all(FALSE);
}
@@ -1824,7 +1793,7 @@
on_project_close1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- project_close(TRUE);
+ project_close(TRUE, TRUE);
}
Modified: branches/sm/src/document.c
===================================================================
--- branches/sm/src/document.c 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/src/document.c 2009-12-08 16:26:11 UTC (rev 4483)
@@ -2850,6 +2850,18 @@
}
+/* @return TRUE if there are some unsaved documents */
+gboolean document_any_unsaved(void)
+{
+ guint i;
+
+ foreach_document(i)
+ if (documents[i]->changed)
+ return TRUE;
+ return FALSE;
+}
+
+
/* @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. */
@@ -2904,13 +2916,12 @@
}
-gboolean document_close_all(void)
+gboolean document_close_all(gboolean force)
{
- if (! document_account_for_unsaved())
+ if (!force && !document_account_for_unsaved())
return FALSE;
force_close_all();
-
return TRUE;
}
Modified: branches/sm/src/document.h
===================================================================
--- branches/sm/src/document.h 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/src/document.h 2009-12-08 16:26:11 UTC (rev 4483)
@@ -196,9 +196,11 @@
gboolean document_close(GeanyDocument *doc);
+gboolean document_any_unsaved(void);
+
gboolean document_account_for_unsaved(void);
-gboolean document_close_all(void);
+gboolean document_close_all(gboolean force);
GeanyDocument *document_clone(GeanyDocument *old_doc, const gchar *utf8_filename);
Modified: branches/sm/src/main.c
===================================================================
--- branches/sm/src/main.c 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/src/main.c 2009-12-08 16:26:11 UTC (rev 4483)
@@ -1095,10 +1095,28 @@
}
-void main_quit()
+gboolean main_save(gboolean interactive)
{
+ if (interactive && !document_account_for_unsaved())
+ return FALSE;
+
+ configuration_save();
+
+ if (app->project)
+ project_save(FALSE);
+
+ return TRUE;
+}
+
+
+void main_finalize()
+{
geany_debug("Quitting...");
+ if (app->project)
+ project_close(FALSE, FALSE);
+ document_close_all(TRUE);
+
#ifdef HAVE_SOCKET
socket_finalize();
#endif
Modified: branches/sm/src/main.h
===================================================================
--- branches/sm/src/main.h 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/src/main.h 2009-12-08 16:26:11 UTC (rev 4483)
@@ -56,8 +56,10 @@
gchar *main_get_argv_filename(const gchar *filename);
-void main_quit(void);
+gboolean main_save(gboolean interactive);
+void main_finalize(void);
+
gboolean main_handle_filename(const gchar *locale_filename);
void main_reload_configuration(void);
Modified: branches/sm/src/project.c
===================================================================
--- branches/sm/src/project.c 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/src/project.c 2009-12-08 16:26:11 UTC (rev 4483)
@@ -335,15 +335,22 @@
}
+void project_save(gboolean emit_signal)
+{
+ write_config(emit_signal);
+}
+
+
/* open_default will make function reload default session files on close */
-void project_close(gboolean open_default)
+void project_close(gboolean save_config, gboolean open_default)
{
g_return_if_fail(app->project != NULL);
ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);
/* use write_config() to save project session files */
- write_config(FALSE);
+ if (save_config)
+ write_config(FALSE);
/* remove project filetypes build entries */
if (app->project->build_filetypes_list != NULL)
@@ -370,7 +377,7 @@
if (project_prefs.project_session)
{
/* close all existing tabs first */
- document_close_all();
+ document_close_all(FALSE);
/* after closing all tabs let's open the tabs found in the default config */
if (open_default && cl_options.load_session)
@@ -601,7 +608,7 @@
_("Do you want to close it before proceeding?"),
_("The '%s' project is already open."), app->project->name))
{
- project_close(FALSE);
+ project_close(TRUE, FALSE);
return TRUE;
}
else
@@ -976,7 +983,7 @@
/* save current (non-project) session (it could has been changed since program startup) */
configuration_save_default_session();
/* now close all open files */
- document_close_all();
+ document_close_all(FALSE);
/* read session files so they can be opened with configuration_open_files() */
configuration_load_session_files(config, FALSE);
}
Modified: branches/sm/src/project.h
===================================================================
--- branches/sm/src/project.h 2009-12-08 16:06:57 UTC (rev 4482)
+++ branches/sm/src/project.h 2009-12-08 16:26:11 UTC (rev 4483)
@@ -68,8 +68,10 @@
void project_open(void);
-void project_close(gboolean open_default);
+void project_save(gboolean emit_signal);
+void project_close(gboolean save_config, gboolean open_default);
+
void project_properties(void);
gboolean project_ask_close(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