Renaming, order categories by name.

So at least in English the order will make some sense.
And it shall stay consistent.
This commit is contained in:
Přemysl Eric Janouch 2012-08-29 18:27:41 +02:00
parent 0e952b084c
commit 6a633c8321
4 changed files with 32 additions and 22 deletions

View File

@ -199,7 +199,7 @@ reload_library (LdLibraryPane *self)
{ {
GSList *categories; GSList *categories;
categories = (GSList *) ld_symbol_category_get_subcategories categories = (GSList *) ld_symbol_category_get_children
(ld_library_get_root (self->priv->library)); (ld_library_get_root (self->priv->library));
g_slist_foreach (categories, load_category_cb, self); g_slist_foreach (categories, load_category_cb, self);
} }

View File

@ -216,7 +216,7 @@ load_category_cb (const gchar *base, const gchar *path, gpointer userdata)
cat = load_category (data->self, path, base); cat = load_category (data->self, path, base);
if (cat) if (cat)
{ {
ld_symbol_category_insert_subcategory (data->cat, cat, -1); ld_symbol_category_add_child (data->cat, cat);
g_object_unref (cat); g_object_unref (cat);
} }
} }
@ -368,7 +368,7 @@ ld_library_find_symbol (LdLibrary *self, const gchar *identifier)
{ {
gboolean found = FALSE; gboolean found = FALSE;
list = ld_symbol_category_get_subcategories (cat); list = ld_symbol_category_get_children (cat);
for (list_el = list; list_el; list_el = g_slist_next (list_el)) for (list_el = list; list_el; list_el = g_slist_next (list_el))
{ {
cat = LD_SYMBOL_CATEGORY (list_el->data); cat = LD_SYMBOL_CATEGORY (list_el->data);

View File

@ -329,60 +329,70 @@ static void
on_category_notify_name (LdSymbolCategory *category, on_category_notify_name (LdSymbolCategory *category,
GParamSpec *pspec, gpointer user_data) GParamSpec *pspec, gpointer user_data)
{ {
/* XXX: We could disown the category if a name collision has occured. */ LdSymbolCategory *self;
self = (LdSymbolCategory *) user_data;
g_warning ("name of a library subcategory has changed"); g_warning ("name of a library subcategory has changed");
/* The easy way of handling it. */
g_object_ref (category);
ld_symbol_category_remove_child (self, category);
ld_symbol_category_add_child (self, category);
g_object_unref (category);
} }
/** /**
* ld_symbol_category_insert_subcategory: * ld_symbol_category_add_child:
* @self: an #LdSymbolCategory object. * @self: an #LdSymbolCategory object.
* @category: the category to be inserted. * @category: the category to be inserted.
* @pos: the position at which the category will be inserted.
* Negative values will append to the end of list.
* *
* Insert a subcategory into the category. * Insert a subcategory into the category.
* *
* Return value: %TRUE if successful (no name collisions). * Return value: %TRUE if successful (no name collisions).
*/ */
gboolean gboolean
ld_symbol_category_insert_subcategory (LdSymbolCategory *self, ld_symbol_category_add_child (LdSymbolCategory *self,
LdSymbolCategory *category, gint pos) LdSymbolCategory *category)
{ {
const gchar *name; const gchar *name;
const GSList *iter; GSList *iter;
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), FALSE); g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), FALSE);
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (category), FALSE); g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (category), FALSE);
/* Check for name collisions. */
name = ld_symbol_category_get_name (category); name = ld_symbol_category_get_name (category);
for (iter = self->priv->subcategories; iter; iter = iter->next) for (iter = self->priv->subcategories; iter; iter = iter->next)
{ {
if (!strcmp (name, ld_symbol_category_get_name (iter->data))) gint comp;
comp = g_utf8_collate (name, ld_symbol_category_get_name (iter->data));
if (!comp)
{ {
g_warning ("attempted to insert multiple `%s' subcategories into" g_warning ("attempted to insert multiple `%s' subcategories into"
" category `%s'", name, ld_symbol_category_get_name (self)); " category `%s'", name, ld_symbol_category_get_name (self));
return FALSE; return FALSE;
} }
if (comp < 0)
break;
} }
g_signal_connect (category, "notify::name", g_signal_connect (category, "notify::name",
G_CALLBACK (on_category_notify_name), self); G_CALLBACK (on_category_notify_name), self);
self->priv->subcategories self->priv->subcategories = g_slist_insert_before
= g_slist_insert (self->priv->subcategories, category, pos); (self->priv->subcategories, iter, category);
g_object_ref (category); g_object_ref (category);
return TRUE; return TRUE;
} }
/** /**
* ld_symbol_category_remove_subcategory: * ld_symbol_category_remove_child:
* @self: an #LdSymbolCategory object. * @self: an #LdSymbolCategory object.
* @category: the category to be removed. * @category: the category to be removed.
* *
* Removes a subcategory from the category. * Removes a subcategory from the category.
*/ */
void void
ld_symbol_category_remove_subcategory (LdSymbolCategory *self, ld_symbol_category_remove_child (LdSymbolCategory *self,
LdSymbolCategory *category) LdSymbolCategory *category)
{ {
g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self)); g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self));
@ -399,14 +409,14 @@ ld_symbol_category_remove_subcategory (LdSymbolCategory *self,
} }
/** /**
* ld_symbol_category_get_subcategories: * ld_symbol_category_get_children:
* @self: an #LdSymbolCategory object. * @self: an #LdSymbolCategory object.
* *
* Return value: (element-type LdSymbolCategory *): * Return value: (element-type LdSymbolCategory *):
* a list of subcategories. Do not modify. * a list of subcategories. Do not modify.
*/ */
const GSList * const GSList *
ld_symbol_category_get_subcategories (LdSymbolCategory *self) ld_symbol_category_get_children (LdSymbolCategory *self)
{ {
g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL); g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL);
return self->priv->subcategories; return self->priv->subcategories;

View File

@ -69,11 +69,11 @@ void ld_symbol_category_remove_symbol (LdSymbolCategory *self,
LdSymbol *symbol); LdSymbol *symbol);
const GSList *ld_symbol_category_get_symbols (LdSymbolCategory *self); const GSList *ld_symbol_category_get_symbols (LdSymbolCategory *self);
gboolean ld_symbol_category_insert_subcategory (LdSymbolCategory *self, gboolean ld_symbol_category_add_child (LdSymbolCategory *self,
LdSymbolCategory *category, gint pos);
void ld_symbol_category_remove_subcategory (LdSymbolCategory *self,
LdSymbolCategory *category); LdSymbolCategory *category);
const GSList *ld_symbol_category_get_subcategories (LdSymbolCategory *self); void ld_symbol_category_remove_child (LdSymbolCategory *self,
LdSymbolCategory *category);
const GSList *ld_symbol_category_get_children (LdSymbolCategory *self);
G_END_DECLS G_END_DECLS