From 1d8bbfae4cde28e9102ee0ed020ac28f499c1d59 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 14 Oct 2008 22:43:02 +0000 Subject: Implemented the ability to add hotlist entries to the Hotlist menu. Modified the default Hotlist links so they show up in the menu. Currently deleting items from the menu is dangerous. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To add to the Hotlist menu, add a folder node called "Menu" to the root node of the hotlist tree. Items in this folder node up to a maximum (currently) of 40 items will be added to the Hotlist menu, within the limits of the Intuition menu system. Items in folders within the Menu folder node will be converted to subitems in the menu. Folder nodes with no entries and folder nodes at level 3 in the heirarchy will become menu items with no action. Items deeper will not be included in the menu at all. eg. Root | +- Menu | +- Netsurf | | | +- NetSurf Homepage | | | +- More NetSurf links | | | +- NetSurf bugtracker | +- Google Will look something like the following within the menu: |NetSurf ยป| - |NetSurf Homepage | |Google | |More NetSurf links| svn path=/trunk/netsurf/; revision=5577 --- amiga/menu.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 115 insertions(+), 11 deletions(-) (limited to 'amiga/menu.c') diff --git a/amiga/menu.c b/amiga/menu.c index 5bce2c897..3eb8c019c 100755 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -35,13 +35,16 @@ #include "amiga/history.h" #include "amiga/cookies.h" +void ami_menu_scan(struct tree *tree,struct NewMenu *menu); +void ami_menu_scan_2(struct tree *tree,struct node *root,WORD *gen,ULONG *item,struct NewMenu *menu); + void ami_free_menulabs(void) { int i; for(i=0;i<=AMI_MENU_MAX;i++) { - if(menulab[i] != NM_BARLABEL) ami_utf8_free(menulab[i]); + if(menulab[i] && (menulab[i] != NM_BARLABEL)) ami_utf8_free(menulab[i]); } } @@ -71,9 +74,11 @@ void ami_init_menulabs(void) 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")); + menulab[24] = NM_BARLABEL; + + menulab[65] = ami_utf8_easy((char *)messages_get("Settings")); + menulab[66] = ami_utf8_easy((char *)messages_get("SnapshotWindow")); + menulab[67] = ami_utf8_easy((char *)messages_get("SettingsSave")); } struct NewMenu *ami_create_menu(ULONG type) @@ -105,6 +110,47 @@ struct NewMenu *ami_create_menu(ULONG type) {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_ITEM,NM_BARLABEL,0,0,0,0,}, + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** + { NM_IGNORE,0,0,0,0,0,}, // ** hotlist entry ** {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 @@ -130,10 +176,69 @@ struct NewMenu *ami_create_menu(ULONG type) menu[7].nm_Flags = NM_ITEMDISABLED; #endif + ami_menu_scan(hotlist,menu); + return(menu); } -void ami_menupick(ULONG code,struct gui_window_2 *gwin) +void ami_menu_scan(struct tree *tree,struct NewMenu *menu) +{ + struct node *root = tree->root->child; + struct node_element *element=NULL; + struct node *node; + static WORD gen = 0; + static ULONG item = AMI_MENU_HOTLIST; + + for (node = root; node; node = node->next) + { + element = tree_find_element(node, TREE_ELEMENT_NAME); + if(!element) element = tree_find_element(node, TREE_ELEMENT_TITLE); + if(element && (strcmp(element->text,"Menu")==0)) + { + // found menu + ami_menu_scan_2(tree,node,&gen,&item,menu); + } + } +} + +void ami_menu_scan_2(struct tree *tree,struct node *root,WORD *gen,ULONG *item,struct NewMenu *menu) +{ + struct node *tempnode; + struct node_element *element=NULL; + struct node *node; + + *gen = *gen + 1; + + for (node = root; node; node = node->next) + { + element = tree_find_element(node, TREE_ELEMENT_TITLE); + + if((*gen > 1) && (*gen < 4)) + { + if(*item >= AMI_MENU_HOTLIST_MAX) return; + + if(*gen == 2) menu[*item].nm_Type = NM_ITEM; + if(*gen == 3) menu[*item].nm_Type = NM_SUB; + + menu[*item].nm_Label = element->text; + + element = tree_find_element(node, TREE_ELEMENT_URL); + if(element && element->text) + menu[*item].nm_UserData = element->text; + + *item = *item + 1; + } + + if (node->child) + { + ami_menu_scan_2(tree,node->child,gen,item,menu); + } + } + + *gen = *gen - 1; +} + +void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item) { struct browser_window *bw; struct gui_window tgw; @@ -290,15 +395,14 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin) options_save_tree(hotlist,"Resources/Hotlist","NetSurf hotlist"); break; - case 2: // show -/* this along with save_tree above is very temporary! -config option for this? */ - browser_window_go(gwin->bw,"file:///netsurf/resources/hotlist",NULL,true); - break; - case 1: // show ami_open_tree(hotlist,AMI_TREE_HOTLIST); break; + + default: // bookmarks + if(GTMENUITEM_USERDATA(item)) + browser_window_go(gwin->bw,GTMENUITEM_USERDATA(item),NULL, true); + break; } break; -- cgit v1.2.3