r18637 - gnucash/trunk/src - Bug #608329: Add Color to Account tabs

Christian Stimming cstim at code.gnucash.org
Wed Feb 10 15:35:12 EST 2010


Author: cstim
Date: 2010-02-10 15:35:11 -0500 (Wed, 10 Feb 2010)
New Revision: 18637
Trac: http://svn.gnucash.org/trac/changeset/18637

Modified:
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Account.h
   gnucash/trunk/src/gnome-utils/dialog-account.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.h
   gnucash/trunk/src/gnome-utils/gnc-plugin-page.c
   gnucash/trunk/src/gnome-utils/gnc-plugin-page.h
   gnucash/trunk/src/gnome/glade/account.glade
   gnucash/trunk/src/gnome/gnc-plugin-page-register.c
Log:
Bug #608329: Add Color to Account tabs

Patch by "Bob":
I wanted a way to select an account easily when I have several accounts open in
the main window. I decided to add a color option to the account so that the tab
can be set to a specific color and so easily identifiable. This could also be
used to link like minded accounts together.

This patch also fixes the account tooltip not being
updated when the name changes.

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/engine/Account.c	2010-02-10 20:35:11 UTC (rev 18637)
@@ -58,6 +58,7 @@
   PROP_FULL_NAME,
   PROP_CODE,
   PROP_DESCRIPTION,
+  PROP_COLOR,
   PROP_NOTES,
   PROP_TYPE,
 
@@ -294,6 +295,9 @@
 	case PROP_DESCRIPTION:
 	    g_value_set_string(value, priv->description);
 	    break;
+	case PROP_COLOR:
+	    g_value_set_string(value, xaccAccountGetColor(account));
+	    break;
 	case PROP_NOTES:
 	    g_value_set_string(value, xaccAccountGetNotes(account));
 	    break;
@@ -390,6 +394,9 @@
 	case PROP_DESCRIPTION:
 	    xaccAccountSetDescription(account, g_value_get_string(value));
 	    break;
+	case PROP_COLOR:
+	    xaccAccountSetColor(account, g_value_get_string(value));
+	    break;
 	case PROP_NOTES:
 	    xaccAccountSetNotes(account, g_value_get_string(value));
 	    break;
