[gnome-latex: 28/205] log zone: command output in red when it's an error



commit 8c07587f8094aefaef8dd922919f56da65880e86
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Mon Aug 24 12:59:20 2009 +0200

    log zone: command output in red when it's an error

 TODO            | 37 +++++++++----------------------------
 src/callbacks.c | 34 ++++++++++++++++++++++++----------
 src/main.c      |  9 +++++++--
 src/main.h      |  1 +
 src/print.c     |  8 ++++++--
 src/print.h     |  2 +-
 6 files changed, 48 insertions(+), 43 deletions(-)
---
diff --git a/TODO b/TODO
index abda921..6726fe6 100644
--- a/TODO
+++ b/TODO
@@ -1,42 +1,23 @@
 TODO LaTeXila
 
-Tue Aug 18, 2009 to Mon Aug 24, 2009
+Mon Aug 24, 2009 to Mon Aug 31, 2009
 
-[x] tabs with close buttons
-
-[-] log zone
-       x horizontal pane
-         left: list with an history of the actions numbered
-         right: details of the action selected
-       x function print_log ()
-       x default height and width
-       - text in red when it's an error
+[-] search and replace
 
-[x] files recently opened (in the File menu)
+[-] copy/cut/paste
 
-[x] statusbar
-       x write some text in the statusbar
-       x show which line and which column the cursor is
+[-] printing
 
-[x] icons: PDF, DVI, ...
+[-] enlarge/shrink font
 
