Improved Amiga treeview support. Now creates trees for cookies and history (history

doesn't populate at the moment).  Can add folders and edit titles in hotlist
treeviews, and delete entries in all treeviews.

svn path=/trunk/netsurf/; revision=5542
This commit is contained in:
Chris Young 2008-10-11 21:38:04 +00:00
parent 3b0c91c91d
commit 86042c61ea
12 changed files with 969 additions and 330 deletions

View File

@ -88,7 +88,8 @@ S_DEBUG := $(addprefix debug/,$(S_DEBUG))
# S_AMIGA are sources purely for the Amiga build
S_AMIGA := compat.c gui.c tree.c history.c hotlist.c schedule.c \
thumbnail.c misc.c bitmap.c font.c filetype.c utf8.c login.c \
plotters.c object.c menu.c save_pdf.c arexx.c version.c
plotters.c object.c menu.c save_pdf.c arexx.c version.c \
cookies.c
S_AMIGA := $(addprefix amiga/,$(S_AMIGA))
# S_FRAMEBUFFER are sources purely for the framebuffer build

View File

@ -64,6 +64,8 @@
#include "utils/url.h"
#include <string.h>
#include "amiga/arexx.h"
#include "amiga/hotlist.h"
#include "amiga/history.h"
#ifdef WITH_HUBBUB
#include <hubbub/hubbub.h>
@ -260,6 +262,9 @@ void gui_init(int argc, char** argv)
if((!option_url_file) || (option_url_file[0] == '\0'))
option_url_file = (char *)strdup("Resources/URLs");
if((!option_recent_file) || (option_recent_file[0] == '\0'))
option_recent_file = (char *)strdup("Resources/Recent");
/*
if((!option_cookie_jar) || (option_cookie_jar[0] == '\0'))
option_cookie_jar = (char *)strdup("Resources/CookieJar");
@ -303,6 +308,8 @@ void gui_init(int argc, char** argv)
hotlist = options_load_tree(option_hotlist_file);
if(!hotlist) ami_hotlist_init(&hotlist);
ami_global_history_initialise();
ami_cookies_initialise();
if(dto = NewDTObject("Resources/Throbber",
DTA_GroupID,GID_PICTURE,
@ -980,6 +987,10 @@ void gui_quit(void)
urldb_save(option_url_file);
urldb_save_cookies(option_cookie_file);
options_save_tree(hotlist,option_hotlist_file,messages_get("TreeHotlist"));
void ami_global_history_save();
ami_cookies_free();
ami_global_history_free();
#ifdef WITH_HUBBUB
hubbub_finalise(myrealloc,NULL);
@ -1163,7 +1174,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw,
}
gwin->shared->scrollerhook.h_Entry = ami_scroller_hook;
gwin->shared->scrollerhook.h_Data = gwin;
gwin->shared->scrollerhook.h_Data = gwin->shared;
switch(bw->browser_window_type)
{
@ -2531,7 +2542,7 @@ bool gui_search_term_highlighted(struct gui_window *g,
void ami_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg)
{
ULONG gid,x,y;
struct gui_window *gwin = hook->h_Data;
struct gui_window_2 *gwin = hook->h_Data;
if (msg->Class == IDCMP_IDCMPUPDATE)
{
@ -2540,11 +2551,11 @@ void ami_scroller_hook(struct Hook *hook,Object *object,struct IntuiMessage *msg
switch( gid )
{
case OID_HSCROLL:
gwin->shared->redraw_required = true;
gwin->redraw_required = true;
break;
case OID_VSCROLL:
gwin->shared->redraw_required = true;
gwin->redraw_required = true;
break;
}
}

View File

@ -55,6 +55,12 @@ enum
GID_LOGIN,
GID_CANCEL,
GID_TREEBROWSER,
GID_OPEN,
GID_UP,
GID_DOWN,
GID_NEWF,
GID_NEWB,
GID_DEL,
GID_LAST
};

View File

@ -1,4 +1,5 @@
/*
* Copyright 2005 Richard Wilson <info@tinct.net>
* Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
@ -17,16 +18,288 @@
*/
#include "desktop/browser.h"
#include "amiga/history.h"
#include "amiga/tree.h"
#include "content/urldb.h"
#include <proto/dos.h>
#include "amiga/options.h"
#include <proto/exec.h>
#include <assert.h>
#include <utils/log.h>
#define MAXIMUM_URL_LENGTH 1024
#define MAXIMUM_BASE_NODES 16
static struct node *global_history_base_node[MAXIMUM_BASE_NODES];
static int global_history_base_node_time[MAXIMUM_BASE_NODES];
static int global_history_base_node_count = 0;
static char *global_history_recent_url[GLOBAL_HISTORY_RECENT_URLS];
static int global_history_recent_count = 0;
static bool global_history_init;
static struct node *ami_global_history_find(const char *url);
static bool global_history_add_internal(const char *url,
const struct url_data *data);
void ami_global_history_initialise(void)
{
char s[MAXIMUM_URL_LENGTH];
BPTR *fp;
if(global_history_tree) return;
/* Create an empty tree */
global_history_tree = AllocVec(sizeof(struct tree), MEMF_CLEAR | MEMF_PRIVATE);
if (!global_history_tree) {
warn_user("NoMemory", 0);
return;
}
global_history_tree->root = tree_create_folder_node(NULL, "Root");
if (!global_history_tree->root) {
warn_user("NoMemory", 0);
FreeVec(global_history_tree);
global_history_tree = NULL;
}
global_history_tree->root->expanded = true;
global_history_tree->movable = false;
/* load recent URLs */
fp = FOpen(option_recent_file, MODE_OLDFILE,0);
if (!fp)
LOG(("Failed to open file '%s' for reading",
option_recent_file));
else {
while (FGets(fp,s, MAXIMUM_URL_LENGTH)) {
if (s[strlen(s) - 1] == '\n')
s[strlen(s) - 1] = '\0';
global_history_add_recent(s);
}
FClose(fp);
}
global_history_init = true;
urldb_iterate_entries(global_history_add_internal);
global_history_init = false;
tree_initialise(global_history_tree);
}
void global_history_add(const char *url)
{
const struct url_data *data;
data = urldb_get_url_data(url);
if (!data)
return;
global_history_add_internal(url, data);
}
/**
* Internal routine to actually perform global history addition
*
* \param url The URL to add
* \param data URL data associated with URL
* \return true (for urldb_iterate_entries)
*/
bool global_history_add_internal(const char *url,
const struct url_data *data)
{
int i, j;
struct node *parent = NULL;
struct node *link;
struct node *node;
bool before = false;
int visit_date;
assert(url && data);
visit_date = data->last_visit;
/* find parent node */
for (i = 0; i < global_history_base_node_count; i++) {
if (global_history_base_node_time[i] <= visit_date) {
parent = global_history_base_node[i];
break;
}
}
/* the entry is too old to care about */
if (!parent)
return true;
if (parent->deleted) {
/* parent was deleted, so find place to insert it */
link = global_history_tree->root;
for (j = global_history_base_node_count - 1; j >= 0; j--) {
if (!global_history_base_node[j]->deleted &&
global_history_base_node_time[j] >
global_history_base_node_time[i]) {
link = global_history_base_node[j];
before = true;
break;
}
}
tree_set_node_selected(global_history_tree,
parent, false);
tree_set_node_expanded(global_history_tree,
parent, false);
tree_link_node(link, parent, before);
/*
if (!global_history_init) {
tree_recalculate_node(global_history_tree, parent, true);
tree_recalculate_node_positions(global_history_tree,
global_history_tree->root);
tree_redraw_area(global_history_tree,
0, 0, 16384, 16384);
}
*/
}
/* find any previous occurance */
if (!global_history_init) {
node = ami_global_history_find(url);
if (node) {
/* \todo: calculate old/new positions and redraw
* only the relevant portion */
/*
tree_redraw_area(global_history_tree,
0, 0, 16384, 16384);
*/
tree_update_URL_node(node, url, data);
tree_delink_node(node);
tree_link_node(parent, node, false);
tree_handle_node_changed(global_history_tree,
node, false, true);
return true;
}
}
/* Add the node at the bottom */
node = tree_create_URL_node_shared(parent, url, data);
if ((!global_history_init) && (node)) {
/*
tree_redraw_area(global_history_tree,
node->box.x - NODE_INSTEP,
0, NODE_INSTEP, 16384);
*/
tree_handle_node_changed(global_history_tree, node,
true, false);
}
return true;
}
/**
* Find an entry in the global history
*
* \param url The URL to find
* \return Pointer to node, or NULL if not found
*/
struct node *ami_global_history_find(const char *url)
{
int i;
struct node *node;
struct node_element *element;
for (i = 0; i < global_history_base_node_count; i++) {
if (!global_history_base_node[i]->deleted) {
for (node = global_history_base_node[i]->child;
node; node = node->next) {
element = tree_find_element(node,
TREE_ELEMENT_URL);
if ((element) && !strcmp(url, element->text))
return node;
}
}
}
return NULL;
}
/**
* Saves the global history's recent URL data.
*/
void ami_global_history_save(void)
{
BPTR *fp;
int i;
/* save recent URLs */
fp = fopen(option_recent_file, "w");
if (!fp)
LOG(("Failed to open file '%s' for writing",
option_recent_file));
else {
for (i = global_history_recent_count - 1; i >= 0; i--)
if (strlen(global_history_recent_url[i]) <
MAXIMUM_URL_LENGTH)
fprintf(fp, "%s\n",
global_history_recent_url[i]);
fclose(fp);
}
}
void global_history_add_recent(const char *url)
{
int i;
int j = -1;
char *current;
/* try to find a string already there */
for (i = 0; i < global_history_recent_count; i++)
if (global_history_recent_url[i] &&
!strcmp(global_history_recent_url[i], url))
j = i;
/* already at head of list */
if (j == 0)
return;
if (j < 0) {
/* add to head of list */
free(global_history_recent_url[
GLOBAL_HISTORY_RECENT_URLS - 1]);
memmove(&global_history_recent_url[1],
&global_history_recent_url[0],
(GLOBAL_HISTORY_RECENT_URLS - 1) *
sizeof(char *));
global_history_recent_url[0] = strdup(url);
global_history_recent_count++;
if (global_history_recent_count > GLOBAL_HISTORY_RECENT_URLS)
global_history_recent_count =
GLOBAL_HISTORY_RECENT_URLS;
/*
if (global_history_recent_count == 1)
ro_gui_window_prepare_navigate_all();
*/
} else {
/* move to head of list */
current = global_history_recent_url[j];
for (i = j; i > 0; i--)
global_history_recent_url[i] =
global_history_recent_url[i - 1];
global_history_recent_url[0] = current;
}
}
/**
* Gets details of the currently used URL list.
*
* \param count set to the current number of entries in the URL array on exit
* \return the current URL array
*/
char **global_history_get_recent(int *count)
{
*count = global_history_recent_count;
return global_history_recent_url;
}
void ami_global_history_free()
{
FreeVec(global_history_tree);
}

28
amiga/history.h Executable file
View File

@ -0,0 +1,28 @@
/*
* Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AMIGA_HISTORY_H
#define AMIGA_HISTORY_H
#include "desktop/tree.h"
#define GLOBAL_HISTORY_RECENT_URLS 16
void ami_global_history_initialise(void);
struct tree *global_history_tree;
#endif

View File

@ -21,15 +21,68 @@
#include "desktop/tree.h"
#include <proto/exec.h>
#include "content/urldb.h"
#include "amiga/hotlist.h"
void ami_gui_hotlist_visited(struct content *content, struct tree *tree,
struct node *node);
static const struct {
const char *url;
const char *msg_key;
} default_entries[] = {
{ "http://www.netsurf-browser.org/", "HotlistHomepage" },
// { "http://www.netsurf-browser.org/builds/", "HotlistTestBuild" },
{ "http://www.netsurf-browser.org/documentation/", "HotlistDocumentation" },
{ "http://sourceforge.net/tracker/?atid=464312&group_id=51719",
"HotlistBugTracker" },
{ "http://sourceforge.net/tracker/?atid=464315&group_id=51719",
"HotlistFeatureRequest" },
{ "http://www.unsatisfactorysoftware.co.uk",
"Unsatisfactory Software" }
};
#define ENTRIES_COUNT (sizeof(default_entries) / sizeof(default_entries[0]))
void hotlist_visited(struct content *content)
{
if ((!content) || (!content->url) || (!hotlist))
return;
ami_gui_hotlist_visited(content, hotlist, hotlist->root);
}
/**
* Informs the hotlist that some content has been visited
*
* \param content the content visited
* \param tree the tree to find the URL data from
* \param node the node to update siblings and children of
*/
void ami_gui_hotlist_visited(struct content *content, struct tree *tree,
struct node *node)
{
struct node_element *element;
for (; node; node = node->next) {
if (!node->folder) {
element = tree_find_element(node, TREE_ELEMENT_URL);
if ((element) && (!strcmp(element->text,
content->url))) {
tree_update_URL_node(node, content->url, NULL);
tree_handle_node_changed(tree, node, true,
false);
}
}
if (node->child)
ami_gui_hotlist_visited(content, tree, node->child);
}
}
void ami_hotlist_init(struct tree **hotlist)
{
struct tree *hotlist_tree;
struct node *node;
int i;
const struct url_data *data;
*hotlist = AllocVec(sizeof(struct tree),MEMF_CLEAR);
hotlist_tree = *hotlist;
@ -50,7 +103,6 @@ void ami_hotlist_init(struct tree **hotlist)
if (!node)
node = hotlist_tree->root;
/*
for (i = 0; i != ENTRIES_COUNT; i++) {
data = urldb_get_url_data(default_entries[i].url);
if (!data) {
@ -67,7 +119,7 @@ void ami_hotlist_init(struct tree **hotlist)
messages_get(default_entries[i].msg_key));
}
}
*/
tree_initialise(hotlist_tree);
}
@ -87,4 +139,6 @@ void ami_hotlist_add(struct node *node,struct content *c)
{
tree_create_URL_node(node,c->url,data,c->title);
}
tree_handle_node_changed(hotlist,node,false,true);
}

