Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Mon, 11 Feb 2013 03:46:40 UTC Commit: 36581d6638236768e3ba00b1da2c15e795bc95f3 https://github.com/geany/geany/commit/36581d6638236768e3ba00b1da2c15e795bc95...
Log Message: ----------- Move document status color definition to the gtkrc file
This allows for users to change the colors if needed (may be useful with some themes or color blind persons).
On the sidebar, only the color is applied for now. This is because it is not possible to style cell renderers through RC files, all having to be done in the code; so currently only the color is applied.
Modified Paths: -------------- data/geany.gtkrc src/document.c src/document.h src/ui_utils.c
Modified: data/geany.gtkrc 17 files changed, 17 insertions(+), 0 deletions(-) =================================================================== @@ -22,3 +22,20 @@ style "geany-search-entry-no-match-style" { text[NORMAL] = "#ffffffffffff" } widget "*.geany-search-entry-no-match" style:theme "geany-search-entry-no-match-style" + +# document status colors +style "geany-document-status-changed-style" { + fg[NORMAL] = "#ffff00000000" + fg[ACTIVE] = "#ffff00000000" +} +style "geany-document-status-disk-changed-style" { + fg[NORMAL] = "#ffff7fff0000" + fg[ACTIVE] = "#ffff7fff0000" +} +style "geany-document-status-readonly-style" { + fg[NORMAL] = "#00007fff0000" + fg[ACTIVE] = "#00007fff0000" +} +widget "*.geany-document-status-changed" style:theme "geany-document-status-changed-style" +widget "*.geany-document-status-disk-changed" style:theme "geany-document-status-disk-changed-style" +widget "*.geany-document-status-readonly" style:theme "geany-document-status-readonly-style"
Modified: src/document.c 84 files changed, 69 insertions(+), 15 deletions(-) =================================================================== @@ -2693,6 +2693,60 @@ static void document_redo_add(GeanyDocument *doc, guint type, gpointer data) }
+enum +{ + STATUS_CHANGED, +#ifdef USE_GIO_FILEMON + STATUS_DISK_CHANGED, +#endif + STATUS_READONLY +}; +static struct +{ + const gchar *name; + GdkColor color; + gboolean loaded; +} document_status_styles[] = { + { "geany-document-status-changed", {0}, FALSE }, +#ifdef USE_GIO_FILEMON + { "geany-document-status-disk-changed", {0}, FALSE }, +#endif + { "geany-document-status-readonly", {0}, FALSE } +}; + + +static gint document_get_status_id(GeanyDocument *doc) +{ + if (doc->changed) + return STATUS_CHANGED; +#ifdef USE_GIO_FILEMON + else if (doc->priv->file_disk_status == FILE_CHANGED) + return STATUS_DISK_CHANGED; +#endif + else if (doc->readonly) + return STATUS_READONLY; + + return -1; +} + + +/* returns an identifier that is to be set as a widget name or class to get it styled + * depending on the document status (changed, readonly, etc.) + * a NULL return value means default (unchanged) style */ +const gchar *document_get_status_widget_class(GeanyDocument *doc) +{ + gint status; + + g_return_val_if_fail(doc != NULL, NULL); + + status = document_get_status_id(doc); + if (status < 0) + return NULL; + else + return document_status_styles[status].name; +} + + /** * Gets the status color of the document, or @c NULL if default widget coloring should be used. * Returned colors are red if the document has changes, green if the document is read-only @@ -2707,25 +2761,25 @@ static void document_redo_add(GeanyDocument *doc, guint type, gpointer data) */ const GdkColor *document_get_status_color(GeanyDocument *doc) { - static GdkColor red = {0, 0xFFFF, 0, 0}; - static GdkColor green = {0, 0, 0x7FFF, 0}; -#ifdef USE_GIO_FILEMON - static GdkColor orange = {0, 0xFFFF, 0x7FFF, 0}; -#endif - GdkColor *color = NULL; + gint status;
g_return_val_if_fail(doc != NULL, NULL);
- if (doc->changed) - color = &red; -#ifdef USE_GIO_FILEMON - else if (doc->priv->file_disk_status == FILE_CHANGED) - color = &orange; -#endif - else if (doc->readonly) - color = &green; + status = document_get_status_id(doc); + if (status < 0) + return NULL; + if (! document_status_styles[status].loaded) + { + GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(doc->editor->sci)); + gchar *path = g_strconcat("GeanyMainWindow.GtkHBox.GtkNotebook.", + document_status_styles[status].name, NULL); + GtkStyle *style = gtk_rc_get_style_by_paths(settings, path, NULL, GTK_TYPE_LABEL);
- return color; /* return pointer to static GdkColor. */ + document_status_styles[status].color = style->fg[GTK_STATE_NORMAL]; + document_status_styles[status].loaded = TRUE; + g_free(path); + } + return &document_status_styles[status].color; }
Modified: src/document.h 2 files changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -259,6 +259,8 @@ void document_replace_sel(GeanyDocument *doc, const gchar *find_text, const gcha
void document_update_tab_label(GeanyDocument *doc);
+const gchar *document_get_status_widget_class(GeanyDocument *doc); + const GdkColor *document_get_status_color(GeanyDocument *doc);
gchar *document_get_basename_for_display(GeanyDocument *doc, gint length);
Modified: src/ui_utils.c 11 files changed, 2 insertions(+), 9 deletions(-) =================================================================== @@ -1515,11 +1515,7 @@ void ui_combo_box_prepend_text_once(GtkComboBox *combo, const gchar *text) * document status. */ void ui_update_tab_status(GeanyDocument *doc) { - const GdkColor *color = document_get_status_color(doc); - - /* NULL color will reset to default */ - gtk_widget_modify_fg(doc->priv->tab_label, GTK_STATE_NORMAL, color); - gtk_widget_modify_fg(doc->priv->tab_label, GTK_STATE_ACTIVE, color); + gtk_widget_set_name(doc->priv->tab_label, document_get_status_widget_class(doc));
sidebar_openfiles_update(doc); } @@ -2532,7 +2528,6 @@ void ui_menu_add_document_items_sorted(GtkMenu *menu, GeanyDocument *active, GCallback callback, GCompareFunc compare_func) { GtkWidget *menu_item, *menu_item_label, *image; - const GdkColor *color; GeanyDocument *doc; guint i, len; gchar *base_name, *label; @@ -2565,10 +2560,8 @@ void ui_menu_add_document_items_sorted(GtkMenu *menu, GeanyDocument *active, gtk_container_add(GTK_CONTAINER(menu), menu_item); g_signal_connect(menu_item, "activate", callback, doc);
- color = document_get_status_color(doc); menu_item_label = gtk_bin_get_child(GTK_BIN(menu_item)); - gtk_widget_modify_fg(menu_item_label, GTK_STATE_NORMAL, color); - gtk_widget_modify_fg(menu_item_label, GTK_STATE_ACTIVE, color); + gtk_widget_set_name(menu_item_label, document_get_status_widget_class(doc));
if (doc == active) {
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).