treeviews: set text color to default when item is selected
This ensures that the text color is properly inverted against the
selection color for better visibility.
Change-Id: I2fdacecf1ff2eac0dfd8a376cd915b0da66a2ab7
Tuleap: #41
diff --git a/src/accountview.cpp b/src/accountview.cpp
index fd6746e..0837be7 100644
--- a/src/accountview.cpp
+++ b/src/accountview.cpp
@@ -328,8 +328,15 @@
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
- G_GNUC_UNUSED gpointer data)
+ GtkTreeView *treeview)
{
+ // check if this iter is selected
+ gboolean is_selected = FALSE;
+ if (GTK_IS_TREE_VIEW(treeview)) {
+ auto selection = gtk_tree_view_get_selection(treeview);
+ is_selected = gtk_tree_selection_iter_is_selected(selection, iter);
+ }
+
gchar *display_state = NULL;
/* get account */
@@ -339,23 +346,29 @@
auto account = AccountModel::instance()->getAccountByModelIndex(idx);
auto humanState = account->toHumanStateName();
- switch (account->registrationState()) {
- case Account::RegistrationState::READY:
- display_state = g_strdup_printf("<span fgcolor=\"green\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::UNREGISTERED:
- display_state = g_strdup_printf("<span fgcolor=\"gray\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::TRYING:
- display_state = g_strdup_printf("<span fgcolor=\"orange\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::ERROR:
- display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
- break;
- case Account::RegistrationState::COUNT__:
- g_warning("registration state should never be \"count\"");
- display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
- break;
+ /* we want the color of the status text to be the default color if this iter is
+ * selected so that the treeview is able to invert it against the selection color */
+ if (is_selected) {
+ display_state = g_strdup_printf("%s", humanState.toUtf8().constData());
+ } else {
+ switch (account->registrationState()) {
+ case Account::RegistrationState::READY:
+ display_state = g_strdup_printf("<span fgcolor=\"green\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::UNREGISTERED:
+ display_state = g_strdup_printf("<span fgcolor=\"gray\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::TRYING:
+ display_state = g_strdup_printf("<span fgcolor=\"orange\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::ERROR:
+ display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
+ break;
+ case Account::RegistrationState::COUNT__:
+ g_warning("registration state should never be \"count\"");
+ display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
+ break;
+ }
}
}
@@ -401,7 +414,7 @@
column,
renderer,
(GtkTreeCellDataFunc)state_to_string,
- NULL,
+ priv->treeview_account_list,
NULL);
/* add an empty box to the account stack initially, otherwise there will