View File

@ -32,6 +32,8 @@
#include "desktop/save_pdf/pdf_plotters.h"
#include <string.h>
#include "amiga/tree.h"
#include "amiga/history.h"
#include "amiga/cookies.h"
void ami_free_menulabs(void)
{
@ -69,6 +71,8 @@ void ami_init_menulabs(void)
menulab[21] = ami_utf8_easy((char *)messages_get("Settings"));
menulab[22] = ami_utf8_easy((char *)messages_get("SnapshotWindow"));
menulab[23] = ami_utf8_easy((char *)messages_get("SettingsSave"));
menulab[24] = ami_utf8_easy((char *)messages_get("GlobalHistory"));
menulab[25] = ami_utf8_easy((char *)messages_get("ShowCookies"));
}
struct NewMenu *ami_create_menu(ULONG type)
@ -100,6 +104,8 @@ struct NewMenu *ami_create_menu(ULONG type)
{NM_TITLE,0,0,0,0,0,}, // settings
{ NM_ITEM,0,0,0,0,0,}, // snapshot window
{ NM_ITEM,0,0,0,0,0,}, // save settings
{ NM_ITEM,0,0,0,0,0,}, // show history
{ NM_ITEM,0,0,0,0,0,}, // show cookies
{ NM_END,0,0,0,0,0,},
};
@ -276,7 +282,7 @@ config option for this? */
break;
case 1: // show
ami_open_tree(hotlist);
ami_open_tree(hotlist,AMI_TREE_HOTLIST);
break;
}
break;
@ -294,6 +300,14 @@ config option for this? */
case 1: // save settings
options_write("Resources/Options");
break;
case 2: // global history
ami_open_tree(global_history_tree,AMI_TREE_HISTORY);
break;
case 3: // cookies tree
ami_open_tree(cookies_tree,AMI_TREE_COOKIES);
break;
}
break;
}

