[gnome-latex: 176/205] Go to previous or next error/warning/badbox



commit 5c82df1b1bc4abe89622b523c1326b8df17fb7e4
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Thu Jan 21 13:04:28 2010 +0100

    Go to previous or next error/warning/badbox
    
    There is a vertical toolbar at the right of the output log view.

 TODO                                      |  21 +++--
 data/images/icons/go_next_badbox.png      | Bin 0 -> 301 bytes
 data/images/icons/go_next_error.png       | Bin 0 -> 293 bytes
 data/images/icons/go_next_warning.png     | Bin 0 -> 293 bytes
 data/images/icons/go_previous_badbox.png  | Bin 0 -> 304 bytes
 data/images/icons/go_previous_error.png   | Bin 0 -> 296 bytes
 data/images/icons/go_previous_warning.png | Bin 0 -> 295 bytes
 src/log.c                                 | 128 +++++++++++++++++++++++++++---
 src/log.h                                 |   8 +-
 src/main.c                                |   7 +-
 src/ui.c                                  |  48 ++++++++++-
 src/ui.h                                  |   2 +-
 src/utils.c                               |  16 ++++
 src/utils.h                               |   1 +
 14 files changed, 199 insertions(+), 32 deletions(-)
---
diff --git a/TODO b/TODO
index 3b56c55..ad78281 100644
--- a/TODO
+++ b/TODO
@@ -1,22 +1,19 @@
 TODO LaTeXila
 
 - User-friendly output for the compilation
-       x filter the messages
-       x show the exit code
-       x button to stop the execution
-       x show statistics: nb of errors, warnings and badboxes
-       x extract informations: file, line, message
-       x GtkTextBuffer -> GtkListStore
-       x colors
-       x jump to lines and files
-       - buttons for going to the previous/next error/warning/badbox
+       - sensitivity of buttons (previous/next error/...)
+       - convert file size in KB or MB or ... ("Output written on ...")
 
-- Auto-completion of LaTeX commands
+- File browser
+       - optimisations, check memory leaks, ...
+       - two cell renderers (icon + basename) in one column
+       - list with all parent directories
+       - sort with GtkTreeSortable?
 
 - Some various improvements:
        - Make a copy of a file before saving it for the first time (with a name like "file~")
        - Autosave files every X minutes
        - Symbols: most recently used
-       - File browser: list with all parents directories
-       - File browser: two cell renderers in one column
        - Create personnal templates: choose an icon
+
+- Auto-completion of LaTeX commands
diff --git a/data/images/icons/go_next_badbox.png b/data/images/icons/go_next_badbox.png
new file mode 100644
index 0000000..b21e057
Binary files /dev/null and b/data/images/icons/go_next_badbox.png differ
diff --git a/data/images/icons/go_next_error.png b/data/images/icons/go_next_error.png
new file mode 100644
index 0000000..7c0c52c
Binary files /dev/null and b/data/images/icons/go_next_error.png differ
diff --git a/data/images/icons/go_next_warning.png b/data/images/icons/go_next_warning.png
new file mode 100644
index 0000000..ef7dfbe
Binary files /dev/null and b/data/images/icons/go_next_warning.png differ
diff --git a/data/images/icons/go_previous_badbox.png b/data/images/icons/go_previous_badbox.png
new file mode 100644
index 0000000..42768b6
Binary files /dev/null and b/data/images/icons/go_previous_badbox.png differ
diff --git a/data/images/icons/go_previous_error.png b/data/images/icons/go_previous_error.png
new file mode 100644
index 0000000..91b7036
Binary files /dev/null and b/data/images/icons/go_previous_error.png differ
diff --git a/data/images/icons/go_previous_warning.png b/data/images/icons/go_previous_warning.png
new file mode 100644
index 0000000..6417fff
Binary files /dev/null and b/data/images/icons/go_previous_warning.png differ
diff --git a/src/log.c b/src/log.c
index f706eff..a1622a4 100644
--- a/src/log.c
+++ b/src/log.c
@@ -25,6 +25,7 @@
 #include "log.h"
 #include "utils.h"
 #include "callbacks.h"
+#include "print.h"
 
 static void cb_action_history_changed (GtkTreeSelection *selection,
                gpointer user_data);