@@ -521,6 +528,17 @@
 
     g_object_class_install_property
 	(gobject_class,
+	 PROP_COLOR,
+	 g_param_spec_string ("color",
+			      "Account Color",
+			      "The account color is a color string assigned "
+			      "by the user. It is intended to highlight the "
+			      "account based on the users wishes.",
+			      NULL,
+			      G_PARAM_READWRITE));
+
+    g_object_class_install_property
+	(gobject_class,
 	 PROP_NOTES,
 	 g_param_spec_string ("notes",
 			      "Account Notes",
@@ -2076,6 +2094,24 @@
     xaccAccountCommitEdit(acc);
 }
 
+void
+xaccAccountSetColor (Account *acc, const char *str) 
+{
+  g_return_if_fail(GNC_IS_ACCOUNT(acc));
+
+  xaccAccountBeginEdit(acc);
+  if (str) {
+    gchar *tmp = g_strstrip(g_strdup(str));
+    kvp_frame_set_slot_nc(acc->inst.kvp_data, "color", 
+			  strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
+    g_free(tmp);
+  } else {
+    kvp_frame_set_slot_nc(acc->inst.kvp_data, "color", NULL);
+  }
+    mark_account (acc);
+    xaccAccountCommitEdit(acc);
+}
+
 static void
 qofAccountSetParent (Account *acc, QofInstance *parent) 
 {
@@ -2829,6 +2865,13 @@
 }
 
 const char * 
+xaccAccountGetColor (const Account *acc)
+{
+    g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
+    return acc ? kvp_frame_get_string(acc->inst.kvp_data, "color") : NULL;
+}
+
+const char * 
 xaccAccountGetNotes (const Account *acc) 
 {
     g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
@@ -4395,6 +4438,9 @@
 	continue;
       if (0 != null_strcmp(priv_a->description, priv_b->description))
 	continue;
+      if (0 != null_strcmp(xaccAccountGetColor(acc_a),
+			   xaccAccountGetColor(acc_b)))
+	continue;
       if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
 	continue;
       if (0 != null_strcmp(xaccAccountGetNotes(acc_a),
@@ -4637,6 +4683,9 @@
     { ACCOUNT_DESCRIPTION_, QOF_TYPE_STRING, 
       (QofAccessFunc) xaccAccountGetDescription,
       (QofSetterFunc) xaccAccountSetDescription },
+    { ACCOUNT_COLOR_, QOF_TYPE_STRING, 
+      (QofAccessFunc) xaccAccountGetColor,
+      (QofSetterFunc) xaccAccountSetColor },
     { ACCOUNT_NOTES_, QOF_TYPE_STRING, 
       (QofAccessFunc) xaccAccountGetNotes,
       (QofSetterFunc) xaccAccountSetNotes },

Modified: gnucash/trunk/src/engine/Account.h
===================================================================
--- gnucash/trunk/src/engine/Account.h	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/engine/Account.h	2010-02-10 20:35:11 UTC (rev 18637)
@@ -263,6 +263,8 @@
 void xaccAccountSetCode (Account *account, const char *code);
 /** Set the account's description */
 void xaccAccountSetDescription (Account *account, const char *desc);
+/** Set the account's Color */
+void xaccAccountSetColor (Account *account, const char *color);
 /** Set the account's notes */
 void xaccAccountSetNotes (Account *account, const char *notes);
 /** Set the last num field of an Account */
@@ -354,6 +356,8 @@
 const char * xaccAccountGetCode (const Account *account);
 /** Get the account's description */
 const char * xaccAccountGetDescription (const Account *account);
+/** Get the account's color */
+const char * xaccAccountGetColor (const Account *account);
 /** Get the account's notes */
 const char * xaccAccountGetNotes (const Account *account);
 /** Get the last num field of an Account */
@@ -1408,10 +1412,11 @@
 /** @name Account parameter names 
  @{
 */
-#define ACCOUNT_KVP			"kvp"
+#define ACCOUNT_KVP		"kvp"
 #define ACCOUNT_NAME_		"name"
 #define ACCOUNT_CODE_		"code"
 #define ACCOUNT_DESCRIPTION_	"desc"
+#define ACCOUNT_COLOR_		"color"
 #define ACCOUNT_NOTES_		"notes"
 #define ACCOUNT_BALANCE_	"balance"
 #define ACCOUNT_CLEARED_	"cleared"
@@ -1420,7 +1425,7 @@
 #define ACCOUNT_FUTURE_MINIMUM_ "future-minimum"
 #define ACCOUNT_TAX_RELATED	"tax-related-p"
 #define ACCOUNT_TYPE_		"account-type"
-#define ACCOUNT_SCU			"smallest-commodity-unit"
+#define ACCOUNT_SCU		"smallest-commodity-unit"
 #define ACCOUNT_NSCU		"non-standard-scu"
 #define ACCOUNT_PARENT		"parent-account"
 

Modified: gnucash/trunk/src/gnome/glade/account.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/account.glade	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/gnome/glade/account.glade	2010-02-10 20:35:11 UTC (rev 18637)
@@ -165,7 +165,7 @@
 		  <child>
 		    <widget class="GtkTable" id="table3">
 		      <property name="visible">True</property>
-		      <property name="n_rows">8</property>
+		      <property name="n_rows">9</property>
 		      <property name="n_columns">2</property>
 		      <property name="homogeneous">False</property>
 		      <property name="row_spacing">6</property>
@@ -335,6 +335,81 @@
 			</packing>
 		      </child>
 
+
+                      <child>
+                        <widget class="GtkLabel" id="label6">
+                          <property name="visible">True</property>
+                          <property name="xalign">0</property>
+                          <property name="label" translatable="yes">Account _Color:</property>
+                          <property name="use_underline">True</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">False</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+                          <property name="mnemonic_widget">color_entry_button</property>
+			  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+			  <property name="width_chars">-1</property>
+			  <property name="single_line_mode">False</property>
+			  <property name="angle">0</property>
+                        </widget>
+                        <packing>
+                          <property name="top_attach">5</property>
+                          <property name="bottom_attach">6</property>
+                          <property name="x_options">GTK_FILL</property>
+                          <property name="y_options"></property>
+                        </packing>
+                      </child>
+  
+
+                      <child>
+                        <widget class="GtkHBox" id="color_hbox">
+                          <property name="visible">True</property>
+                          <property name="spacing">3</property>
+                          <child>
+                            <widget class="GtkColorButton" id="color_entry_button">
+                              <property name="visible">True</property>
+                              <property name="can_focus">True</property>
+                              <property name="receives_default">True</property>
+                              <property name="color">#ededececebeb</property>
+                            </widget>
+                            <packing>
+                              <property name="position">0</property>
+                            </packing>
+                          </child>
+                          <child>
+                            <widget class="GtkButton" id="color_default_button">
+                              <property name="label" translatable="yes">Default</property>
+                              <property name="visible">True</property>
+                              <property name="can_focus">True</property>
+                              <property name="receives_default">True</property>
+                            </widget>
+                            <packing>
+                              <property name="expand">False</property>
+                              <property name="position">1</property>
+                            </packing>
+                          </child>
+                        </widget>
+                        <packing>
+                          <property name="left_attach">1</property>
+                          <property name="right_attach">2</property>
+                          <property name="top_attach">5</property>
+                          <property name="bottom_attach">6</property>
+                          <property name="x_options">GTK_FILL</property>
+                          <property name="y_options">GTK_FILL</property>
+                        </packing>
+                      </child>
+
+
+
+
+
+
+
+
 		      <child>
 			<widget class="GtkLabel" id="label">
 			  <property name="visible">True</property>
@@ -357,8 +432,8 @@
 			<packing>
 			  <property name="left_attach">0</property>
 			  <property name="right_attach">1</property>
-			  <property name="top_attach">5</property>
-			  <property name="bottom_attach">6</property>
+			  <property name="top_attach">6</property>
+			  <property name="bottom_attach">7</property>
 			  <property name="x_options">fill</property>
 			  <property name="y_options">fill</property>
 			</packing>
@@ -381,8 +456,8 @@
 			<packing>
 			  <property name="left_attach">0</property>
 			  <property name="right_attach">1</property>
-			  <property name="top_attach">6</property>
-			  <property name="bottom_attach">7</property>
+			  <property name="top_attach">7</property>
+			  <property name="bottom_attach">8</property>
 			  <property name="x_options">fill</property>
 			  <property name="y_options"></property>
 			</packing>
@@ -404,8 +479,8 @@
 			<packing>
 			  <property name="left_attach">0</property>
 			  <property name="right_attach">1</property>
-			  <property name="top_attach">7</property>
-			  <property name="bottom_attach">8</property>
+			  <property name="top_attach">8</property>
+			  <property name="bottom_attach">9</property>
 			  <property name="x_options">fill</property>
 			  <property name="y_options"></property>
 			</packing>
@@ -427,8 +502,8 @@
 			<packing>
 			  <property name="left_attach">1</property>
 			  <property name="right_attach">2</property>
-			  <property name="top_attach">6</property>
-			  <property name="bottom_attach">7</property>
+			  <property name="top_attach">7</property>
+			  <property name="bottom_attach">8</property>
 			  <property name="x_options">fill</property>
 			  <property name="y_options"></property>
 			</packing>
@@ -529,8 +604,8 @@
 			<packing>
 			  <property name="left_attach">1</property>
 			  <property name="right_attach">2</property>
-			  <property name="top_attach">5</property>
-			  <property name="bottom_attach">6</property>
+			  <property name="top_attach">6</property>
+			  <property name="bottom_attach">7</property>
 			  <property name="x_options">fill</property>
 			  <property name="y_options">fill</property>
 			</packing>

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2010-02-10 20:35:11 UTC (rev 18637)
@@ -98,6 +98,7 @@
 static gboolean gnc_plugin_page_register_finish_pending (GncPluginPage *page);
 
 static gchar *gnc_plugin_page_register_get_tab_name (GncPluginPage *plugin_page);
+static gchar *gnc_plugin_page_register_get_tab_color (GncPluginPage *plugin_page);
 static gchar *gnc_plugin_page_register_get_long_name (GncPluginPage *plugin_page);
 
 static void gnc_plugin_page_register_summarybar_position_changed(GConfEntry *entry, gpointer user_data);
@@ -448,6 +449,7 @@
 	const GList *item;
 	GList *book_list;
 	gchar *label;
+	gchar *label_color;
 	QofQuery *q;
 
 	/* Is there an existing page? */
@@ -472,6 +474,10 @@
 	gnc_plugin_page_set_page_name(plugin_page, label);
 	g_free(label);
 
+	label_color = gnc_plugin_page_register_get_tab_color(plugin_page);
+	gnc_plugin_page_set_page_color(plugin_page, label_color);
+	g_free(label_color);
+
 	label = gnc_plugin_page_register_get_long_name(plugin_page);
         gnc_plugin_page_set_page_long_name(plugin_page, label);
         g_free(label);
@@ -1192,6 +1198,37 @@
 }
 
 static gchar *
+gnc_plugin_page_register_get_tab_color (GncPluginPage *plugin_page)
+{
+	GncPluginPageRegisterPrivate *priv;
+	GNCLedgerDisplayType ledger_type;
+  	GNCLedgerDisplay *ld;
+	SplitRegister *reg;
+	Account *leader;
+
+	g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), _("unknown"));
+
+	priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
+	ld = priv->ledger;
+	reg = gnc_ledger_display_get_split_register (ld);
+	ledger_type = gnc_ledger_display_type (ld);
+	leader = gnc_ledger_display_leader (ld);
+
+	switch (ledger_type) {
+	 case LD_SINGLE:
+	  return g_strdup(xaccAccountGetColor (leader));
+
+	 case LD_SUBACCOUNT:
+	  return g_strdup_printf("%s+", xaccAccountGetColor (leader));
+
+	 default:
+	  break;
+	}
+
+	return g_strdup("Not Set");
+}
+
+static gchar *
 gnc_plugin_page_register_get_long_name (GncPluginPage *plugin_page)
 {
 	GncPluginPageRegisterPrivate *priv;
@@ -3015,7 +3052,7 @@
   QofBook *book;
   GncPluginPage *visible_page;
   GtkWidget *window;
-  gchar *label;
+  gchar *label, *color;
 
   g_return_if_fail(page);	/* Required */
   if (!GNC_IS_TRANS(entity) && !GNC_IS_ACCOUNT(entity))
@@ -3030,6 +3067,9 @@
     if (GNC_IS_MAIN_WINDOW(window)) {
       label = gnc_plugin_page_register_get_tab_name(GNC_PLUGIN_PAGE(page));
       main_window_update_page_name(GNC_PLUGIN_PAGE(page), label);
+      color = gnc_plugin_page_register_get_tab_color(GNC_PLUGIN_PAGE(page));
+      main_window_update_page_color(GNC_PLUGIN_PAGE(page), color);
+      g_free(color);
       g_free(label);
     }
     LEAVE("tab name updated");

Modified: gnucash/trunk/src/gnome-utils/dialog-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-account.c	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/gnome-utils/dialog-account.c	2010-02-10 20:35:11 UTC (rev 18637)
@@ -53,6 +53,7 @@
 #define DIALOG_NEW_ACCOUNT_CM_CLASS "dialog-new-account"
 #define DIALOG_EDIT_ACCOUNT_CM_CLASS "dialog-edit-account"
 #define GCONF_SECTION "dialogs/account"
+#define DEFAULT_COLOR "#ededececebeb"
 
 enum account_cols {
   ACCOUNT_COL_FULLNAME = 0,
@@ -88,6 +89,8 @@
 
   GtkWidget * name_entry;
   GtkWidget * description_entry;
+  GtkWidget * color_entry_button;
+  GtkWidget * color_default_button;
   GtkWidget * code_entry;
   GtkTextBuffer * notes_text_buffer;
 
@@ -191,6 +194,7 @@
   Account *account;
   gnc_commodity * commodity;
   const char *string;
+  GdkColor color;
   gboolean flag, nonstd_scu;
   gint index;
 
@@ -209,6 +213,12 @@
   if (string == NULL) string = "";
   gtk_entry_set_text(GTK_ENTRY(aw->description_entry), string);
 
+  string = xaccAccountGetColor (account);
+  if (string == NULL) string = "";
+  if (gdk_color_parse(string, &color)) {
+    gtk_color_button_set_color(GTK_COLOR_BUTTON(aw->color_entry_button), &color);
+  }
+
   commodity = xaccAccountGetCommodity (account);
   gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
                                     commodity);
@@ -308,6 +318,7 @@
   Account *parent_account;
   const char *old_string;
   const char *string;
+  GdkColor color;
   gboolean flag;
   gnc_numeric balance;
   gboolean use_equity, nonstd;
@@ -344,6 +355,12 @@
   if (safe_strcmp (string, old_string) != 0)
     xaccAccountSetDescription (account, string);
 
+  gtk_color_button_get_color(GTK_COLOR_BUTTON(aw->color_entry_button), &color );
+  string = gdk_color_to_string(&color);
+  old_string = xaccAccountGetColor (account);
+  if (safe_strcmp (string, old_string) != 0)
+    xaccAccountSetColor (account, string);
+
   commodity = (gnc_commodity *)
     gnc_general_select_get_selected (GNC_GENERAL_SELECT (aw->commodity_edit));
   if (commodity &&
@@ -1103,6 +1120,17 @@
 }
 
 static void
+gnc_account_color_default_cb(GtkWidget *widget, gpointer data)
+{
+  GdkColor color;
+  AccountWindow *aw = data;
+
+  gdk_color_parse( DEFAULT_COLOR, &color);
+  gtk_color_button_set_color(GTK_COLOR_BUTTON(aw->color_entry_button), &color);
+
+}
+
+static void
 commodity_changed_cb (GNCGeneralSelect *gsl, gpointer data)
 {
   AccountWindow *aw = data;
@@ -1205,6 +1233,13 @@
 		    G_CALLBACK (gnc_account_name_changed_cb), aw);
 
   aw->description_entry = glade_xml_get_widget (xml, "description_entry");
+
+  aw->color_entry_button = glade_xml_get_widget (xml, "color_entry_button");
+
+  aw->color_default_button = glade_xml_get_widget (xml, "color_default_button");
+  g_signal_connect (G_OBJECT (aw->color_default_button), "clicked",
+		    G_CALLBACK (gnc_account_color_default_cb), aw);
+
   aw->code_entry =        glade_xml_get_widget (xml, "code_entry");
   aw->notes_text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (glade_xml_get_widget (xml, "notes_text")));
 

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2010-02-10 20:35:11 UTC (rev 18637)
@@ -94,6 +94,7 @@
 
 #define GNC_MAIN_WINDOW_NAME "GncMainWindow"
 
+
 /* Static Globals *******************************************************/
 
 /** The debugging module that this .o belongs to.  */
@@ -1698,38 +1699,68 @@
 			    GtkWidget **entry_p)
 {
   GncMainWindowPrivate *priv;
-  GtkWidget *tab_hbox, *widget;
+  GtkWidget *tab_hbox, *widget, *event_box;
   GList *children, *tmp;
 
   ENTER("window %p, page %p, label_p %p, entry_p %p",
 	window, page, label_p, entry_p);
   priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
   *label_p = *entry_p = NULL;
-  tab_hbox = gtk_notebook_get_tab_label(GTK_NOTEBOOK(priv->notebook),
+
+  event_box = gtk_notebook_get_tab_label(GTK_NOTEBOOK(priv->notebook),
 					page->notebook_page);
+
+  tab_hbox = gtk_bin_get_child(GTK_BIN(event_box));
+
   children = gtk_container_get_children(GTK_CONTAINER(tab_hbox));
   for (tmp = children; tmp; tmp = g_list_next(tmp)) {
     widget = tmp->data;
-    if (GTK_IS_EVENT_BOX(widget)) {
-      *label_p = gtk_bin_get_child(GTK_BIN(widget));
+    if (GTK_IS_LABEL(widget)) {
+      *label_p = widget;
     } else if (GTK_IS_ENTRY(widget)) {
       *entry_p = widget;
     }
   }
+
   g_list_free(children);
 
   LEAVE("label %p, entry %p", *label_p, *entry_p);
   return (*label_p && *entry_p);
 }
 
+static gboolean
+main_window_find_tab_event (GncMainWindow *window,
+			    GncPluginPage *page,
+			    GtkWidget **event_p)
+{
+  GncMainWindowPrivate *priv;
+  GtkWidget *event_box;
+
+  ENTER("window %p, page %p, event %p",
+	window, page, event_p);
+  priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
+  *event_p = NULL;
+
+  event_box = gtk_notebook_get_tab_label(GTK_NOTEBOOK(priv->notebook),
+					page->notebook_page);
+  if (GTK_IS_EVENT_BOX(event_box)) {
+    *event_p = event_box;
+    LEAVE("event %p", *event_p);
+    return (TRUE);
+  }
+
+  LEAVE("event %p", *event_p);
+  return (FALSE);
+}
+
 void
 main_window_update_page_name (GncPluginPage *page,
 			      const gchar *name_in)
 {
   GncMainWindow *window;
   GncMainWindowPrivate *priv;
-  GtkWidget *label, *entry;
-  gchar *name;
+  GtkWidget *label, *entry, *event_box;
+  gchar *name, *old_page_name, *old_page_long_name;
 
   ENTER(" ");
 
@@ -1738,6 +1769,7 @@
     return;
   }
   name = g_strstrip(g_strdup(name_in));
+
   /* Optimization, if the name hasn't changed, don't update X. */
   if (*name == '\0' || 0 == strcmp(name, gnc_plugin_page_get_page_name(page))) {
     g_free(name);
@@ -1745,6 +1777,10 @@
     return;
   }
 
+  old_page_name = g_strdup( gnc_plugin_page_get_page_name(page));
+  old_page_long_name = g_strdup( gnc_plugin_page_get_page_long_name(page));
+
+
   /* Update the plugin */
   window = GNC_MAIN_WINDOW(page->window);
   priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
@@ -1754,6 +1790,22 @@
   main_window_find_tab_items(window, page, &label, &entry);
   gtk_label_set_text(GTK_LABEL(label), name);
 
+  /* Update Tooltip on notebook Tab */
+  main_window_find_tab_event(window, page, &event_box);
+
+  if (strstr(old_page_long_name,old_page_name) != NULL) {
+    gchar *new_page_long_name;
+    gint string_position;
+
+    string_position = strlen(old_page_long_name) - strlen(old_page_name);
+    new_page_long_name = g_strconcat(g_strndup(old_page_long_name, string_position), name, NULL);
+
+    gnc_plugin_page_set_page_long_name(page, new_page_long_name);
+    gtk_tooltips_set_tip(GTK_TOOLTIPS(tips), event_box, new_page_long_name, NULL);
+
+    g_free(new_page_long_name);
+  }
+
   /* Update the notebook menu */
   label = gtk_notebook_get_menu_label (GTK_NOTEBOOK(priv->notebook),
 				       page->notebook_page);
@@ -1761,10 +1813,56 @@
   
   /* Force an update of the window title */
   gnc_main_window_update_title(window);
+  g_free(old_page_long_name);
+  g_free(old_page_name);
   g_free(name);
   LEAVE("done");
 }
 
+
+void
+main_window_update_page_color (GncPluginPage *page,
+			      const gchar *color_in)
+{
+  GncMainWindow *window;
+  GncMainWindowPrivate *priv;
+  GtkWidget *event_box;
+  GdkColor tab_color;
+  gchar *color_string;
+
+
+  ENTER(" ");
+
+  if ((color_in == NULL) || (*color_in == '\0')) {
+    LEAVE("no string");
+    return;
+  }
+  color_string = g_strstrip(g_strdup(color_in));
+
+  /* Optimization, if the color hasn't changed, don't update. */
+  if (*color_string == '\0' || 0 == safe_strcmp(color_string, gnc_plugin_page_get_page_color(page))) {
+    g_free(color_string);
+    LEAVE("empty string or color unchanged");
+    return;
+  }
+
+  /* Update the plugin */
+  window = GNC_MAIN_WINDOW(page->window);
+  priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
+  gnc_plugin_page_set_page_color(page, color_string);
+
+  /* Update the notebook tab */
+  main_window_find_tab_event(window, page, &event_box);
+
+  if (gdk_color_parse(color_string, &tab_color)) {
+    gtk_widget_modify_bg(event_box, GTK_STATE_NORMAL, &tab_color);
+    gtk_widget_modify_bg(event_box, GTK_STATE_ACTIVE, &tab_color);
+  }
+  g_free(color_string);
+  LEAVE("done");
+}
+
+
 static void
 gnc_main_window_tab_entry_activate (GtkWidget *entry,
 				    GncPluginPage *page)
@@ -2276,10 +2374,11 @@
 	GncMainWindowPrivate *priv;
 	GtkWidget *tab_hbox;
 	GtkWidget *label, *entry, *event_box;
-	const gchar *icon, *text;
+	const gchar *icon, *text, *color_string;
 	GtkWidget *image;
 	GList *tmp;
 	gint width;
+	GdkColor tab_color;
 
 	ENTER("window %p, page %p", window, page);
 
@@ -2335,14 +2434,24 @@
 		image = gtk_image_new_from_stock (icon, GTK_ICON_SIZE_MENU);
 		gtk_widget_show (image);
 		gtk_box_pack_start (GTK_BOX (tab_hbox), image, FALSE, FALSE, 0);
-	} 
+		gtk_box_pack_start (GTK_BOX (tab_hbox), label, FALSE, FALSE, 0);
+	}
+	else
+		gtk_box_pack_start (GTK_BOX (tab_hbox), label, FALSE, FALSE, 0);
 
         event_box = gtk_event_box_new();
