SF.net SVN: geany:[5045] branches/sm/src/sm.c
statc at users.sourceforge.net
statc at xxxxx
Thu Jun 17 19:50:28 UTC 2010
Revision: 5045
http://geany.svn.sourceforge.net/geany/?rev=5045&view=rev
Author: statc
Date: 2010-06-17 19:50:28 +0000 (Thu, 17 Jun 2010)
Log Message:
-----------
SM: pass current line and column for each file specified in restart command; correctly restore current file
Modified Paths:
--------------
branches/sm/src/sm.c
Modified: branches/sm/src/sm.c
===================================================================
--- branches/sm/src/sm.c 2010-06-17 17:28:28 UTC (rev 5044)
+++ branches/sm/src/sm.c 2010-06-17 19:50:28 UTC (rev 5045)
@@ -62,6 +62,8 @@
#include "document.h"
#include "utils.h"
#include "project.h"
+#include "editor.h"
+#include "sciwrappers.h"
static void ice_connection_watch(IceConn icecon, IcePointer client_data, Bool opening,
@@ -75,6 +77,7 @@
static void sm_set_runtime_props(SmcConn smcon);
static void sm_cmd_props(GArray * arr);
static void sm_files_props(GArray * arr);
+static void sm_file_prop(GArray * arr, gint notebook_page);
static void sm_save_yourself_callback(SmcConn smcon, SmPointer client_data,
int save_type, Bool shutdown, int interact_style, Bool fast);
@@ -470,7 +473,7 @@
static void sm_files_props(GArray * arr)
{
SmPropValue val;
- gint i, page_count;
+ gint i, current_page, page_count;
/* Unfortunately, we can't rely entirely on Geany session management facilities and have to pass
* active project and opened files even if they are probably, for example, stored in geany.conf */
@@ -492,20 +495,50 @@
val.value = g_strdup("--");
g_array_append_val(arr, val);
+ current_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
- /* NOTE: compare this cycle with the one inside
- * configuration_save_session_files() function in keyfile.c. */
- for (i = 0; i < page_count; i++)
+ for (i = 0; i < current_page; i++)
+ sm_file_prop(arr, i);
+ for (i = current_page + 1; i < page_count; i++)
+ sm_file_prop(arr, i);
+
+ /* specify current file last, so that its tab is opened after restore */
+ sm_file_prop(arr, current_page);
+}
+
+
+/*
+ * If a "real" file is opened in the specified tab, append an SmPropValue
+ * containing command line option to restore the file to the array.
+ *
+ * @param arr An array of SmPropValues
+ * @param notebook_page Notebook page number
+ *
+ * The appended SmPropValue (if any) will store a dynamically allocated string,
+ * which must be freed by the caller with @c g_free().
+ */
+static void sm_file_prop(GArray * arr, gint notebook_page)
+{
+ SmPropValue val;
+ GeanyDocument * doc = document_get_from_page(notebook_page);
+
+ if (doc && doc->real_path)
{
- GeanyDocument * doc = document_get_from_page(i);
- if (doc && doc->real_path)
- {
- gchar * locale_filename = utils_get_locale_from_utf8(doc->file_name);
- val.value = locale_filename;
- val.length = strlen(val.value);
- g_array_append_val(arr, val);
- }
+ gchar * locale_filename;
+ gchar * file_string;
+ gint pos;
+
+ locale_filename = utils_get_locale_from_utf8(doc->file_name);
+ pos = sci_get_current_position(doc->editor->sci);
+ file_string = g_strdup_printf("%s:%d:%d", locale_filename,
+ sci_get_line_from_position(doc->editor->sci, pos)+1,
+ sci_get_col_from_position(doc->editor->sci, pos));
+ g_free(locale_filename);
+
+ val.value = file_string;
+ val.length = strlen(val.value);
+ g_array_append_val(arr, val);
}
}
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