From f1a06ac5d921a365f555c80c7f5621c4c2750678 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 13 Oct 2008 18:00:44 +0000 Subject: Various minor fixes for treeviews, history tree now populates. svn path=/trunk/netsurf/; revision=5563 --- !NetSurf/Resources/de/Messages | 7 ++++ !NetSurf/Resources/en/Messages | 7 ++++ !NetSurf/Resources/fr/Messages | 7 ++++ !NetSurf/Resources/nl/Messages | 7 ++++ amiga/history.c | 75 +++++++++++++++++++++++++++++++++++++++++- amiga/hotlist.c | 4 +++ amiga/menu.c | 47 +++++++++++++++----------- amiga/menu.h | 62 +++++++++++++++++----------------- amiga/tree.c | 49 +++++++++++++++------------ amiga/tree.h | 1 + 10 files changed, 193 insertions(+), 73 deletions(-) diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index be3aa08d7..87d240f24 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -238,6 +238,11 @@ Paste:Paste SelectAllNS:Select all ClearNS:Clear selection +# Browser menu +# +Browser:Browser +HistGlobalNS:Show global history... + # Hotlist menu # HotlistShowNS:Show hotlist... @@ -279,6 +284,8 @@ TreeSession:Session end TreeUnused:Nicht benutzt TreeImport:Importierte URL TreeNewFolder:Neues Verzeichnis +TreeLaunch:Visit URL +TreeDelete:Delete # Tree export # diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index 6dc8d548c..2db73456f 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -238,6 +238,11 @@ Paste:Paste SelectAllNS:Select all ClearNS:Clear selection +# Browser menu +# +Browser:Browser +HistGlobalNS:Show global history... + # Hotlist menu # HotlistShowNS:Show hotlist... @@ -279,6 +284,8 @@ TreeSession:Session end TreeUnused:Unused TreeImport:Imported URL TreeNewFolder:New directory +TreeLaunch:Visit URL +TreeDelete:Delete # Tree export # diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index db182a309..c9e59b58a 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -238,6 +238,11 @@ Paste:Paste SelectAllNS:Select all ClearNS:Clear selection +# Browser menu +# +Browser:Browser +HistGlobalNS:Show global history... + # Hotlist menu # HotlistShowNS:Show hotlist... @@ -279,6 +284,8 @@ TreeSession:Fin de session TreeUnused:Inutilisé TreeImport:URL importée TreeNewFolder:Nouv. répertoire +TreeLaunch:Visit URL +TreeDelete:Delete # Tree export # diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index c10e8f593..3fabc3066 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -238,6 +238,11 @@ Paste:Paste SelectAllNS:Select all ClearNS:Clear selection +# Browser menu +# +Browser:Browser +HistGlobalNS:Show global history... + # Hotlist menu # HotlistShowNS:Show hotlist... @@ -279,6 +284,8 @@ TreeSession:Sessie einde TreeUnused:Ongebruikt TreeImport:Ge-importeerde URL TreeNewFolder:Nieuwe map +TreeLaunch:Visit URL +TreeDelete:Delete # Tree export # diff --git a/amiga/history.c b/amiga/history.c index 8ccd63bbf..5e685b76a 100755 --- a/amiga/history.c +++ b/amiga/history.c @@ -42,13 +42,16 @@ 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_node(const char *title, + time_t base, int days_back); +void ami_global_history_initialise_nodes(void); void ami_global_history_initialise(void) { char s[MAXIMUM_URL_LENGTH]; BPTR *fp; - if(global_history_tree) return; +// if(global_history_tree) return; /* Create an empty tree */ global_history_tree = AllocVec(sizeof(struct tree), MEMF_CLEAR | MEMF_PRIVATE); @@ -63,6 +66,7 @@ void ami_global_history_initialise(void) global_history_tree = NULL; } global_history_tree->root->expanded = true; + ami_global_history_initialise_nodes(); global_history_tree->movable = false; /* load recent URLs */ @@ -303,3 +307,72 @@ void ami_global_history_free() { FreeVec(global_history_tree); } + +/** + * Initialises the base nodes + */ +void ami_global_history_initialise_nodes(void) +{ + struct tm *full_time; + time_t t; + int weekday; + int i; + + /* get the current time */ + t = time(NULL); + if (t == -1) + return; + + /* get the time at the start of today */ + full_time = localtime(&t); + weekday = full_time->tm_wday; + full_time->tm_sec = 0; + full_time->tm_min = 0; + full_time->tm_hour = 0; + t = mktime(full_time); + if (t == -1) + return; + + ami_global_history_initialise_node((char *)messages_get("DateToday"), t, 0); + if (weekday > 0) + ami_global_history_initialise_node( + (char *)messages_get("DateYesterday"), t, -1); + for (i = 2; i <= weekday; i++) + ami_global_history_initialise_node(NULL, t, -i); + ami_global_history_initialise_node((char *)messages_get("Date1Week"), + t, -weekday - 7); + ami_global_history_initialise_node((char *)messages_get("Date2Week"), + t, -weekday - 14); + ami_global_history_initialise_node((char *)messages_get("Date3Week"), + t, -weekday - 21); +} + +/** + * Create and initialise a node + */ +void ami_global_history_initialise_node(const char *title, + time_t base, int days_back) +{ + struct tm *full_time; + char buffer[64]; + struct node *node; + + base += days_back * 60 * 60 * 24; + if (!title) { + full_time = localtime(&base); + strftime((char *)&buffer, (size_t)64, "%A", full_time); + node = tree_create_folder_node(NULL, buffer); + } else + node = tree_create_folder_node(NULL, title); + + if (!node) + return; + + node->retain_in_memory = true; + node->deleted = true; + node->editable = false; + global_history_base_node[global_history_base_node_count] = node; + global_history_base_node_time[global_history_base_node_count] = base; + global_history_base_node_count++; +} + diff --git a/amiga/hotlist.c b/amiga/hotlist.c index 3dbd1e00f..f5dc11a8d 100755 --- a/amiga/hotlist.c +++ b/amiga/hotlist.c @@ -22,6 +22,7 @@ #include #include "content/urldb.h" #include "amiga/hotlist.h" +#include "amiga/tree.h" void ami_gui_hotlist_visited(struct content *content, struct tree *tree, struct node *node); @@ -141,4 +142,7 @@ void ami_hotlist_add(struct node *node,struct content *c) } tree_handle_node_changed(hotlist,node,false,true); + + if(hotlist->handle) + ami_recreate_listbrowser((struct treeview_window *)hotlist->handle); } diff --git a/amiga/menu.c b/amiga/menu.c index b4f728528..5bce2c897 100755 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -65,14 +65,15 @@ void ami_init_menulabs(void) menulab[15] = ami_utf8_easy((char *)messages_get("Paste")); menulab[16] = ami_utf8_easy((char *)messages_get("SelectAllNS")); menulab[17] = ami_utf8_easy((char *)messages_get("ClearNS")); - menulab[18] = ami_utf8_easy((char *)messages_get("Hotlist")); - menulab[19] = ami_utf8_easy((char *)messages_get("HotlistAdd")); - menulab[20] = ami_utf8_easy((char *)messages_get("HotlistShowNS")); - 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")); + menulab[18] = ami_utf8_easy((char *)messages_get("Browser")); + menulab[19] = ami_utf8_easy((char *)messages_get("HistGlobalNS")); + menulab[20] = ami_utf8_easy((char *)messages_get("ShowCookies")); + menulab[21] = ami_utf8_easy((char *)messages_get("Hotlist")); + menulab[22] = ami_utf8_easy((char *)messages_get("HotlistAdd")); + menulab[23] = ami_utf8_easy((char *)messages_get("HotlistShowNS")); + menulab[24] = ami_utf8_easy((char *)messages_get("Settings")); + menulab[25] = ami_utf8_easy((char *)messages_get("SnapshotWindow")); + menulab[26] = ami_utf8_easy((char *)messages_get("SettingsSave")); } struct NewMenu *ami_create_menu(ULONG type) @@ -98,14 +99,15 @@ struct NewMenu *ami_create_menu(ULONG type) { NM_ITEM,0,"V",0,0,0,}, // paste { NM_ITEM,0,"A",0,0,0,}, // select all { NM_ITEM,0,"Z",0,0,0,}, // clear selection + {NM_TITLE,0,0,0,0,0,}, // browser + { NM_ITEM,0,0,0,0,0,}, // global history + { NM_ITEM,0,0,0,0,0,}, // cookies {NM_TITLE,0,0,0,0,0,}, // hotlist { NM_ITEM,0,0,0,0,0,}, // add to hotlist { NM_ITEM,0,"H",0,0,0,}, // show hotlist (treeview) {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,}, }; @@ -267,7 +269,20 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin) } break; - case 2: // hotlist + case 2: + switch(itemnum) + { + case 0: // global history + ami_open_tree(global_history_tree,AMI_TREE_HISTORY); + break; + + case 1: // cookies tree + ami_open_tree(cookies_tree,AMI_TREE_COOKIES); + break; + } + break; + + case 3: // hotlist switch(itemnum) { case 0: // add @@ -287,7 +302,7 @@ config option for this? */ } break; - case 3: // settings + case 4: // settings switch(itemnum) { case 0: // snapshot @@ -300,14 +315,6 @@ 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; } diff --git a/amiga/menu.h b/amiga/menu.h index 77c56bc72..00ee5d1f7 100755 --- a/amiga/menu.h +++ b/amiga/menu.h @@ -1,31 +1,31 @@ -/* - * Copyright 2008 Chris Young - * - * 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 . - */ - -#ifndef AMIGA_MENU_H -#define AMIGA_MENU_H -#include -#include "amiga/gui.h" - -#define AMI_MENU_MAX 25 -char *menulab[AMI_MENU_MAX+1]; - -struct NewMenu *ami_create_menu(ULONG type); -void ami_init_menulabs(void); -void ami_free_menulabs(void); -void ami_menupick(ULONG code,struct gui_window_2 *gwin); -#endif +/* + * Copyright 2008 Chris Young + * + * 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 . + */ + +#ifndef AMIGA_MENU_H +#define AMIGA_MENU_H +#include +#include "amiga/gui.h" + +#define AMI_MENU_MAX 27 +char *menulab[AMI_MENU_MAX+1]; + +struct NewMenu *ami_create_menu(ULONG type); +void ami_init_menulabs(void); +void ami_free_menulabs(void); +void ami_menupick(ULONG code,struct gui_window_2 *gwin); +#endif diff --git a/amiga/tree.c b/amiga/tree.c index 09a1ed33d..60e5be78e 100755 --- a/amiga/tree.c +++ b/amiga/tree.c @@ -115,12 +115,10 @@ 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) { @@ -188,7 +186,7 @@ void tree_set_node_sprite(struct node *node, const char *sprite, void ami_open_tree(struct tree *tree,int type) { struct treeview_window *twin; - BOOL msel = TRUE,nothl = TRUE; + BOOL msel = TRUE,nothl = TRUE,launchdisable=FALSE; static WORD gen=0; char *wintitle; @@ -205,8 +203,8 @@ void ami_open_tree(struct tree *tree,int type) static struct ColumnInfo columninfo[] = { - { 22,"Name", CIF_DRAGGABLE | CIF_SORTABLE}, - { 5,"URL", CIF_DRAGGABLE }, + { 80,"Name", CIF_DRAGGABLE | CIF_SORTABLE}, + { 20,"URL", CIF_DRAGGABLE }, // { 5,"Visits", CIF_DRAGGABLE }, { -1, (STRPTR)~0, -1 } }; @@ -221,11 +219,12 @@ void ami_open_tree(struct tree *tree,int type) break; case AMI_TREE_COOKIES: nothl = TRUE; + launchdisable=TRUE; wintitle = (char *)messages_get("Cookies"); break; case AMI_TREE_HISTORY: nothl = TRUE; - wintitle = (char *)messages_get("History"); + wintitle = (char *)messages_get("GlobalHistory"); break; } @@ -250,8 +249,8 @@ void ami_open_tree(struct tree *tree,int type) WINDOW_Position, WPOS_CENTERSCREEN, WINDOW_ParentGroup, twin->gadgets[GID_MAIN] = VGroupObject, LAYOUT_AddChild, twin->gadgets[GID_TREEBROWSER] = ListBrowserObject, - GA_ID, GID_TREEBROWSER, - GA_RelVerify, TRUE, + GA_ID, GID_TREEBROWSER, + GA_RelVerify, TRUE, GA_ReadOnly,FALSE, LISTBROWSER_ColumnInfo, &columninfo, // LISTBROWSER_ColumnTitles, TRUE, @@ -268,9 +267,9 @@ void ami_open_tree(struct tree *tree,int type) LAYOUT_AddChild, HGroupObject, LAYOUT_AddChild, twin->gadgets[GID_OPEN] = ButtonObject, GA_ID,GID_OPEN, - GA_Text,messages_get("Open"), + GA_Text,messages_get("TreeLaunch"), GA_RelVerify,TRUE, - GA_Disabled,nothl, + GA_Disabled,launchdisable, ButtonEnd, LAYOUT_AddChild, twin->gadgets[GID_NEWF] = ButtonObject, GA_ID,GID_NEWF, @@ -298,7 +297,7 @@ void ami_open_tree(struct tree *tree,int type) ButtonEnd, LAYOUT_AddChild, twin->gadgets[GID_DEL] = ButtonObject, GA_ID,GID_DEL, - GA_Text,messages_get("Delete"), + GA_Text,messages_get("TreeDelete"), GA_RelVerify,TRUE, ButtonEnd, EndGroup, @@ -409,14 +408,17 @@ area below the listview when items are selected */ // element = tree_find_element(node, TREE_ELEMENT_VISITS); - if(node->expanded) flags = LBFLG_SHOWCHILDREN; + flags = 0; + /*if(node->expanded) */ flags = LBFLG_SHOWCHILDREN; + if(node->folder) flags |= LBFLG_HASCHILDREN; + if(!node->parent) flags |= LBFLG_HIDDEN; switch (element->type) { case NODE_ELEMENT_TEXT_PLUS_SPRITE: case NODE_ELEMENT_TEXT: if (lbnode = AllocListBrowserNode(3, LBNA_UserData,node, - LBNA_Generation,*gen, + LBNA_Generation,*gen - 1, LBNA_Selected,node->selected, LBNA_Flags,flags, LBNA_Column, 0, @@ -592,7 +594,7 @@ BOOL ami_tree_event(struct treeview_window *twin) void ami_move_node(struct treeview_window *twin,bool up) { struct Node *lbnode = NULL; - struct node *treenode; + struct node *treenode,*moveto; BOOL sel = FALSE; GetAttr(LISTBROWSER_SelectedNode,twin->gadgets[GID_TREEBROWSER],(ULONG *)&lbnode); @@ -601,17 +603,22 @@ void ami_move_node(struct treeview_window *twin,bool up) { GetListBrowserNodeAttrs(lbnode, LBNA_UserData,(ULONG *)&treenode, - LBNA_Selected,(BOOL *)&sel, +// for multiselects? LBNA_Selected,(BOOL *)&sel, TAG_DONE); } - if(sel) - { - tree_set_node_selected(twin->tree,treenode,true); + tree_set_node_selected(twin->tree,treenode,true); - tree_move_selected_nodes(twin->tree,treenode,up); + if(up) + { + moveto = treenode->previous; + } + else + { + moveto = treenode->next; } + tree_move_selected_nodes(twin->tree,moveto,up); tree_set_node_selected(twin->tree,treenode,false); ami_recreate_listbrowser(twin); } @@ -636,7 +643,6 @@ void ami_new_bookmark(struct treeview_window *twin) } url = (char *)strdup("http://www.netsurf-browser.org"); - title = (char *)messages_get("NewBookmark"); data = urldb_get_url_data(url); if (!data) @@ -648,6 +654,7 @@ void ami_new_bookmark(struct treeview_window *twin) if (data) { + title = data->title; tree_create_URL_node(treenode,url,data,title); ami_recreate_listbrowser(twin); } diff --git a/amiga/tree.h b/amiga/tree.h index 4ff38edfc..210891fc2 100755 --- a/amiga/tree.h +++ b/amiga/tree.h @@ -43,4 +43,5 @@ enum 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); +void ami_recreate_listbrowser(struct treeview_window *twin); #endif -- cgit v1.2.3