[gnome-latex: 119/205] Remember the files opened at exit and reopen them at starting
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 119/205] Remember the files opened at exit and reopen them at starting
- Date: Fri, 14 Dec 2018 10:56:53 +0000 (UTC)
commit 86380ce26304151f20927770748ef4b0e9ed9573
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Tue Nov 17 18:01:15 2009 +0100
Remember the files opened at exit and reopen them at starting
In callbacks.c there is a GList (list_opened_docs) which is filled in
the close_document () function, only when save_list_opened_docs is TRUE.
In cb_quit () we set save_list_opened_docs to TRUE, and close_document
is called inderectly when we call close_all ().
We use the g_key_file_set_string_list (), which take an array in
argument, not a GList, so we must convert the GList into an array, which
is done in cb_quit before calling save_preferences.
INSTALL | 4 +---
README | 3 +--
TODO | 11 +++++++++++
src/callbacks.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/main.c | 18 ++++++++++++++++++
src/main.h | 2 ++
src/prefs.c | 24 +++++++++++++++++++++---
7 files changed, 104 insertions(+), 8 deletions(-)
---
diff --git a/INSTALL b/INSTALL
index cc44138..601e6c6 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
LaTeXila requires GTK+-2.16.x and GtkSourceView 2.4.x minimum.
-For the compilation, CMake 2.6.2 minimum is also required.
+For the compilation, CMake 2.6.4 minimum is also required.
Simple install procedure
========================
@@ -8,7 +8,6 @@ $ tar xvf latexila-0.0.2.tar.gz # unpack the sources
$ cd latexila-0.0.2/build/ # go to the build directory
$ cmake ../ # run the Makefile generator
$ make # build LaTeXila
-$ make translations # build the *.mo files
[ Become root if necessary ]
$ make install # install LaTeXila
@@ -27,7 +26,6 @@ Configuration
* Disable Native Language Support (NLS)
run cmake with this option: -DENABLE_NLS=OFF
- then you don't need to run "make translations"
* Change the install directory
run cmake with this option:
diff --git a/README b/README
index ce8429e..311ed4f 100644
--- a/README
+++ b/README
@@ -15,7 +15,7 @@ Installation
============
LaTeXila requires GTK+-2.16.x and GtkSourceView 2.4.x minimum.
-For the compilation, CMake 2.6.2 minimum is also required.
+For the compilation, CMake 2.6.4 minimum is also required.
Simple install procedure:
@@ -23,7 +23,6 @@ Simple install procedure:
$ cd latexila-0.0.2/build/ # go to the build directory
$ cmake ../ # run the Makefile generator
$ make # build LaTeXila
- $ make translations # build the *.mo files
[ Become root if necessary ]
$ make install # install LaTeXila
diff --git a/TODO b/TODO
index 8f1a43f..9d51d65 100644
--- a/TODO
+++ b/TODO
@@ -18,6 +18,17 @@ TODO LaTeXila
[-] BibTeX support
+[-] delete auxiliaries files on exit (*.aux, *.log, *.out, *.toc, ...)
+
+[-] remember the files opened at exit and reopen them at starting
+ x do the main work
+ - add an option in the preferences
+
+[-] Documents menu
+ - close all
+ - save all
+ - previous/next document
+
[-] undo/redo and the "saved" document property
- detect when the buffer is the same as in the file currently saved
diff --git a/src/callbacks.c b/src/callbacks.c
index 773f3c3..a18a127 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -51,6 +51,9 @@ static gboolean find_next_match (const gchar *what, GtkSourceSearchFlags flags,
gboolean backward, GtkTextIter *match_start, GtkTextIter *match_end);
static void free_latexila (void);
+static gboolean save_list_opened_docs = FALSE;
+static GList *list_opened_docs = NULL;
+
void
cb_new (void)
{
@@ -185,13 +188,54 @@ cb_close_tab (GtkWidget *widget, GtkWidget *child)
void
cb_quit (void)
{
+ // remember the files opened at exit for reopening them at next starting
+ // list_opened_docs (a GList) is filled in the close_document () function
+ // (wich is called indirectly by calling close_all ())
+ save_list_opened_docs = TRUE;
+ list_opened_docs = NULL;
+
if (close_all ())
{
+ g_strfreev (latexila.prefs.list_opened_docs);
+
+ // convert the GList into an array
+ guint nb_opened_docs = g_list_length (list_opened_docs);
+ latexila.prefs.nb_opened_docs = nb_opened_docs;
+ latexila.prefs.list_opened_docs = g_malloc (
+ (nb_opened_docs + 1) * sizeof (gchar *));
+
+ gint i = 0;
+ GList *current = list_opened_docs;
+ while (TRUE)
+ {
+ if (current == NULL)
+ {
+ // NULL-terminate the array so we can call g_strfreev () to free the
+ // list
+ latexila.prefs.list_opened_docs[i] = NULL;
+ break;
+ }
+
+ latexila.prefs.list_opened_docs[i] = g_list_nth_data (current, 0);
+
+ current = g_list_next (current);
+ i++;
+ }
+
save_preferences (&latexila.prefs);
free_latexila ();
print_info ("Bye bye");
gtk_main_quit ();
}
+
+ // free the list of opened documents
+ else
+ {
+ save_list_opened_docs = FALSE;
+ g_list_foreach (list_opened_docs, (GFunc) g_free, NULL);
+ g_list_free (list_opened_docs);
+ list_opened_docs = NULL;
+ }
}
void
@@ -1020,6 +1064,10 @@ close_document (gint index)
latexila.all_docs = g_list_remove (latexila.all_docs, latexila.active_doc);
if (latexila.active_doc->path != NULL)
{
+ if (save_list_opened_docs)
+ list_opened_docs = g_list_append (list_opened_docs,
+ g_strdup (latexila.active_doc->path));
+
print_info ("close the file \"%s\"", latexila.active_doc->path);
g_free (latexila.active_doc->path);
}
@@ -1336,6 +1384,8 @@ free_latexila (void)
g_free (latexila.prefs.command_dvips);
g_free (latexila.prefs.file_chooser_dir);
g_free (latexila.prefs.file_browser_dir);
+ g_strfreev (latexila.prefs.list_opened_docs);
+ g_list_free (list_opened_docs);
for (int i = 0 ; i < 7 ; i++)
g_object_unref (latexila.symbols.list_stores[i]);
diff --git a/src/main.c b/src/main.c
index e0c7aa7..03c8be1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -312,6 +312,24 @@ main (int argc, char *argv[])
if (! latexila.prefs.show_edit_toolbar)
gtk_widget_hide (latexila.edit_toolbar);
+ /* open documents opened the last time */
+ for (int i = 0 ; i < latexila.prefs.nb_opened_docs ; i++)
+ {
+ gchar *path = latexila.prefs.list_opened_docs[i];
+ gchar *uri = g_filename_to_uri (path, NULL, &error);
+ if (error != NULL)
+ {
+ print_warning ("can not open the file \"%s\": %s", path,
+ error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ open_new_document (path, uri);
+
+ g_free (uri);
+ }
+
/* if --new-document option is used */
if (option_new_document)
cb_new ();
diff --git a/src/main.h b/src/main.h
index b7e5cf2..9669049 100644
--- a/src/main.h
+++ b/src/main.h
@@ -91,6 +91,8 @@ typedef struct
gchar *command_dvips;
gchar *file_chooser_dir;
gchar *file_browser_dir;
+ gchar **list_opened_docs;
+ guint nb_opened_docs;
} preferences_t;
typedef struct
diff --git a/src/prefs.c b/src/prefs.c
index 5161b84..d59e20d 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -270,6 +270,20 @@ load_preferences (preferences_t *prefs)
error = NULL;
}
+ gsize nb_opened_docs;
+ prefs->list_opened_docs = g_key_file_get_string_list (key_file, PROGRAM_NAME,
+ "list_opened_documents", &nb_opened_docs, &error);
+ if (error != NULL)
+ {
+ print_warning ("%s", error->message);
+ prefs->nb_opened_docs = 0;
+ prefs->list_opened_docs = NULL;
+ g_error_free (error);
+ error = NULL;
+ }
+ else
+ prefs->nb_opened_docs = (guint) nb_opened_docs;
+
print_info ("load user preferences: OK");
g_key_file_free (key_file);
}
@@ -297,11 +311,13 @@ save_preferences (preferences_t *prefs)
prefs->command_dvipdf);
g_key_file_set_string (key_file, PROGRAM_NAME, "command_dvips",
prefs->command_dvips);
- //if (prefs->file_chooser_dir != NULL)
- g_key_file_set_string (key_file, PROGRAM_NAME, "file_chooser_directory",
- prefs->file_chooser_dir);
+ if (prefs->file_chooser_dir != NULL)
+ g_key_file_set_string (key_file, PROGRAM_NAME, "file_chooser_directory",
+ prefs->file_chooser_dir);
g_key_file_set_string (key_file, PROGRAM_NAME, "file_browser_directory",
prefs->file_browser_dir);
+ g_key_file_set_string_list (key_file, PROGRAM_NAME, "list_opened_documents",
+ (const gchar **) prefs->list_opened_docs, prefs->nb_opened_docs);
/* set the keys that must be taken from the widgets */
GdkWindowState flag = gdk_window_get_state (gtk_widget_get_window (
@@ -391,6 +407,8 @@ load_default_preferences (preferences_t *prefs)
prefs->command_dvips = g_strdup (command_dvips_);
prefs->file_chooser_dir = NULL;
prefs->file_browser_dir = g_strdup (g_get_home_dir ());
+ prefs->list_opened_docs = NULL;
+ prefs->nb_opened_docs = 0;
set_current_font_prefs (prefs);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]