Functions to add entry/folder at y-coord or at selection.
This commit is contained in:
parent
43d1e777df
commit
77a090e9d0
|
@ -175,7 +175,7 @@ static void hotlist_delete_entry_internal(struct hotlist_entry *e)
|
|||
|
||||
|
||||
/**
|
||||
* Add an entry to the hotlist (creates the entry).
|
||||
* Create hotlist entry data for URL.
|
||||
*
|
||||
* If set, 'title' must be allocated on the heap, ownership is yeilded to
|
||||
* this function.
|
||||
|
@ -183,18 +183,19 @@ static void hotlist_delete_entry_internal(struct hotlist_entry *e)
|
|||
* \param url URL for entry to add to hotlist.
|
||||
* \param title Title for entry, or NULL if using title from data
|
||||
* \param data URL data for the entry, or NULL
|
||||
* \param relation Existing node to insert as relation of, or NULL
|
||||
* \param rel Entry's relationship to relation
|
||||
* \param entry Updated to new treeview entry node
|
||||
* \param entry Updated to new hotlist entry data
|
||||
* \return NSERROR_OK on success, or appropriate error otherwise
|
||||
*/
|
||||
static nserror hotlist_add_entry_internal(nsurl *url, const char *title,
|
||||
const struct url_data *data, treeview_node *relation,
|
||||
enum treeview_relationship rel, treeview_node **entry)
|
||||
static nserror hotlist_create_entry(nsurl *url, const char *title,
|
||||
const struct url_data *data, struct hotlist_entry **entry)
|
||||
{
|
||||
nserror err;
|
||||
struct hotlist_entry *e;
|
||||
|
||||
assert(url != NULL);
|
||||
|
||||
*entry = NULL;
|
||||
|
||||
if (data == NULL) {
|
||||
/* Get the URL data */
|
||||
data = urldb_get_url_data(url);
|
||||
|
@ -225,6 +226,38 @@ static nserror hotlist_add_entry_internal(nsurl *url, const char *title,
|
|||
return err;
|
||||
}
|
||||
|
||||
*entry = e;
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an entry to the hotlist (creates the entry).
|
||||
*
|
||||
* If set, 'title' must be allocated on the heap, ownership is yeilded to
|
||||
* this function.
|
||||
*
|
||||
* \param url URL for entry to add to hotlist.
|
||||
* \param title Title for entry, or NULL if using title from data
|
||||
* \param data URL data for the entry, or NULL
|
||||
* \param relation Existing node to insert as relation of, or NULL
|
||||
* \param rel Entry's relationship to relation
|
||||
* \param entry Updated to new treeview entry node
|
||||
* \return NSERROR_OK on success, or appropriate error otherwise
|
||||
*/
|
||||
static nserror hotlist_add_entry_internal(nsurl *url, const char *title,
|
||||
const struct url_data *data, treeview_node *relation,
|
||||
enum treeview_relationship rel, treeview_node **entry)
|
||||
{
|
||||
nserror err;
|
||||
struct hotlist_entry *e;
|
||||
|
||||
err = hotlist_create_entry(url, title, data, &e);
|
||||
if (err != NSERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = hotlist_entry_insert(e, relation, rel);
|
||||
if (err != NSERROR_OK) {
|
||||
hotlist_delete_entry_internal(e);
|
||||
|
@ -262,7 +295,7 @@ static nserror hotlist_add_folder_internal(
|
|||
|
||||
if (title == NULL) {
|
||||
/* TODO: use messages */
|
||||
title = strdup("Folder");
|
||||
title = strdup("New folder");
|
||||
}
|
||||
if (title == NULL) {
|
||||
return NSERROR_NOMEM;
|
||||
|
@ -1280,6 +1313,63 @@ void hotlist_update_url(nsurl *url)
|
|||
}
|
||||
|
||||
|
||||
/* Exported interface, documented in hotlist.h */
|
||||
nserror hotlist_add_entry(nsurl *url, const char *title, bool at_y, int y)
|
||||
{
|
||||
nserror err;
|
||||
treeview_node *entry;
|
||||
treeview_node *relation;
|
||||
enum treeview_relationship rel;
|
||||
|
||||
if (url == NULL) {
|
||||
err = nsurl_create("http://netsurf-browser.org/", &url);
|
||||
if (err != NSERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
assert(url != NULL);
|
||||
} else {
|
||||
nsurl_ref(url);
|
||||
}
|
||||
|
||||
err = treeview_get_relation(hl_ctx.tree, &relation, &rel, at_y, y);
|
||||
if (err != NSERROR_OK) {
|
||||
nsurl_unref(url);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = hotlist_add_entry_internal(url, NULL, NULL,
|
||||
relation, rel, &entry);
|
||||
if (err != NSERROR_OK) {
|
||||
nsurl_unref(url);
|
||||
return err;
|
||||
}
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Exported interface, documented in hotlist.h */
|
||||
nserror hotlist_add_folder(const char *title, bool at_y, int y)
|
||||
{
|
||||
nserror err;
|
||||
struct hotlist_folder *f;
|
||||
treeview_node *relation;
|
||||
enum treeview_relationship rel;
|
||||
|
||||
err = treeview_get_relation(hl_ctx.tree, &relation, &rel, at_y, y);
|
||||
if (err != NSERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = hotlist_add_folder_internal(title, relation, rel, &f);
|
||||
if (err != NSERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Exported interface, documented in hotlist.h */
|
||||
void hotlist_redraw(int x, int y, struct rect *clip,
|
||||
const struct redraw_context *ctx)
|
||||
|
|
|
@ -83,6 +83,27 @@ void hotlist_remove_url(nsurl *url);
|
|||
*/
|
||||
void hotlist_update_url(nsurl *url);
|
||||
|
||||
/**
|
||||
* Add an entry to the hotlist for given Title/URL.
|
||||
*
|
||||
* \param url URL for entry to be added, or NULL
|
||||
* \param title Title for entry being added, or NULL
|
||||
* \param at_y Iff true, insert at y-offest
|
||||
* \param y Y-offset in px from top of hotlist. Ignored if (!at_y).
|
||||
* \return NSERROR_OK on success, appropriate error otherwise
|
||||
*/
|
||||
nserror hotlist_add_entry(nsurl *url, const char *title, bool at_y, int y);
|
||||
|
||||
/**
|
||||
* Add a folder to the hotlist.
|
||||
*
|
||||
* \param url Title for folder being added, or NULL
|
||||
* \param at_y Iff true, insert at y-offest
|
||||
* \param y Y-offset in px from top of hotlist. Ignored if (!at_y).
|
||||
* \return NSERROR_OK on success, appropriate error otherwise
|
||||
*/
|
||||
nserror hotlist_add_folder(const char *title, bool at_y, int y);
|
||||
|
||||
/**
|
||||
* Redraw the hotlist.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue