Revision: 4549 http://geany.svn.sourceforge.net/geany/?rev=4549&view=rev Author: statc Date: 2010-01-24 20:24:52 +0000 (Sun, 24 Jan 2010)
Log Message: ----------- Use `GeanyDocument.file_name's instead of `GeanyDocument.real_path's in restart command like Geany session management facilities do.
Modified Paths: -------------- branches/sm/src/sm.c
Modified: branches/sm/src/sm.c =================================================================== --- branches/sm/src/sm.c 2010-01-24 20:24:33 UTC (rev 4548) +++ branches/sm/src/sm.c 2010-01-24 20:24:52 UTC (rev 4549) @@ -59,6 +59,7 @@ #include "main.h" /* for cl_options */ #include "ui_utils.h" /* access main_widgets.notebook to iterate over opened docs */ #include "document.h" +#include "utils.h"
static void ice_connection_watch(IceConn icecon, IcePointer client_data, Bool opening, @@ -390,26 +391,31 @@ static void sm_set_runtime_props(SmcConn smcon) { const gint page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); - gint page;
GArray * arr; - gint arr_real_len; + gint arr_real_len, arr_filenames_begin;
SmProp restart_command_prop, clone_command_prop; SmPropValue * val; SmProp * prop; + gint i;
/* - * Allocate space for `page_count+4' elements: + * Allocate space for `page_count+5' elements: * * two elements for program name and client ID; * * possibly one element for "--no-session" option; * * possibly one element for "--new-instance" option; + * * possible one element for "--" to separate options and filenames; * * max `page_count' elements for file paths. - * Store the number of actually used elements in `arr_real_len'. + * The number of actually used elements is saved in `arr_real_len'. + * Variable `arr_filenames_begin' stores the index in the array where + * the list of filenames begin. If there are no filenames in `arr', + * the value is -1. */ - arr = g_array_sized_new(FALSE, FALSE, sizeof(SmPropValue), page_count+4); + arr = g_array_sized_new(FALSE, FALSE, sizeof(SmPropValue), page_count + 5); arr_real_len = 0; + arr_filenames_begin = -1;
((SmPropValue *)arr->data)[arr_real_len++] = sm_program_val; ((SmPropValue *)arr->data)[arr_real_len++] = sm_client_id_arg_val; @@ -441,15 +447,29 @@ } else { - /* specify file names in the command line */ - for (page = 0; page < page_count; page++) + /* Specify file names in the command line */ + + val = ((SmPropValue *)arr->data) + arr_real_len++; + val->length = 2; /* length of "--" */ + val->value = "--"; + + arr_filenames_begin = arr_real_len; + + /* + * NOTE: compare this cycle with the one inside + * configuration_save_session_files() function in keyfile.c. + */ + for (i = 0; i < page_count; i++) { - GeanyDocument * doc = document_get_from_page(page); - if (doc->real_path) + GeanyDocument * doc = document_get_from_page(i); + if (doc && doc->real_path) { + /* this string will be freed when `arr' is no longer needed */ + gchar * locale_filename = utils_get_locale_from_utf8(doc->file_name); + val = ((SmPropValue *)arr->data) + arr_real_len++; - val->length = strlen(doc->real_path); - val->value = doc->real_path; + val->length = strlen(locale_filename); + val->value = locale_filename; } } } @@ -470,10 +490,14 @@ clone_command_prop.name = SmCloneCommand; clone_command_prop.type = SmLISTofARRAY8; clone_command_prop.num_vals = arr_real_len - 1; - clone_command_prop.vals = (SmPropValue *)arr->data + 1; + clone_command_prop.vals = ((SmPropValue *)arr->data) + 1; prop = &clone_command_prop; SmcSetProperties(smcon, 1, &prop);
+ + if (arr_filenames_begin != -1) + for (i = arr_filenames_begin; i < arr_real_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.