aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table
diff options
context:
space:
mode:
authorMike Kestner <mkestner@ximian.com>2003-02-21 03:15:14 +0800
committerMike Kestner <mkestner@src.gnome.org>2003-02-21 03:15:14 +0800
commit4a0d26411c9591ac23f86d60b799b7422d99fca3 (patch)
tree7149c0bd6d670e950bb01652005a9d4da5f56f8e /widgets/table
parent12f146c032eb21c73f9a941ce812876a23e625f0 (diff)
downloadgsoc2013-evolution-4a0d26411c9591ac23f86d60b799b7422d99fca3.tar.gz
gsoc2013-evolution-4a0d26411c9591ac23f86d60b799b7422d99fca3.tar.zst
gsoc2013-evolution-4a0d26411c9591ac23f86d60b799b7422d99fca3.zip
kill (etsm_find_node_unless_equals): use new etta_orig_position
2003-02-20 Mike Kestner <mkestner@ximian.com> * e-tree-selection-model.c (etsm_orig_position): kill (etsm_find_node_unless_equals): use new etta_orig_position (update_parents): use new etta_orig_position (etsm_recurse_is_path_selected): use new etta_orig_position * e-tree-table-adapter.c (e_tree_table_adapter_orig_position): new (resort_node): populate orig_pos, fix sorting_map bound bug (create_gnode): initialize orig_pos (delete_node): call resort_node so orig_pos gets updated (insert_node): always call resort_node let it decide whether to sort svn path=/trunk/; revision=19975
Diffstat (limited to 'widgets/table')
-rw-r--r--widgets/table/e-tree-selection-model.c23
-rw-r--r--widgets/table/e-tree-table-adapter.c78
-rw-r--r--widgets/table/e-tree-table-adapter.h3
3 files changed, 57 insertions, 47 deletions
diff --git a/widgets/table/e-tree-selection-model.c b/widgets/table/e-tree-selection-model.c
index a790498c61..17c596062a 100644
--- a/widgets/table/e-tree-selection-model.c
+++ b/widgets/table/e-tree-selection-model.c
@@ -180,23 +180,6 @@ etsm_real_clear (ETreeSelectionModel *etsm)
}
-static gint
-etsm_orig_position(ETreeModel *etm, ETreePath path)
-{
- ETreePath parent, p;
- gint pos;
-
- parent = e_tree_model_node_get_parent(etm, path);
- for (pos = 0, p = e_tree_model_node_get_first_child(etm, parent);
- p && (p != path);
- p = e_tree_model_node_get_next(etm, p), pos++);
-
- if (p)
- return pos;
-
- return -1;
-}
-
static ETreeSelectionModelNode *
etsm_find_node_unless_equals (ETreeSelectionModel *etsm,
ETreePath path,
@@ -210,7 +193,7 @@ etsm_find_node_unless_equals (ETreeSelectionModel *etsm,
if (parent) {
selection_node = etsm_find_node_unless_equals(etsm, parent, grow);
if (selection_node) {
- int position = etsm_orig_position(etsm->priv->model, path);
+ int position = e_tree_table_adapter_orig_position(etsm->priv->etta, path);
if (selection_node->all_children_selected && grow)
return NULL;
if (!(selection_node->any_children_selected || grow))
@@ -260,7 +243,7 @@ update_parents (ETreeSelectionModel *etsm, ETreePath path)
g_free(node_sequence);
return;
}
- orig_position_sequence[i] = etsm_orig_position(etsm->priv->model, parents);
+ orig_position_sequence[i] = e_tree_table_adapter_orig_position(etsm->priv->etta, parents);
parents = e_tree_model_node_get_parent(etsm->priv->model, parents);
}
@@ -622,7 +605,7 @@ etsm_recurse_is_path_selected (ETreeSelectionModel *etsm,
if (parent) {
selection_node = etsm_recurse_is_path_selected (etsm, parent, is_selected);
if (selection_node) {
- int position = etsm_orig_position(etsm->priv->model, path);
+ int position = e_tree_table_adapter_orig_position(etsm->priv->etta, path);
if (position < 0 || position >= selection_node->num_children) {
*is_selected = FALSE;
return NULL;
diff --git a/widgets/table/e-tree-table-adapter.c b/widgets/table/e-tree-table-adapter.c
index ead9650cce..9f77bd7350 100644
--- a/widgets/table/e-tree-table-adapter.c
+++ b/widgets/table/e-tree-table-adapter.c
@@ -48,6 +48,7 @@ typedef struct {
ETreePath path;
guint32 num_visible_children;
guint32 index;
+ guint32 orig_pos;
guint expanded : 1;
guint expandable : 1;
@@ -138,34 +139,53 @@ remap_indices(ETreeTableAdapter *etta)
etta->priv->remap_needed = FALSE;
}
+static node_t *
+get_node(ETreeTableAdapter *etta, ETreePath path)
+{
+ GNode *gnode = lookup_gnode(etta, path);
+
+ if (!gnode)
+ return NULL;
+
+ return (node_t *)gnode->data;
+}
+
static void
resort_node(ETreeTableAdapter *etta, GNode *gnode, gboolean recurse)
{
node_t *node = (node_t *)gnode->data;
ETreePath *paths, path;
GNode *prev, *curr;
- int i;
+ int i, count;
+ gboolean sort_needed;
- if (node->num_visible_children == 0 || !gnode->children)
- return;
- else if (node->num_visible_children == 1 && recurse) {
- resort_node(etta, gnode->children, recurse);
+ if (node->num_visible_children == 0)
return;
+
+ sort_needed = etta->priv->sort_info && e_table_sort_info_sorting_get_count (etta->priv->sort_info) > 0;
+
+ for (i = 0, path = e_tree_model_node_get_first_child(etta->priv->source, node->path); path;
+ path = e_tree_model_node_get_next(etta->priv->source, path), i++) {
+ node_t *child = get_node(etta, path);
+ if (child)
+ child->orig_pos = i;
}
- paths = g_new0(ETreePath, node->num_visible_children);
-
- g_return_if_fail(paths != NULL);
+ count = i;
+ if (count <= 1)
+ return;
+
+ paths = g_new0(ETreePath, count);
for (i = 0, path = e_tree_model_node_get_first_child(etta->priv->source, node->path); path;
path = e_tree_model_node_get_next(etta->priv->source, path), i++)
paths[i] = path;
- if (etta->priv->sort_info && e_table_sort_info_sorting_get_count > 0)
- e_table_sorting_utils_tree_sort(etta->priv->source, etta->priv->sort_info, etta->priv->header, paths, node->num_visible_children);
+ if (count > 1 && sort_needed)
+ e_table_sorting_utils_tree_sort(etta->priv->source, etta->priv->sort_info, etta->priv->header, paths, count);
prev = NULL;
- for (i = 0; i < node->num_visible_children; i++) {
+ for (i = 0; i < count; i++) {
curr = lookup_gnode(etta, paths[i]);
if (!curr)
continue;
@@ -185,17 +205,6 @@ resort_node(ETreeTableAdapter *etta, GNode *gnode, gboolean recurse)
g_free(paths);
}
-static node_t *
-get_node(ETreeTableAdapter *etta, ETreePath path)
-{
- GNode *gnode = lookup_gnode(etta, path);
-
- if (!gnode)
- return NULL;
-
- return (node_t *)gnode->data;
-}
-
static gint
get_row(ETreeTableAdapter *etta, ETreePath path)
{
@@ -295,6 +304,8 @@ delete_node(ETreeTableAdapter *etta, ETreePath parent, ETreePath path)
parent_node->expandable = expandable;
e_table_model_row_changed(E_TABLE_MODEL(etta), parent_row);
}
+
+ resort_node (etta, parent_gnode, FALSE);
}
e_table_model_rows_deleted(E_TABLE_MODEL(etta), row, to_remove);
@@ -309,6 +320,7 @@ create_gnode(ETreeTableAdapter *etta, ETreePath path)
node = g_new0(node_t, 1);
node->path = path;
node->index = -1;
+ node->orig_pos = 0;
node->expanded = e_tree_model_get_expanded_default(etta->priv->source);
node->expandable = e_tree_model_node_is_expandable(etta->priv->source, path);
node->expandable_set = 1;
@@ -323,13 +335,15 @@ insert_children(ETreeTableAdapter *etta, GNode *gnode)
{
ETreePath path, tmp;
int count = 0;
+ int pos = 0;
path = ((node_t *)gnode->data)->path;
for (tmp = e_tree_model_node_get_first_child(etta->priv->source, path);
tmp;
- tmp = e_tree_model_node_get_next(etta->priv->source, tmp)) {
+ tmp = e_tree_model_node_get_next(etta->priv->source, tmp), pos++) {
GNode *child = create_gnode(etta, tmp);
node_t *node = (node_t *) child->data;
+ node->orig_pos = pos;
if (node->expanded)
node->num_visible_children = insert_children(etta, child);
g_node_prepend(gnode, child);
@@ -418,10 +432,9 @@ insert_node(ETreeTableAdapter *etta, ETreePath parent, ETreePath path)
g_node_append(parent_gnode, gnode);
update_child_counts(parent_gnode, node->num_visible_children + 1);
- if (etta->priv->sort_info && e_table_sort_info_sorting_get_count(etta->priv->sort_info) > 0) {
- resort_node(etta, parent_gnode, FALSE);
- resort_node(etta, gnode, TRUE);
- }
+ resort_node(etta, parent_gnode, FALSE);
+ resort_node(etta, gnode, TRUE);
+
size = node->num_visible_children + 1;
resize_map(etta, etta->priv->n_map + size);
if (parent_gnode == etta->priv->root)
@@ -1106,3 +1119,14 @@ e_tree_table_adapter_set_sort_info (ETreeTableAdapter *etta, ETableSortInfo *sor
fill_map(etta, 0, etta->priv->root);
e_table_model_changed(E_TABLE_MODEL(etta));
}
+
+gint
+e_tree_table_adapter_orig_position (ETreeTableAdapter *etta, ETreePath path)
+{
+ node_t *node = get_node (etta, path);
+
+ if (!node)
+ return -1;
+
+ return node->orig_pos;
+}
diff --git a/widgets/table/e-tree-table-adapter.h b/widgets/table/e-tree-table-adapter.h
index a856489a40..2f6629a005 100644
--- a/widgets/table/e-tree-table-adapter.h
+++ b/widgets/table/e-tree-table-adapter.h
@@ -88,6 +88,9 @@ void e_tree_table_adapter_load_expanded_state (ETreeTableAdapter
void e_tree_table_adapter_set_sort_info (ETreeTableAdapter *etta,
ETableSortInfo *sort_info);
+gint e_tree_table_adapter_orig_position (ETreeTableAdapter *etta,
+ ETreePath path);
+
G_END_DECLS
#endif /* _E_TREE_TABLE_ADAPTER_H_ */