From 657d6ed587a4d27510de7c5836d790e1589c1075 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 3 Jul 2013 12:37:58 +0100 Subject: [PATCH] Implement DEL_EMPTY_DIRS flag. --- desktop/treeview.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/desktop/treeview.c b/desktop/treeview.c index 7603033f1..45d3a081c 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -485,15 +485,18 @@ static nserror treeview_delete_node_internal(struct treeview *tree, struct treeview_node_msg msg; msg.msg = TREE_MSG_NODE_DELETE; struct treeview_node *p; + static int nest_depth = 0; if (interaction && (tree->flags & TREEVIEW_NO_DELETES)) { return NSERROR_OK; } /* Destroy children first */ + nest_depth++; while (n->children != NULL) { treeview_delete_node_internal(tree, n->children, interaction); } + nest_depth--; /* Unlink node from tree */ if (n->parent != NULL && n->parent->children == n) { @@ -531,8 +534,23 @@ static nserror treeview_delete_node_internal(struct treeview *tree, return NSERROR_BAD_PARAMETER; } - /* Inform front end of change in dimensions */ - tree->cw_t->update_size(tree->cw_h, -1, tree->root->height); + if (nest_depth == 0) { + /* This is the node we were originally asked to delete */ + + if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS && + n->parent != NULL && + n->parent->type != TREE_NODE_ROOT && + n->parent->children == NULL) { + /* Delete empty parent */ + nest_depth++; + treeview_delete_node_internal(tree, n->parent, + interaction); + nest_depth--; + } + + /* Inform front end of change in dimensions */ + tree->cw_t->update_size(tree->cw_h, -1, tree->root->height); + } /* Free the node */ free(n);