-[x] DVI to PDF, DVI to PS, view PS
+[-] Preferences
+       - show line numbers
+       - commands
+       - source code font
 
 [-] bugs correction
        - sometimes command output is not UTF-8:
          Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion `g_utf8_validate (text, len, NULL)' failed
-       x bad title with save as -> cancel
-
-
-Tue Aug 25, 2009 to Mon Aug 31, 2009
-
-[-] search and replace
-
-[-] copy/cut/paste
-
-[-] Preferences
-       - commands
-       - source code font
 
 [-] CMake
 
diff --git a/src/callbacks.c b/src/callbacks.c
index b60dfd2..f188969 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -26,7 +26,8 @@ static void run_compilation (gchar *title, gchar *command);
 static void view_document (gchar *title, gchar *doc_extension);
 static void convert_document (gchar *title, gchar *doc_extension,
                gchar *command);
-static void add_action (gchar *title, gchar *command, gchar *command_output);
+static void add_action (gchar *title, gchar *command, gchar *command_output,
+               gboolean error);
 static void update_cursor_position_statusbar ();
 
 void
@@ -270,12 +271,14 @@ cb_action_list_changed (GtkTreeSelection *selection, gpointer user_data)
        if (gtk_tree_selection_get_selected (selection, &model, &iter))
        {
                gchar *title, *command, *command_output;
+               gboolean error;
                gtk_tree_model_get (model, &iter,
                                COLUMN_ACTION_TITLE, &title,
                                COLUMN_ACTION_COMMAND, &command,
                                COLUMN_ACTION_COMMAND_OUTPUT, &command_output,
+                               COLUMN_ACTION_ERROR, &error,
                                -1);
-               print_log (latexila.log, title, command, command_output);
+               print_log (latexila.log, title, command, command_output, error);
        }
 }
 
@@ -658,6 +661,7 @@ run_compilation (gchar *title, gchar *command)
        if (latexila.active_doc != NULL)
        {
                gchar *command_output;
+               gboolean is_error = TRUE;
 
                /* the current document is a *.tex file? */
                gboolean tex_file = g_str_has_suffix (latexila.active_doc->path, ".tex");
@@ -666,7 +670,7 @@ run_compilation (gchar *title, gchar *command)
                        command_output = g_strdup_printf (_("compilation failed: %s is not a *.tex file"),
                                        g_path_get_basename (latexila.active_doc->path));
 
-                       add_action (title, command, command_output);
+                       add_action (title, command, command_output, is_error);
                        g_free (command_output);
                        return;
                }
@@ -699,8 +703,10 @@ run_compilation (gchar *title, gchar *command)
                                        error->message);
                        g_error_free (error);
                }
+               else
+                       is_error = FALSE;
 
-               add_action (title, command, command_output);
+               add_action (title, command, command_output, is_error);
 
                gtk_statusbar_pop (latexila.statusbar, context_id);
 
@@ -716,6 +722,7 @@ view_document (gchar *title, gchar *doc_extension)
        if (latexila.active_doc != NULL)
        {
                gchar *command, *command_output;
+               gboolean is_error = TRUE;
 
                GError *error = NULL;
                GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
@@ -733,7 +740,7 @@ view_document (gchar *title, gchar *doc_extension)
                        command_output = g_strdup_printf (_("failed: %s is not a *.tex file"),
                                        g_path_get_basename (latexila.active_doc->path));
 
-                       add_action (title, command, command_output);
+                       add_action (title, command, command_output, is_error);
                        g_free (command);
                        g_free (command_output);
                        g_free (doc_path);
@@ -748,7 +755,7 @@ view_document (gchar *title, gchar *doc_extension)
                                        _("%s does not exist. If this is not already made, compile the 
document with the right command."),
                                        g_path_get_basename (doc_path));
 
-                       add_action (title, command, command_output);
+                       add_action (title, command, command_output, is_error);
                        g_free (command);
                        g_free (command_output);
                        g_free (doc_path);
@@ -767,9 +774,12 @@ view_document (gchar *title, gchar *doc_extension)
                        g_error_free (error);
                }
                else
+               {
                        command_output = g_strdup (_("Viewing in progress. Please wait..."));
+                       is_error = FALSE;
+               }
 
-               add_action (title, command, command_output);
+               add_action (title, command, command_output, is_error);
 
                g_free (command);
                g_free (command_output);
@@ -784,6 +794,7 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
        if (latexila.active_doc != NULL)
        {
                gchar *full_command, *command_output;
+               gboolean is_error = TRUE;
 
                GError *error = NULL;
                GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
@@ -801,7 +812,7 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
                                        _("%s does not exist. If this is not already made, compile the 
document with the right command."),
                                        g_path_get_basename (doc_path));
 
-                       add_action (title, full_command, command_output);
+                       add_action (title, full_command, command_output, is_error);
                        g_free (full_command);
                        g_free (command_output);
                        g_free (doc_path);
@@ -835,8 +846,10 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
                                        error->message);
                        g_error_free (error);
                }
+               else
+                       is_error = FALSE;
 
-               add_action (title, full_command, command_output);
+               add_action (title, full_command, command_output, is_error);
 
                gtk_statusbar_pop (latexila.statusbar, context_id);
 
@@ -848,7 +861,7 @@ convert_document (gchar *title, gchar *doc_extension, gchar *command)
 }
 
 static void
-add_action (gchar *title, gchar *command, gchar *command_output)
+add_action (gchar *title, gchar *command, gchar *command_output, gboolean error)
 {
        static gint num = 1;
        gchar *title2 = g_strdup_printf ("%d. %s", num, title);
@@ -860,6 +873,7 @@ add_action (gchar *title, gchar *command, gchar *command_output)
                        COLUMN_ACTION_TITLE, title2,
                        COLUMN_ACTION_COMMAND, command,
                        COLUMN_ACTION_COMMAND_OUTPUT, command_output,
+                       COLUMN_ACTION_ERROR, error,
                        -1);
 
        // the new entry is selected
diff --git a/src/main.c b/src/main.c
index 246cc79..06dab28 100644
--- a/src/main.c
+++ b/src/main.c
@@ -213,7 +213,7 @@ main (int argc, char *argv[])
 
        // actions list
        GtkListStore *list_store = gtk_list_store_new (N_COLUMNS_ACTION,
-                       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+                       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
        latexila.list_store = list_store;
        
        GtkWidget *list_view = gtk_tree_view_new_with_model (
@@ -257,7 +257,12 @@ main (int argc, char *argv[])
        latexila.log = GTK_TEXT_VIEW (log_view);
 
        // tags
-       gtk_text_buffer_create_tag (log_buffer, "bold", "font", "bold", NULL);
+       gtk_text_buffer_create_tag (log_buffer, "bold",
+                       "weight", PANGO_WEIGHT_BOLD,
+                       NULL);
+       gtk_text_buffer_create_tag (log_buffer, "error",
+                       "foreground", "red",
+                       NULL);
 
        /* statusbar */
        GtkWidget *statusbar = gtk_statusbar_new ();
diff --git a/src/main.h b/src/main.h
index 865af37..137f187 100644
--- a/src/main.h
+++ b/src/main.h
@@ -45,6 +45,7 @@ enum
        COLUMN_ACTION_TITLE,
        COLUMN_ACTION_COMMAND,
        COLUMN_ACTION_COMMAND_OUTPUT,
+       COLUMN_ACTION_ERROR,
        N_COLUMNS_ACTION
 };
 
diff --git a/src/print.c b/src/print.c
index 2f83702..ae99875 100644
--- a/src/print.c
+++ b/src/print.c
@@ -7,7 +7,7 @@
 
 void
 print_log (GtkTextView *log, gchar *title, gchar *command,
-               gchar *command_output)
+               gchar *command_output, gboolean error)
 {
        GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (log);
        gtk_text_buffer_set_text (log_buffer, "", -1);
@@ -27,7 +27,11 @@ print_log (GtkTextView *log, gchar *title, gchar *command,
 
        // command output
        gtk_text_buffer_get_end_iter (log_buffer, &end);
-       gtk_text_buffer_insert (log_buffer, &end, command_output, -1);
+       if (error)
+               gtk_text_buffer_insert_with_tags_by_name (log_buffer, &end,
+                               command_output, -1, "error", NULL);
+       else
+               gtk_text_buffer_insert (log_buffer, &end, command_output, -1);
 }
 
 void
diff --git a/src/print.h b/src/print.h
index 6490c14..659cd78 100644
--- a/src/print.h
+++ b/src/print.h
@@ -2,7 +2,7 @@
 #define PRINT_H
 
 void print_log (GtkTextView *log, gchar *title, gchar *command,
-               gchar *command_output);
+               gchar *command_output, gboolean error);
 
 void print_info (char *, ...);
 void print_warning (char *, ...);


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