summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2011-11-10 13:07:47 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2011-11-10 13:07:47 +0000
commitdd6d1ce527ec4c8c1999f7fc646cea755ac00ca7 (patch)
tree3333e0c431665ecb19049b14b958bb05a9af9030
parent10237e0bde004c5a6db6674d7f521b67dbfde9b9 (diff)
downloadnetsurf-dd6d1ce527ec4c8c1999f7fc646cea755ac00ca7.tar.gz
netsurf-dd6d1ce527ec4c8c1999f7fc646cea755ac00ca7.tar.bz2
Make default hotlist folder persistent across sessions
svn path=/trunk/netsurf/; revision=13141
-rw-r--r--desktop/hotlist.c2
-rw-r--r--desktop/tree.c31
-rw-r--r--desktop/tree.h3
-rw-r--r--desktop/tree_url_node.c21
4 files changed, 46 insertions, 11 deletions
diff --git a/desktop/hotlist.c b/desktop/hotlist.c
index 681456517..dadf49bb6 100644
--- a/desktop/hotlist.c
+++ b/desktop/hotlist.c
@@ -479,6 +479,6 @@ bool hotlist_set_default_folder(bool clear)
tree_clear_default_folder_node(hotlist_tree);
return true;
} else {
- return tree_set_default_folder_node(hotlist_tree);
+ return tree_set_default_folder_node(hotlist_tree, NULL);
}
}
diff --git a/desktop/tree.c b/desktop/tree.c
index 1da1f7248..1b37b21a8 100644
--- a/desktop/tree.c
+++ b/desktop/tree.c
@@ -118,6 +118,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 retain_in_memory; /**< Whether the node remains
in memory after deletion */
bool deleted; /**< Whether the node is currently
@@ -1397,6 +1398,18 @@ bool tree_node_is_folder(struct node *node)
/**
+ * Returns true if the node is the default folder for a tree
+ *
+ * \param node the node to be checked
+ * \return true if the node is a default folder, false otherwise
+ */
+bool tree_node_is_default(struct node *node)
+{
+ return node->def_folder;
+}
+
+
+/**
* Update the text of a node element if it has changed.
*
* \param element The node element to update.
@@ -1567,13 +1580,18 @@ struct node *tree_get_default_folder_node(struct tree *tree)
* Set the default node of a tree to the selected node
*
* \param tree the tree to set the default node of
+ * \param node the node to set as default (NULL for selected node)
* \return success
*/
-bool tree_set_default_folder_node(struct tree *tree)
+bool tree_set_default_folder_node(struct tree *tree, struct node *node)
{
struct node *sel_node;
- sel_node = tree_get_selected_node(tree->root);
+ if (node == NULL) {
+ sel_node = tree_get_selected_node(tree->root);
+ } else {
+ sel_node = node;
+ }
if((sel_node == NULL) ||
(tree_node_is_folder(sel_node) == false)) {
@@ -1581,6 +1599,7 @@ bool tree_set_default_folder_node(struct tree *tree)
}
tree->def_folder = sel_node;
+ sel_node->def_folder = true;
return true;
}
@@ -1592,7 +1611,13 @@ bool tree_set_default_folder_node(struct tree *tree)
*/
void tree_clear_default_folder_node(struct tree *tree)
{
- tree->def_folder = NULL;
+ struct node *def_node = NULL;
+ def_node = tree_get_default_folder_node(tree);
+
+ if (def_node != NULL) {
+ tree->def_folder = NULL;
+ def_node->def_folder = false;
+ }
}
diff --git a/desktop/tree.h b/desktop/tree.h
index dc54e5e54..ed71f911e 100644
--- a/desktop/tree.h
+++ b/desktop/tree.h
@@ -166,6 +166,7 @@ bool tree_get_redraw(struct tree *tree);
bool tree_node_has_selection(struct node *node);
bool tree_node_is_deleted(struct node *node);
bool tree_node_is_folder(struct node *node);
+bool tree_node_is_default(struct node *node);
void tree_update_node_element(struct tree *tree, struct node_element *element,
const char *text, void *bitmap);
bool tree_update_element_text(struct tree *tree, struct node_element *element, char *text);
@@ -175,7 +176,7 @@ 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);
+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 */
diff --git a/desktop/tree_url_node.c b/desktop/tree_url_node.c
index c1e72bfc4..fee361b85 100644
--- a/desktop/tree_url_node.c
+++ b/desktop/tree_url_node.c
@@ -576,6 +576,7 @@ static void tree_url_load_directory(xmlNode *ul, struct tree *tree,
char *title;
struct node *dir;
xmlNode *xmlnode;
+ xmlChar *id;
assert(ul != NULL);
assert(directory != NULL);
@@ -595,6 +596,7 @@ static void tree_url_load_directory(xmlNode *ul, struct tree *tree,
} else if (strcmp((const char *)xmlnode->name, "h4") == 0) {
/* directory */
+ bool dir_is_default = false;
title = (char *) xmlNodeGetContent(xmlnode );
if (!title) {
warn_user("TreeLoadError", "(Empty <h4> "
@@ -613,6 +615,13 @@ static void tree_url_load_directory(xmlNode *ul, struct tree *tree,
warn_user("TreeLoadError", "(Expected "
"<ul> not present.)");
return;
+ } else {
+ id = xmlGetProp(xmlnode, "id");
+ if (id != NULL) {
+ if(strcmp((const char *)id, "default") == 0)
+ dir_is_default = true;
+ xmlFree(id);
+ }
}
dir = tree_create_folder_node(tree, directory, title,
@@ -622,6 +631,10 @@ static void tree_url_load_directory(xmlNode *ul, struct tree *tree,
return;
}
+ if(dir_is_default == true) {
+ tree_set_default_folder_node(tree, dir);
+ }
+
if (callback != NULL)
tree_set_node_user_callback(dir, callback,
callback_data);
@@ -738,6 +751,8 @@ static bool tree_url_save_directory(struct node *directory, xmlNode *node)
ul = xmlNewChild(node, NULL, (const xmlChar *)"ul", NULL);
if (ul == NULL)
return false;
+ if (tree_node_is_default(directory) == true)
+ xmlSetProp(ul, "id", "default");
for (child = tree_node_get_child(directory); child;
child = tree_node_get_next(child)) {
@@ -767,12 +782,6 @@ static bool tree_url_save_directory(struct node *directory, xmlNode *node)
}
-
-
-
-
-
-
/**
* Perform a save to a specified file in the form of a html page
*