[Users] [PATCH] Add an option to color diff when it is in message body

Blatinox blatinox at lse.epita.fr
Fri Nov 13 19:41:43 CET 2015


From: Blatinox <mail at blatinox.fr>

Signed-off-by: Blatinox <mail at blatinox.fr>
---
I would like to color diff when a patch is inside the message body and
not only of it is attached. Some people on #claws at freenode.net said that
a plugin would be welcomed. But I think the code is very small to
require a plugin. So I wrote this feature as an option to enable in
preferences.

 src/prefs_common.c  |  3 +++
 src/prefs_common.h  |  1 +
 src/prefs_message.c | 12 ++++++++++++
 src/textview.c      |  2 +-
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/prefs_common.c b/src/prefs_common.c
index b94f722..dd77636 100644
--- a/src/prefs_common.c
+++ b/src/prefs_common.c
@@ -738,6 +738,9 @@ static PrefParam param[] = {
 	{"never_send_retrcpt", "FALSE", &prefs_common.never_send_retrcpt, P_BOOL,
 	 NULL, NULL, NULL},
 
+	{"color_diff_body", "FALSE", &prefs_common.color_diff_body, P_BOOL,
+	 NULL, NULL, NULL},
+
 	{"enable_smooth_scroll", "FALSE",
 	 &prefs_common.enable_smooth_scroll, P_BOOL,
 	 NULL, NULL, NULL},
diff --git a/src/prefs_common.h b/src/prefs_common.h
index 6c98ae1..d425dc2 100644
--- a/src/prefs_common.h
+++ b/src/prefs_common.h
@@ -337,6 +337,7 @@ struct _PrefsCommon
 	gboolean hide_quoted;
 	gboolean respect_flowed_format;
 	gboolean show_all_headers;
+	gboolean color_diff_body;
 
 	gboolean show_other_header;
 	GSList *disphdr_list;
diff --git a/src/prefs_message.c b/src/prefs_message.c
index c83af9e..dd5fdd0 100644
--- a/src/prefs_message.c
+++ b/src/prefs_message.c
@@ -63,6 +63,8 @@ typedef struct _MessagePage
 
 	GtkWidget *checkbtn_attach_desc;
 	GtkWidget *entry_quote_chars;
+
+	GtkWidget *checkbtn_diff_body;
 } MessagePage;
 
 static void disphdr_pane_toggled(GtkToggleButton *toggle_btn, GtkWidget *widget)
@@ -113,6 +115,8 @@ static void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
 	GtkWidget *entry_quote_chars;
 	GtkWidget *label_quote_chars;
 
+	GtkWidget *checkbtn_diff_body;
+
 	vbox1 = gtk_vbox_new (FALSE, VSPACING);
 	gtk_widget_show (vbox1);
 	gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
@@ -256,6 +260,9 @@ static void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
 			    FALSE, FALSE, 0);
 	gtk_widget_set_size_request (entry_quote_chars, 64, -1);
 
+	PACK_CHECK_BUTTON(vbox1, checkbtn_diff_body,
+			  _("Color patches in message body"));
+
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_disphdrpane),
 		prefs_common.display_header_pane);
 
@@ -284,6 +291,8 @@ static void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
 		prefs_common.scroll_step);
 	gtk_entry_set_text(GTK_ENTRY(entry_quote_chars), 
 			prefs_common.quote_chars?prefs_common.quote_chars:"");
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_diff_body),
+		prefs_common.color_diff_body);
 		
 	prefs_message->window = GTK_WIDGET(window);
 	prefs_message->checkbtn_disphdrpane = checkbtn_disphdrpane;
@@ -299,6 +308,7 @@ static void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
 	prefs_message->checkbtn_halfpage = checkbtn_halfpage;
 	prefs_message->checkbtn_attach_desc = checkbtn_attach_desc;
 	prefs_message->entry_quote_chars = entry_quote_chars;
+	prefs_message->checkbtn_diff_body = checkbtn_diff_body;
 	
 	prefs_message->page.widget = vbox1;
 }
@@ -331,6 +341,8 @@ static void prefs_message_save(PrefsPage *_page)
 		GTK_SPIN_BUTTON(page->spinbtn_linespc));
 	prefs_common.scroll_step = gtk_spin_button_get_value_as_int(
 		GTK_SPIN_BUTTON(page->spinbtn_scrollstep));
+	prefs_common.color_diff_body = gtk_toggle_button_get_active(
+		GTK_TOGGLE_BUTTON(page->checkbtn_diff_body));
 
 	g_free(prefs_common.quote_chars); 
 	prefs_common.quote_chars = gtk_editable_get_chars(
diff --git a/src/textview.c b/src/textview.c
index 5962823..042c838 100644
--- a/src/textview.c
+++ b/src/textview.c
@@ -1068,7 +1068,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
 	procmime_force_encoding(textview->messageview->forced_encoding);
 	
 	textview->is_in_signature = FALSE;
-	textview->is_diff = FALSE;
+	textview->is_diff = prefs_common.color_diff_body;
 
 	procmime_decode_content(mimeinfo);
 
-- 
2.6.2




More information about the Users mailing list