Revision: 1888 http://geany.svn.sourceforge.net/geany/?rev=1888&view=rev Author: ntrel Date: 2007-09-18 09:04:22 -0700 (Tue, 18 Sep 2007)
Log Message: ----------- Save and restore the current notebook page when quitting.
Modified Paths: -------------- trunk/ChangeLog trunk/src/keyfile.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-09-17 16:33:17 UTC (rev 1887) +++ trunk/ChangeLog 2007-09-18 16:04:22 UTC (rev 1888) @@ -1,3 +1,9 @@ +2007-09-18 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com> + + * src/keyfile.c: + Save and restore the current notebook page when quitting. + + 2007-09-17 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/build.h, src/plugindata.h, src/plugins.c:
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2007-09-17 16:33:17 UTC (rev 1887) +++ trunk/src/keyfile.c 2007-09-18 16:04:22 UTC (rev 1888) @@ -55,6 +55,7 @@
static gchar *scribble_text = NULL; static GPtrArray *session_files = NULL; +static gint session_notebook_page; static gint hpan_position; static gint vpan_position;
@@ -88,54 +89,54 @@
static void save_session_files(GKeyFile *config) { - gint idx; - gboolean have_session_files; + gint idx, npage; gchar *tmp; - gchar *entry = g_malloc(14); + gchar entry[14]; guint i = 0, j = 0, max;
- if (cl_options.load_session) + if (! cl_options.load_session) + return; + + npage = gtk_notebook_get_current_page(GTK_NOTEBOOK(app->notebook)); + g_key_file_set_integer(config, "files", "current_page", npage); + + // store the filenames to reopen them the next time + max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); + for (i = 0; i < max; i++) { - // store the filenames to reopen them the next time - max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); - for(i = 0; i < max; i++) + idx = document_get_n_idx(i); + if (idx >= 0 && doc_list[idx].file_name) { - idx = document_get_n_idx(i); - if (idx >= 0 && doc_list[idx].file_name) - { - gchar *fname; - filetype *ft = doc_list[idx].file_type; + gchar *fname; + filetype *ft = doc_list[idx].file_type;
- if (ft == NULL) // can happen when saving a new file when quitting - ft = filetypes[GEANY_FILETYPES_ALL]; - g_snprintf(entry, 13, "FILE_NAME_%d", j); - fname = g_strdup_printf("%d:%d:%s", sci_get_current_position(doc_list[idx].sci), - ft->uid, doc_list[idx].file_name); - g_key_file_set_string(config, "files", entry, fname); - g_free(fname); - j++; - } + if (ft == NULL) // can happen when saving a new file when quitting + ft = filetypes[GEANY_FILETYPES_ALL]; + g_snprintf(entry, 13, "FILE_NAME_%d", j); + fname = g_strdup_printf("%d:%d:%s", sci_get_current_position(doc_list[idx].sci), + ft->uid, doc_list[idx].file_name); + g_key_file_set_string(config, "files", entry, fname); + g_free(fname); + j++; } - // if open filenames less than saved session files, delete existing entries in the list - have_session_files = TRUE; - i = j; - while (have_session_files) + } + // if open filenames less than saved session files, delete existing entries in the list + i = j; + while (TRUE) + { + g_snprintf(entry, 13, "FILE_NAME_%d", i); + tmp = g_key_file_get_string(config, "files", entry, NULL); + if (tmp == NULL) { - g_snprintf(entry, 13, "FILE_NAME_%d", i); - tmp = g_key_file_get_string(config, "files", entry, NULL); - if (tmp == NULL) - { - have_session_files = FALSE; - } - else - { - g_key_file_remove_key(config, "files", entry, NULL); - g_free(tmp); - i++; - } + break; } + else + { + g_key_file_remove_key(config, "files", entry, NULL); + g_free(tmp); + i++; + } } - g_free(entry); }
@@ -349,10 +350,12 @@ guint i; gsize len = 0; gboolean have_session_files; - gchar *entry = g_malloc(14); + gchar entry[14]; gchar *tmp_string; GError *error = NULL;
+ session_notebook_page = utils_get_setting_integer(config, "files", "current_page", -1); + recent_files = g_key_file_get_string_list(config, "files", "recent_files", &len, NULL); if (recent_files != NULL) { @@ -380,7 +383,6 @@ g_ptr_array_add(session_files, tmp_string); i++; } - g_free(entry); }
@@ -652,6 +654,7 @@ }
+// open session files gboolean configuration_open_files() { gint i; @@ -723,8 +726,11 @@ document_colourise_new();
g_ptr_array_free(session_files, TRUE); + if (failure) msgwin_status_add(_("Failed to load one or more session files.")); + else if (session_notebook_page >= 0) + gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook), session_notebook_page); return ret; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.