mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-18 16:49:18 +03:00
Make node delete callback msg differentiate between deletes caused by user interaction and other deletes (e.g. treeview destruction).
This commit is contained in:
parent
9f72b5e046
commit
ec9608c4de
@ -576,6 +576,7 @@ static nserror treeview_walk_internal(treeview_node *root, bool full,
|
|||||||
struct treeview_node_delete {
|
struct treeview_node_delete {
|
||||||
treeview *tree;
|
treeview *tree;
|
||||||
int height_reduction;
|
int height_reduction;
|
||||||
|
bool user_interaction;
|
||||||
};
|
};
|
||||||
/** Treewalk node callback deleting nodes. */
|
/** Treewalk node callback deleting nodes. */
|
||||||
static nserror treeview_delete_node_walk_cb(treeview_node *n,
|
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_delete *nd = (struct treeview_node_delete *)ctx;
|
||||||
struct treeview_node_msg msg;
|
struct treeview_node_msg msg;
|
||||||
msg.msg = TREE_MSG_NODE_DELETE;
|
msg.msg = TREE_MSG_NODE_DELETE;
|
||||||
|
msg.data.delete.user = nd->user_interaction;
|
||||||
|
|
||||||
assert(n->children == NULL);
|
assert(n->children == NULL);
|
||||||
|
|
||||||
@ -651,7 +653,8 @@ static nserror treeview_delete_node_internal(treeview *tree, treeview_node *n,
|
|||||||
treeview_node *p = n->parent;
|
treeview_node *p = n->parent;
|
||||||
struct treeview_node_delete nd = {
|
struct treeview_node_delete nd = {
|
||||||
.tree = tree,
|
.tree = tree,
|
||||||
.height_reduction = 0
|
.height_reduction = 0,
|
||||||
|
.user_interaction = interaction
|
||||||
};
|
};
|
||||||
|
|
||||||
if (interaction && (tree->flags & TREEVIEW_NO_DELETES)) {
|
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
|
* Delete a treeview node
|
||||||
*
|
*
|
||||||
* \param tree Treeview object to delete empty nodes from
|
* \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
|
* \return NSERROR_OK on success, appropriate error otherwise
|
||||||
*
|
*
|
||||||
* Note this must not be called within a treeview_walk. It may delete the
|
* 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
|
* walker's 'current' node, making it impossible to move on without invalid
|
||||||
* reads.
|
* 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 *node, *child, *parent, *next_sibling;
|
||||||
treeview_node *root = tree->root;
|
treeview_node *root = tree->root;
|
||||||
@ -705,7 +709,8 @@ static nserror treeview_delete_empty_nodes(treeview *tree)
|
|||||||
nserror err;
|
nserror err;
|
||||||
struct treeview_node_delete nd = {
|
struct treeview_node_delete nd = {
|
||||||
.tree = tree,
|
.tree = tree,
|
||||||
.height_reduction = 0
|
.height_reduction = 0,
|
||||||
|
.user_interaction = interaction
|
||||||
};
|
};
|
||||||
|
|
||||||
node = root;
|
node = root;
|
||||||
@ -778,7 +783,7 @@ nserror treeview_delete_node(treeview *tree, treeview_node *n)
|
|||||||
|
|
||||||
if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) {
|
if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) {
|
||||||
/* Delete any empty nodes */
|
/* Delete any empty nodes */
|
||||||
err = treeview_delete_empty_nodes(tree);
|
err = treeview_delete_empty_nodes(tree, false);
|
||||||
if (err != NSERROR_OK)
|
if (err != NSERROR_OK)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -1686,7 +1691,7 @@ bool treeview_keypress(treeview *tree, uint32_t key)
|
|||||||
|
|
||||||
if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) {
|
if (tree->flags & TREEVIEW_DEL_EMPTY_DIRS) {
|
||||||
/* Delete any empty nodes */
|
/* Delete any empty nodes */
|
||||||
err = treeview_delete_empty_nodes(tree);
|
err = treeview_delete_empty_nodes(tree, true);
|
||||||
r.y0 = 0;
|
r.y0 = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -59,6 +59,9 @@ enum treeview_msg {
|
|||||||
struct treeview_node_msg {
|
struct treeview_node_msg {
|
||||||
enum treeview_msg msg; /**< The message type */
|
enum treeview_msg msg; /**< The message type */
|
||||||
union {
|
union {
|
||||||
|
struct {
|
||||||
|
bool user; /* True iff delete by user interaction */
|
||||||
|
} delete;
|
||||||
struct {
|
struct {
|
||||||
lwc_string *feild; /* The field being edited */
|
lwc_string *feild; /* The field being edited */
|
||||||
const char *text; /* The proposed new value */
|
const char *text; /* The proposed new value */
|
||||||
|
Loading…
Reference in New Issue
Block a user