[gnome-latex: 117/205] Open document: verify if the doc is not already opened



commit 7084ec9555eb213845391a4ee2834dab95313fec
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Tue Nov 10 19:30:12 2009 +0100

    Open document: verify if the doc is not already opened
    
    We traverse the GList latexila.all_docs and compare all the filenames.
    If a document is already in the GList, we switch to the corresponding
    tab on the notebook (which have the same numerotation).

 TODO            |  4 ++--
 src/callbacks.c | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/TODO b/TODO
index 00c0ecb..4b6b862 100644
--- a/TODO
+++ b/TODO
@@ -21,5 +21,5 @@ TODO LaTeXila
 [-] undo/redo and the "saved" document property
        - detect when the buffer is the same as in the file currently saved
 
-[-] open document
-       - verify if the document is not already opened
+[x] open document
+       x verify if the document is not already opened
diff --git a/src/callbacks.c b/src/callbacks.c
index eda1823..bd3b85e 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -782,6 +782,28 @@ open_new_document (const gchar *filename, const gchar *uri)
 {
        print_info ("open file: \"%s\"", filename);
 
+       /* check if the document is not already opened */
+       GList *current = latexila.all_docs;
+       gint n = 0;
+       while (TRUE)
+       {
+               if (current == NULL)
+                       break;
+
+               document_t *current_doc = g_list_nth_data (current, 0);
+
+               // if the filename is the same, just go to that tab on the notebook
+               if (strcmp (filename, current_doc->path) == 0)
+               {
+                       gtk_notebook_set_current_page (latexila.notebook, n);
+                       return;
+               }
+
+               current = g_list_next (current);
+               n++;
+       }
+
+       /* get the contents */
        gchar *contents = NULL;
        if (g_file_get_contents (filename, &contents, NULL, NULL))
        {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]