-        gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE);
+        gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), TRUE);
         gtk_widget_show(event_box);
-        gtk_container_add(GTK_CONTAINER(event_box), label);
-	gtk_box_pack_start (GTK_BOX (tab_hbox), event_box, TRUE, TRUE, 0);
 
+        gtk_container_add(GTK_CONTAINER(event_box), tab_hbox);
+
+	color_string = gnc_plugin_page_get_page_color(page);
+	if (color_string == NULL) color_string = "";
+	if (gdk_color_parse(color_string, &tab_color)) {
+	  gtk_widget_modify_bg(event_box, GTK_STATE_NORMAL, &tab_color);
+	  gtk_widget_modify_bg(event_box, GTK_STATE_ACTIVE, &tab_color);
+	}
+
         text = gnc_plugin_page_get_page_long_name(page);
         if (text) {
           gtk_tooltips_set_tip(tips, event_box, text, NULL);
@@ -2398,7 +2507,7 @@
 	/*
 	 * Now install it all in the window.
 	 */
-	gnc_main_window_connect(window, page, tab_hbox, label);
+	gnc_main_window_connect(window, page, event_box, label);
 
 	LEAVE("");
 }

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.h	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.h	2010-02-10 20:35:11 UTC (rev 18637)
@@ -156,10 +156,28 @@
 GncPluginPage *gnc_main_window_get_current_page (GncMainWindow *window);
 
 
