SF.net SVN: geany-plugins:[1285] trunk/geanygendoc

colombanw at users.sourceforge.net colombanw at xxxxx
Thu Apr 22 17:24:37 UTC 2010


Revision: 1285
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1285&view=rev
Author:   colombanw
Date:     2010-04-22 17:24:37 +0000 (Thu, 22 Apr 2010)

Log Message:
-----------
GeanyGenDoc: Fix ordering of tag children

Make ggd_tag_find_children() return a sorted list of the tags, in the
order they appears in the source.
This fixes wrong order of some children such as structure members or
enumeration values that were sorted alphabetically.

Modified Paths:
--------------
    trunk/geanygendoc/TODO
    trunk/geanygendoc/src/ggd-tag-utils.c

Modified: trunk/geanygendoc/TODO
===================================================================
--- trunk/geanygendoc/TODO	2010-04-22 15:07:18 UTC (rev 1284)
+++ trunk/geanygendoc/TODO	2010-04-22 17:24:37 UTC (rev 1285)
@@ -1,12 +1,3 @@
-* Fix tag children sorting.
-  Currently tag children (for e.g. structures, enumerations, etc.) are
-  sorted as we get them from Geany, which means alphabetically by name.
-  This is no good since it reorders structure, enumeration, etc,
-  children.
-  The easiest fix is probably to sort the tag array by line before
-  doing anything, but it would be interesting to sort only the symbol
-  list that we build for the environment.
-
 * support setting duplication in filetype configuration
     function = {
       template = "my template";

Modified: trunk/geanygendoc/src/ggd-tag-utils.c
===================================================================
--- trunk/geanygendoc/src/ggd-tag-utils.c	2010-04-22 15:07:18 UTC (rev 1284)
+++ trunk/geanygendoc/src/ggd-tag-utils.c	2010-04-22 17:24:37 UTC (rev 1285)
@@ -27,16 +27,27 @@
 #include "ggd-plugin.h" /* to access Geany data/funcs */
 
 
-/* Compare function for g_ptr_array_sort() to compare two TMTag by their
- * lines.
- * (gint)data is strictly positive for ASC sort, strictly negative DESC sort */
+/*
+ * tag_cmp_by_line:
+ * @a: A #TMTag
+ * @b: Another #TMTag
+ * @data: A pointer that, converted with GPOINTER_TO_INT(), becomes an integer
+ *        strictly positive for an ascending sort or strictly negative for a
+ *        descending sort. The constants %GGD_SORT_ASC and %GGD_SORT_DESC can be
+ *        used here.
+ * 
+ * Compares two #TMTag<!-- -->s by their lines.
+ * 
+ * Returns: A positive integer if line(a) > line(b), a negative integer if
+ *          line(a) < line(b) and a nul integer (0) if line(a) == line(b).
+ */
 static gint
 tag_cmp_by_line (gconstpointer a,
                  gconstpointer b,
                  gpointer      data)
 {
-  const TMTag  *t1 = *((const TMTag**)a);
-  const TMTag  *t2 = *((const TMTag**)b);
+  const TMTag  *t1 = a;
+  const TMTag  *t2 = b;
   gint          direction = GPOINTER_TO_INT (data);
   gint          rv;
   
@@ -55,6 +66,15 @@
   return rv;
 }
 
+/* A wrapper for tag_cmp_by_line() that works with g_ptr_array_sort() */
+static gint
+tag_cmp_by_line_ptr_array (gconstpointer a,
+                           gconstpointer b,
+                           gpointer      data)
+{
+  return tag_cmp_by_line (*((const TMTag**)a), *((const TMTag**)b), data);
+}
+
 /**
  * ggd_tag_sort_by_line:
  * @tags: A #GPtrArray of #TMTag<!-- -->s
@@ -71,7 +91,7 @@
   g_return_if_fail (tags != NULL);
   g_return_if_fail (direction != 0);
   
-  g_ptr_array_sort_with_data (tags, tag_cmp_by_line,
+  g_ptr_array_sort_with_data (tags, tag_cmp_by_line_ptr_array,
                               GINT_TO_POINTER (direction));
 }
 
@@ -411,6 +431,8 @@
  * @depth: Maximum depth for children to be found (< 0 means infinite)
  * 
  * Finds children tags of a #TMTag.
+ * <note><para>The returned list of children is sorted in the order they appears
+ * in the source file (by their lines positions)</para></note>
  * 
  * Returns: The list of children found for @parent
  */
@@ -427,7 +449,6 @@
   g_return_val_if_fail (tags != NULL, NULL);
   g_return_val_if_fail (parent != NULL, NULL);
   
-  /* FIXME: sort by line? */
   if (parent->atts.entry.scope) {
     fake_scope = g_strconcat (parent->atts.entry.scope, parent->name, NULL);
   } else {
@@ -435,7 +456,9 @@
   }
   GGD_PTR_ARRAY_FOR (tags, i, el) {
     if (scope_child_matches (fake_scope, el->atts.entry.scope, depth)) {
-      children = g_list_append (children, el);
+      children = g_list_insert_sorted_with_data (children, el,
+                                                 tag_cmp_by_line,
+                                                 GINT_TO_POINTER (GGD_SORT_ASC));
     }
   }
   g_free (fake_scope);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list