Revision: 5560 http://geany.svn.sourceforge.net/geany/?rev=5560&view=rev Author: colombanw Date: 2011-03-05 22:50:04 +0000 (Sat, 05 Mar 2011)
Log Message: ----------- Provide a GType for TMTag and use it
It is a boxed type but uses reference counting behind the scene. This allow for example the tag store to make sure the tags it holds are always valid.
Modified Paths: -------------- trunk/src/sidebar.c trunk/src/symbols.c trunk/tagmanager/include/tm_tag.h trunk/tagmanager/tm_tag.c
Modified: trunk/src/sidebar.c =================================================================== --- trunk/src/sidebar.c 2011-03-05 22:48:25 UTC (rev 5559) +++ trunk/src/sidebar.c 2011-03-05 22:50:04 UTC (rev 5560) @@ -216,7 +216,7 @@ if (doc->priv->tag_tree == NULL) { doc->priv->tag_store = gtk_tree_store_new( - SYMBOLS_N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING); + SYMBOLS_N_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING, TM_TYPE_TAG, G_TYPE_STRING); doc->priv->tag_tree = gtk_tree_view_new(); prepare_taglist(doc->priv->tag_tree, doc->priv->tag_store); gtk_widget_show(doc->priv->tag_tree); @@ -874,6 +874,7 @@ change_focus_to_editor(doc, NULL); } } + tm_tag_unref(tag); } return FALSE; }
Modified: trunk/src/symbols.c =================================================================== --- trunk/src/symbols.c 2011-03-05 22:48:25 UTC (rev 5559) +++ trunk/src/symbols.c 2011-03-05 22:50:04 UTC (rev 5560) @@ -1224,7 +1224,8 @@ gpointer user_data) { gboolean sort_by_name = GPOINTER_TO_INT(user_data); - const TMTag *tag_a, *tag_b; + TMTag *tag_a, *tag_b; + gint cmp;
gtk_tree_model_get(model, a, SYMBOLS_COLUMN_TAG, &tag_a, -1); gtk_tree_model_get(model, b, SYMBOLS_COLUMN_TAG, &tag_b, -1); @@ -1234,13 +1235,12 @@ if (tag_a && !tag_has_missing_parent(tag_a, GTK_TREE_STORE(model), a) && tag_b && !tag_has_missing_parent(tag_b, GTK_TREE_STORE(model), b)) { - return sort_by_name ? compare_symbol(tag_a, tag_b) : + cmp = sort_by_name ? compare_symbol(tag_a, tag_b) : compare_symbol_lines(tag_a, tag_b); } else { gchar *astr, *bstr; - gint cmp;
gtk_tree_model_get(model, a, SYMBOLS_COLUMN_NAME, &astr, -1); gtk_tree_model_get(model, b, SYMBOLS_COLUMN_NAME, &bstr, -1); @@ -1254,23 +1254,28 @@ { /* this is what g_strcmp0() does */ if (! astr) - return -(astr != bstr); + cmp = -(astr != bstr); if (! bstr) - return astr != bstr; + cmp = astr != bstr; + else + { + cmp = strcmp(astr, bstr);
- cmp = strcmp(astr, bstr); - - /* sort duplicate 'ScopeName::OverloadedTagName' items by line as well */ - if (tag_a && tag_b) - if (!sort_by_name || - (utils_str_equal(tag_a->name, tag_b->name) && - utils_str_equal(tag_a->atts.entry.scope, tag_b->atts.entry.scope))) - cmp = compare_symbol_lines(tag_a, tag_b); + /* sort duplicate 'ScopeName::OverloadedTagName' items by line as well */ + if (tag_a && tag_b) + if (!sort_by_name || + (utils_str_equal(tag_a->name, tag_b->name) && + utils_str_equal(tag_a->atts.entry.scope, tag_b->atts.entry.scope))) + cmp = compare_symbol_lines(tag_a, tag_b); + } } g_free(astr); g_free(bstr); - return cmp; } + tm_tag_unref(tag_a); + tm_tag_unref(tag_b); + + return cmp; }
Modified: trunk/tagmanager/include/tm_tag.h =================================================================== --- trunk/tagmanager/include/tm_tag.h 2011-03-05 22:48:25 UTC (rev 5559) +++ trunk/tagmanager/include/tm_tag.h 2011-03-05 22:50:04 UTC (rev 5560) @@ -30,6 +30,7 @@ */
#include "tm_source_file.h" +#include <glib-object.h>
#ifdef __cplusplus extern "C" @@ -159,6 +160,12 @@ */ typedef int (*TMTagCompareFunc) (const void *ptr1, const void *ptr2);
+/*! The GType for a TMTag */ +#define TM_TYPE_TAG (tm_tag_get_type()) + +/*! Gets the GType for a TMTag */ +GType tm_tag_get_type(void) G_GNUC_CONST; + /*! Initializes a TMTag structure with information from a tagEntryInfo struct used by the ctags parsers. Note that the TMTag structure must be malloc()ed
Modified: trunk/tagmanager/tm_tag.c =================================================================== --- trunk/tagmanager/tm_tag.c 2011-03-05 22:48:25 UTC (rev 5559) +++ trunk/tagmanager/tm_tag.c 2011-03-05 22:50:04 UTC (rev 5560) @@ -9,6 +9,7 @@
#include <stdlib.h> #include <string.h> +#include <glib-object.h>
#include "general.h" #include "entry.h" @@ -105,6 +106,17 @@ tm_tag_other_t };
+GType tm_tag_get_type(void) +{ + static GType gtype = 0; + if (G_UNLIKELY (gtype == 0)) + { + gtype = g_boxed_type_register_static("TMTag", (GBoxedCopyFunc)tm_tag_ref, + (GBoxedFreeFunc)tm_tag_unref); + } + return gtype; +} + static int get_tag_type(const char *tag_name) { unsigned int i;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.