diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2013-08-20 15:44:24 +0100 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2013-08-20 15:44:24 +0100 |
commit | 9e29ef4bdd09a8844d961219c5c9dd438916bad8 (patch) | |
tree | ff7e321381a5df45c51271677f696bd9e0a305c4 | |
parent | a9e92e335c3f658ced46b6c6ca1362335b8b8b6f (diff) | |
download | netsurf-9e29ef4bdd09a8844d961219c5c9dd438916bad8.tar.gz netsurf-9e29ef4bdd09a8844d961219c5c9dd438916bad8.tar.bz2 |
Pass edit message to treeview client, when editing ends.
-rw-r--r-- | desktop/treeview.c | 47 | ||||
-rw-r--r-- | desktop/treeview.h | 2 |
2 files changed, 47 insertions, 2 deletions
diff --git a/desktop/treeview.c b/desktop/treeview.c index 9c21621e7..0f998fc4e 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -127,6 +127,7 @@ struct treeview_move { struct treeview_edit { treeview_node *node; /**< Node being edited, or NULL */ struct textarea *textarea; /**< Textarea for edit, or NULL */ + lwc_string *field; /**< The field being edited, or NULL */ int x; /**< Textarea x position */ int y; /**< Textarea y position */ int w; /**< Textarea width */ @@ -782,11 +783,54 @@ static void treeview_edit_cancel(treeview *tree, bool redraw) */ static void treeview_edit_done(treeview *tree) { + int len, error; + char* new_text; + treeview_node *n = tree->edit.node; + struct treeview_node_msg msg; + msg.msg = TREE_MSG_NODE_EDIT; + if (tree->edit.textarea == NULL) return; + assert(n != NULL); + + /* Get new text length */ + len = textarea_get_text(tree->edit.textarea, NULL, 0); + + new_text = malloc(len); + if (new_text == NULL) { + /* TODO: don't just silently ignore */ + return; + } + + /* Get the new text from textarea */ + error = textarea_get_text(tree->edit.textarea, new_text, len); + if (error == -1) { + /* TODO: don't just silently ignore */ + free(new_text); + return; + } + /* Inform the treeview client with change request message */ - /* TODO */ + msg.data.node_edit.field = tree->edit.field; + msg.data.node_edit.text = new_text; + + switch (n->type) { + case TREE_NODE_ENTRY: + tree->callbacks->entry(msg, n->client_data); + break; + case TREE_NODE_FOLDER: + tree->callbacks->folder(msg, n->client_data); + break; + case TREE_NODE_ROOT: + break; + default: + break; + } + + + /* Finished with the new text */ + free(new_text); /* Finally, destroy the treeview, and redraw */ treeview_edit_cancel(tree, true); @@ -2447,6 +2491,7 @@ static bool treeview_edit_node_at_point(treeview *tree, treeview_node *n, } tree->edit.node = n; + tree->edit.field = ef->field; /* Position the caret */ mouse_x -= field_x; diff --git a/desktop/treeview.h b/desktop/treeview.h index ddd9be661..c623b8516 100644 --- a/desktop/treeview.h +++ b/desktop/treeview.h @@ -69,7 +69,7 @@ struct treeview_node_msg { bool user; /* True iff delete by user interaction */ } delete; struct { - lwc_string *feild; /* The field being edited */ + lwc_string *field; /* The field being edited */ const char *text; /* The proposed new value */ } node_edit; /* Client may call treeview_update_node_* */ struct { |