aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/e-table/ChangeLog18
-rw-r--r--widgets/e-table/e-tree-model.c54
-rw-r--r--widgets/e-table/e-tree-model.h3
-rw-r--r--widgets/table/e-tree-model.c54
-rw-r--r--widgets/table/e-tree-model.h3
5 files changed, 122 insertions, 10 deletions
diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog
index cf4a023179..1f10215bec 100644
--- a/widgets/e-table/ChangeLog
+++ b/widgets/e-table/ChangeLog
@@ -1,5 +1,23 @@
2000-08-21 Chris Toshok <toshok@helixcode.com>
+ * e-tree-example-1.c (remove_node): we can remove nodes with
+ children now.
+
+ * e-tree-model.h: add prototype for e_tree_model_node_sort.
+
+ * e-tree-model.c (etree_set_expanded): if the node is invisible,
+ just set its expanded flag and return.
+ (e_tree_model_root_node_set_visible): call set_expanded before we
+ remove it from the row array or else the aforementioned change
+ will result in nothing happening.
+ (e_tree_model_node_insert): use a position of -1 as "append".
+ (e_tree_model_node_insert): if the model was marked with
+ root_visible == FALSE, make sure to set it's expanded flag to TRUE
+ when the root node is inserted.
+ (e_tree_model_node_sort): new function.
+
+2000-08-21 Chris Toshok <toshok@helixcode.com>
+
* e-table.c (e_table_drag_source_set): pass table, not site as the
closure for these drag signals, since e_table_drag_source_event_cb
assumes it's the table.
diff --git a/widgets/e-table/e-tree-model.c b/widgets/e-table/e-tree-model.c
index fefe6c68da..943f190732 100644
--- a/widgets/e-table/e-tree-model.c
+++ b/widgets/e-table/e-tree-model.c
@@ -138,7 +138,11 @@ etree_set_expanded (ETreeModel *etm, ETreePath* node, gboolean expanded)
enode->expanded = expanded;
- row = e_tree_model_row_of_node (etm, node) + 1;
+ /* if the node wasn't visible at present */
+ if ((row = e_tree_model_row_of_node (etm, node)) == -1)
+ return;
+
+ row++;
if (expanded) {
GNode *parent;
@@ -445,6 +449,8 @@ e_tree_model_row_of_node (ETreeModel *etree, ETreePath *node)
if (g_array_index (etree->row_array, GNode*, i) == node)
return i;
+ g_warning ("e_tree_model_row_of_node failed for node %p\n", node);
+
return -1;
}
@@ -459,8 +465,8 @@ e_tree_model_root_node_set_visible (ETreeModel *etm, gboolean visible)
}
else {
ETreePath *root_path = e_tree_model_get_root (etm);
- etm->row_array = g_array_remove_index (etm->row_array, 0);
e_tree_model_node_set_expanded (etm, root_path, TRUE);
+ etm->row_array = g_array_remove_index (etm->row_array, 0);
}
e_table_model_changed (E_TABLE_MODEL (etm));
@@ -597,17 +603,20 @@ e_tree_model_node_insert (ETreeModel *tree_model,
if (e_tree_model_node_is_visible (tree_model, new_path)) {
int parent_row;
- GNode *node;
+ GNode *n;
/* we need to iterate back up to the root, incrementing the number of visible
descendents */
- for (node = parent_path; node; node = node->parent) {
- ENode *parent_enode = (ENode*)node->data;
+ for (n = parent_path; n; n = n->parent) {
+ ENode *parent_enode = (ENode*)n->data;
parent_enode->visible_descendents ++;
}
/* finally, insert a row into the table */
+ if (position == -1)
+ position = e_tree_model_node_num_visible_descendents (tree_model, parent_path) - 1;
+
parent_row = e_tree_model_row_of_node (tree_model, parent_path);
tree_model->row_array = g_array_insert_val (tree_model->row_array,
@@ -622,6 +631,11 @@ e_tree_model_node_insert (ETreeModel *tree_model,
tree_model->row_array = g_array_insert_val (tree_model->row_array, 0, tree_model->root);
e_table_model_row_inserted (E_TABLE_MODEL (tree_model), 0);
}
+ else {
+ /* need to mark the new node as expanded or
+ we'll never see it's children */
+ node->expanded = TRUE;
+ }
new_path = tree_model->root;
}
@@ -713,3 +727,33 @@ add_visible_descendents_to_array (ETreeModel *etm, GNode *gnode, int *row, int *
}
}
}
+
+void
+e_tree_model_node_sort (ETreeModel *tree_model,
+ ETreePath *node,
+ GCompareFunc compare)
+{
+ int num_nodes = g_node_n_children (node);
+ ETreePath **path_array;
+ int i;
+
+ if (num_nodes == 0)
+ return;
+
+ path_array = g_new (ETreePath*, num_nodes);
+
+ for (i = 0; i < num_nodes; i ++) {
+ path_array[i] = g_node_first_child(node);
+ g_node_unlink (path_array[i]);
+ }
+
+ qsort (path_array, num_nodes, sizeof(ETreePath*), compare);
+
+ for (i = 0; i < num_nodes; i ++) {
+ g_node_append (node, path_array[i]);
+ }
+
+ g_free (path_array);
+
+ e_table_model_changed (E_TABLE_MODEL (tree_model));
+}
diff --git a/widgets/e-table/e-tree-model.h b/widgets/e-table/e-tree-model.h
index 7b8d86826f..403aff9a30 100644
--- a/widgets/e-table/e-tree-model.h
+++ b/widgets/e-table/e-tree-model.h
@@ -94,6 +94,9 @@ int e_tree_model_row_of_node (ETreeModel *etree, ETreePath *pat
void e_tree_model_root_node_set_visible (ETreeModel *etree, gboolean visible);
gboolean e_tree_model_root_node_is_visible (ETreeModel *etree);
+/* sort routine, analogous to gtk_ctree_node_sort */
+void e_tree_model_node_sort (ETreeModel *tree_model, ETreePath *node, GCompareFunc compare);
+
/*
** Routines for emitting signals on the ETreeModel
*/
diff --git a/widgets/table/e-tree-model.c b/widgets/table/e-tree-model.c
index fefe6c68da..943f190732 100644
--- a/widgets/table/e-tree-model.c
+++ b/widgets/table/e-tree-model.c
@@ -138,7 +138,11 @@ etree_set_expanded (ETreeModel *etm, ETreePath* node, gboolean expanded)
enode->expanded = expanded;
- row = e_tree_model_row_of_node (etm, node) + 1;
+ /* if the node wasn't visible at present */
+ if ((row = e_tree_model_row_of_node (etm, node)) == -1)
+ return;
+
+ row++;
if (expanded) {
GNode *parent;
@@ -445,6 +449,8 @@ e_tree_model_row_of_node (ETreeModel *etree, ETreePath *node)
if (g_array_index (etree->row_array, GNode*, i) == node)
return i;
+ g_warning ("e_tree_model_row_of_node failed for node %p\n", node);
+
return -1;
}
@@ -459,8 +465,8 @@ e_tree_model_root_node_set_visible (ETreeModel *etm, gboolean visible)
}
else {
ETreePath *root_path = e_tree_model_get_root (etm);
- etm->row_array = g_array_remove_index (etm->row_array, 0);
e_tree_model_node_set_expanded (etm, root_path, TRUE);
+ etm->row_array = g_array_remove_index (etm->row_array, 0);
}
e_table_model_changed (E_TABLE_MODEL (etm));
@@ -597,17 +603,20 @@ e_tree_model_node_insert (ETreeModel *tree_model,
if (e_tree_model_node_is_visible (tree_model, new_path)) {
int parent_row;
- GNode *node;
+ GNode *n;
/* we need to iterate back up to the root, incrementing the number of visible
descendents */
- for (node = parent_path; node; node = node->parent) {
- ENode *parent_enode = (ENode*)node->data;
+ for (n = parent_path; n; n = n->parent) {
+ ENode *parent_enode = (ENode*)n->data;
parent_enode->visible_descendents ++;
}
/* finally, insert a row into the table */
+ if (position == -1)
+ position = e_tree_model_node_num_visible_descendents (tree_model, parent_path) - 1;
+
parent_row = e_tree_model_row_of_node (tree_model, parent_path);
tree_model->row_array = g_array_insert_val (tree_model->row_array,
@@ -622,6 +631,11 @@ e_tree_model_node_insert (ETreeModel *tree_model,
tree_model->row_array = g_array_insert_val (tree_model->row_array, 0, tree_model->root);
e_table_model_row_inserted (E_TABLE_MODEL (tree_model), 0);
}
+ else {
+ /* need to mark the new node as expanded or
+ we'll never see it's children */
+ node->expanded = TRUE;
+ }
new_path = tree_model->root;
}
@@ -713,3 +727,33 @@ add_visible_descendents_to_array (ETreeModel *etm, GNode *gnode, int *row, int *
}
}
}
+
+void
+e_tree_model_node_sort (ETreeModel *tree_model,
+ ETreePath *node,
+ GCompareFunc compare)
+{
+ int num_nodes = g_node_n_children (node);
+ ETreePath **path_array;
+ int i;
+
+ if (num_nodes == 0)
+ return;
+
+ path_array = g_new (ETreePath*, num_nodes);
+
+ for (i = 0; i < num_nodes; i ++) {
+ path_array[i] = g_node_first_child(node);
+ g_node_unlink (path_array[i]);
+ }
+
+ qsort (path_array, num_nodes, sizeof(ETreePath*), compare);
+
+ for (i = 0; i < num_nodes; i ++) {
+ g_node_append (node, path_array[i]);
+ }
+
+ g_free (path_array);
+
+ e_table_model_changed (E_TABLE_MODEL (tree_model));
+}
diff --git a/widgets/table/e-tree-model.h b/widgets/table/e-tree-model.h
index 7b8d86826f..403aff9a30 100644
--- a/widgets/table/e-tree-model.h
+++ b/widgets/table/e-tree-model.h
@@ -94,6 +94,9 @@ int e_tree_model_row_of_node (ETreeModel *etree, ETreePath *pat
void e_tree_model_root_node_set_visible (ETreeModel *etree, gboolean visible);
gboolean e_tree_model_root_node_is_visible (ETreeModel *etree);
+/* sort routine, analogous to gtk_ctree_node_sort */
+void e_tree_model_node_sort (ETreeModel *tree_model, ETreePath *node, GCompareFunc compare);
+
/*
** Routines for emitting signals on the ETreeModel
*/