From 951ad51cd45ba2e5f49fab169ccbabc8f98a5185 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 13 Sep 2013 14:24:25 +0100 Subject: Add functions to get first selected hotlist/global_history node data. --- desktop/global_history.c | 21 +++++++++++++++++++++ desktop/global_history.h | 9 +++++++++ desktop/hotlist.c | 21 +++++++++++++++++++++ desktop/hotlist.h | 9 +++++++++ desktop/treeview.c | 9 +++++++++ desktop/treeview.h | 8 ++++++++ 6 files changed, 77 insertions(+) diff --git a/desktop/global_history.c b/desktop/global_history.c index 191ff1966..94521e7c3 100644 --- a/desktop/global_history.c +++ b/desktop/global_history.c @@ -949,6 +949,27 @@ bool global_history_has_selection(void) } +/* Exported interface, documented in global_history.h */ +bool global_history_get_selection(nsurl **url, const char **title) +{ + struct global_history_entry *e; + void *v; + + treeview_get_selection(gh_ctx.tree, &v); + if (v == NULL) { + *url = NULL; + *title = NULL; + return false; + } + + e = (struct global_history_entry *)v; + + *url = e->url; + *title = e->data[GH_TITLE].value; + return true; +} + + /* Exported interface, documented in global_history.h */ nserror global_history_expand(bool only_folders) { diff --git a/desktop/global_history.h b/desktop/global_history.h index 4ebe13980..7c49cfcb7 100644 --- a/desktop/global_history.h +++ b/desktop/global_history.h @@ -109,6 +109,15 @@ void global_history_keypress(uint32_t key); */ bool global_history_has_selection(void); +/** + * Get the first selected node + * + * \param url Updated to the selected entry's address, or NULL + * \param title Updated to the selected entry's title, or NULL + * \return true iff global history has a selection + */ +bool global_history_get_selection(nsurl **url, const char **title); + /** * Expand the treeview's nodes * diff --git a/desktop/hotlist.c b/desktop/hotlist.c index fde4c33cf..bedb09535 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -1482,6 +1482,27 @@ bool hotlist_has_selection(void) } +/* Exported interface, documented in hotlist.h */ +bool hotlist_get_selection(nsurl **url, const char **title) +{ + struct hotlist_entry *e; + void *v; + + treeview_get_selection(hl_ctx.tree, &v); + if (v == NULL) { + *url = NULL; + *title = NULL; + return false; + } + + e = (struct hotlist_entry *)v; + + *url = e->url; + *title = e->data[HL_TITLE].value; + return true; +} + + /* Exported interface, documented in hotlist.h */ void hotlist_edit_selection(void) { diff --git a/desktop/hotlist.h b/desktop/hotlist.h index c6e74f2cc..e5ae83499 100644 --- a/desktop/hotlist.h +++ b/desktop/hotlist.h @@ -200,6 +200,15 @@ void hotlist_keypress(uint32_t key); */ bool hotlist_has_selection(void); +/** + * Get the first selected node + * + * \param url Updated to the selected entry's address, or NULL + * \param title Updated to the selected entry's title, or NULL + * \return true iff hotlist has a selection + */ +bool hotlist_get_selection(nsurl **url, const char **title); + /** * Edit the first selected node */ diff --git a/desktop/treeview.c b/desktop/treeview.c index 6b74c9033..d1eae4030 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -2075,6 +2075,15 @@ static treeview_node * treeview_get_first_selected(treeview *tree) } +/* Exported interface, documented in treeview.h */ +void treeview_get_selection(treeview *tree, void **node_data) +{ + assert(tree != NULL); + + *node_data = treeview_get_first_selected(tree); +} + + /** * Clear any selection in a treeview * diff --git a/desktop/treeview.h b/desktop/treeview.h index 6fe6521dc..8f5c44ebd 100644 --- a/desktop/treeview.h +++ b/desktop/treeview.h @@ -375,6 +375,14 @@ void treeview_mouse_action(treeview *tree, */ bool treeview_has_selection(treeview *tree); +/** + * Get the first selected node + * + * \param tree Treeview object to get selected node in + * \param node_data Client data for the selected treeview node, or NULL + */ +void treeview_get_selection(treeview *tree, void **node_data); + /** * Edit the first selected node * -- cgit v1.2.3