@@ -33,7 +34,8 @@ static gboolean output_row_selection_func (GtkTreeSelection *selection,
                GtkTreeModel *model, GtkTreePath *path,
                gboolean path_currently_selected, gpointer data);
 static GtkListStore * get_new_output_list_store (void);
-static void scroll_to_end (GtkTreeIter *iter, gboolean force);
+static void go_to_message (gboolean next, gint message_type);
+static void scroll_to_iter (GtkTreeIter *iter, gboolean force);
 
 static GtkTreeView *history_view;
 static GtkTreeView *output_view;
@@ -42,7 +44,7 @@ static GtkTreeView *output_view;
 static gint nb_lines = 0;
 
 void
-init_log_zone (GtkPaned *log_hpaned)
+init_log_zone (GtkPaned *log_hpaned, GtkWidget *log_toolbar)
 {
        /* action history */
        {
@@ -132,7 +134,14 @@ init_log_zone (GtkPaned *log_hpaned)
                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollbar),
                                GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
                gtk_container_add (GTK_CONTAINER (scrollbar), GTK_WIDGET (output_view));
-               gtk_paned_add2 (log_hpaned, scrollbar);
+
+               /* left: output view
+                * right: log toolbar (vertical)
+                */
+               GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (hbox), scrollbar, TRUE, TRUE, 0);
+               gtk_box_pack_start (GTK_BOX (hbox), log_toolbar, FALSE, FALSE, 0);
+               gtk_paned_add2 (log_hpaned, hbox);
        }
 }
 
@@ -159,8 +168,8 @@ cb_output_row_changed (GtkTreeSelection *selection, gpointer data)
        GtkTreeModel *model;
        if (gtk_tree_selection_get_selected (selection, &model, &iter))
        {
-               gchar *filename;
-               gchar *line_number;
+               gchar *filename = NULL;
+               gchar *line_number = NULL;
                gint message_type;
 
                gtk_tree_model_get (model, &iter,
@@ -170,7 +179,7 @@ cb_output_row_changed (GtkTreeSelection *selection, gpointer data)
                                -1);
 
                if (message_type != MESSAGE_TYPE_OTHER && filename != NULL
-                               && strlen (filename) != 0)
+                               && strlen (filename) > 0)
                {
                        // open the file (if the file is already opened, go to it)
                        open_new_document_without_uri (filename);
@@ -190,6 +199,9 @@ cb_output_row_changed (GtkTreeSelection *selection, gpointer data)
 
                        gtk_widget_grab_focus (latexila.active_doc->source_view);
                }
+
+               g_free (filename);
+               g_free (line_number);
        }
 }
 
@@ -207,11 +219,16 @@ output_row_selection_func (GtkTreeSelection *selection, GtkTreeModel *model,
                                COL_OUTPUT_MESSAGE_TYPE, &message_type,
                                -1);
 
-               if (message_type == MESSAGE_TYPE_OTHER || filename == NULL
-                               || strlen (filename) == 0)
+               if (message_type == MESSAGE_TYPE_OTHER || filename == NULL || strlen (filename) == 0)
+               {
+                       g_free (filename);
                        return FALSE;
+               }
                else
+               {
+                       g_free (filename);
                        return TRUE;
+               }
        }
 
        return FALSE; // not allow the selection state to change
@@ -286,6 +303,91 @@ add_action (const gchar *title, const gchar *command)
        g_free (title_with_num);
 }
 