View File

@ -21,7 +21,7 @@
#include <exec/types.h>
#include "amiga/gui.h"
#define AMI_MENU_MAX 23
#define AMI_MENU_MAX 25
char *menulab[AMI_MENU_MAX+1];
struct NewMenu *ami_create_menu(ULONG type);

View File

@ -49,9 +49,6 @@ void die(const char *error)
exit(1);
}
bool cookies_update(const char *domain, const struct cookie_data *data)
{ return true; }
char *url_to_path(const char *url)
{
return (char *)strdup(url + 5);

View File

@ -34,6 +34,7 @@ extern bool option_use_os_pointers;
extern bool option_force_tabs;
extern bool option_new_tab_active;
extern bool option_kiosk_mode;
extern char *option_recent_file;
#define EXTRA_OPTION_DEFINE \
bool option_verbose_log = false; \
@ -50,6 +51,7 @@ bool option_use_os_pointers = false; \
bool option_force_tabs = false; \
bool option_new_tab_active = false; \
bool option_kiosk_mode = false; \
char *option_recent_file = 0; \
#define EXTRA_OPTION_TABLE \
{ "verbose_log", OPTION_BOOL, &option_verbose_log}, \
@ -65,5 +67,6 @@ bool option_kiosk_mode = false; \
{ "os_mouse_pointers", OPTION_BOOL, &option_use_os_pointers}, \
{ "always_open_tabs", OPTION_BOOL, &option_force_tabs}, \
{ "new_tab_is_active", OPTION_BOOL, &option_new_tab_active}, \
{ "kiosk_mode", OPTION_BOOL, &option_kiosk_mode},
{ "kiosk_mode", OPTION_BOOL, &option_kiosk_mode}, \
{ "recent_file", OPTION_STRING, &option_recent_file },
#endif

View File

@ -30,10 +30,17 @@
#include <assert.h>
#include <proto/intuition.h>
#include "amiga/tree.h"
#include <proto/button.h>
#include <gadgets/button.h>
#include <string.h>
#include "utils/messages.h"
void ami_add_elements(struct treeview_window *twin,struct node *root,WORD *gen);
bool ami_tree_launch_node(struct tree *tree, struct node *node);
void free_browserlist(struct List *list);
void ami_move_node(struct treeview_window *twin,bool up);
void ami_new_bookmark(struct treeview_window *twin);
void ami_recreate_listbrowser(struct treeview_window *twin);
void tree_initialise_redraw(struct tree *tree)
{
@ -49,6 +56,8 @@ void tree_draw_line(int x, int y, int width, int height)
void tree_draw_node_element(struct tree *tree, struct node_element *element)
{
return;
#if 0
/* add element to listbrowser list */
struct Node *lbnode;
@ -88,10 +97,12 @@ void tree_draw_node_element(struct tree *tree, struct node_element *element)
}
break;
}
#endif
}
void tree_draw_node_expansion(struct tree *tree, struct node *node)
{
DebugPrintF("tree_draw_node_expansion\n");
}
void tree_recalculate_node_element(struct node_element *element)
@ -104,9 +115,12 @@ void tree_update_URL_node(struct node *node, const char *url,
struct node_element *element;
char buffer[256];
DebugPrintF("tree_update_URL_node\n");
assert(node);
element = tree_find_element(node, TREE_ELEMENT_URL);
DebugPrintF("%s\n",element->text);
if (!element)
return;
if (data) {
@ -139,22 +153,22 @@ void tree_update_URL_node(struct node *node, const char *url,
element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT);
if (element) {
snprintf(buffer, 256, messages_get("TreeLast"),
snprintf(buffer, 256, (char *)messages_get("TreeLast"),
(data->last_visit > 0) ?
ctime((time_t *)&data->last_visit) :
messages_get("TreeUnknown"));
(char *)messages_get("TreeUnknown"));
if (data->last_visit > 0)
buffer[strlen(buffer) - 1] = '\0';
free((void *)element->text);
element->text = strdup(buffer);
element->text = (char *)strdup(buffer);
}
element = tree_find_element(node, TREE_ELEMENT_VISITS);
if (element) {
snprintf(buffer, 256, messages_get("TreeVisits"),
snprintf(buffer, 256, (char *)messages_get("TreeVisits"),
data->visits);
free((void *)element->text);
element->text = strdup(buffer);
element->text = (char *)strdup(buffer);
}
}
@ -171,15 +185,16 @@ void tree_set_node_sprite(struct node *node, const char *sprite,
{
}
void ami_open_tree(struct tree *tree)
void ami_open_tree(struct tree *tree,int type)
{
struct treeview_window *twin;
BOOL msel = TRUE;
BOOL msel = TRUE,nothl = TRUE;
static WORD gen=0;
char *wintitle;
if(tree->handle)
{
twin = tree->handle;
twin = (struct treeview_window *)tree->handle;
WindowToFront(twin->win);
ActivateWindow(twin->win);
return;
@ -192,12 +207,28 @@ void ami_open_tree(struct tree *tree)
{
{ 22,"Name", CIF_DRAGGABLE | CIF_SORTABLE},
{ 5,"URL", CIF_DRAGGABLE },
{ 5,"Visits", CIF_DRAGGABLE },
// { 5,"Visits", CIF_DRAGGABLE },
{ -1, (STRPTR)~0, -1 }
};
if(tree->single_selection) msel = FALSE;
switch(type)
{
case AMI_TREE_HOTLIST:
nothl = FALSE;
wintitle = (char *)messages_get("Hotlist");
break;
case AMI_TREE_COOKIES:
nothl = TRUE;
wintitle = (char *)messages_get("Cookies");
break;
case AMI_TREE_HISTORY:
nothl = TRUE;
wintitle = (char *)messages_get("History");
break;
}
NewList(twin->listbrowser_list);
tree->handle = (void *)twin;
@ -206,7 +237,7 @@ void ami_open_tree(struct tree *tree)
twin->objects[OID_MAIN] = WindowObject,
WA_ScreenTitle,nsscreentitle,
WA_Title, "treeview window",
WA_Title,wintitle,
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
@ -223,17 +254,55 @@ void ami_open_tree(struct tree *tree)
GA_RelVerify, TRUE,
GA_ReadOnly,FALSE,
LISTBROWSER_ColumnInfo, &columninfo,
LISTBROWSER_ColumnTitles, TRUE,
// LISTBROWSER_ColumnTitles, TRUE,
LISTBROWSER_Hierarchical,TRUE,
LISTBROWSER_Editable,TRUE,
// LISTBROWSER_TitleClickable,TRUE,
LISTBROWSER_AutoFit, TRUE,
LISTBROWSER_HorizontalProp, TRUE,
LISTBROWSER_Labels, twin->listbrowser_list,
LISTBROWSER_MultiSelect,msel,
// LISTBROWSER_MultiSelect,msel,
LISTBROWSER_ShowSelected,TRUE,
ListBrowserEnd,
CHILD_NominalSize,TRUE,
LAYOUT_AddChild, HGroupObject,
LAYOUT_AddChild, twin->gadgets[GID_OPEN] = ButtonObject,
GA_ID,GID_OPEN,
GA_Text,messages_get("Open"),
GA_RelVerify,TRUE,
GA_Disabled,nothl,
ButtonEnd,
LAYOUT_AddChild, twin->gadgets[GID_NEWF] = ButtonObject,
GA_ID,GID_NEWF,
BUTTON_AutoButton,BAG_POPDRAWER,
GA_RelVerify,TRUE,
GA_Disabled,nothl,
ButtonEnd,
LAYOUT_AddChild, twin->gadgets[GID_NEWB] = ButtonObject,
GA_ID,GID_NEWB,
BUTTON_AutoButton,BAG_POPFILE,
GA_RelVerify,TRUE,
GA_Disabled,nothl,
ButtonEnd,
LAYOUT_AddChild, twin->gadgets[GID_UP] = ButtonObject,
GA_ID,GID_UP,
BUTTON_AutoButton,BAG_UPARROW,
GA_RelVerify,TRUE,
GA_Disabled,nothl, //(!tree->movable),
ButtonEnd,
LAYOUT_AddChild, twin->gadgets[GID_DOWN] = ButtonObject,
GA_ID,GID_DOWN,
BUTTON_AutoButton,BAG_DNARROW,
GA_RelVerify,TRUE,
GA_Disabled,nothl, //(!tree->movable),
ButtonEnd,
LAYOUT_AddChild, twin->gadgets[GID_DEL] = ButtonObject,
GA_ID,GID_DEL,
GA_Text,messages_get("Delete"),
GA_RelVerify,TRUE,
ButtonEnd,
EndGroup,
CHILD_WeightedHeight,0,
EndGroup,
EndWindow;
@ -276,7 +345,7 @@ bool ami_tree_launch_node(struct tree *tree, struct node *node)
void ami_tree_close(struct treeview_window *twin)
{
twin->tree->handle = NULL;
twin->tree->handle = 0;
DisposeObject(twin->objects[OID_MAIN]);
FreeListBrowserList(twin->listbrowser_list);
FreeVec(twin->listbrowser_list);
@ -295,7 +364,7 @@ void free_browserlist(struct List *list)
do
{
nextnode = GetSucc(node);
FreeVec(node->ln_Name);
// FreeVec(node->ln_Name);
FreeListBrowserNode(node);
} while(node = nextnode);
}
@ -319,15 +388,23 @@ void ami_add_elements(struct treeview_window *twin,struct node *root,WORD *gen)
if(!element) element = tree_find_element(node, TREE_ELEMENT_TITLE);
if(element && element->text)
{
text1 = element->text;
text1 = (char *)element->text;
}
// printf("node %lx url %s gen %ld\n",node,element->text,*gen);
/* Really, the second column needs axing - relevant data should appear in an
area below the listview when items are selected */
element2 = tree_find_element(node, TREE_ELEMENT_URL);
if(!element2) element2 = tree_find_element(node, TREE_ELEMENT_VALUE);
if(!element2) element2 = tree_find_element(node, TREE_ELEMENT_COMMENT);
if(element2 && element2->text)
{
text2 = element2->text;
text2 = (char *)element2->text;
}
else
{
text2 = "";
}
// element = tree_find_element(node, TREE_ELEMENT_VISITS);
@ -351,12 +428,7 @@ void ami_add_elements(struct treeview_window *twin,struct node *root,WORD *gen)
LBNCA_CopyText,TRUE,
LBNCA_MaxChars,256,
LBNCA_Text, text2,
LBNCA_Editable,node->editable,
LBNA_Column, 2,
LBNCA_CopyText,TRUE,
LBNCA_MaxChars,256,
LBNCA_Text,"",
LBNCA_Editable,node->editable,
LBNCA_Editable,FALSE,
TAG_DONE))
{
AddTail(twin->listbrowser_list, lbnode);
@ -376,10 +448,15 @@ BOOL ami_tree_event(struct treeview_window *twin)
{
/* return TRUE if window destroyed */
ULONG class,result,relevent = 0;
ULONG column;
uint16 code;
struct MenuItem *item;
struct node *treenode;
struct Node *lbnode;
struct node_element *element;
char *text;
// ULONG editcols[] = {TREE_ELEMENT_TITLE,TREE_ELEMENT_URL};
static WORD gen=0;
while((result = RA_HandleInput(twin->objects[OID_MAIN],&code)) != WMHI_LASTMSG)
{
@ -402,8 +479,92 @@ BOOL ami_tree_event(struct treeview_window *twin)
TAG_DONE);
ami_tree_launch_node(twin->tree,treenode);
break;
case LBRE_EDIT:
GetAttrs(twin->gadgets[GID_TREEBROWSER],
LISTBROWSER_SelectedNode,(ULONG *)&lbnode,
// LISTBROWSER_RelColumn,(ULONG *)&column,
TAG_DONE);
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
TAG_DONE);
element = tree_find_element(treenode,TREE_ELEMENT_TITLE);
GetListBrowserNodeAttrs(lbnode,
LBNA_Column,column,
LBNCA_Text,(ULONG *)&text,
TAG_DONE);
element->text = (char *)strdup(text);
tree_handle_node_element_changed(twin->tree, element);
break;
case LBRE_HIDECHILDREN:
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
TAG_DONE);
tree_set_node_expanded(twin->tree, treenode, false);
break;
case LBRE_SHOWCHILDREN:
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
TAG_DONE);
tree_set_node_expanded(twin->tree, treenode, true);
break;
}
break;
case GID_OPEN:
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
TAG_DONE);
ami_tree_launch_node(twin->tree,treenode);
break;
case GID_NEWF:
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
if(lbnode)
{
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
TAG_DONE);
}
else
{
treenode = twin->tree->root;
}
tree_create_folder_node(treenode,(char *)messages_get("TreeNewFolder"));
ami_recreate_listbrowser(twin);
break;
case GID_NEWB:
ami_new_bookmark(twin);
break;
case GID_UP:
ami_move_node(twin,true);
break;
case GID_DOWN:
ami_move_node(twin,false);
break;
case GID_DEL:
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
TAG_DONE);
tree_delete_node(twin->tree, treenode, true);
/* We are recreating the list from scratch as there is no obvious easy way
to delete children from a listbrowser list */
ami_recreate_listbrowser(twin);
break;
}
break;
@ -427,3 +588,83 @@ BOOL ami_tree_event(struct treeview_window *twin)
}
return FALSE;
}
void ami_move_node(struct treeview_window *twin,bool up)
{
struct Node *lbnode = NULL;
struct node *treenode;
BOOL sel = FALSE;
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
if(lbnode)
{
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
LBNA_Selected,(BOOL *)&sel,
TAG_DONE);
}
if(sel)
{
tree_set_node_selected(twin->tree,treenode,true);
tree_move_selected_nodes(twin->tree,treenode,up);
}
tree_set_node_selected(twin->tree,treenode,false);
ami_recreate_listbrowser(twin);
}
void ami_new_bookmark(struct treeview_window *twin)
{
const struct url_data *data;
struct Node *lbnode;
struct node *treenode;
char *url,*title;
GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode);
if(lbnode)
{
GetListBrowserNodeAttrs(lbnode,
LBNA_UserData,(ULONG *)&treenode,
TAG_DONE);
}
else
{
treenode = twin->tree->root;
}
url = (char *)strdup("http://www.netsurf-browser.org");
title = (char *)messages_get("NewBookmark");
data = urldb_get_url_data(url);
if (!data)
{
urldb_add_url(url);
urldb_set_url_persistence(url,true);
data = urldb_get_url_data(url);
}
if (data)
{
tree_create_URL_node(treenode,url,data,title);
ami_recreate_listbrowser(twin);
}
}
void ami_recreate_listbrowser(struct treeview_window *twin)
{
static WORD gen=0;
SetGadgetAttrs(twin->gadgets[GID_TREEBROWSER],twin->win,NULL,
LISTBROWSER_Labels,~0,
TAG_DONE);
FreeListBrowserList(twin->listbrowser_list);
ami_add_elements(twin,twin->tree->root,&gen);
RefreshSetGadgetAttrs(twin->gadgets[GID_TREEBROWSER],twin->win,NULL,
LISTBROWSER_Labels,twin->listbrowser_list,
TAG_DONE);
}

View File

@ -19,6 +19,10 @@
#ifndef AMIGA_TREE_H
#define AMIGA_TREE_H
#include <exec/types.h>
#include <intuition/classusr.h>
#include "amiga/gui.h"
struct treeview_window {
struct Window *win;
Object *objects[OID_LAST];
@ -29,7 +33,14 @@ struct treeview_window {
struct List *listbrowser_list;
};
void ami_open_tree(struct tree *tree);
enum
{
AMI_TREE_HOTLIST,
AMI_TREE_HISTORY,
AMI_TREE_COOKIES
};
void ami_open_tree(struct tree *tree,int type);
void ami_tree_close(struct treeview_window *twin);
BOOL ami_tree_event(struct treeview_window *twin);
#endif