>From 37607d54e82dd83ea49c6422ec61563af60a66de Mon Sep 17 00:00:00 2001
From: Colomban Wendling <ban@herbesfolles.org>
Date: Sat, 29 Sep 2012 20:18:19 +0200
Subject: [PATCH] Move custom styles to a resource file

---
 Makefile.am      |    3 ++-
 data/geany.gtkrc |   23 +++++++++++++++++++++++
 src/notebook.c   |   11 -----------
 src/search.c     |   28 ----------------------------
 src/ui_utils.c   |   26 ++++++++++++--------------
 wscript          |    1 +
 6 files changed, 38 insertions(+), 54 deletions(-)
 create mode 100644 data/geany.gtkrc

diff --git a/Makefile.am b/Makefile.am
index db612be..d3035f0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,7 +24,8 @@ SYS_DATA_FILES = \
 	$(srcdir)/data/templates/* \
 	$(srcdir)/data/templates/files/* \
 	$(srcdir)/data/colorschemes/* \
-	$(top_srcdir)/data/geany.glade
+	$(top_srcdir)/data/geany.glade \
+	$(top_srcdir)/data/geany.gtkrc
 
 EXTRA_DIST = \
 	autogen.sh \
diff --git a/data/geany.gtkrc b/data/geany.gtkrc
new file mode 100644
index 0000000..7947c7d
--- /dev/null
+++ b/data/geany.gtkrc
@@ -0,0 +1,23 @@
+# custom GTK2 style for Geany
+
+# make close button on the editor's tabs smaller
+style "geany-close-tab-button-style" {
+	GtkWidget::focus-padding = 0
+	GtkWidget::focus-line-width = 0
+	xthickness = 0
+	ythickness = 0
+}
+widget "*.geany-close-tab-button" style "geany-close-tab-button-style"
+
+# use monospaced font in search entries for easier reading of regexp (#1907117)
+style "geany-monospace" {
+	font_name = "Monospace"
+}
+widget "GeanyDialogSearch.*.GtkEntry" style "geany-monospace"
+
+# set red background for GtkEntries showing unmatched searches
+style "geany-search-entry-no-match-style" {
+	base[NORMAL] = "#ffff66666666"
+	text[NORMAL] = "#ffffffffffff"
+}
+widget "*.geany-search-entry-no-match" style "geany-search-entry-no-match-style"
diff --git a/src/notebook.c b/src/notebook.c
index 3bf62a4..420c4e3 100644
--- a/src/notebook.c
+++ b/src/notebook.c
@@ -535,17 +535,6 @@ static gboolean notebook_tab_bar_click_cb(GtkWidget *widget, GdkEventButton *eve
 
 void notebook_init()
 {
-	/* Individual style for the tab close buttons */
-	gtk_rc_parse_string(
-		"style \"geany-close-tab-button-style\" {\n"
-		"	GtkWidget::focus-padding = 0\n"
-		"	GtkWidget::focus-line-width = 0\n"
-		"	xthickness = 0\n"
-		"	ythickness = 0\n"
-		"}\n"
-		"widget \"*.geany-close-tab-button\" style \"geany-close-tab-button-style\""
-	);
-
 	g_signal_connect_after(main_widgets.notebook, "button-press-event",
 		G_CALLBACK(notebook_tab_bar_click_cb), NULL);
 
diff --git a/src/search.c b/src/search.c
index 68ab767..22bc29b 100644
--- a/src/search.c
+++ b/src/search.c
@@ -423,28 +423,6 @@ void search_find_selection(GeanyDocument *doc, gboolean search_backwards)
 }
 
 