+static void
+go_to_message (gboolean next, gint message_type)
+{
+       GtkTreeSelection *selection = gtk_tree_view_get_selection (output_view);
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       gboolean valid = gtk_tree_selection_get_selected (selection, &model, &iter);
+
+       // if no row is selected, we take the first
+       if (! valid)
+               valid = gtk_tree_model_get_iter_first (model, &iter);
+       if (! valid)
+               return;
+
+       // get the next or previous iter
+       if (next)
+               valid = gtk_tree_model_iter_next (model, &iter);
+       else
+               valid = tree_model_iter_prev (model, &iter);
+
+       gint current_message_type;
+       gchar *filename;
+       while (valid)
+       {
+               gtk_tree_model_get (model, &iter, 
+                               COL_OUTPUT_MESSAGE_TYPE, &current_message_type,
+                               COL_OUTPUT_FILENAME, &filename,
+                               -1);
+
+               // if found, select the row
+               if (current_message_type == message_type && filename != NULL
+                               && strlen (filename) > 0)
+               {
+                       gtk_tree_selection_select_iter (selection, &iter);
+                       scroll_to_iter (&iter, TRUE);
+                       g_free (filename);
+                       break;
+               }
+
+               g_free (filename);
+
+               // get the next or previous iter
+               if (next)
+                       valid = gtk_tree_model_iter_next (model, &iter);
+               else
+                       valid = tree_model_iter_prev (model, &iter);
+       }
+}
+
+void
+cb_go_previous_latex_error (void)
+{
+       go_to_message (FALSE, MESSAGE_TYPE_ERROR);
+}
+
+void
+cb_go_previous_latex_warning (void)
+{
+       go_to_message (FALSE, MESSAGE_TYPE_WARNING);
+}
+
+void
+cb_go_previous_latex_badbox (void)
+{
+       go_to_message (FALSE, MESSAGE_TYPE_BADBOX);
+}
+
+void
+cb_go_next_latex_error (void)
+{
+       go_to_message (TRUE, MESSAGE_TYPE_ERROR);
+}
+
+void
+cb_go_next_latex_warning (void)
+{
+       go_to_message (TRUE, MESSAGE_TYPE_WARNING);
+}
+
+void
+cb_go_next_latex_badbox (void)
+{
+       go_to_message (TRUE, MESSAGE_TYPE_BADBOX);
+}
+
 void
 set_history_sensitivity (gboolean sensitive)
 {
@@ -336,7 +438,7 @@ print_output_info (const gchar *info)
                        COL_OUTPUT_COLOR_SET, FALSE,
                        COL_OUTPUT_WEIGHT, WEIGHT_NORMAL,
                        -1);
-       scroll_to_end (&iter, FALSE);
+       scroll_to_iter (&iter, FALSE);
 }
 
 // if message != NULL the exit_code is not taken into account
@@ -382,7 +484,7 @@ print_output_exit (const gint exit_code, const gchar *message)
        }
 
        // force the scrolling and the flush
-       scroll_to_end (&iter, TRUE);
+       scroll_to_iter (&iter, TRUE);
 }
 
 void
@@ -437,7 +539,7 @@ print_output_message (const gchar *filename, const gint line_number,
                        COL_OUTPUT_COLOR_SET, TRUE,
                        COL_OUTPUT_WEIGHT, WEIGHT_NORMAL,
                        -1);
-       scroll_to_end (&iter, FALSE);
+       scroll_to_iter (&iter, FALSE);
 
        g_free (basename);
        g_free (line_number_str);
@@ -460,11 +562,11 @@ print_output_normal (const gchar *message)
                        COL_OUTPUT_COLOR_SET, FALSE,
                        COL_OUTPUT_WEIGHT, WEIGHT_NORMAL,
                        -1);
-       scroll_to_end (&iter, FALSE);
+       scroll_to_iter (&iter, FALSE);
 }
 
 static void
