aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-03-22 14:56:15 +0800
committerChris Lahey <clahey@src.gnome.org>2001-03-22 14:56:15 +0800
commitfd03473c711a20ed4eaf0e309caff1a28a83010e (patch)
treefeb97434b9875a3e5f59be94a4e1762bee391622
parentcda1baeb5b7c2cd08607629e4fd9d98fc48c5489 (diff)
downloadgsoc2013-evolution-fd03473c711a20ed4eaf0e309caff1a28a83010e.tar
gsoc2013-evolution-fd03473c711a20ed4eaf0e309caff1a28a83010e.tar.gz
gsoc2013-evolution-fd03473c711a20ed4eaf0e309caff1a28a83010e.tar.bz2
gsoc2013-evolution-fd03473c711a20ed4eaf0e309caff1a28a83010e.tar.lz
gsoc2013-evolution-fd03473c711a20ed4eaf0e309caff1a28a83010e.tar.xz
gsoc2013-evolution-fd03473c711a20ed4eaf0e309caff1a28a83010e.tar.zst
gsoc2013-evolution-fd03473c711a20ed4eaf0e309caff1a28a83010e.zip
New function to allow you to do non live sorts with weird rules.
2001-03-22 Christopher James Lahey <clahey@ximian.com> * e-tree-memory.c, e-tree-memory.h (e_tree_memory_sort_node): New function to allow you to do non live sorts with weird rules. svn path=/trunk/; revision=8881
-rw-r--r--widgets/table/e-tree-memory.c66
-rw-r--r--widgets/table/e-tree-memory.h48
2 files changed, 102 insertions, 12 deletions
diff --git a/widgets/table/e-tree-memory.c b/widgets/table/e-tree-memory.c
index 88e9cd9a55..20d96ad6e6 100644
--- a/widgets/table/e-tree-memory.c
+++ b/widgets/table/e-tree-memory.c
@@ -546,3 +546,69 @@ e_tree_memory_node_remove (ETreeMemory *etree, ETreePath node)
return ret;
}
+
+typedef struct {
+ ETreeMemory *memory;
+ gpointer closure;
+ ETreeMemorySortCallback callback;
+} MemoryAndClosure;
+
+static int
+sort_callback(const void *data1, const void *data2, gpointer user_data)
+{
+ ETreePath path1 = (void *) data1;
+ ETreePath path2 = (void *) data2;
+ MemoryAndClosure *mac = user_data;
+ return (*mac->callback) (mac->memory, path1, path2, mac->closure);
+}
+
+void
+e_tree_memory_sort_node (ETreeMemory *etmm,
+ ETreePath node,
+ ETreeMemorySortCallback callback,
+ gpointer user_data)
+{
+ ETreeMemoryPath **children;
+ ETreeMemoryPath *child;
+ int count;
+ int i;
+ ETreeMemoryPath *path = node;
+ MemoryAndClosure mac;
+ ETreeMemoryPath *last;
+
+ i = 0;
+ for (child = path->first_child; child; child = child->next_sibling)
+ i++;
+
+ children = g_new(ETreeMemoryPath *, i);
+
+ count = i;
+
+ for (child = path->first_child, i = 0;
+ child;
+ child = child->next_sibling, i++) {
+ children[i] = child;
+ }
+
+ mac.memory = etmm;
+ mac.closure = user_data;
+ mac.callback = callback;
+
+ e_sort (children, count, sizeof (ETreeMemoryPath *), sort_callback, &mac);
+
+ last = NULL;
+ for (i = 0;
+ i < count;
+ i++) {
+ children[i]->prev_sibling = last;
+ if (last)
+ last->next_sibling = children[i];
+ last = children[i];
+ }
+ if (last)
+ last->next_sibling = NULL;
+
+ g_free(children);
+
+ e_tree_model_node_changed(E_TREE_MODEL(etmm), node);
+}
diff --git a/widgets/table/e-tree-memory.h b/widgets/table/e-tree-memory.h
index 264df86acb..633594c2d5 100644
--- a/widgets/table/e-tree-memory.h
+++ b/widgets/table/e-tree-memory.h
@@ -20,6 +20,8 @@ typedef struct ETreeMemory ETreeMemory;
typedef struct ETreeMemoryPriv ETreeMemoryPriv;
typedef struct ETreeMemoryClass ETreeMemoryClass;
+typedef int (*ETreeMemorySortCallback) (ETreeMemory *etmm, ETreePath path1, ETreePath path2, gpointer closure);
+
struct ETreeMemory {
ETreeModel base;
ETreeMemoryPriv *priv;
@@ -29,26 +31,48 @@ struct ETreeMemoryClass {
ETreeModelClass parent_class;
};
-GtkType e_tree_memory_get_type (void);
-void e_tree_memory_construct (ETreeMemory *etree);
-ETreeMemory *e_tree_memory_new (void);
+
+GtkType e_tree_memory_get_type (void);
+void e_tree_memory_construct (ETreeMemory *etree);
+ETreeMemory *e_tree_memory_new (void);
/* node operations */
-ETreePath e_tree_memory_node_insert (ETreeMemory *etree, ETreePath parent, int position, gpointer node_data);
-ETreePath e_tree_memory_node_insert_id (ETreeMemory *etree, ETreePath parent, int position, gpointer node_data, char *id);
-ETreePath e_tree_memory_node_insert_before (ETreeMemory *etree, ETreePath parent, ETreePath sibling, gpointer node_data);
-gpointer e_tree_memory_node_remove (ETreeMemory *etree, ETreePath path);
+ETreePath e_tree_memory_node_insert (ETreeMemory *etree,
+ ETreePath parent,
+ int position,
+ gpointer node_data);
+ETreePath e_tree_memory_node_insert_id (ETreeMemory *etree,
+ ETreePath parent,
+ int position,
+ gpointer node_data,
+ char *id);
+ETreePath e_tree_memory_node_insert_before (ETreeMemory *etree,
+ ETreePath parent,
+ ETreePath sibling,
+ gpointer node_data);
+gpointer e_tree_memory_node_remove (ETreeMemory *etree,
+ ETreePath path);
/* Freeze and thaw */
-void e_tree_memory_freeze (ETreeMemory *etree);
-void e_tree_memory_thaw (ETreeMemory *etree);
+void e_tree_memory_freeze (ETreeMemory *etree);
+void e_tree_memory_thaw (ETreeMemory *etree);
-void e_tree_memory_set_expanded_default (ETreeMemory *etree, gboolean expanded);
-gpointer e_tree_memory_node_get_data (ETreeMemory *etm, ETreePath node);
-void e_tree_memory_node_set_data (ETreeMemory *etm, ETreePath node, gpointer node_data);
+
+void e_tree_memory_set_expanded_default (ETreeMemory *etree,
+ gboolean expanded);
+gpointer e_tree_memory_node_get_data (ETreeMemory *etm,
+ ETreePath node);
+void e_tree_memory_node_set_data (ETreeMemory *etm,
+ ETreePath node,
+ gpointer node_data);
+void e_tree_memory_sort_node (ETreeMemory *etm,
+ ETreePath node,
+ ETreeMemorySortCallback callback,
+ gpointer user_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _E_TREE_MEMORY_H */
+