From 0b6e5da662decfc08f56bd28a8c7bc1f4fe90780 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Thu, 10 Nov 2011 12:22:48 +0000 Subject: Allow setting a default folder in the tree for hotlist entries to go into. Frontends will need to be updated to use hotlist_set_default_folder() if they want to use this functionality. svn path=/trunk/netsurf/; revision=13139 --- desktop/hotlist.c | 32 ++++++++++++++++++++++++++------ desktop/hotlist.h | 2 +- desktop/tree.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ desktop/tree.h | 4 ++++ 4 files changed, 83 insertions(+), 7 deletions(-) (limited to 'desktop') diff --git a/desktop/hotlist.c b/desktop/hotlist.c index 1f4028595..681456517 100644 --- a/desktop/hotlist.c +++ b/desktop/hotlist.c @@ -370,7 +370,7 @@ void hotlist_collapse_addresses(void) */ void hotlist_add_folder(void) { - struct node *node; + struct node *node, *parent; struct node_element *element; char *title = strdup("Untitled"); @@ -380,7 +380,9 @@ void hotlist_add_folder(void) return; } creating_node = true; - node = tree_create_folder_node(hotlist_tree, hotlist_tree_root, title, + + parent = tree_get_default_folder_node(hotlist_tree); + node = tree_create_folder_node(hotlist_tree, parent, title, true, false, false); if (node == NULL) { free(title); @@ -397,9 +399,11 @@ void hotlist_add_folder(void) */ void hotlist_add_entry(void) { - struct node *node; + struct node *node, *parent; creating_node = true; - node = tree_create_URL_node(hotlist_tree, hotlist_tree_root, "Address", + + parent = tree_get_default_folder_node(hotlist_tree); + node = tree_create_URL_node(hotlist_tree, parent, "Address", "Untitled", hotlist_node_callback, NULL); if (node == NULL) @@ -414,7 +418,7 @@ void hotlist_add_entry(void) void hotlist_add_page(const char *url) { const struct url_data *data; - struct node *node; + struct node *node, *parent; if (url == NULL) return; @@ -422,7 +426,8 @@ void hotlist_add_page(const char *url) if (data == NULL) return; - node = tree_create_URL_node(hotlist_tree, hotlist_tree_root, url, NULL, + parent = tree_get_default_folder_node(hotlist_tree); + node = tree_create_URL_node(hotlist_tree, parent, url, NULL, hotlist_node_callback, NULL); tree_update_URL_node(hotlist_tree, node, url, data); } @@ -462,3 +467,18 @@ void hotlist_launch_selected(bool tabs) { tree_launch_selected(hotlist_tree, tabs); } + +/** + * Set the hotlist's default folder to the selected node. + * + * \param clear reset the default to tree root + */ +bool hotlist_set_default_folder(bool clear) +{ + if (clear == true) { + tree_clear_default_folder_node(hotlist_tree); + return true; + } else { + return tree_set_default_folder_node(hotlist_tree); + } +} diff --git a/desktop/hotlist.h b/desktop/hotlist.h index b17d98baa..544cd02d0 100644 --- a/desktop/hotlist.h +++ b/desktop/hotlist.h @@ -58,5 +58,5 @@ void hotlist_add_entry(void); void hotlist_add_page(const char *url); void hotlist_add_page_xy(const char *url, int x, int y); void hotlist_launch_selected(bool tabs); - +bool hotlist_set_default_folder(bool clear); #endif diff --git a/desktop/tree.c b/desktop/tree.c index bf7b643b9..1da1f7248 100644 --- a/desktop/tree.c +++ b/desktop/tree.c @@ -159,6 +159,7 @@ struct tree { const struct treeview_table *callbacks; void *client_data; /* User assigned data for the callbacks */ + struct node *def_folder; /* Node to be used for additions by default */ }; void tree_set_icon_dir(char *icon_dir) @@ -1034,6 +1035,8 @@ static void tree_delete_node_internal(struct tree *tree, struct node *node, parent = node->parent; if (tree != NULL && parent == tree->root) parent = NULL; + if ((tree != NULL) && (tree->def_folder == node)) + tree->def_folder = NULL; tree_delink_node(tree, node); child = node->child; node->child = NULL; @@ -1544,6 +1547,55 @@ tree_drag_type tree_drag_status(struct tree *tree) } +/** + * Get the default node of a tree for additions + * + * \param tree the tree to get the default node of + * \return the default node + */ +struct node *tree_get_default_folder_node(struct tree *tree) +{ + if (tree->def_folder != NULL) { + return tree->def_folder; + } else { + return tree_get_root(tree); + } +} + + +/** + * Set the default node of a tree to the selected node + * + * \param tree the tree to set the default node of + * \return success + */ +bool tree_set_default_folder_node(struct tree *tree) +{ + struct node *sel_node; + + sel_node = tree_get_selected_node(tree->root); + + if((sel_node == NULL) || + (tree_node_is_folder(sel_node) == false)) { + return false; + } + + tree->def_folder = sel_node; + return true; +} + + +/** + * Clear the default node of a tree + * + * \param tree the tree to clear the default node of + */ +void tree_clear_default_folder_node(struct tree *tree) +{ + tree->def_folder = NULL; +} + + /** * Returns the first child of a node * diff --git a/desktop/tree.h b/desktop/tree.h index 0ff8948bc..dc54e5e54 100644 --- a/desktop/tree.h +++ b/desktop/tree.h @@ -174,6 +174,10 @@ struct node *tree_get_root(struct tree *tree); bool tree_is_edited(struct tree *tree); tree_drag_type tree_drag_status(struct tree *tree); +struct node *tree_get_default_folder_node(struct tree *tree); +bool tree_set_default_folder_node(struct tree *tree); +void tree_clear_default_folder_node(struct tree *tree); + /* functions for traversing the tree */ struct node *tree_node_get_child(struct node *node); struct node *tree_node_get_next(struct node *node); -- cgit v1.2.3