Get rid of the `expander prefix' property.

And make the root be named after whatever the path separator is set to.
This commit is contained in:
Přemysl Eric Janouch 2012-08-30 09:04:36 +02:00
parent 8acfeae8c8
commit 819917536e
3 changed files with 50 additions and 67 deletions

View File

@ -193,41 +193,6 @@ ld_category_view_get_category (LdCategoryView *self)
return self->priv->category; return self->priv->category;
} }
/**
* ld_category_view_set_expander_prefix:
* @self: an #LdCategoryView object.
* @category: (allow-none): the new prefix.
*
* Set the prefix for inner #GtkExpander labels.
*/
void
ld_category_view_set_expander_prefix (LdCategoryView *self,
const gchar *prefix)
{
g_return_if_fail (LD_IS_CATEGORY_VIEW (self));
g_free (self->priv->expander_prefix);
if (prefix)
self->priv->expander_prefix = g_strdup (prefix);
else
self->priv->expander_prefix = NULL;
reload_category (self);
}
/**
* ld_category_view_get_expander_prefix:
* @self: an #LdCategoryView object.
*
* Return value: the prefix for inner expander labels.
*/
const gchar *
ld_category_view_get_expander_prefix (LdCategoryView *self)
{
g_return_val_if_fail (LD_IS_CATEGORY_VIEW (self), NULL);
return self->priv->expander_prefix;
}
static GtkWidget * static GtkWidget *
create_empty_label (void) create_empty_label (void)
{ {
@ -247,12 +212,52 @@ create_empty_label (void)
return label; return label;
} }
static void
reconstruct_prefix (LdCategoryView *self)
{
LdCategory *iter;
gchar *start, *end;
start = g_strdup ("");
end = g_strdup ("");
for (iter = self->priv->category; iter;
iter = ld_category_get_parent (iter))
{
const gchar *name;
gchar *new_start, *new_end, *name_escaped;
/* Stop at the root category. */
if (!strcmp (ld_category_get_name (iter),
LD_LIBRARY_IDENTIFIER_SEPARATOR))
break;
name = ld_category_get_human_name (iter);
name_escaped = g_markup_escape_text (name, -1);
new_start = g_strconcat (start, "<small>", NULL);
new_end = g_strconcat (name_escaped, ":</small> ", end, NULL);
g_free (name_escaped);
g_free (start);
g_free (end);
start = new_start;
end = new_end;
}
g_free (self->priv->expander_prefix);
self->priv->expander_prefix = g_strconcat (start, end, NULL);
g_free (start);
g_free (end);
}
static void static void
reload_category (LdCategoryView *self) reload_category (LdCategoryView *self)
{ {
g_return_if_fail (LD_IS_CATEGORY_VIEW (self)); g_return_if_fail (LD_IS_CATEGORY_VIEW (self));
/* Clear the toolbar first, if there was already something in it. */ /* Clear the container first, if there is already something in it. */
gtk_container_foreach (GTK_CONTAINER (self), gtk_container_foreach (GTK_CONTAINER (self),
(GtkCallback) gtk_widget_destroy, NULL); (GtkCallback) gtk_widget_destroy, NULL);
@ -264,7 +269,10 @@ reload_category (LdCategoryView *self)
children = (GSList *) ld_category_get_children (self->priv->category); children = (GSList *) ld_category_get_children (self->priv->category);
if (children) if (children)
{
reconstruct_prefix (self);
g_slist_foreach (children, load_category_cb, self); g_slist_foreach (children, load_category_cb, self);
}
else else
/* TODO: Don't show this if there are any symbols. */ /* TODO: Don't show this if there are any symbols. */
gtk_box_pack_start (GTK_BOX (self), gtk_box_pack_start (GTK_BOX (self),
@ -278,8 +286,7 @@ load_category_cb (gpointer data, gpointer user_data)
LdCategoryView *self; LdCategoryView *self;
LdCategory *cat; LdCategory *cat;
GtkWidget *expander, *child; GtkWidget *expander, *child;
const gchar *name; gchar *name, *label_markup;
gchar *label, *label_markup;
g_return_if_fail (LD_IS_CATEGORY_VIEW (user_data)); g_return_if_fail (LD_IS_CATEGORY_VIEW (user_data));
g_return_if_fail (LD_IS_CATEGORY (data)); g_return_if_fail (LD_IS_CATEGORY (data));
@ -287,40 +294,19 @@ load_category_cb (gpointer data, gpointer user_data)
self = user_data; self = user_data;
cat = data; cat = data;
name = ld_category_get_human_name (cat); name = g_markup_escape_text (ld_category_get_human_name (cat), -1);
if (self->priv->expander_prefix) label_markup = g_strconcat (self->priv->expander_prefix, name, NULL);
{ g_free (name);
/* It's the least I can do to make it not look bad right now. */
gchar *prefix_escaped, *name_escaped;
prefix_escaped = g_markup_escape_text (self->priv->expander_prefix, -1);
name_escaped = g_markup_escape_text (name, -1);
label = g_strdup_printf ("%s: %s", self->priv->expander_prefix, name);
label_markup = g_strdup_printf ("<small>%s:</small> %s",
prefix_escaped, name_escaped);
g_free (name_escaped);
g_free (prefix_escaped);
}
else
{
label = g_strdup (name);
label_markup = g_markup_escape_text (name, -1);
}
expander = gtk_expander_new (label_markup); expander = gtk_expander_new (label_markup);
gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE); gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
gtk_expander_set_use_markup (GTK_EXPANDER (expander), TRUE); gtk_expander_set_use_markup (GTK_EXPANDER (expander), TRUE);
g_free (label_markup);
child = ld_category_view_new (); child = ld_category_view_new ();
ld_category_view_set_expander_prefix (LD_CATEGORY_VIEW (child), label);
ld_category_view_set_category (LD_CATEGORY_VIEW (child), cat); ld_category_view_set_category (LD_CATEGORY_VIEW (child), cat);
gtk_container_add (GTK_CONTAINER (expander), child); gtk_container_add (GTK_CONTAINER (expander), child);
gtk_box_pack_start (GTK_BOX (self), expander, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (self), expander, FALSE, FALSE, 0);
g_free (label);
g_free (label_markup);
} }

View File

@ -54,9 +54,6 @@ GtkWidget *ld_category_view_new (void);
void ld_category_view_set_category (LdCategoryView *self, LdCategory *category); void ld_category_view_set_category (LdCategoryView *self, LdCategory *category);
LdCategory *ld_category_view_get_category (LdCategoryView *self); LdCategory *ld_category_view_get_category (LdCategoryView *self);
void ld_category_view_set_expander_prefix (LdCategoryView *self,
const gchar *prefix);
const gchar *ld_category_view_get_expander_prefix (LdCategoryView *self);
G_END_DECLS G_END_DECLS

View File

@ -81,7 +81,7 @@ ld_library_init (LdLibrary *self)
(self, LD_TYPE_LIBRARY, LdLibraryPrivate); (self, LD_TYPE_LIBRARY, LdLibraryPrivate);
self->priv->lua = ld_lua_new (); self->priv->lua = ld_lua_new ();
self->priv->root = ld_category_new ("/", "/"); self->priv->root = ld_category_new (LD_LIBRARY_IDENTIFIER_SEPARATOR, "/");
} }
static void static void