Allow new (blank) hotlist entries to be created in the currently-selected folder

(if there is one) as this gives the user more control where their additions are
being created.
Functionality can be enabled/disabled by passing true/false to
hotlist_add_folder/hotlist_add_entry.

svn path=/trunk/netsurf/; revision=13185
This commit is contained in:
Chris Young 2011-11-27 20:07:26 +00:00
parent 714f07c48b
commit d169eefe59
4 changed files with 46 additions and 9 deletions

View File

@ -367,10 +367,12 @@ void hotlist_collapse_addresses(void)
/**
* Add a folder node.
*
* \param selected create the folder in the currently-selected node
*/
void hotlist_add_folder(void)
void hotlist_add_folder(bool selected)
{
struct node *node, *parent;
struct node *node, *parent = NULL;
struct node_element *element;
char *title = strdup("Untitled");
@ -381,7 +383,17 @@ void hotlist_add_folder(void)
}
creating_node = true;
parent = tree_get_default_folder_node(hotlist_tree);
if (selected == true) {
parent = tree_get_selected_node(tree_get_root(hotlist_tree));
if (parent && (tree_node_is_folder == false)) {
parent = tree_node_get_parent(parent);
}
}
if (parent == NULL) {
parent = tree_get_default_folder_node(hotlist_tree);
}
node = tree_create_folder_node(hotlist_tree, parent, title,
true, false, false);
if (node == NULL) {
@ -396,13 +408,25 @@ void hotlist_add_folder(void)
/**
* Add an entry node.
*
* \param selected add the entry in the currently-selected node
*/
void hotlist_add_entry(void)
void hotlist_add_entry(bool selected)
{
struct node *node, *parent;
creating_node = true;
parent = tree_get_default_folder_node(hotlist_tree);
if (selected == true) {
parent = tree_get_selected_node(tree_get_root(hotlist_tree));
if (parent && (tree_node_is_folder == false)) {
parent = tree_node_get_parent(parent);
}
}
if (parent == NULL) {
parent = tree_get_default_folder_node(hotlist_tree);
}
node = tree_create_URL_node(hotlist_tree, parent, "Address",
"Untitled", hotlist_node_callback, NULL);
@ -433,7 +457,7 @@ void hotlist_add_page(const char *url)
}
/**
* Adds the currently viewed page to the hotlist at the given cooridinates
* Adds the currently viewed page to the hotlist at the given co-ordinates
* \param url url of the page
* \param x X cooridinate with respect to tree origin
* \param y Y cooridinate with respect to tree origin

View File

@ -53,8 +53,8 @@ void hotlist_expand_addresses(void);
void hotlist_collapse_all(void);
void hotlist_collapse_directories(void);
void hotlist_collapse_addresses(void);
void hotlist_add_folder(void);
void hotlist_add_entry(void);
void hotlist_add_folder(bool selected);
void hotlist_add_entry(bool selected);
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);

View File

@ -132,7 +132,7 @@ struct node {
bool selected; /**< Whether the node is selected */
bool expanded; /**< Whether the node is expanded */
bool folder; /**< Whether the node is a folder */
bool def_folder; /**< Whether the node is the default folder */
bool def_folder; /**< Whether the node is the default folder */
bool retain_in_memory; /**< Whether the node remains
in memory after deletion */
bool deleted; /**< Whether the node is currently
@ -1653,6 +1653,18 @@ void tree_clear_default_folder_node(struct tree *tree)
}
/**
* Returns the parent of a node
*
* \param node the node to get the parent of
* \return the node's parent
*/
struct node *tree_node_get_parent(struct node *node)
{
return node->parent;
}
/**
* Returns the first child of a node
*

View File

@ -181,6 +181,7 @@ bool tree_set_default_folder_node(struct tree *tree, struct node *node);
void tree_clear_default_folder_node(struct tree *tree);
/* functions for traversing the tree */
struct node *tree_node_get_parent(struct node *node);
struct node *tree_node_get_child(struct node *node);
struct node *tree_node_get_next(struct node *node);