+/** Update the name of the page in the main window.
+ *
+ *  @parm page The page to be updated.
+ *
+ *  @parm name_in The new name for the page.
+*/
 void
 main_window_update_page_name (GncPluginPage *page,
 			      const gchar *name_in);
 
+
+/** Update the color on the page tabs in the main window.
+ *
+ *  @parm page The page to be updated.
+ *
+ *  @parm color_in The new color string for the page tab.
+*/
+void
+main_window_update_page_color (GncPluginPage *page,
+			      const gchar *color_in);
+
+
 /** Manually add a set of actions to the specified window.  Plugins
  *  whose user interface is not hard coded (e.g. the menu-additions *
  *  plugin) must create their actions at run time, then use this *

Modified: gnucash/trunk/src/gnome-utils/gnc-plugin-page.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-plugin-page.c	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/gnome-utils/gnc-plugin-page.c	2010-02-10 20:35:11 UTC (rev 18637)
@@ -69,6 +69,7 @@
 enum {
   PROP_0,
   PROP_PAGE_NAME,
+  PROP_PAGE_COLOR,
   PROP_PAGE_URI,
   PROP_BOOK,
   PROP_STATUSBAR_TEXT,
@@ -96,6 +97,7 @@
 
 	gchar *page_name;
 	gchar *page_long_name;
+	gchar *page_color;
 	gchar *uri;
 	gchar *statusbar_text;
 } GncPluginPagePrivate;
@@ -402,6 +404,17 @@
 
         g_object_class_install_property
 	  (gobject_class,
+	   PROP_PAGE_COLOR,
+	   g_param_spec_string ("page-color",
+				"Page Color",
+				"The color of this page.  This value is "
+				"used to generate the notebook tab color "
+				"when this page is visible.",
+				NULL,
+				G_PARAM_READWRITE));
+
+        g_object_class_install_property
+	  (gobject_class,
 	   PROP_PAGE_URI,
 	   g_param_spec_string ("page-uri",
 				"Page URI",
@@ -514,6 +527,7 @@
 
 	priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
 	priv->page_name   = NULL;
+	priv->page_color  = NULL;
 	priv->uri         = NULL;
 
 	page->window      = NULL;
@@ -541,6 +555,8 @@
   priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
   if (priv->page_name)
 	g_free(priv->page_name);
+  if (priv->page_color)
+	g_free(priv->page_color);
   if (priv->uri)
 	g_free(priv->uri);
   if (priv->statusbar_text)
@@ -596,6 +612,9 @@
     case PROP_PAGE_NAME:
       g_value_set_string (value, priv->page_name);
       break;
+    case PROP_PAGE_COLOR:
+      g_value_set_string (value, priv->page_color);
+      break;
     case PROP_PAGE_URI:
       g_value_set_string (value, priv->uri);
       break;
@@ -654,6 +673,9 @@
     case PROP_PAGE_NAME:
       gnc_plugin_page_set_page_name(page, g_value_get_string(value));
       break;
+    case PROP_PAGE_COLOR:
+      gnc_plugin_page_set_page_color(page, g_value_get_string(value));
+      break;
     case PROP_PAGE_URI:
       gnc_plugin_page_set_uri(page, g_value_get_string(value));
       break;
@@ -787,7 +809,7 @@
 
 
 /*  Set the long name of this page.  This is the string used in the
- *  tooltip that is attached to the pate name in the notebook tab. */
+ *  tooltip that is attached to the page name in the notebook tab. */
 void
 gnc_plugin_page_set_page_long_name (GncPluginPage *page, const gchar *name)
 {
@@ -802,6 +824,34 @@
 }
 
 