-/* this will load a GTK rc style to set a monospace font for text fields(GtkEntry) in all
- * search dialogs. This needs to be done only once.
- * The monospace font should increase readibility of regular expressions containing spaces, points,
- * commas and similar (#1907117). */
-static void load_monospace_style(void)
-{
-	static const gchar *rcstyle =
-		"style \"geany-monospace\"\n" \
-		"{\n" \
-		"    font_name=\"Monospace\"\n" \
-		"}\n" \
-		"widget \"GeanyDialogSearch.*.GtkEntry\" style \"geany-monospace\"";
-	static gboolean load = TRUE;
-
-	if (load)
-	{
-		gtk_rc_parse_string(rcstyle);
-		load = FALSE;
-	}
-}
-
-
 static void on_expander_activated(GtkExpander *exp, gpointer data)
 {
 	gboolean *setting = data;
@@ -458,8 +436,6 @@ static void create_find_dialog(void)
 	GtkWidget *label, *entry, *sbox, *vbox;
 	GtkWidget *exp, *bbox, *button, *check_close;
 
-	load_monospace_style();
-
 	find_dlg.dialog = gtk_dialog_new_with_buttons(_("Find"),
 		GTK_WINDOW(main_widgets.window), GTK_DIALOG_DESTROY_WITH_PARENT,
 		GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL);
@@ -614,8 +590,6 @@ static void create_replace_dialog(void)
 		*check_close, *button, *rbox, *fbox, *vbox, *exp, *bbox;
 	GtkSizeGroup *label_size;
 
-	load_monospace_style();
-
 	replace_dlg.dialog = gtk_dialog_new_with_buttons(_("Replace"),
 		GTK_WINDOW(main_widgets.window), GTK_DIALOG_DESTROY_WITH_PARENT,
 		GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL, NULL);
@@ -865,8 +839,6 @@ static void create_fif_dialog(void)
 	gchar *encoding_string;
 	guint i;
 
-	load_monospace_style();
-
 	fif_dlg.dialog = gtk_dialog_new_with_buttons(
 		_("Find in Files"), GTK_WINDOW(main_widgets.window), GTK_DIALOG_DESTROY_WITH_PARENT,
 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
diff --git a/src/ui_utils.c b/src/ui_utils.c
index ec8662d..0eecbdd 100644
--- a/src/ui_utils.c
+++ b/src/ui_utils.c
@@ -944,20 +944,7 @@ void ui_document_show_hide(GeanyDocument *doc)
 
 void ui_set_search_entry_background(GtkWidget *widget, gboolean success)
 {
-	static const GdkColor red   = {0, 0xffff, 0x6666, 0x6666};
-	static const GdkColor white = {0, 0xffff, 0xffff, 0xffff};
-	static gboolean old_value = TRUE;
-
-	g_return_if_fail(widget != NULL);
-
-	/* update only if really needed */
-	if (old_value != success)
-	{
-		gtk_widget_modify_base(widget, GTK_STATE_NORMAL, success ? NULL : &red);
-		gtk_widget_modify_text(widget, GTK_STATE_NORMAL, success ? NULL : &white);
-
-		old_value = success;
-	}
+	gtk_widget_set_name(widget, success ? NULL : "geany-search-entry-no-match");
 }
 
 
@@ -2270,8 +2257,19 @@ void ui_init_builder(void)
 }
 
 
+static void init_custom_style(void)
+{
+	gchar *gtkrc_file = g_build_filename(app->datadir, "geany.gtkrc", NULL);
+
+	gtk_rc_parse(gtkrc_file);
+	g_free(gtkrc_file);
+}
+
+
 void ui_init(void)
 {
+	init_custom_style();
+
 	init_recent_files();
 
 	ui_widgets.statusbar = ui_lookup_widget(main_widgets.window, "statusbar");
diff --git a/wscript b/wscript
index bf95a75..1617b5d 100644
--- a/wscript
+++ b/wscript
@@ -485,6 +485,7 @@ def build(bld):
     bld.install_files('${DATADIR}/%s' % data_dir, start_dir.ant_glob('filetype*'), cwd=start_dir)
     bld.install_files('${DATADIR}/%s' % data_dir, start_dir.ant_glob('*.tags'), cwd=start_dir)
     bld.install_files('${DATADIR}/%s' % data_dir, 'data/geany.glade')
+    bld.install_files('${DATADIR}/%s' % data_dir, 'data/geany.gtkrc')
     bld.install_files('${DATADIR}/%s' % data_dir, 'data/snippets.conf')
     bld.install_files('${DATADIR}/%s' % data_dir, 'data/ui_toolbar.xml')
     start_dir = bld.path.find_dir('data/colorschemes')
-- 
1.7.10.4

