SF.net SVN: geany:[4548] branches/sm/src/sm.c

statc at users.sourceforge.net statc at xxxxx
Sun Jan 24 20:24:33 UTC 2010


Revision: 4548
          http://geany.svn.sourceforge.net/geany/?rev=4548&view=rev
Author:   statc
Date:     2010-01-24 20:24:33 +0000 (Sun, 24 Jan 2010)

Log Message:
-----------
Handle --no-session properly.

The previous commit allows us to change --no-session command line option
handling back to normal. The issue was described in a FIXME section
inside src/sm.c, the section is now deleted.

Modified Paths:
--------------
    branches/sm/src/sm.c

Modified: branches/sm/src/sm.c
===================================================================
--- branches/sm/src/sm.c	2010-01-24 20:24:13 UTC (rev 4547)
+++ branches/sm/src/sm.c	2010-01-24 20:24:33 UTC (rev 4548)
@@ -389,44 +389,6 @@
  */
 static void sm_set_runtime_props(SmcConn smcon)
 {
-	/*
-	 * FIXME: We have to specify '--no-session' command-line argument in commands.
-	 *
-	 * Reason:
-	 *
-	 *   Currently all Geany instances try to save session. Consider the
-	 *   following use case.
-	 *
-	 *   User creates two instances of geany, a "main" one (for example, using
-	 *   the main menu of his DE) and a "non-main" one typing 'geany --new-instance'
-	 *   in a terminal emulator. When this user logouts, session manager sends
-	 *   termination messages to Geany instances in unpredictable order. Geany
-	 *   session will be saved by the instance that was last to handle the
-	 *   message. Suppose that was the "non-main" Geany instance.
-	 *
-	 *   When the user logins again, session manager restores Geany instances,
-	 *   again in unpredictable order. If we do not supply '--no-session' argument,
-	 *   the "main" instance will catch the session stored by the "non-main"
-	 *   one, which is not desired behaviour.
-	 *
-	 * Drawbacks of the '--no-session' solution:
-	 *
-	 *   The "main" instance won't save Geany session as required.
-	 *
-	 * Possible fixes:
-	 *
-	 *   * Disable saving of Geany session for "non-main" Geany instances.
-	 *     Sounds sensible and applicable.
-	 *
-	 *   * Save session even when '--no-session' option is specified (i.e.,
-	 *     consider this options only when reading Geany session). Sounds
-	 *     non-applicable as the described behaviour does not match
-	 *     even the option's name.
-	 *
-	 *   * Create a separate option to be used when reading Geany session
-	 *     is needed and writing Geany session is forbidden. Sounds awkward.
-	 */
-
 	const gint page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
 	gint page;
 
@@ -440,20 +402,25 @@
 
 		/*
 		 * Allocate space for `page_count+4' elements:
-		 *   * tree elements for program name, client ID and '--no-session' option;
-		 *   * possibly one element for '--new-instance' option;
+		 *   * two elements for program name and client ID;
+		 *   * possibly one element for "--no-session" option;
+		 *   * possibly one element for "--new-instance" option;
 		 *   * max `page_count' elements for file paths.
 		 * Store the number of actually used elements in `arr_real_len'.
 		 */
 	arr = g_array_sized_new(FALSE, FALSE, sizeof(SmPropValue), page_count+4);
 	arr_real_len = 0;
 
-	((SmPropValue *)arr->data)[0] = sm_program_val;
-	((SmPropValue *)arr->data)[1] = sm_client_id_arg_val;
-	((SmPropValue *)arr->data)[2].length = 2; /* length of "-s" */
-	((SmPropValue *)arr->data)[2].value = "-s";
-	arr_real_len = 3;
+	((SmPropValue *)arr->data)[arr_real_len++] = sm_program_val;
+	((SmPropValue *)arr->data)[arr_real_len++] = sm_client_id_arg_val;
 
+	if (!cl_options.load_session)
+	{
+		val = ((SmPropValue *)arr->data) + arr_real_len++;
+		val->length = 2; /* length of "-s" */
+		val->value = "-s";
+	}
+
 #ifdef HAVE_SOCKET
 	if (cl_options.new_instance)
 	{
@@ -462,19 +429,32 @@
 		val->value = "-i";
 	}
 #endif
+
 	/* TODO: handle other command-line options */
 
-	for (page = 0; page < page_count; page++)
+	if (cl_options.load_session && !cl_options.new_instance)
 	{
-		GeanyDocument * doc = document_get_from_page(page);
-		if (doc->real_path)
+		/*
+		 * Files will be restored by Geany session management facilities.
+		 * NOTE: the condition matches the one inside configuration_save() function in keyfile.c.
+		 */
+	}
+	else
+	{
+		/* specify file names in the command line */
+		for (page = 0; page < page_count; page++)
 		{
-			val = ((SmPropValue *)arr->data) + arr_real_len++;
-			val->length = strlen(doc->real_path);
-			val->value = doc->real_path;
+			GeanyDocument * doc = document_get_from_page(page);
+			if (doc->real_path)
+			{
+				val = ((SmPropValue *)arr->data) + arr_real_len++;
+				val->length = strlen(doc->real_path);
+				val->value = doc->real_path;
+			}
 		}
 	}
 
+
 	restart_command_prop.name = SmRestartCommand;
 	restart_command_prop.type = SmLISTofARRAY8;
 	restart_command_prop.num_vals = arr_real_len;
@@ -487,7 +467,6 @@
 		 * so "remove" the corresponding element from `arr'.
 		 */
 	((SmPropValue *)arr->data)[1] = sm_program_val;
-
 	clone_command_prop.name = SmCloneCommand;
 	clone_command_prop.type = SmLISTofARRAY8;
 	clone_command_prop.num_vals = arr_real_len - 1;


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