From 26befde81c6d0c40ce5ebf9244b0f963587b7646 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 3 Jul 2013 11:50:23 +0100 Subject: [PATCH] Make READ_ONLY flag a combinator for NO_MOVES and NO_DELETES. Implement NO_DELETES. --- desktop/treeview.c | 31 ++++++++++++++++++++++++++----- desktop/treeview.h | 9 +++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/desktop/treeview.c b/desktop/treeview.c index 5d8a72f31..062ef9bc7 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -469,16 +469,30 @@ nserror treeview_create_node_entry(struct treeview *tree, } -/* Exported interface, documented in treeview.h */ -nserror treeview_delete_node(struct treeview *tree, struct treeview_node *n) +/** + * Delete a treeview node + * + * \param tree Treeview object to delete node from + * \param n Node to delete + * \param interaction Delete is result of user interaction with treeview + * \return NSERROR_OK on success, appropriate error otherwise + * + * Will emit folder or entry deletion msg callback. + */ +static nserror treeview_delete_node_internal(struct treeview *tree, + struct treeview_node *n, bool interaction) { struct treeview_node_msg msg; msg.msg = TREE_MSG_NODE_DELETE; struct treeview_node *p; + if (interaction && (tree->flags & TREEVIEW_NO_DELETES)) { + return NSERROR_OK; + } + /* Destroy children first */ while (n->children != NULL) { - treeview_delete_node(tree, n->children); + treeview_delete_node_internal(tree, n->children, interaction); } /* Unlink node from tree */ @@ -527,6 +541,13 @@ nserror treeview_delete_node(struct treeview *tree, struct treeview_node *n) } +/* Exported interface, documented in treeview.h */ +nserror treeview_delete_node(struct treeview *tree, struct treeview_node *n) +{ + return treeview_delete_node_internal(tree, n, false); +} + + /* Exported interface, documented in treeview.h */ nserror treeview_create(struct treeview **tree, const struct treeview_callback_table *callbacks, @@ -614,7 +635,7 @@ nserror treeview_destroy(struct treeview *tree) assert(tree != NULL); /* Destroy nodes */ - treeview_delete_node(tree, tree->root); + treeview_delete_node_internal(tree, tree->root, false); /* Destroy feilds */ for (f = 0; f <= tree->n_fields; f++) { @@ -1086,7 +1107,7 @@ static bool treeview_node_selection_walk_cb(struct treeview_node *node, case TREEVIEW_WALK_DELETE_SELECTION: if (node->flags & TREE_NODE_SELECTED) { - treeview_delete_node(sw->tree, node); + treeview_delete_node_internal(sw->tree, node, true); changed = true; } break; diff --git a/desktop/treeview.h b/desktop/treeview.h index 5704014c5..475b90e67 100644 --- a/desktop/treeview.h +++ b/desktop/treeview.h @@ -44,10 +44,11 @@ typedef enum { } treeview_node_create_flags; /**< Relationship between nodes */ typedef enum { - TREEVIEW_NO_FLAGS = (0), /* No flags set */ - TREEVIEW_READ_ONLY = (1 << 0), /* No edits */ - TREEVIEW_NO_MOVES = (1 << 1), /* No node drags */ - TREEVIEW_DELETE_EMPTY_DIRS = (1 << 2) /* Del. dirs on empty */ + TREEVIEW_NO_FLAGS = (0), /**< No flags set */ + TREEVIEW_NO_MOVES = (1 << 0), /**< No node drags */ + TREEVIEW_NO_DELETES = (1 << 1), /**< No node deletes */ + TREEVIEW_READ_ONLY = TREEVIEW_NO_MOVES | TREEVIEW_NO_DELETES, + TREEVIEW_DEL_EMPTY_DIRS = (1 << 2) /**< Delete dirs on empty */ } treeview_flags; enum treeview_msg {