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.

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
This commit is contained in:
Chris Young 2008-10-14 22:43:02 +00:00
parent a55c1f6e41
commit 1d8bbfae4c
4 changed files with 128 additions and 15 deletions

View File

@ -651,7 +651,7 @@ void ami_handle_msg(void)
item = ItemAddress(gwin->win->MenuStrip,code);
while (code != MENUNULL)
{
ami_menupick(code,gwin);
ami_menupick(code,gwin,item);
if(win_destroyed) break;
code = item->NextSelect;
}

View File

@ -100,7 +100,12 @@ void ami_hotlist_init(struct tree **hotlist)
}
hotlist_tree->root->expanded = true;
node = tree_create_folder_node(hotlist_tree->root, "NetSurf");
node = tree_create_folder_node(hotlist_tree->root, "Menu");
if (!node)
node = hotlist_tree->root;
node = tree_create_folder_node(node, "NetSurf");
if (!node)
node = hotlist_tree->root;

View File

@ -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;

View File

@ -20,12 +20,16 @@
#define AMIGA_MENU_H
#include <exec/types.h>
#include "amiga/gui.h"
#include <intuition/intuition.h>
#define AMI_MENU_MAX 27
#define AMI_HOTLIST_ITEMS 40
#define AMI_MENU_MAX 28 + AMI_HOTLIST_ITEMS
#define AMI_MENU_HOTLIST 25
#define AMI_MENU_HOTLIST_MAX AMI_MENU_HOTLIST+AMI_HOTLIST_ITEMS
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);
void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item);
#endif