[anjuta] libanjuta/anjuta-cell-renderer-diff: Detect diff headers



commit c07b92163e2e355f2cdf843810324a204c373d86
Author: James Liggett <jrliggett cox net>
Date:   Mon Aug 19 00:29:16 2013 -0700

    libanjuta/anjuta-cell-renderer-diff: Detect diff headers
    
    Display the diff headers in bold so they are easier to see in long listings.
    Also make sure that diff headers for multiple file diff displays aren't marked
    as additions and deletions.

 libanjuta/anjuta-cell-renderer-diff.c       |   16 ++++++++++++-
 libanjuta/tests/anjuta-diff-renderer-test.c |   32 +++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/libanjuta/anjuta-cell-renderer-diff.c b/libanjuta/anjuta-cell-renderer-diff.c
index e52729b..f69d47b 100644
--- a/libanjuta/anjuta-cell-renderer-diff.c
+++ b/libanjuta/anjuta-cell-renderer-diff.c
@@ -148,6 +148,7 @@ create_attribute_list (const gchar *diff)
        PangoAttrList *list;
        const gchar *line_begin, *line_end;
        guint begin_index, end_index;
+       gboolean found_diff = FALSE;
        gboolean found_hunk = FALSE;
        PangoAttribute *attribute;
 
@@ -169,6 +170,15 @@ create_attribute_list (const gchar *diff)
                end_index = line_end - diff;
                attribute = NULL;
 
+               /* Handle multiple files. Context lines should start with a 
+                * whitespace, so just searching the first few characters 
+                * of the line for "diff" should detect the next file */
+               if (g_str_has_prefix (line_begin, "diff"))
+               {
+                       found_diff = TRUE;
+                       found_hunk = FALSE;
+               }
+
                if (line_begin[0] == '@' && line_begin[1] == '@')
                {
                        /* Dark blue */
@@ -190,6 +200,11 @@ create_attribute_list (const gchar *diff)
                                attribute = pango_attr_foreground_new (0xffff, 0, 0);   
                        }
                }
+               else if (found_diff)
+               {
+                       /* Make file headers easier to see by making them bold */
+                       attribute = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
+               }
                        
                if (attribute)
                {
@@ -203,7 +218,6 @@ create_attribute_list (const gchar *diff)
                        line_begin = line_end + 1;
                else
                        line_begin = NULL;
-
        }
 
        return list;
diff --git a/libanjuta/tests/anjuta-diff-renderer-test.c b/libanjuta/tests/anjuta-diff-renderer-test.c
index 78dc01c..563f4c0 100644
--- a/libanjuta/tests/anjuta-diff-renderer-test.c
+++ b/libanjuta/tests/anjuta-diff-renderer-test.c
@@ -58,6 +58,34 @@ main (int argc, char **argv)
                "\n"
                "# Glade module\n"
                "if ENABLE_GLADE_CATALOG\n";
+       
+       const gchar multi_file_diff[] =
+               "diff --git a/AUTHORS b/AUTHORS\n"
+               "index 9f20595..7f6ead6 100644\n"
+               "--- a/AUTHORS\n"
+               "+++ b/AUTHORS\n"
+               "@@ -11,7 +11,7 @@ Maintainers and Lead Developers:\n"
+               " Developers:\n"
+               "-------------------------------------------------------------------------------\n"
+               "       Massimo Cora'  <maxcvs email it> (Italy)\n"
+               "-      Carl-Anton Ingmarsson <ca ingmarsson gmail com>\n"      
+               "+      Carl-Anton Ingmarsson <carlantoni gnome org> (Sweden)\n"
+               "\n"
+               " Past Developers:\n"
+               "-------------------------------------------------------------------------------\n"
+               "diff --git a/plugins/git/git-clone-command.c b/plugins/git/git-clone-command.c\n"
+               "index 8fbb96a..f1665e2 100644\n"
+               "--- a/plugins/git/git-clone-command.c\n"
+               "+++ b/plugins/git/git-clone-command.c\n"
+               "@@ -1,7 +1,7 @@\n"
+               " /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */\n"
+               " /*\n"
+               "  * anjuta\n"
+               "- * Copyright (C) Carl-Anton Ingmarsson 2009 <ca ingmarsson gmail com>\n"
+               "+ * Copyright (C) Carl-Anton Ingmarsson 2009 <carlantoni gnome org>\n"
+               "  *\n" 
+               "  * anjuta is free software.\n"
+               "  *\n";
 
        const gchar non_diff[] = "non-diff text";
        const gchar hunk_line[] = "@@";
@@ -90,6 +118,10 @@ main (int argc, char **argv)
        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter, COL_DIFF, diff, -1);
 
+       /* Test multi-file diffs */
+       gtk_list_store_append (list_store, &iter);
+       gtk_list_store_set (list_store, &iter, COL_DIFF, multi_file_diff, -1);
+
        /* Test non-diff text */
        gtk_list_store_append (list_store, &iter);
        gtk_list_store_set (list_store, &iter, COL_DIFF, non_diff, -1);


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