[gnome-latex: 127/205] Documents menu



commit c8fa3d9bca72762147d4fab1525fc14cf5f31115
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Sat Nov 28 00:21:24 2009 +0100

    Documents menu
    
    Save all, Close all, Previous document, Next document.
    For previous document, if the current document is the first, we go to
    the last. For next document, if the current document is the last, we go
    to the first.

 TODO            | 13 +++++-------
 src/callbacks.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/callbacks.h |  4 ++++
 src/ui.c        | 10 ++++++++++
 src/ui.xml      |  8 ++++++++
 5 files changed, 86 insertions(+), 10 deletions(-)
---
diff --git a/TODO b/TODO
index ba5f12e..8ebd5fc 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
 TODO LaTeXila
 
-[x] clean-up auxiliaries files after close (*.aux, *.log, *.out, *.toc, ...)
-
 [-] Templates
        - create a few default templates
        - on the action "new file", possibility to select a template
@@ -10,10 +8,9 @@ TODO LaTeXila
 
 [-] BibTeX support
 
-[-] Documents menu
-       - close all
-       - save all
-       - previous/next document
+[x] Documents menu
+       x close all
+       x save all
+       x previous/next document
 
-[-] undo/redo and the "saved" document property
-       - detect when the buffer is the same as in the file currently saved
+[-] Search -> Goto line
diff --git a/src/callbacks.c b/src/callbacks.c
index d292c09..8e28c57 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -124,7 +124,7 @@ cb_save_as (void)
        if (latexila.active_doc == NULL)
                return;
 
-       document_t doc_backup = *latexila.active_doc;
+       document_t *doc_backup = latexila.active_doc;
 
        latexila.active_doc->path = NULL;
        latexila.active_doc->saved = FALSE;
@@ -133,7 +133,7 @@ cb_save_as (void)
        // if the user click on cancel
        if (! latexila.active_doc->saved)
        {
-               *latexila.active_doc = doc_backup;
+               latexila.active_doc = doc_backup;
                set_title ();
        }
 }
@@ -641,6 +641,63 @@ cb_dvi_to_ps (void)
        convert_document (_("DVI to PS"), ".dvi", latexila.prefs.command_dvips);
 }
 
+void
+cb_documents_save_all (void)
+{
+       GList *current = latexila.all_docs;
+       while (TRUE)
+       {
+               if (current == NULL)
+                       break;
+
+               document_t *current_doc = g_list_nth_data (current, 0);
+               document_t *active_doc = latexila.active_doc;
+               latexila.active_doc = current_doc;
+               cb_save ();
+               latexila.active_doc = active_doc;
+
+               current = g_list_next (current);
+       }
+}
+
+void
+cb_documents_close_all (void)
+{
+       close_all ();
+}
+
+void
+cb_documents_previous (void)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       gint current_page = gtk_notebook_get_current_page (latexila.notebook);
+       gint nb_pages = gtk_notebook_get_n_pages (latexila.notebook);
+
+       // if first page, go to the last
+       if (current_page == 0)
+               gtk_notebook_set_current_page (latexila.notebook, nb_pages - 1);
+       else
+               gtk_notebook_set_current_page (latexila.notebook, current_page - 1);
+}
+
+void
+cb_documents_next (void)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       gint current_page = gtk_notebook_get_current_page (latexila.notebook);
+       gint nb_pages = gtk_notebook_get_n_pages (latexila.notebook);
+
+       // if last page, go to the first
+       if (current_page == nb_pages - 1)
+               gtk_notebook_set_current_page (latexila.notebook, 0);
+       else
+               gtk_notebook_set_current_page (latexila.notebook, current_page + 1);
+}
+
 void
 cb_action_list_changed (GtkTreeSelection *selection, gpointer user_data)
 {
diff --git a/src/callbacks.h b/src/callbacks.h
index 9ed7d17..04dc584 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -46,6 +46,10 @@ void cb_view_pdf (void);
 void cb_view_ps (void);
 void cb_dvi_to_pdf (void);
 void cb_dvi_to_ps (void);
+void cb_documents_save_all (void);
+void cb_documents_close_all (void);
+void cb_documents_previous (void);
+void cb_documents_next (void);
 void cb_action_list_changed (GtkTreeSelection *selection,
                gpointer user_data);
 void cb_about_dialog (void);
diff --git a/src/ui.c b/src/ui.c
index 092249e..5e5d30f 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -131,6 +131,16 @@ static GtkActionEntry entries[] = {
                N_("Convert the DVI document to the PostScript format"), G_CALLBACK (cb_dvi_to_ps)},
        {"viewPS", "view_ps", N_("View PS"), NULL,
                N_("View the PostScript file"), G_CALLBACK (cb_view_ps)},
+
+       {"Documents", NULL, N_("Documents"), NULL, NULL, NULL},
+       {"DocumentsSaveAll", GTK_STOCK_SAVE, N_("Save All"), "<Shift><Control>L",
+               N_("Save all open files"), G_CALLBACK (cb_documents_save_all)},
+       {"DocumentsCloseAll", GTK_STOCK_CLOSE, N_("Close All"), "<Shift><Control>W",
+               N_("Close all open files"), G_CALLBACK (cb_documents_close_all)},
+       {"DocumentsPrevious", GTK_STOCK_GO_BACK, N_("Previous Document"), "<Control><Alt>Page_Up",
+               N_("Activate previous document"), G_CALLBACK (cb_documents_previous)},
+       {"DocumentsNext", GTK_STOCK_GO_FORWARD, N_("Next Document"), "<Control><Alt>Page_Down",
+               N_("Activate next document"), G_CALLBACK (cb_documents_next)},
        
        {"Help", NULL, N_("Help"), NULL, NULL, NULL},
        {"HelpAbout", GTK_STOCK_ABOUT, N_("About"), NULL,
diff --git a/src/ui.xml b/src/ui.xml
index 8a66631..9c9dec5 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -159,6 +159,14 @@ In the code, GtkUIManager is used to construct them.
         </menu>
       </menu>
     </menu>
+
+    <menu action="Documents">
+      <menuitem action="DocumentsSaveAll" />
+      <menuitem action="DocumentsCloseAll" />
+      <separator />
+      <menuitem action="DocumentsPrevious" />
+      <menuitem action="DocumentsNext" />
+    </menu>
     
     <menu action="Help">
       <menuitem action="HelpAbout" />


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