-scroll_to_end (GtkTreeIter *iter, gboolean force)
+scroll_to_iter (GtkTreeIter *iter, gboolean force)
 {
        /* Flush the queue for the 50 first lines and then every 40 lines.
         * This is for the fluidity of the output, without that the lines do not
diff --git a/src/log.h b/src/log.h
index 386c2cb..255c95a 100644
--- a/src/log.h
+++ b/src/log.h
@@ -29,8 +29,14 @@
 #define WEIGHT_BOLD            800
 #define INFO_MESSAGE   "*****"
 
-void init_log_zone (GtkPaned *log_hpaned);
+void init_log_zone (GtkPaned *log_hpaned, GtkWidget *log_toolbar);
 void add_action (const gchar *title, const gchar *command);
+void cb_go_previous_latex_error (void);
+void cb_go_previous_latex_warning (void);
+void cb_go_previous_latex_badbox (void);
+void cb_go_next_latex_error (void);
+void cb_go_next_latex_warning (void);
+void cb_go_next_latex_badbox (void);
 void set_history_sensitivity (gboolean sensitive);
 void output_view_columns_autosize (void);
 
diff --git a/src/main.c b/src/main.c
index 5b11c83..5b97607 100644
--- a/src/main.c
+++ b/src/main.c
@@ -420,7 +420,10 @@ main (int argc, char *argv[])
        GtkWidget *main_vbox = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (latexila.main_window), main_vbox);
 
-       init_ui (main_vbox);
+       // init_ui() will set log_toolbar so we can pass it to init_log_zone()
+       GtkWidget *log_toolbar;
+
+       init_ui (main_vbox, &log_toolbar);
        
        /* horizontal pane
         * left: side pane (symbol tables and the file browser)
@@ -462,7 +465,7 @@ main (int argc, char *argv[])
        gtk_paned_set_position (GTK_PANED (hpaned), latexila.prefs.log_hpaned_pos);
        gtk_paned_add2 (GTK_PANED (vpaned), hpaned);
 
-       init_log_zone (latexila.log_hpaned);
+       init_log_zone (latexila.log_hpaned, log_toolbar);
 
        /* statusbar */
        init_statusbar (main_vbox);
diff --git a/src/ui.c b/src/ui.c
index d7ceccd..7a7360b 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -29,6 +29,7 @@
 #include "tool_menu_action.h"
 #include "prefs.h"
 #include "templates.h"
+#include "log.h"
 
 static void register_my_stock_icons (void);
 
@@ -71,6 +72,12 @@ static struct {
        {DATA_DIR "/images/icons/math-nth-root.png", "math-nth-root"},
        {DATA_DIR "/images/icons/delimiters-left.png", "delimiters-left"},
        {DATA_DIR "/images/icons/delimiters-right.png", "delimiters-right"},
+       {DATA_DIR "/images/icons/go_previous_error.png", "go-previous-error"},
+       {DATA_DIR "/images/icons/go_next_error.png", "go-next-error"},
+       {DATA_DIR "/images/icons/go_previous_warning.png", "go-previous-warning"},
+       {DATA_DIR "/images/icons/go_next_warning.png", "go-next-warning"},
+       {DATA_DIR "/images/icons/go_previous_badbox.png", "go-previous-badbox"},
+       {DATA_DIR "/images/icons/go_next_badbox.png", "go-next-badbox"},
 };
 
 static const char *ui =
@@ -136,6 +143,13 @@ static const char *ui =
 "      <separator />"
 "      <menuitem action='clean_up_build_files' />"
 "      <menuitem action='stop_execution' />"
+"      <separator />"
+"      <menuitem action='go_previous_error' />"
+"      <menuitem action='go_next_error' />"
+"      <menuitem action='go_previous_warning' />"
+"      <menuitem action='go_next_warning' />"
+"      <menuitem action='go_previous_badbox' />"
+"      <menuitem action='go_next_badbox' />"
 "    </menu>"
 
 "    <menu action='Latex'>"
@@ -306,8 +320,6 @@ static const char *ui =
 "    <separator />"
 "    <toolitem action='compile_pdflatex' />"
 "    <toolitem action='viewPDF' />"
-"    <separator />"
-"    <toolitem action='stop_execution' />"
 "  </toolbar>"
 
 "  <toolbar name='EditToolbar'>"
@@ -413,6 +425,16 @@ static const char *ui =
 "      </menu>"
 "    </toolitem>"
 "  </toolbar>"
+
+"  <toolbar name='LogToolbar'>"
+"    <toolitem action='stop_execution' />"
+"    <toolitem action='go_previous_error' />"
+"    <toolitem action='go_next_error' />"
+"    <toolitem action='go_previous_warning' />"
+"    <toolitem action='go_next_warning' />"
+"    <toolitem action='go_previous_badbox' />"
+"    <toolitem action='go_next_badbox' />"
+"  </toolbar>"
 "</ui>";
 
 // all the actions (for the menu and the toolbar)
@@ -495,6 +517,18 @@ static GtkActionEntry entries[] = {
                G_CALLBACK (cb_clean_up_build_files)},
        {"stop_execution", GTK_STOCK_STOP, N_("_Stop Execution"), "<Release>F9",
                N_("Stop Execution"), G_CALLBACK (cb_stop_execution)},
+       {"go_previous_error", "go-previous-error", N_("_Previous LaTeX Error"), NULL,
+               N_("Previous LaTeX Error"), G_CALLBACK (cb_go_previous_latex_error)},
+       {"go_previous_warning", "go-previous-warning", N_("_Previous LaTeX Warning"), NULL,
+               N_("Previous LaTeX Warning"), G_CALLBACK (cb_go_previous_latex_warning)},
+       {"go_previous_badbox", "go-previous-badbox", N_("_Previous LaTeX Badbox"), NULL,
+               N_("Previous LaTeX Badbox"), G_CALLBACK (cb_go_previous_latex_badbox)},
+       {"go_next_error", "go-next-error", N_("_Next LaTeX Error"), NULL,
+               N_("Next LaTeX Error"), G_CALLBACK (cb_go_next_latex_error)},
+       {"go_next_warning", "go-next-warning", N_("_Next LaTeX Warning"), NULL,
+               N_("Next LaTeX Warning"), G_CALLBACK (cb_go_next_latex_warning)},
+       {"go_next_badbox", "go-next-badbox", N_("_Next LaTeX Badbox"), NULL,
+               N_("Next LaTeX Badbox"), G_CALLBACK (cb_go_next_latex_badbox)},
 
        {"Tools", NULL, N_("_Tools"), NULL, NULL, NULL},
        {"ToolsComment", NULL, N_("_Comment"), "<Control>D",
@@ -735,7 +769,7 @@ register_my_stock_icons (void)
 }
 
 void
-init_ui (GtkWidget *box)
+init_ui (GtkWidget *box, GtkWidget **log_toolbar)
 {
        GError *error = NULL;
 
@@ -825,11 +859,19 @@ init_ui (GtkWidget *box)
 
        GtkWidget *toolbar = gtk_ui_manager_get_widget (ui_manager, "/MainToolbar");
        GtkWidget *edit_toolbar = gtk_ui_manager_get_widget (ui_manager, "/EditToolbar");
+       *log_toolbar = gtk_ui_manager_get_widget (ui_manager, "/LogToolbar");
        latexila.edit_toolbar = edit_toolbar;
 
        // toolbars with icons only
        gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
        gtk_toolbar_set_style (GTK_TOOLBAR (edit_toolbar), GTK_TOOLBAR_ICONS);
+       gtk_toolbar_set_style (GTK_TOOLBAR (*log_toolbar), GTK_TOOLBAR_ICONS);
+
+       // log toolbar vertical, with small icons
+       gtk_orientable_set_orientation (GTK_ORIENTABLE (*log_toolbar),
+                       GTK_ORIENTATION_VERTICAL);
+       gtk_toolbar_set_icon_size (GTK_TOOLBAR (*log_toolbar), GTK_ICON_SIZE_MENU);
+
 
        if (latexila.prefs.toolbars_horizontal)
        {
diff --git a/src/ui.h b/src/ui.h
index 92b480f..7c4bb69 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -20,6 +20,6 @@
 #ifndef UI_H
 #define UI_H
 
-void init_ui (GtkWidget *box);
+void init_ui (GtkWidget *box, GtkWidget **log_zone);
 
 #endif /* UI_H */
diff --git a/src/utils.c b/src/utils.c
index 92d4e99..9678ec3 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -43,3 +43,19 @@ scroll_to_cursor (void)
                                GTK_TEXT_BUFFER (latexila.active_doc->source_buffer)),
                        0.25, FALSE, 0, 0);
 }
+
+// same as gtk_tree_model_iter_next(), but previous instead of next
+gboolean
+tree_model_iter_prev (GtkTreeModel *tree_model, GtkTreeIter *iter)
+{
+       GtkTreePath *path = gtk_tree_model_get_path (tree_model, iter);
+       if (gtk_tree_path_prev (path))
+       {
+               gboolean ret_val = gtk_tree_model_get_iter (tree_model, iter, path);
+               gtk_tree_path_free (path);
+               return ret_val;
+       }
+
+       gtk_tree_path_free (path);
+       return FALSE;
+}
diff --git a/src/utils.h b/src/utils.h
index 17841be..621b149 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -22,5 +22,6 @@
 
 void flush_queue (void);
 void scroll_to_cursor (void);
+gboolean tree_model_iter_prev (GtkTreeModel *tree_model, GtkTreeIter *iter);
 
 #endif /* UTILS_H */


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