+/*  Get the color of this page.  This is the string used in the notebook tab. */
+const gchar *
+gnc_plugin_page_get_page_color (GncPluginPage *page)
+{
+  GncPluginPagePrivate *priv;
+
+  g_return_val_if_fail (GNC_IS_PLUGIN_PAGE (page), NULL);
+
+  priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
+  return priv->page_color;
+}
+
+
+/*  Set the color of this page.  This is the string used in the notebook tab. */
+void
+gnc_plugin_page_set_page_color (GncPluginPage *page, const gchar *color)
+{
+  GncPluginPagePrivate *priv;
+
+  g_return_if_fail (GNC_IS_PLUGIN_PAGE (page));
+
+  priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
+  if (priv->page_color)
+    g_free(priv->page_color);
+  priv->page_color = g_strdup(color);
+}
+
+
 /*  Retrieve the Uniform Resource Identifier for this page. */
 const gchar *
 gnc_plugin_page_get_uri (GncPluginPage *page)

Modified: gnucash/trunk/src/gnome-utils/gnc-plugin-page.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-plugin-page.h	2010-02-10 20:34:51 UTC (rev 18636)
+++ gnucash/trunk/src/gnome-utils/gnc-plugin-page.h	2010-02-10 20:35:11 UTC (rev 18637)
@@ -374,6 +374,28 @@
 void gnc_plugin_page_set_page_long_name (GncPluginPage *page, const char *name);
 
 
+/** Retrieve the color of this page. This is the color string used
+ *  in the notebook tab.
+ *
+ *  @param page The page whose name should be retrieved.
+ *
+ *  @return The color for this page.  This string is owned by the page and
+ *  should not be freed by the caller.
+ */
+const gchar *gnc_plugin_page_get_page_color (GncPluginPage *page);
+
+
+/** Set the color of this page. This is the color string used
+ *  in the notebook tab.
+ *
+ *  @param page The page whose name should be retrieved.
+ *
+ *  @return The color for this page.  This string is owned by the page and
+ *  should not be freed by the caller.
+ */
+void gnc_plugin_page_set_page_color (GncPluginPage *page, const char *color);
+
+
 /** Retrieve the Uniform Resource Identifier for this page.
  *
  *  @param page The page whose URI should be retrieved.



More information about the gnucash-changes mailing list