From ec9608c4ded5f286d91fcb3df09906b8ac8ec025 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 15 Jul 2013 14:34:56 +0100 Subject: [PATCH] Make node delete callback msg differentiate between deletes caused by user interaction and other deletes (e.g. treeview destruction). --- desktop/treeview.c | 15 ++++++++++----- desktop/treeview.h | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/desktop/treeview.c b/desktop/treeview.c index c15c9eeae..b9200735b 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -576,6 +576,7 @@ static nserror treeview_walk_internal(treeview_node *root, bool full, struct treeview_node_delete { treeview *tree; int height_reduction; + bool user_interaction; }; /** Treewalk node callback deleting nodes. */ static nserror treeview_delete_node_walk_cb(treeview_node *n, @@ -584,6 +585,7 @@ static nserror treeview_delete_node_walk_cb(treeview_node *n, struct treeview_node_delete *nd = (struct treeview_node_delete *)ctx; struct treeview_node_msg msg; msg.msg = TREE_MSG_NODE_DELETE; + msg.data.delete.user = nd->user_interaction; assert(n->children == NULL); @@ -651,7 +653,8 @@ static nserror treeview_delete_node_internal(treeview *tree, treeview_node *n, treeview_node *p = n->parent; struct treeview_node_delete nd = { .tree = tree, - .height_reduction = 0 + .height_reduction = 0, + .user_interaction = interaction }; if (interaction && (tree->flags & TREEVIEW_NO_DELETES)) { @@ -691,13 +694,14 @@ static nserror treeview_delete_node_internal(treeview *tree, treeview_node *n, * Delete a treeview node * * \param tree Treeview object to delete empty nodes from + * \param interaction Delete is result of user interaction with treeview * \return NSERROR_OK on success, appropriate error otherwise * * Note this must not be called within a treeview_walk. It may delete the * walker's 'current' node, making it impossible to move on without invalid * reads. */ -static nserror treeview_delete_empty_nodes(treeview *tree) +static nserror treeview_delete_empty_nodes(treeview *tree, bool interaction) { treeview_node *node, *child, *parent, *next_sibling; treeview_node *root = tree->root; @@ -705,7 +709,8 @@ static nserror treeview_delete_empty_nodes(treeview *tree) nserror err; struct treeview_node_delete nd = { .tree = tree, - .height_reduction = 0 + .height_reduction = 0, + .user_interaction = interaction }; node = root; @@ -778,7 +783,7 @@ nserror treeview_delete_node(treeview *tree, treeview_node *n) if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) { /* Delete any empty nodes */ - err = treeview_delete_empty_nodes(tree); + err = treeview_delete_empty_nodes(tree, false); if (err != NSERROR_OK) return err; } @@ -1686,7 +1691,7 @@ bool treeview_keypress(treeview *tree, uint32_t key) if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) { /* Delete any empty nodes */ - err = treeview_delete_empty_nodes(tree); + err = treeview_delete_empty_nodes(tree, true); r.y0 = 0; } break; diff --git a/desktop/treeview.h b/desktop/treeview.h index 5662dfaac..82a7af17f 100644 --- a/desktop/treeview.h +++ b/desktop/treeview.h @@ -59,6 +59,9 @@ enum treeview_msg { struct treeview_node_msg { enum treeview_msg msg; /**< The message type */ union { + struct { + bool user; /* True iff delete by user interaction */ + } delete; struct { lwc_string *feild; /* The field being edited */ const char *text; /* The proposed new value */