diff --git a/desktop/treeview.c b/desktop/treeview.c index 7cf454ea2..bca2deade 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -1195,6 +1195,54 @@ static void treeview_commit_selection_drag(struct treeview *tree) treeview_node_selection_walk_cb, &sw); } + +/* Exported interface, documented in treeview.h */ +bool treeview_keypress(struct treeview *tree, uint32_t key) +{ + struct rect r; /**< Redraw rectangle */ + bool redraw = false; + + assert(tree != NULL); + + switch (key) { + case KEY_SELECT_ALL: + redraw = treeview_select_all(tree, &r); + break; + case KEY_COPY_SELECTION: + /* TODO: Copy selection as text */ + break; + case KEY_DELETE_LEFT: + case KEY_DELETE_RIGHT: + /* TODO: Delete selection */ + break; + case KEY_CR: + case KEY_NL: + /* TODO: Launch selection */ + break; + case KEY_ESCAPE: + case KEY_CLEAR_SELECTION: + redraw = treeview_clear_selection(tree, &r); + break; + /* TODO: Trivial keyboard navigation */ + case KEY_LEFT: + break; + case KEY_RIGHT: + break; + case KEY_UP: + break; + case KEY_DOWN: + break; + default: + return false; + } + + if (redraw) { + tree->cw_t->redraw_request(tree->cw_h, r); + } + + return true; +} + struct treeview_mouse_action { struct treeview *tree; browser_mouse_state mouse; diff --git a/desktop/treeview.h b/desktop/treeview.h index 2579d8553..9692d0aa7 100644 --- a/desktop/treeview.h +++ b/desktop/treeview.h @@ -27,6 +27,7 @@ #include #include "desktop/core_window.h" +#include "desktop/textinput.h" #include "utils/types.h" struct treeview; @@ -231,6 +232,15 @@ nserror treeview_node_contract(struct treeview *tree, void treeview_redraw(struct treeview *tree, int x, int y, struct rect *clip, const struct redraw_context *ctx); +/** + * Key press handling for treeviews. + * + * \param tree The treeview which got the keypress + * \param key The ucs4 character codepoint + * \return true if the keypress is dealt with, false otherwise. + */ +bool treeview_keypress(struct treeview *tree, uint32_t key); + /** * Handles all kinds of mouse action *