SF.net SVN: geany:[4699] branches/sm/src/sm.c
statc at users.sourceforge.net
statc at xxxxx
Tue Feb 23 19:34:44 UTC 2010
Revision: 4699
http://geany.svn.sourceforge.net/geany/?rev=4699&view=rev
Author: statc
Date: 2010-02-23 19:34:44 +0000 (Tue, 23 Feb 2010)
Log Message:
-----------
Properly handle the case when "Preferences > General > Misc > Use project-based session files" check button is unchecked. An addition to r4693.
Modified Paths:
--------------
branches/sm/src/sm.c
Modified: branches/sm/src/sm.c
===================================================================
--- branches/sm/src/sm.c 2010-02-23 19:34:23 UTC (rev 4698)
+++ branches/sm/src/sm.c 2010-02-23 19:34:44 UTC (rev 4699)
@@ -72,6 +72,8 @@
static void sm_set_constant_props(SmcConn smcon);
static void sm_store_props(const char * argv0, const char * libsm_client_id);
static void sm_set_runtime_props(SmcConn smcon);
+static void sm_cmd_props();
+static void sm_files_props();
static void sm_save_yourself_callback(SmcConn smcon, SmPointer client_data,
int save_type, Bool shutdown, int interact_style, Bool fast);
@@ -388,8 +390,6 @@
static void sm_set_runtime_props(SmcConn smcon)
{
GArray * arr = g_array_new(FALSE, FALSE, sizeof(SmPropValue));
- GOptionEntry * optentry;
- SmPropValue val;
SmProp * prop;
SmProp restart_command_prop, clone_command_prop;
gint i;
@@ -397,7 +397,49 @@
g_array_append_val(arr, sm_program_val);
g_array_append_val(arr, sm_client_id_arg_val);
- /* Handle command-line options */
+ sm_cmd_props(arr);
+ sm_files_props(arr);
+
+ restart_command_prop.name = SmRestartCommand;
+ restart_command_prop.type = SmLISTofARRAY8;
+ restart_command_prop.num_vals = arr->len;
+ restart_command_prop.vals = (SmPropValue *)arr->data;
+ prop = &restart_command_prop;
+ SmcSetProperties(smcon, 1, &prop);
+
+ /* We should not specify client ID in SmCloneCommand,
+ * 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->len - 1;
+ clone_command_prop.vals = ((SmPropValue *)arr->data) + 1;
+ prop = &clone_command_prop;
+ SmcSetProperties(smcon, 1, &prop);
+
+ for (i = 2; i < (gint)arr->len; i++)
+ g_free(((SmPropValue *)arr->data)[i].value);
+ g_array_free(arr, TRUE);
+}
+
+
+/*
+ * Append SmPropValues containing Geany command line parameters to the specified array.
+ *
+ * @param arr An array of SmPropValues
+ *
+ * In order to determine which command line options to handle, global @c optentries_aux array
+ * is used.
+ *
+ * Each appended SmPropValue will store a dynamically allocated string, which must
+ * be freed by the caller with @c g_free().
+ */
+static void sm_cmd_props(GArray * arr)
+{
+ GOptionEntry *optentry;
+ SmPropValue val;
+ gint i;
+
for (i = 0, optentry = optentries; optentry->long_name; i++, optentry++)
{
if (optentries_aux[i].persist_upon_restart)
@@ -410,26 +452,45 @@
val.length = strlen(val.value);
g_array_append_val(arr, val);
}
- /* elements are freed after `arr' is used */
g_array_free(arr2, TRUE);
}
}
+}
- /* Handle opened files */
+
+/*
+ * Append SmPropValues containing command line options to restore opened files and project,
+ * to the specified array.
+ *
+ * @param arr An array of SmPropValues
+ *
+ * Each appended SmPropValue will store a dynamically allocated string, which must
+ * be freed by the caller with @c g_free().
+ */
+static void sm_files_props(GArray * arr)
+{
+ gboolean store_project = TRUE, store_files = TRUE;
+ SmPropValue val;
+ gint i;
+
if (cl_options.load_session)
- {
/* Files will be restored by Geany session management facilities. */
- }
- else if (app->project)
+ store_project = store_files = FALSE;
+
+ if (store_project && app->project)
{
- /* Files will be restored when the project is reopened. */
gchar * locale_filename = utils_get_locale_from_utf8(app->project->file_name);
val.value = g_strconcat("--project=", locale_filename, NULL);
val.length = strlen(val.value);
g_free(locale_filename);
g_array_append_val(arr, val);
+
+ if (project_prefs.project_session)
+ /* Files will be restored when the project is reopened. */
+ store_files = FALSE;
}
- else
+
+ if (store_files)
{
/* Specify file names in the command line */
const gint page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
@@ -452,27 +513,6 @@
}
}
}
-
- restart_command_prop.name = SmRestartCommand;
- restart_command_prop.type = SmLISTofARRAY8;
- restart_command_prop.num_vals = arr->len;
- restart_command_prop.vals = (SmPropValue *)arr->data;
- prop = &restart_command_prop;
- SmcSetProperties(smcon, 1, &prop);
-
- /* We should not specify client ID in SmCloneCommand,
- * 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->len - 1;
- clone_command_prop.vals = ((SmPropValue *)arr->data) + 1;
- prop = &clone_command_prop;
- SmcSetProperties(smcon, 1, &prop);
-
- for (i = 2; i < (gint)arr->len; i++)
- g_free(((SmPropValue *)arr->data)[i].value);
- g_array_free(arr, TRUE);
}
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