Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/53ce28c170ac5264405a7a12a718cf57a382518d
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/53ce28c170ac5264405a7a12a718cf57a382518d
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/53ce28c170ac5264405a7a12a718cf57a382518d

The branch, master has been updated
       via  53ce28c170ac5264405a7a12a718cf57a382518d (commit)
       via  d871be3ea00ef74ab28b936526768bbf121e3eb0 (commit)
       via  d843f78c202900409b0cd0c16397f6dae77bbe2b (commit)
       via  9e814fd0f0f03584debb43b6d8acf144bd8675a2 (commit)
       via  b78d6f458e5d5cb9c78d7430aacf10abd227eb32 (commit)
       via  b8640956d48af03f2f7f6c07e66958fa825a4972 (commit)
       via  8e7603e6a263eb765df4886a321537f209d88245 (commit)
       via  606cc0c2196f5934a7c48e89ab05da7d5e05081f (commit)
       via  52f98c9fb2b3dc04412ad25b7c24fa8cf357e78d (commit)
       via  24fed9d51ccf3e786e59983ae84b4f13e68b0ea4 (commit)
       via  b6f7ea536cececaa07fb2c46c129675d91167177 (commit)
       via  e4d6d9a972736bbea70eb0af62a430e77cc05ee5 (commit)
       via  313aaabdde2e6f0bb1f0dfe571b77261cc697a95 (commit)
       via  9f10babe645fe67b02fae90f852d5e4cdfcbb70e (commit)
       via  0d9023148d2a34bd908aac38e44d449359b03438 (commit)
       via  439deddba14f509fa0be90beff07481643178b69 (commit)
      from  7dab7cb43d4091648ceb40684ff70aff7091c648 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=53ce28c170ac5264405a7a12a718cf57a382518d
commit 53ce28c170ac5264405a7a12a718cf57a382518d
Merge: 7dab7cb d871be3
Author: Chris Young <[email protected]>
Commit: Chris Young <[email protected]>

    Merge branch 'chris/menuclass'
    Use menuclass to create menus when available.
    This gives certain advantages, including being able to add more than one 
level of sub-menu to the hotlist menu
    It also makes it easier to update and synchronise menu changes across our 
windows.



-----------------------------------------------------------------------

Summary of changes:
 frontends/amiga/Makefile               |    2 +-
 frontends/amiga/clipboard.c            |    8 +-
 frontends/amiga/cookies.c              |   39 +-
 frontends/amiga/dist/NetSurf.guide     |    4 +-
 frontends/amiga/gui.c                  |   39 +-
 frontends/amiga/gui.h                  |    4 +-
 frontends/amiga/{menu.c => gui_menu.c} |  971 ++++++++++++++----------------
 frontends/amiga/{menu.h => gui_menu.h} |   81 +--
 frontends/amiga/gui_options.c          |    7 +-
 frontends/amiga/history.c              |   43 +-
 frontends/amiga/hotlist.c              |   51 +-
 frontends/amiga/menu.c                 | 1026 +++++---------------------------
 frontends/amiga/menu.h                 |  153 +----
 13 files changed, 739 insertions(+), 1689 deletions(-)
 copy frontends/amiga/{menu.c => gui_menu.c} (54%)
 copy frontends/amiga/{menu.h => gui_menu.h} (56%)

diff --git a/frontends/amiga/Makefile b/frontends/amiga/Makefile
index 985a085..f57b4ef 100644
--- a/frontends/amiga/Makefile
+++ b/frontends/amiga/Makefile
@@ -46,7 +46,7 @@ S_FRONTEND := gui.c history.c hotlist.c schedule.c file.c     
\
        stringview/stringview.c stringview/urlhistory.c rtg.c           \
        agclass/amigaguide_class.c os3support.c font_diskfont.c         \
        selectmenu.c hash/xxhash.c font_cache.c font_bullet.c           \
-       nsoption.c corewindow.c
+       nsoption.c corewindow.c gui_menu.c
 
 # This is the final source build list
 # Note this is deliberately *not* expanded here as common and image
diff --git a/frontends/amiga/clipboard.c b/frontends/amiga/clipboard.c
index 9489110..27b8015 100644
--- a/frontends/amiga/clipboard.c
+++ b/frontends/amiga/clipboard.c
@@ -44,7 +44,7 @@
 #include "amiga/gui.h"
 #include "amiga/iff_cset.h"
 #include "amiga/iff_dr2d.h"
-#include "amiga/menu.h"
+#include "amiga/gui_menu.h"
 #include "amiga/utf8.h"
 
 #define ID_UTF8  MAKE_ID('U','T','F','8')
@@ -89,11 +89,11 @@ void gui_start_selection(struct gui_window *g)
        if(!g->shared->win) return;
        if(nsoption_bool(kiosk_mode) == true) return;
 
-       OnMenu(g->shared->win, AMI_MENU_CLEAR);
-       OnMenu(g->shared->win, AMI_MENU_COPY);
+       ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, M_COPY, 
false);
+       ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, M_CLEAR, 
false);
 
        if (browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT)
-               OnMenu(g->shared->win, AMI_MENU_CUT);
+               ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, 
M_CUT, false);
 }
 
 static char *ami_clipboard_cat_collection(struct CollectionItem *ci, LONG 
codeset, size_t *text_length)
diff --git a/frontends/amiga/cookies.c b/frontends/amiga/cookies.c
index 74c89cb..877805c 100644
--- a/frontends/amiga/cookies.c
+++ b/frontends/amiga/cookies.c
@@ -43,6 +43,7 @@
 #include "amiga/cookies.h"
 #include "amiga/corewindow.h"
 #include "amiga/libs.h"
+#include "amiga/menu.h"
 #include "amiga/utf8.h"
 
 enum {
@@ -239,38 +240,38 @@ HOOKF(void, ami_cookies_menu_item_edit_delete, APTR, 
window, struct IntuiMessage
 
 static void ami_cookies_menulabs(struct ami_menu_data **md)
 {
-       ami_menu_alloc_item(md, AMI_COOKIE_M_PROJECT, NM_TITLE, "Tree",       
0, NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND,   NM_ITEM, "Expand", 0, 
"TBImages:list_folderunfold", NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_ALL,   NM_SUB, "All", '+', 
NULL,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_PROJECT, NM_TITLE, "Tree", NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND,   NM_ITEM, "Expand", NULL, 
"TBImages:list_folderunfold", NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_ALL,   NM_SUB, "All", "+", 
NULL,
                ami_cookies_menu_item_project_expand_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_DOMAINS,   NM_SUB, 
"Domains", 0, NULL,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_DOMAINS,   NM_SUB, 
"Domains", NULL, NULL,
                ami_cookies_menu_item_project_expand_domains, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_COOKIES,   NM_SUB, 
"Cookies", 0, NULL,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_EXPAND_COOKIES,   NM_SUB, 
"Cookies", NULL, NULL,
                ami_cookies_menu_item_project_expand_cookies, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE,   NM_ITEM, "Collapse", 
0, "TBImages:list_folderfold", NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_ALL,   NM_SUB, "All", 
'-', NULL,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE,   NM_ITEM, "Collapse", 
NULL, "TBImages:list_folderfold", NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_ALL,   NM_SUB, "All", 
"-", NULL,
                ami_cookies_menu_item_project_collapse_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_DOMAINS,   NM_SUB, 
"Domains", 0, NULL,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_DOMAINS,   NM_SUB, 
"Domains", NULL, NULL,
                ami_cookies_menu_item_project_collapse_domains, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_COOKIES,   NM_SUB, 
"Cookies", 0, NULL,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_COLLAPSE_COOKIES,   NM_SUB, 
"Cookies", NULL, NULL,
                ami_cookies_menu_item_project_collapse_cookies, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_SNAPSHOT,   NM_ITEM, 
"SnapshotWindow", 0, "TBImages:list_hold",
+       ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P1, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_SNAPSHOT,   NM_ITEM, 
"SnapshotWindow", NULL, "TBImages:list_hold",
                ami_cookies_menu_item_project_snapshot, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_CLOSE,   NM_ITEM, "CloseWindow", 
'K', "TBImages:list_cancel",
+       ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_P2, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_CLOSE,   NM_ITEM, "CloseWindow", 
"K", "TBImages:list_cancel",
                ami_cookies_menu_item_project_close, NULL, 0);
 
-       ami_menu_alloc_item(md, AMI_COOKIE_M_EDIT, NM_TITLE, "Edit",       0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_SELECTALL,   NM_ITEM, 
"SelectAllNS", 'A', NSA_SPACE,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_EDIT, NM_TITLE, "Edit", NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_SELECTALL,   NM_ITEM, 
"SelectAllNS", "A", NSA_SPACE,
                ami_cookies_menu_item_edit_select_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_CLEAR,   NM_ITEM, "ClearNS", 0, 
NSA_SPACE,
+       ami_menu_alloc_item(md, AMI_COOKIE_M_CLEAR,   NM_ITEM, "ClearNS", NULL, 
NSA_SPACE,
                ami_cookies_menu_item_edit_clear, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_COOKIE_M_DELETE,   NM_ITEM, "TreeDelete", 
0, "TBImages:list_delete",
+       ami_menu_alloc_item(md, AMI_COOKIE_M_BAR_E1, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_DELETE,   NM_ITEM, "TreeDelete", 
"Del", "TBImages:list_delete",
                ami_cookies_menu_item_edit_delete, NULL, 0);
 
-       ami_menu_alloc_item(md, AMI_COOKIE_M_LAST,   NM_END, NULL,     0, NULL, 
NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_COOKIE_M_LAST,   NM_END, NULL, NULL, NULL, 
NULL, NULL, 0);
 }
 
 static struct Menu *
diff --git a/frontends/amiga/dist/NetSurf.guide 
b/frontends/amiga/dist/NetSurf.guide
index 754cdbe..512a264 100755
--- a/frontends/amiga/dist/NetSurf.guide
+++ b/frontends/amiga/dist/NetSurf.guide
@@ -285,11 +285,11 @@ Items from the hotlist can be added to the Hotlist menu 
as follows:
 
 Select Hotlist => Show hotlist...
 
-Items in the "Hotlist menu" 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 the "Hotlist menu" folder node, up to a maximum (currently) of 200 
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.
 
-Folders more than one level down in the heirarchy will become menu items with 
no action.  Items deeper will not be included in the menu at all (until we 
switch to using menuclass).
+When using a version of AmigaOS older than OS4.1FE, folders more than one 
level down in the heirarchy will become menu items with no action.  Items 
deeper will not be included in the menu at all.
 
 Folders with no items in them will show up disabled in the menu.  If they are 
named "--" they will be displayed as separator bars.
 
diff --git a/frontends/amiga/gui.c b/frontends/amiga/gui.c
index 6627e87..bee7a8d 100644
--- a/frontends/amiga/gui.c
+++ b/frontends/amiga/gui.c
@@ -1206,16 +1206,12 @@ static void ami_update_buttons(struct gui_window_2 
*gwin)
        if(!browser_window_reload_available(gwin->gw->bw))
                reload=TRUE;
 
-       if(nsoption_bool(kiosk_mode) == false)
-       {
-               if(gwin->tabs <= 1)
-               {
+       if(nsoption_bool(kiosk_mode) == false) {
+               if(gwin->tabs <= 1) {
                        tabclose=TRUE;
-                       OffMenu(gwin->win,AMI_MENU_CLOSETAB);
-               }
-               else
-               {
-                       OnMenu(gwin->win,AMI_MENU_CLOSETAB);
+                       ami_gui_menu_set_disabled(gwin->win, gwin->imenu, 
M_CLOSETAB, true);
+               } else {
+                       ami_gui_menu_set_disabled(gwin->win, gwin->imenu, 
M_CLOSETAB, false);
                }
        }
 
@@ -1641,7 +1637,7 @@ static void ami_gui_menu_update_all(void)
 
                if(node->Type == AMINS_WINDOW)
                {
-                       ami_menu_update_checked(gwin);
+                       ami_gui_menu_update_checked(gwin);
                }
        } while((node = nnode));
 }
@@ -1968,11 +1964,11 @@ static BOOL ami_handle_msg(void)
                }
        } while((node = nnode));
 
-       if(ami_menu_quit_selected() == true) {
+       if(ami_gui_menu_quit_selected() == true) {
                ami_quit_netsurf();
        }
        
-       if(ami_menu_get_check_toggled() == true) {
+       if(ami_gui_menu_get_check_toggled() == true) {
                ami_gui_menu_update_all();
        }
 
@@ -2907,7 +2903,7 @@ void ami_switch_tab(struct gui_window_2 *gwin, bool 
redraw)
 
        ami_plot_release_pens(gwin->shared_pens);
        ami_update_buttons(gwin);
-       ami_menu_update_disabled(gwin->gw, 
browser_window_get_content(gwin->gw->bw));
+       ami_gui_menu_update_disabled(gwin->gw, 
browser_window_get_content(gwin->gw->bw));
 
        if(redraw)
        {
@@ -3331,16 +3327,16 @@ void ami_gui_hotlist_update_all(void)
 
        if(IsMinListEmpty(window_list)) return;
 
+       //ami_gui_menu_refresh_hotlist(); /**\todo disabled as menuclass isn't 
updating correctly */
+
        node = (struct nsObject *)GetHead((struct List *)window_list);
 
        do {
                nnode=(struct nsObject *)GetSucc((struct Node *)node);
                gwin = node->objstruct;
 
-               if(node->Type == AMINS_WINDOW)
-               {
+               if(node->Type == AMINS_WINDOW) {
                        ami_gui_hotlist_toolbar_update(gwin);
-                       ami_menu_refresh(gwin);
                }
        } while((node = nnode));
 }
@@ -3989,7 +3985,7 @@ gui_window_create(struct browser_window *bw,
                                iconifygadget = TRUE;
 
                LOG("Creating menu");
-               struct Menu *menu = ami_menu_create(g->shared);
+               struct Menu *menu = ami_gui_menu_create(g->shared);
 
                NewList(&g->shared->tab_list);
                g->tab_node = 
AllocClickTabNode(TNA_Text,messages_get("NetSurf"),
@@ -4607,8 +4603,7 @@ static void gui_window_destroy(struct gui_window *g)
        DisposeObject((Object 
*)g->shared->history_ctxmenu[AMI_CTXMENU_HISTORY_BACK]);
        DisposeObject((Object 
*)g->shared->history_ctxmenu[AMI_CTXMENU_HISTORY_FORWARD]);
        ami_ctxmenu_release_hook(g->shared->ctxmenu_hook);
-       ami_free_menulabs(g->shared->menu_data);
-       ami_menu_free(g->shared);
+       ami_gui_menu_free(g->shared);
 
        free(g->shared->wintitle);
        ami_utf8_free(g->shared->status);
@@ -5262,7 +5257,7 @@ static void gui_window_place_caret(struct gui_window *g, 
int x, int y, int heigh
        g->c_h = height;
 
        if((nsoption_bool(kiosk_mode) == false))
-               OnMenu(g->shared->win, AMI_MENU_PASTE);
+               ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, 
M_PASTE, false);
 }
 
 static void gui_window_remove_caret(struct gui_window *g)
@@ -5271,7 +5266,7 @@ static void gui_window_remove_caret(struct gui_window *g)
        if(g->c_h == 0) return;
 
        if((nsoption_bool(kiosk_mode) == false))
-               OffMenu(g->shared->win, AMI_MENU_PASTE);
+               ami_gui_menu_set_disabled(g->shared->win, g->shared->imenu, 
M_PASTE, true);
 
        ami_do_redraw_limits(g, g->bw, false, g->c_x, g->c_y,
                g->c_x + g->c_w + 1, g->c_y + g->c_h + 1);
@@ -5295,7 +5290,7 @@ static void gui_window_new_content(struct gui_window *g)
        g->shared->oldv = 0;
        g->favicon = NULL;
        ami_plot_release_pens(g->shared->shared_pens);
-       ami_menu_update_disabled(g, c);
+       ami_gui_menu_update_disabled(g, c);
        ami_gui_update_hotlist_button(g->shared);
        ami_gui_scroller_update(g->shared);
 }
diff --git a/frontends/amiga/gui.h b/frontends/amiga/gui.h
index a176df1..07ff922 100644
--- a/frontends/amiga/gui.h
+++ b/frontends/amiga/gui.h
@@ -28,7 +28,7 @@
 #include "netsurf/window.h"
 #include "netsurf/mouse.h"
 
-#include "amiga/menu.h"
+#include "amiga/gui_menu.h"
 #include "amiga/object.h"
 #include "amiga/os3support.h"
 
@@ -134,7 +134,7 @@ struct gui_window_2 {
        int temp;
        bool redraw_scroll;
        bool new_content;
-       struct ami_menu_data *menu_data[AMI_MENU_AREXX_MAX + 1];
+       struct ami_menu_data *menu_data[AMI_MENU_AREXX_MAX + 1]; /* only for 
GadTools menus */
        ULONG hotlist_items;
        Object *restrict hotlist_toolbar_lab[AMI_GUI_TOOLBAR_MAX];
        struct List hotlist_toolbar_list;
diff --git a/frontends/amiga/menu.c b/frontends/amiga/gui_menu.c
similarity index 54%
copy from frontends/amiga/menu.c
copy to frontends/amiga/gui_menu.c
index c354fef..6b9b207 100644
--- a/frontends/amiga/menu.c
+++ b/frontends/amiga/gui_menu.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008-9, 2013, 2017 Chris Young 
<[email protected]>
+ * Copyright 2017 Chris Young <[email protected]>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -33,6 +33,9 @@
 #endif
 
 #include <libraries/gadtools.h>
+#ifdef __amigaos4__
+#include <intuition/menuclass.h>
+#endif
 
 #include <classes/window.h>
 #include <proto/label.h>
@@ -62,6 +65,7 @@
 #include "amiga/file.h"
 #include "amiga/filetype.h"
 #include "amiga/gui.h"
+#include "amiga/gui_menu.h"
 #include "amiga/gui_options.h"
 #include "amiga/history.h"
 #include "amiga/history_local.h"
@@ -76,31 +80,14 @@
 #include "amiga/utf8.h"
 #include "amiga/schedule.h"
 
-#define NSA_MAX_HOTLIST_MENU_LEN 100
-
-enum {
-       NSA_GLYPH_SUBMENU,
-       NSA_GLYPH_AMIGAKEY,
-       NSA_GLYPH_CHECKMARK,
-       NSA_GLYPH_MX,
-       NSA_GLYPH_MAX
-};
-
-struct ami_menu_data {
-       char *restrict menulab;
-       Object *restrict menuobj;
-       char menukey;
-       char *restrict menuicon;
-       struct Hook menu_hook;
-       UBYTE menutype;
-       UWORD flags;
-};
+#ifdef __amigaos4__
+static struct Menu *restrict gui_menu = NULL;
+static int gui_menu_count = 0;
+struct ami_menu_data *gui_menu_data[AMI_MENU_AREXX_MAX + 1];
+#endif
 
-static bool menu_quit = false;
 static bool ami_menu_check_toggled = false;
-static Object *restrict menu_glyph[NSA_GLYPH_MAX];
-static int menu_glyph_width[NSA_GLYPH_MAX];
-static bool menu_glyphs_loaded = false;
+static bool menu_quit = false;
 
 const char * const netsurf_version;
 const char * const verdate;
@@ -108,23 +95,6 @@ const char * const verdate;
 static nserror ami_menu_scan(struct ami_menu_data **md);
 void ami_menu_arexx_scan(struct ami_menu_data **md);
 
-void ami_menu_set_check_toggled(void)
-{
-       ami_menu_check_toggled = true;
-}
-
-bool ami_menu_get_check_toggled(void)
-{
-       bool check_toggled = ami_menu_check_toggled;
-       ami_menu_check_toggled = false;
-       return check_toggled;
-}
-
-bool ami_menu_quit_selected(void)
-{
-       return menu_quit;
-}
-
 /*
  * The below functions are called automatically by window.class when menu 
items are selected.
  */
@@ -375,10 +345,10 @@ HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, 
struct IntuiMessage *)
        bool checked = false;
 
        GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip);
-       if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true;
-       
+       checked = ami_menu_get_selected(menustrip, msg);
+
        nsoption_set_bool(foreground_images, checked);
-       ami_menu_set_check_toggled();
+       ami_gui_menu_set_check_toggled();
 }
 
 HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *)
@@ -387,10 +357,10 @@ HOOKF(void, ami_menu_item_browser_backimg, APTR, window, 
struct IntuiMessage *)
        bool checked = false;
 
        GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip);
-       if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true;
+       checked = ami_menu_get_selected(menustrip, msg);
        
        nsoption_set_bool(background_images, checked);
-       ami_menu_set_check_toggled();
+       ami_gui_menu_set_check_toggled();
 }
 
 HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage 
*)
@@ -399,10 +369,10 @@ HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, 
struct IntuiMessage *)
        bool checked = false;
 
        GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip);
-       if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true;
+       checked = ami_menu_get_selected(menustrip, msg);
        
        nsoption_set_bool(enable_javascript, checked);
-       ami_menu_set_check_toggled();
+       ami_gui_menu_set_check_toggled();
 }
 
 HOOKF(void, ami_menu_item_browser_scale_decrease, APTR, window, struct 
IntuiMessage *)
@@ -541,461 +511,296 @@ HOOKF(void, ami_menu_item_arexx_entries, APTR, window, 
struct IntuiMessage *)
        }
 }
 
+/* normal GUI-specific menu functions */
 
-/* menu creation code */
-static void ami_menu_free_labs(struct ami_menu_data **md, int max)
+ULONG ami_gui_menu_number(int item)
 {
-       int i;
+       /* horrible, horrible, horrible */
+       ULONG menu_num;
 
-       for(i = 0; i <= max; i++) {
-               if(md[i] == NULL) continue;
-               if(md[i]->menulab && (md[i]->menulab != NM_BARLABEL)) {
-                       if(md[i]->menutype & MENU_IMAGE) {
-                               if(md[i]->menuobj) 
DisposeObject(md[i]->menuobj);
-                       }
-
-                       ami_utf8_free(md[i]->menulab);
-               }
+       switch(item) {
+               case M_SAVETXT:
+                       menu_num = FULLMENUNUM(0,4,1);
+               break;
 
-               md[i]->menulab = NULL;
-               md[i]->menuobj = NULL;
-               md[i]->menukey = 0;
-               md[i]->menutype = 0;
-               free(md[i]);
-       }
-}
+               case M_SAVECOMP:
+                       menu_num = FULLMENUNUM(0,4,2);
+               break;
 
-void ami_free_menulabs(struct ami_menu_data **md)
-{
-       int i;
+               case M_SAVEIFF:
+                       menu_num = FULLMENUNUM(0,4,3);
+               break;
+#ifdef WITH_PDF_EXPORT
+               case M_SAVEPDF:
+                       menu_num = FULLMENUNUM(0,4,4);
+               break;
+#endif
+               case M_CLOSETAB:
+                       menu_num = FULLMENUNUM(0,8,0);
+               break;
 
-       for(i=0;i<=AMI_MENU_AREXX_MAX;i++) {
-               if(md[i] == NULL) continue;
-               if(md[i]->menulab && (md[i]->menulab != NM_BARLABEL)) {
-                       if(md[i]->menutype & MENU_IMAGE) {
-                               if(md[i]->menuobj) 
DisposeObject(md[i]->menuobj);
-                       }
+               case M_CUT:
+                       menu_num = FULLMENUNUM(1,0,0);
+               break;
 
-                       ami_utf8_free(md[i]->menulab);
+               case M_COPY:
+                       menu_num = FULLMENUNUM(1,1,0);
+               break;
 
-                       if(i >= AMI_MENU_AREXX) {
-                               if(md[i]->menu_hook.h_Data) 
free(md[i]->menu_hook.h_Data);
-                               md[i]->menu_hook.h_Data = NULL;
-                       }
-               }
+               case M_PASTE:
+                       menu_num = FULLMENUNUM(1,2,0);
+               break;
 
-               md[i]->menulab = NULL;
-               md[i]->menuobj = NULL;
-               md[i]->menukey = 0;
-               md[i]->menutype = 0;
-               free(md[i]);
-       }
-}
+               case M_SELALL:
+                       menu_num = FULLMENUNUM(1,4,0);
+               break;
 
-void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type,
-                       const char *restrict label, char key, const char 
*restrict icon,
-                       void *restrict func, void *restrict hookdata, UWORD 
flags)
-{
-       char menu_icon[1024];
+               case M_CLEAR:
+                       menu_num = FULLMENUNUM(1,5,0);
+               break;
 
-       md[num] = calloc(1, sizeof(struct ami_menu_data));
-       md[num]->menutype = type;
-       md[num]->flags = flags;
-       
-       if(type == NM_END) return;
-
-       if((label == NM_BARLABEL) || (strcmp(label, "--") == 0)) {
-               md[num]->menulab = NM_BARLABEL;
-       } else { /* horrid non-generic stuff */
-               if((num >= AMI_MENU_HOTLIST) && (num <= AMI_MENU_HOTLIST_MAX)) {
-                       utf8_from_local_encoding(label,
-                       (strlen(label) < NSA_MAX_HOTLIST_MENU_LEN) ? 
strlen(label) : NSA_MAX_HOTLIST_MENU_LEN,
-                       (char **)&md[num]->menulab);
-               } else if((num >= AMI_MENU_AREXX) && (num < 
AMI_MENU_AREXX_MAX)) {
-                       md[num]->menulab = strdup(label);               
-               } else {
-                       md[num]->menulab = ami_utf8_easy(messages_get(label));
-               }
-       }
+               case M_UNDO:
+                       menu_num = FULLMENUNUM(1,8,0);
+               break;
 
-       md[num]->menuicon = NULL;
-       if(key) md[num]->menukey = key;
-       if(func) md[num]->menu_hook.h_Entry = (HOOKFUNC)func;
-       if(hookdata) md[num]->menu_hook.h_Data = hookdata;
+               case M_REDO:
+                       menu_num = FULLMENUNUM(1,9,0);
+               break;
 
-#ifdef __amigaos4__
-       if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
-               if(icon) {
-                       if(ami_locate_resource(menu_icon, icon) == true) {
-                               md[num]->menuicon = (char *)strdup(menu_icon);
-                       } else {
-                               /* If the requested icon can't be found, put 
blank space in instead */
-                               md[num]->menuicon = (char *)strdup(NSA_SPACE);
-                       }
-               }
-       }
-#endif
-}
+               case M_FIND:
+                       menu_num = FULLMENUNUM(2,0,0);
+               break;
 
-static void ami_init_menulabs(struct ami_menu_data **md)
-{
-       UWORD js_flags = CHECKIT | MENUTOGGLE;
-       if(nsoption_bool(enable_javascript) == true)
-               js_flags |= CHECKED;
+               case M_IMGFORE:
+                       menu_num = FULLMENUNUM(2,8,0);
+               break;
 
-       UWORD imgfore_flags = CHECKIT | MENUTOGGLE;
-       if(nsoption_bool(foreground_images) == true)
-               imgfore_flags |= CHECKED;
+               case M_IMGBACK:
+                       menu_num = FULLMENUNUM(2,8,1);
+               break;
 
-       UWORD imgback_flags = CHECKIT | MENUTOGGLE;
-       if(nsoption_bool(background_images) == true)
-               imgback_flags |= CHECKED;
+               case M_JS:
+                       menu_num = FULLMENUNUM(2,9,0);
+               break;
 
-       ami_menu_alloc_item(md, M_PROJECT, NM_TITLE, "Project",       0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_NEWWIN,   NM_ITEM, "NewWindowNS", 'N', 
"TBImages:list_app",
-                       ami_menu_item_project_newwin, NULL, 0);
-       ami_menu_alloc_item(md, M_NEWTAB,   NM_ITEM, "NewTab",      'T', 
"TBImages:list_tab",
-                       ami_menu_item_project_newtab, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_P1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_OPEN,     NM_ITEM, "OpenFile",    'O', 
"TBImages:list_folder_misc",
-                       ami_menu_item_project_open, NULL, 0);
-       ami_menu_alloc_item(md, M_SAVEAS,   NM_ITEM, "SaveAsNS",      0, 
"TBImages:list_saveas", NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SAVESRC,   NM_SUB, "Source",      'S', NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE, 
0);
-       ami_menu_alloc_item(md, M_SAVETXT,   NM_SUB, "TextNS",        0, NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT, 0);
-       ami_menu_alloc_item(md, M_SAVECOMP,  NM_SUB, "SaveCompNS",    0, NULL,
-                       ami_menu_item_project_save, (void 
*)AMINS_SAVE_COMPLETE, 0);
-#ifdef WITH_PDF_EXPORT
-       ami_menu_alloc_item(md, M_SAVEPDF,   NM_SUB, "PDFNS",         0, NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_PDF, 0);
-#endif
-       ami_menu_alloc_item(md, M_SAVEIFF,   NM_SUB, "IFF",           0, NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_IFF, 0);
-       ami_menu_alloc_item(md, M_BAR_P2,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_PRINT,    NM_ITEM, "PrintNS",     'P', 
"TBImages:list_print",
-                       ami_menu_item_project_print, NULL, NM_ITEMDISABLED);
-       ami_menu_alloc_item(md, M_BAR_P3,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_CLOSETAB, NM_ITEM, "CloseTab",    'K', 
"TBImages:list_remove",
-                       ami_menu_item_project_closetab, NULL, 0);
-       ami_menu_alloc_item(md, M_CLOSEWIN, NM_ITEM, "CloseWindow",   0, 
"TBImages:list_cancel",
-                       ami_menu_item_project_closewin, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_P4,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);                          
-       ami_menu_alloc_item(md, M_ABOUT,    NM_ITEM, "About",       '?', 
"TBImages:list_info",
-                       ami_menu_item_project_about, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_P5,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);                          
-       ami_menu_alloc_item(md, M_QUIT,     NM_ITEM, "Quit",        'Q', 
"TBImages:list_warning",
-                       ami_menu_item_project_quit, NULL, 0);
+               default:
+                       LOG("WARNING: Unrecognised menu item %d", item);
+                       menu_num = 0;
+               break;
+       }
 
-       ami_menu_alloc_item(md, M_EDIT,    NM_TITLE, "Edit",          0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_CUT,      NM_ITEM, "CutNS",       'X', 
"TBImages:list_cut",
-                       ami_menu_item_edit_cut, NULL, 0);
-       ami_menu_alloc_item(md, M_COPY,     NM_ITEM, "CopyNS",      'C', 
"TBImages:list_copy",
-                       ami_menu_item_edit_copy, NULL, 0);
-       ami_menu_alloc_item(md, M_PASTE,    NM_ITEM, "PasteNS",     'V', 
"TBImages:list_paste",
-                       ami_menu_item_edit_paste, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_E1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SELALL,   NM_ITEM, "SelectAllNS", 'A', 
NSA_SPACE,
-                       ami_menu_item_edit_selectall, NULL, 0);
-       ami_menu_alloc_item(md, M_CLEAR,    NM_ITEM, "ClearNS",       0, 
NSA_SPACE,
-                       ami_menu_item_edit_clearsel, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_E2,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_UNDO,     NM_ITEM, "Undo",        'Z', 
"TBImages:list_undo",
-                       ami_menu_item_edit_undo, NULL, 0);
-       ami_menu_alloc_item(md, M_REDO,     NM_ITEM, "Redo",        'Y', 
"TBImages:list_redo",
-                       ami_menu_item_edit_redo, NULL, 0);
+       return menu_num;
+}
 
-       ami_menu_alloc_item(md, M_BROWSER, NM_TITLE, "Browser",       0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_FIND,     NM_ITEM, "FindTextNS",   'F', 
"TBImages:list_search",
-                       ami_menu_item_browser_find, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_B1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_HISTLOCL, NM_ITEM, "HistLocalNS",   0, 
"TBImages:list_history",
-                       ami_menu_item_browser_localhistory, NULL, 0);
-       ami_menu_alloc_item(md, M_HISTGLBL, NM_ITEM, "HistGlobalNS",  0, 
"TBImages:list_history",
-                       ami_menu_item_browser_globalhistory, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_B2,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_COOKIES,  NM_ITEM, "ShowCookiesNS",   0, 
"TBImages:list_internet",
-                       ami_menu_item_browser_cookies, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_B3,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALE,    NM_ITEM, "ScaleNS",       0, 
"TBImages:list_preview", NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALEDEC,  NM_SUB, "ScaleDec",    '-', 
"TBImages:list_zoom_out",
-                       ami_menu_item_browser_scale_decrease, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALENRM,  NM_SUB, "ScaleNorm",   '=', 
"TBImages:list_zoom_100",
-                       ami_menu_item_browser_scale_normal, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALEINC,  NM_SUB, "ScaleInc",    '+', 
"TBImages:list_zoom_in",
-                       ami_menu_item_browser_scale_increase, NULL, 0);
-       ami_menu_alloc_item(md, M_IMAGES,   NM_ITEM, "Images",        0, 
"TBImages:list_image", NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_IMGFORE,   NM_SUB, "ForeImg",       0, NULL,
-                       ami_menu_item_browser_foreimg, NULL, imgfore_flags);
-       ami_menu_alloc_item(md, M_IMGBACK,   NM_SUB, "BackImg",       0, NULL,
-                       ami_menu_item_browser_backimg, NULL, imgback_flags);
-       ami_menu_alloc_item(md, M_JS,       NM_ITEM, "EnableJS",      0, NULL,
-                       ami_menu_item_browser_enablejs, NULL, js_flags);
-       ami_menu_alloc_item(md, M_BAR_B4,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_REDRAW,   NM_ITEM, "Redraw",        0, 
"TBImages:list_wand",
-                       ami_menu_item_browser_redraw, NULL, 0);
+#ifdef __amigaos4__
+static void ami_gui_menu_set_checked_mc(struct Menu *menu, int item, bool 
check)
+{
+       ULONG check_state = MS_CHECKED;
 
-       ami_menu_alloc_item(md, M_HOTLIST, NM_TITLE, "Hotlist",       0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_HLADD,    NM_ITEM, "HotlistAdd",  'B', 
"TBImages:list_favouriteadd",
-                       ami_menu_item_hotlist_add, NULL, 0);
-       ami_menu_alloc_item(md, M_HLSHOW,   NM_ITEM,"HotlistShowNS",'H', 
"TBImages:list_favourite",
-                       ami_menu_item_hotlist_show, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_H1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
+       if(check == false) {
+               check_state = 0;
+       }
 
-       ami_menu_alloc_item(md, M_PREFS,   NM_TITLE, "Settings",      0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_PREDIT,   NM_ITEM, "SettingsEdit",  0, 
"TBImages:list_prefs",
-                       ami_menu_item_settings_edit, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_S1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, 
"TBImages:list_hold",
-                       ami_menu_item_settings_snapshot, NULL, 0);
-       ami_menu_alloc_item(md, M_PRSAVE,   NM_ITEM, "SettingsSave",  0, 
"TBImages:list_use",
-                       ami_menu_item_settings_save, NULL, 0);
+       if(menu == NULL) {
+               menu = gui_menu;
+       }
 
-       ami_menu_alloc_item(md, M_AREXX,   NM_TITLE, "ARexx",         0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_AREXXEX,  NM_ITEM, "ARexxExecute",'E', 
"TBImages:list_arexx",
-                       ami_menu_item_arexx_execute, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_A1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_MENU_AREXX_MAX,   NM_END, NULL,     0, 
NULL, NULL, NULL, 0);
+       IDoMethod((Object *)menu, MM_SETSTATE, 0, item, MS_CHECKED, 
check_state);
 }
+#endif
 
-/* Menu refresh for hotlist */
-void ami_menu_refresh(struct gui_window_2 *gwin)
+static void ami_gui_menu_set_checked_gt(struct Menu *menu, int item, bool 
check)
 {
-       return; /**\todo fix this after migrating to menuclass */
-
-       struct Menu *menu;
+       if(menu == NULL) {
+               return;
+       }
 
-       LOG("Clearing MenuStrip");
-       SetAttrs(gwin->objects[OID_MAIN],
-                       WINDOW_MenuStrip, NULL,
-                       TAG_DONE);
+       if(check == true) {
+               if((ItemAddress(menu, ami_gui_menu_number(item))->Flags & 
CHECKED) == 0)
+                       ItemAddress(menu, ami_gui_menu_number(item))->Flags ^= 
CHECKED;
+       } else {
+               if(ItemAddress(menu, ami_gui_menu_number(item))->Flags & 
CHECKED)
+                       ItemAddress(menu, ami_gui_menu_number(item))->Flags ^= 
CHECKED;
+       }
+}
 
-       LOG("Freeing menu");
-       ami_menu_free(gwin);
+void ami_gui_menu_set_checked(struct Menu *menu, int item, bool check)
+{
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+#ifdef __amigaos4__
+               return ami_gui_menu_set_checked_mc(menu, item, check);
+#endif 
+       } else {
+               return ami_gui_menu_set_checked_gt(menu, item, check);
+       }
+}
 
-       LOG("Freeing menu labels");
-       ami_free_menulabs(gwin->menu_data);
+#ifdef __amigaos4__
+static void ami_gui_menu_set_disabled_mc(struct Window *win, struct Menu 
*menu, int item, bool disable)
+{
+       ULONG disable_state = MS_DISABLED;
 
-       LOG("Creating new menu");
-       menu = ami_menu_create(gwin);
+       if(disable == false) {
+               disable_state = 0;
+       }
 
-       LOG("Attaching MenuStrip %p to %p", menu, gwin->objects[OID_MAIN]);
-       SetAttrs(gwin->objects[OID_MAIN],
-                       WINDOW_MenuStrip, menu,
-                       TAG_DONE);
+       IDoMethod((Object *)menu, MM_SETSTATE, 0, item, MS_DISABLED, 
disable_state);
 }
+#endif
 
-static void ami_menu_load_glyphs(struct DrawInfo *dri)
+static void ami_gui_menu_set_disabled_gt(struct Window *win, struct Menu 
*menu, int item, bool disable)
 {
-#ifdef __amigaos4__
-       if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
-               for(int i = 0; i < NSA_GLYPH_MAX; i++)
-                       menu_glyph[i] = NULL;
-
-               menu_glyph[NSA_GLYPH_SUBMENU] = NewObject(NULL, "sysiclass",
-                                                                               
        SYSIA_Which, MENUSUB,
-                                                                               
        SYSIA_DrawInfo, dri,
-                                                                               
TAG_DONE);
-               menu_glyph[NSA_GLYPH_AMIGAKEY] = NewObject(NULL, "sysiclass",
-                                                                               
        SYSIA_Which, AMIGAKEY,
-                                                                               
        SYSIA_DrawInfo, dri,
-                                                                               
TAG_DONE);
-               GetAttr(IA_Width, menu_glyph[NSA_GLYPH_SUBMENU],
-                       (ULONG *)&menu_glyph_width[NSA_GLYPH_SUBMENU]);
-               GetAttr(IA_Width, menu_glyph[NSA_GLYPH_AMIGAKEY],
-                       (ULONG *)&menu_glyph_width[NSA_GLYPH_AMIGAKEY]);
-       
-               menu_glyphs_loaded = true;
+       ULONG menu_num = ami_gui_menu_number(item);
+
+       if(disable == false) {
+               OnMenu(win, menu_num);
+       } else {
+               OffMenu(win, menu_num);
        }
-#endif
 }
 
-void ami_menu_free_glyphs(void)
+void ami_gui_menu_set_disabled(struct Window *win, struct Menu *menu, int 
item, bool disable)
 {
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
 #ifdef __amigaos4__
-       if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
-               int i;
-               if(menu_glyphs_loaded == false) return;
-
-               for(i = 0; i < NSA_GLYPH_MAX; i++) {
-                       if(menu_glyph[i]) DisposeObject(menu_glyph[i]);
-                       menu_glyph[i] = NULL;
-               };
-       
-               menu_glyphs_loaded = false;
+               return ami_gui_menu_set_disabled_mc(win, menu, item, disable);
+#endif 
+       } else {
+               return ami_gui_menu_set_disabled_gt(win, menu, item, disable);
        }
-#endif
 }
 
-static int ami_menu_calc_item_width(struct ami_menu_data **md, int j, struct 
RastPort *rp)
+
+void ami_gui_menu_update_checked(struct gui_window_2 *gwin)
 {
-       int space_width = TextLength(rp, " ", 1);
-       int item_size;
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+               /* Irrelevant when using MenuClass */
+               return;
+       }
 
-       item_size = TextLength(rp, md[j]->menulab, strlen(md[j]->menulab));
-       item_size += space_width;
+       struct Menu *menustrip;
 
-       if(md[j]->menukey) {
-               item_size += TextLength(rp, &md[j]->menukey, 1);
-               item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
-               /**TODO: take account of the size of other imagery too
-                */
+       GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip);
+       if(!menustrip) return;
+       if(nsoption_bool(enable_javascript) == true) {
+               if((ItemAddress(menustrip, ami_gui_menu_number(M_JS))->Flags & 
CHECKED) == 0)
+                       ItemAddress(menustrip, 
ami_gui_menu_number(M_JS))->Flags ^= CHECKED;
+       } else {
+               if(ItemAddress(menustrip, ami_gui_menu_number(M_JS))->Flags & 
CHECKED)
+                       ItemAddress(menustrip, 
ami_gui_menu_number(M_JS))->Flags ^= CHECKED;
+       }
+       if(nsoption_bool(foreground_images) == true) {
+               if((ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGFORE))->Flags & CHECKED) == 0)
+                       ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGFORE))->Flags ^= CHECKED;
        } else {
-               /* assume worst case - it doesn't really matter if we make 
menus wider */
-               item_size += TextLength(rp, "M", 1);
-               item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
+               if(ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGFORE))->Flags & CHECKED)
+                       ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGFORE))->Flags ^= CHECKED;
        }
 
-       if(md[j]->menuicon) {
-               item_size += 16;
+       if(nsoption_bool(background_images) == true) {
+               if((ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGBACK))->Flags & CHECKED) == 0)
+                       ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGBACK))->Flags ^= CHECKED;
+       } else {
+               if(ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGBACK))->Flags & CHECKED)
+                       ItemAddress(menustrip, 
ami_gui_menu_number(M_IMGBACK))->Flags ^= CHECKED;
        }
 
-       return item_size;
+       ResetMenuStrip(gwin->win, menustrip);
 }
 
-
-struct Menu *ami_menu_layout(struct ami_menu_data **md, int max)
+void ami_gui_menu_update_disabled(struct gui_window *g, struct hlcache_handle 
*c)
 {
-       int i, j;
-       int txtlen = 0;
-       int left_posn = 0;
-       struct NewMenu *nm;
-       struct Menu *imenu = NULL;
-       struct VisualInfo *vi;
-       struct RastPort *rp = &scrn->RastPort;
-       struct DrawInfo *dri = GetScreenDrawInfo(scrn);
-       int space_width = TextLength(rp, " ", 1);
-
-       if(menu_glyphs_loaded == false)
-               ami_menu_load_glyphs(dri);
-
-       nm = calloc(1, sizeof(struct NewMenu) * (max + 1));
-       if(nm == NULL) return NULL;
-
-       for(i = 0; i < max; i++) {
-               if(md[i] == NULL) {
-                       nm[i].nm_Type = NM_IGNORE;
-                       continue;
-               }
+       struct Window *win = g->shared->win;
 
-               if(md[i]->menutype == NM_TITLE) {
-                       j = i + 1;
-                       txtlen = 0;
-                       do {
-                               if(md[j]->menulab != NM_BARLABEL) {
-                                       if(md[j]->menutype == NM_ITEM) {
-                                               int item_size = 
ami_menu_calc_item_width(md, j, rp);
-                                               if(item_size > txtlen) {
-                                                       txtlen = item_size;
-                                               }
-                                       }
-                               }
-                               j++;
-                       } while((j <= max) && (md[j] != NULL) && 
(md[j]->menutype != NM_TITLE) && (md[j]->menutype != 0));
+       if(nsoption_bool(kiosk_mode) == true) return;
+
+       if(content_get_type(c) <= CONTENT_CSS)
+       {
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, 
false);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, 
false);
+#ifdef WITH_PDF_EXPORT
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, 
false);
+#endif
+#if 0
+               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) 
{
+                       OnMenu(win,AMI_MENU_COPY);
+                       OnMenu(win,AMI_MENU_CLEAR);
+               } else {
+                       OffMenu(win,AMI_MENU_COPY);
+                       OffMenu(win,AMI_MENU_CLEAR);    
                }
-#ifdef __amigaos4__
-               if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
-                       /* GadTools 53.7+ only. For now we will only create the 
menu
-                               using label.image if there's a bitmap 
associated with the item. */
-                       if((md[i]->menuicon != NULL) && (md[i]->menulab != 
NM_BARLABEL)) {
-                               int icon_width = 0;
-                               Object *restrict submenuarrow = NULL;
-                               Object *restrict icon = BitMapObj,
-                                               IA_Scalable, TRUE,
-                                               BITMAP_Screen, scrn,
-                                               BITMAP_SourceFile, 
md[i]->menuicon,
-                                               BITMAP_Masking, TRUE,
-                                       BitMapEnd;
-
-                               /* \todo make this scale the bitmap to these 
dimensions */
-                               SetAttrs(icon,
-                                       BITMAP_Width, 16,
-                                       BITMAP_Height, 16,
-                                       TAG_DONE);
-
-                               GetAttr(IA_Width, icon, (ULONG *)&icon_width);
-
-                               if(md[i]->menutype != NM_SUB) {
-                                       left_posn = txtlen;
-                               }
 
-                               left_posn = left_posn -
-                                       TextLength(rp, md[i]->menulab, 
strlen(md[i]->menulab)) -
-                                       icon_width - space_width;
+               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT)
+                       OnMenu(win,AMI_MENU_CUT);
+               else
+                       OffMenu(win,AMI_MENU_CUT);              
+               
+               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_PASTE)
+                       OnMenu(win,AMI_MENU_PASTE);
+               else
+                       OffMenu(win,AMI_MENU_PASTE);
+#else
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_CUT, false);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_COPY, false);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_PASTE, 
false);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_CLEAR, 
false);
+#endif
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SELALL, 
false);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_FIND, false);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEIFF, 
true);
+       }
+       else
+       {
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_CUT, true);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_PASTE, true);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_CLEAR, true);
 
-                               if((md[i]->menutype == NM_ITEM) && md[i+1] && 
(md[i+1]->menutype == NM_SUB)) {
-                                       left_posn -= 
menu_glyph_width[NSA_GLYPH_SUBMENU];
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVETXT, 
true);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVECOMP, 
true);
+#ifdef WITH_PDF_EXPORT
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SAVEPDF, 
true);
+#endif
 
-                                       submenuarrow = NewObject(NULL, 
"sysiclass",
-                                                                       
SYSIA_Which, MENUSUB,
-                                                                       
SYSIA_DrawInfo, dri,
-                                                                       
IA_Left, left_posn,
-                                                                       
TAG_DONE);
-                               }
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_SELALL, 
true);
+               ami_gui_menu_set_disabled(win, g->shared->imenu, M_FIND, true);
 
-                               md[i]->menuobj = LabelObj,
-                                       LABEL_MenuMode, TRUE,
-                                       LABEL_DrawInfo, dri,
-                                       LABEL_DisposeImage, TRUE,
-                                       LABEL_Image, icon,
-                                       LABEL_Text, " ",
-                                       LABEL_Text, md[i]->menulab,
-                                       LABEL_DisposeImage, TRUE,
-                                       LABEL_Image, submenuarrow,
-                               LabelEnd;
-
-                               if(md[i]->menuobj) md[i]->menutype |= 
MENU_IMAGE;
-                       }
-               }
+#ifdef WITH_NS_SVG
+               if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == 
true))
+#else
+               if(content_get_bitmap(c))
 #endif
-               nm[i].nm_Type = md[i]->menutype;
-               
-               if(md[i]->menuobj)
-                       nm[i].nm_Label = (void *)md[i]->menuobj;
+               {
+                       ami_gui_menu_set_disabled(win, g->shared->imenu, 
M_COPY, false);
+                       ami_gui_menu_set_disabled(win, g->shared->imenu, 
M_SAVEIFF, false);
+               }
                else
-                       nm[i].nm_Label = md[i]->menulab;
-
-               if(md[i]->menukey) nm[i].nm_CommKey = &md[i]->menukey;
-               nm[i].nm_Flags = md[i]->flags;
-               if(md[i]->menu_hook.h_Entry) nm[i].nm_UserData = 
&md[i]->menu_hook;
-
-               if(md[i]->menuicon) {
-                       free(md[i]->menuicon);
-                       md[i]->menuicon = NULL;
+               {
+                       ami_gui_menu_set_disabled(win, g->shared->imenu, 
M_COPY, true);
+                       ami_gui_menu_set_disabled(win, g->shared->imenu, 
M_SAVEIFF, true);
                }
        }
-       
-       FreeScreenDrawInfo(scrn, dri);
-
-       vi = GetVisualInfo(scrn, TAG_DONE);
-       imenu = CreateMenus(nm, TAG_DONE);
-       LayoutMenus(imenu, vi,
-               GTMN_NewLookMenus, TRUE, TAG_DONE);
-       free(nm);
-       FreeVisualInfo(vi); /* Not using GadTools after layout so shouldn't 
need this */
-       
-       return imenu;
 }
 
-void ami_menu_free(struct gui_window_2 *gwin)
+void ami_gui_menu_set_check_toggled(void)
 {
-       FreeMenus(gwin->imenu);
-}
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+               /* Irrelevant when using MenuClass */
+               return;
+       }
 
-void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu)
-{
-       ami_menu_free_labs(md, max);
-       FreeMenus(imenu);
+       ami_menu_check_toggled = true;
 }
 
-struct Menu *ami_menu_create(struct gui_window_2 *gwin)
+bool ami_gui_menu_get_check_toggled(void)
 {
-       ami_init_menulabs(gwin->menu_data);
-       ami_menu_scan(gwin->menu_data); //\todo this needs to be MenuClass 
created
-       ami_menu_arexx_scan(gwin->menu_data);
-       gwin->imenu = ami_menu_layout(gwin->menu_data, AMI_MENU_AREXX_MAX);
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+               /* Irrelevant when using MenuClass */
+               return false;
+       }
 
-       return gwin->imenu;
+       bool check_toggled = ami_menu_check_toggled;
+       ami_menu_check_toggled = false;
+       return check_toggled;
 }
 
 void ami_menu_arexx_scan(struct ami_menu_data **md)
@@ -1032,7 +837,7 @@ void ami_menu_arexx_scan(struct ami_menu_data **md)
                                                        else
                                                                menu_lab = 
ead->ed_Name;
 
-                                                       ami_menu_alloc_item(md, 
item, NM_ITEM, menu_lab, 0, NSA_SPACE,
+                                                       ami_menu_alloc_item(md, 
item, NM_ITEM, menu_lab, NULL, NSA_SPACE,
                                                                
ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name), 0);
 
                                                        item++;
@@ -1046,7 +851,7 @@ void ami_menu_arexx_scan(struct ami_menu_data **md)
                UnLock(lock);
        }
 
-       ami_menu_alloc_item(md, item, NM_END, NULL, 0, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, item, NM_END, NULL, NULL, NULL, NULL, NULL, 0);
 }
 
 static bool ami_menu_hotlist_add(void *userdata, int level, int item, const 
char *title, nsurl *url, bool is_folder)
@@ -1066,9 +871,12 @@ static bool ami_menu_hotlist_add(void *userdata, int 
level, int item, const char
                        type = NM_SUB;
                break;
                default:
-                       /* entries not at level 1 or 2 are not able to be added
-                        * \todo construct menus using menuclass instead! */
-                       return false;
+                       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 
6)) {
+                               type = NM_SUB + (level - 2);
+                       } else {
+                               /* entries not at level 1 or 2 are not able to 
be added */
+                               return false;
+                       }
                break;
        }
 
@@ -1079,12 +887,14 @@ static bool ami_menu_hotlist_add(void *userdata, int 
level, int item, const char
                if (icon == NULL) icon = ASPrintf("icons/content.png");
        }
 
-       if((is_folder == true) && (type == NM_SUB)) {
-               flags = NM_ITEMDISABLED;
+       if(!LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+               if((is_folder == true) && (type == NM_SUB)) {
+                       flags = NM_ITEMDISABLED;
+               }
        }
 
        ami_menu_alloc_item(md, item, type, title,
-               0, icon, ami_menu_item_hotlist_entries, (void *)url, flags);
+               NULL, icon, ami_menu_item_hotlist_entries, (void *)url, flags);
 
        if(icon) FreeVec(icon);
 
@@ -1093,110 +903,221 @@ static bool ami_menu_hotlist_add(void *userdata, int 
level, int item, const char
 
 static nserror ami_menu_scan(struct ami_menu_data **md)
 {
+       ami_menu_alloc_item(md, M_HLADD,    NM_ITEM, "HotlistAdd",   "B", 
"TBImages:list_favouriteadd",
+                       ami_menu_item_hotlist_add, NULL, 0);
+       ami_menu_alloc_item(md, M_HLSHOW,   NM_ITEM,"HotlistShowNS", "H", 
"TBImages:list_favourite",
+                       ami_menu_item_hotlist_show, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_H1,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+
        return ami_hotlist_scan((void *)md, AMI_MENU_HOTLIST, 
messages_get("HotlistMenu"), ami_menu_hotlist_add);
 }
 
-void ami_menu_update_checked(struct gui_window_2 *gwin)
+static void ami_init_menulabs(struct ami_menu_data **md)
 {
-       struct Menu *menustrip;
+       UWORD js_flags = CHECKIT | MENUTOGGLE;
+       if(nsoption_bool(enable_javascript) == true)
+               js_flags |= CHECKED;
 
-       GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip);
-       if(!menustrip) return;
-       if(nsoption_bool(enable_javascript) == true) {
-               if((ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) == 0)
-                       ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED;
-       } else {
-               if(ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED)
-                       ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED;
-       }
-       if(nsoption_bool(foreground_images) == true) {
-               if((ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) 
== 0)
-                       ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= 
CHECKED;
-       } else {
-               if(ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED)
-                       ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= 
CHECKED;
-       }
+       UWORD imgfore_flags = CHECKIT | MENUTOGGLE;
+       if(nsoption_bool(foreground_images) == true)
+               imgfore_flags |= CHECKED;
 
-       if(nsoption_bool(background_images) == true) {
-               if((ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) 
== 0)
-                       ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= 
CHECKED;
+       UWORD imgback_flags = CHECKIT | MENUTOGGLE;
+       if(nsoption_bool(background_images) == true)
+               imgback_flags |= CHECKED;
+
+       ami_menu_alloc_item(md, M_PROJECT, NM_TITLE, "Project",      NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_NEWWIN,   NM_ITEM, "NewWindowNS",  "N", 
"TBImages:list_app",
+                       ami_menu_item_project_newwin, NULL, 0);
+       ami_menu_alloc_item(md, M_NEWTAB,   NM_ITEM, "NewTab",       "T", 
"TBImages:list_tab",
+                       ami_menu_item_project_newtab, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_P1,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_OPEN,     NM_ITEM, "OpenFile",     "O", 
"TBImages:list_folder_misc",
+                       ami_menu_item_project_open, NULL, 0);
+       ami_menu_alloc_item(md, M_SAVEAS,   NM_ITEM, "SaveAsNS",     NULL, 
"TBImages:list_saveas", NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_SAVESRC,   NM_SUB, "Source",       "S", NULL,
+                       ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE, 
0);
+       ami_menu_alloc_item(md, M_SAVETXT,   NM_SUB, "TextNS",       NULL, NULL,
+                       ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT, 0);
+       ami_menu_alloc_item(md, M_SAVECOMP,  NM_SUB, "SaveCompNS",   NULL, NULL,
+                       ami_menu_item_project_save, (void 
*)AMINS_SAVE_COMPLETE, 0);
+#ifdef WITH_PDF_EXPORT
+       ami_menu_alloc_item(md, M_SAVEPDF,   NM_SUB, "PDFNS",        NULL, NULL,
+                       ami_menu_item_project_save, (void *)AMINS_SAVE_PDF, 0);
+#endif
+       ami_menu_alloc_item(md, M_SAVEIFF,   NM_SUB, "IFF",          NULL, NULL,
+                       ami_menu_item_project_save, (void *)AMINS_SAVE_IFF, 0);
+       ami_menu_alloc_item(md, M_BAR_P2,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_PRINT,    NM_ITEM, "PrintNS",      "P", 
"TBImages:list_print",
+                       ami_menu_item_project_print, NULL, NM_ITEMDISABLED);
+       ami_menu_alloc_item(md, M_BAR_P3,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_CLOSETAB, NM_ITEM, "CloseTab",     "K", 
"TBImages:list_remove",
+                       ami_menu_item_project_closetab, NULL, 0);
+       ami_menu_alloc_item(md, M_CLOSEWIN, NM_ITEM, "CloseWindow",  NULL, 
"TBImages:list_cancel",
+                       ami_menu_item_project_closewin, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_P4,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);                                
+       ami_menu_alloc_item(md, M_ABOUT,    NM_ITEM, "About",        "?", 
"TBImages:list_info",
+                       ami_menu_item_project_about, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_P5,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);                                
+       ami_menu_alloc_item(md, M_QUIT,     NM_ITEM, "Quit",         "Q", 
"TBImages:list_warning",
+                       ami_menu_item_project_quit, NULL, 0);
+
+       ami_menu_alloc_item(md, M_EDIT,    NM_TITLE, "Edit",         NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_CUT,      NM_ITEM, "CutNS",        "X", 
"TBImages:list_cut",
+                       ami_menu_item_edit_cut, NULL, 0);
+       ami_menu_alloc_item(md, M_COPY,     NM_ITEM, "CopyNS",       "C", 
"TBImages:list_copy",
+                       ami_menu_item_edit_copy, NULL, 0);
+       ami_menu_alloc_item(md, M_PASTE,    NM_ITEM, "PasteNS",      "V", 
"TBImages:list_paste",
+                       ami_menu_item_edit_paste, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_E1,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_SELALL,   NM_ITEM, "SelectAllNS",  "A", 
NSA_SPACE,
+                       ami_menu_item_edit_selectall, NULL, 0);
+       ami_menu_alloc_item(md, M_CLEAR,    NM_ITEM, "ClearNS",      NULL, 
NSA_SPACE,
+                       ami_menu_item_edit_clearsel, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_E2,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_UNDO,     NM_ITEM, "Undo",         "Z", 
"TBImages:list_undo",
+                       ami_menu_item_edit_undo, NULL, 0);
+       ami_menu_alloc_item(md, M_REDO,     NM_ITEM, "Redo",         "Y", 
"TBImages:list_redo",
+                       ami_menu_item_edit_redo, NULL, 0);
+
+       ami_menu_alloc_item(md, M_BROWSER, NM_TITLE, "Browser",      NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_FIND,     NM_ITEM, "FindTextNS",   "F", 
"TBImages:list_search",
+                       ami_menu_item_browser_find, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_B1,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_HISTLOCL, NM_ITEM, "HistLocalNS",  NULL, 
"TBImages:list_history",
+                       ami_menu_item_browser_localhistory, NULL, 0);
+       ami_menu_alloc_item(md, M_HISTGLBL, NM_ITEM, "HistGlobalNS", NULL, 
"TBImages:list_history",
+                       ami_menu_item_browser_globalhistory, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_B2,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_COOKIES,  NM_ITEM, "ShowCookiesNS",NULL, 
"TBImages:list_internet",
+                       ami_menu_item_browser_cookies, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_B3,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_SCALE,    NM_ITEM, "ScaleNS",      NULL, 
"TBImages:list_preview", NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_SCALEDEC,  NM_SUB, "ScaleDec",     "-", 
"TBImages:list_zoom_out",
+                       ami_menu_item_browser_scale_decrease, NULL, 0);
+       ami_menu_alloc_item(md, M_SCALENRM,  NM_SUB, "ScaleNorm",    "=", 
"TBImages:list_zoom_100",
+                       ami_menu_item_browser_scale_normal, NULL, 0);
+       ami_menu_alloc_item(md, M_SCALEINC,  NM_SUB, "ScaleInc",     "+", 
"TBImages:list_zoom_in",
+                       ami_menu_item_browser_scale_increase, NULL, 0);
+       ami_menu_alloc_item(md, M_IMAGES,   NM_ITEM, "Images",       NULL, 
"TBImages:list_image", NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_IMGFORE,   NM_SUB, "ForeImg",      NULL, NULL,
+                       ami_menu_item_browser_foreimg, NULL, imgfore_flags);
+       ami_menu_alloc_item(md, M_IMGBACK,   NM_SUB, "BackImg",      NULL, NULL,
+                       ami_menu_item_browser_backimg, NULL, imgback_flags);
+       ami_menu_alloc_item(md, M_JS,       NM_ITEM, "EnableJS",     NULL, NULL,
+                       ami_menu_item_browser_enablejs, NULL, js_flags);
+       ami_menu_alloc_item(md, M_BAR_B4,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_REDRAW,   NM_ITEM, "Redraw",       NULL, 
"TBImages:list_wand",
+                       ami_menu_item_browser_redraw, NULL, 0);
+
+       ami_menu_alloc_item(md, M_HOTLIST, NM_TITLE, "Hotlist",      NULL, 
NULL, NULL, NULL, 0);
+       /* see ami_menu_scan for the rest of this menu */
+
+       ami_menu_alloc_item(md, M_PREFS,   NM_TITLE, "Settings",     NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_PREDIT,   NM_ITEM, "SettingsEdit", NULL, 
"TBImages:list_prefs",
+                       ami_menu_item_settings_edit, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_S1,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",NULL, 
"TBImages:list_hold",
+                       ami_menu_item_settings_snapshot, NULL, 0);
+       ami_menu_alloc_item(md, M_PRSAVE,   NM_ITEM, "SettingsSave", NULL, 
"TBImages:list_use",
+                       ami_menu_item_settings_save, NULL, 0);
+
+       ami_menu_alloc_item(md, M_AREXX,   NM_TITLE, "ARexx",        NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, M_AREXXEX,  NM_ITEM, "ARexxExecute", "E", 
"TBImages:list_arexx",
+                       ami_menu_item_arexx_execute, NULL, 0);
+       ami_menu_alloc_item(md, M_BAR_A1,   NM_ITEM, NM_BARLABEL,    NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_MENU_AREXX_MAX,   NM_END, NULL,  NULL, 
NULL, NULL, NULL, 0);
+}
+
+struct Menu *ami_gui_menu_create(struct gui_window_2 *gwin)
+{
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+#ifdef __amigaos4__
+               if(gui_menu != NULL) {
+                       gwin->imenu = gui_menu;
+                       gui_menu_count++;
+                       return gwin->imenu;
+               }
+               ami_init_menulabs(gui_menu_data);
+               ami_menu_scan(gui_menu_data);
+               ami_menu_arexx_scan(gui_menu_data);
+               gwin->imenu = ami_menu_layout(gui_menu_data, 
AMI_MENU_AREXX_MAX);
+
+               gui_menu = gwin->imenu;
+               gui_menu_count++;
+#endif
        } else {
-               if(ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED)
-                       ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= 
CHECKED;
+               ami_init_menulabs(gwin->menu_data);
+               ami_menu_scan(gwin->menu_data);
+               ami_menu_arexx_scan(gwin->menu_data);
+               gwin->imenu = ami_menu_layout(gwin->menu_data, 
AMI_MENU_AREXX_MAX);
        }
 
-       ResetMenuStrip(gwin->win, menustrip);
+       return gwin->imenu;
 }
 
-void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c)
+static void ami_free_menulabs(struct ami_menu_data **md)
 {
-       struct Window *win = g->shared->win;
+       int i;
 
-       if(nsoption_bool(kiosk_mode) == true) return;
+       for(i=0;i<=AMI_MENU_AREXX_MAX;i++) {
+               if(md[i] == NULL) continue;
+               if(md[i]->menulab &&
+                               (md[i]->menulab != NM_BARLABEL) &&
+                               (md[i]->menulab != ML_SEPARATOR)) {
+                       if(md[i]->menutype & MENU_IMAGE) {
+                               if(md[i]->menuobj) 
DisposeObject(md[i]->menuobj);
+                       }
 
-       if(content_get_type(c) <= CONTENT_CSS)
-       {
-               OnMenu(win,AMI_MENU_SAVEAS_TEXT);
-               OnMenu(win,AMI_MENU_SAVEAS_COMPLETE);
-#ifdef WITH_PDF_EXPORT
-               OnMenu(win,AMI_MENU_SAVEAS_PDF);
-#endif
-#if 0
-               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) 
{
-                       OnMenu(win,AMI_MENU_COPY);
-                       OnMenu(win,AMI_MENU_CLEAR);
-               } else {
-                       OffMenu(win,AMI_MENU_COPY);
-                       OffMenu(win,AMI_MENU_CLEAR);    
+                       ami_utf8_free(md[i]->menulab);
+
+                       if(i >= AMI_MENU_AREXX) {
+                               if(md[i]->menu_hook.h_Data) 
free(md[i]->menu_hook.h_Data);
+                               md[i]->menu_hook.h_Data = NULL;
+                       }
                }
 
-               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT)
-                       OnMenu(win,AMI_MENU_CUT);
-               else
-                       OffMenu(win,AMI_MENU_CUT);              
-               
-               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_PASTE)
-                       OnMenu(win,AMI_MENU_PASTE);
-               else
-                       OffMenu(win,AMI_MENU_PASTE);
-#else
-               OnMenu(win,AMI_MENU_CUT);
-               OnMenu(win,AMI_MENU_COPY);
-               OnMenu(win,AMI_MENU_PASTE);
-               OnMenu(win,AMI_MENU_CLEAR);
-#endif
-               OnMenu(win,AMI_MENU_SELECTALL);
-               OnMenu(win,AMI_MENU_FIND);
-               OffMenu(win,AMI_MENU_SAVEAS_IFF);
+               if(md[i]->menukey != NULL) free(md[i]->menukey);
+
+               md[i]->menulab = NULL;
+               md[i]->menuobj = NULL;
+               md[i]->menukey = NULL;
+               md[i]->menutype = 0;
+               free(md[i]);
+               md[i] = NULL;
        }
-       else
-       {
-               OffMenu(win,AMI_MENU_CUT);
-               OffMenu(win,AMI_MENU_PASTE);
-               OffMenu(win,AMI_MENU_CLEAR);
+}
 
-               OffMenu(win,AMI_MENU_SAVEAS_TEXT);
-               OffMenu(win,AMI_MENU_SAVEAS_COMPLETE);
-#ifdef WITH_PDF_EXPORT
-               OffMenu(win,AMI_MENU_SAVEAS_PDF);
-#endif
-               OffMenu(win,AMI_MENU_SELECTALL);
-               OffMenu(win,AMI_MENU_FIND);
+void ami_gui_menu_free(struct gui_window_2 *gwin)
+{
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+#ifdef __amigaos4__
+               gui_menu_count--;
 
-#ifdef WITH_NS_SVG
-               if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == 
true))
-#else
-               if(content_get_bitmap(c))
-#endif
-               {
-                       OnMenu(win,AMI_MENU_COPY);
-                       OnMenu(win,AMI_MENU_SAVEAS_IFF);
-               }
-               else
-               {
-                       OffMenu(win,AMI_MENU_COPY);
-                       OffMenu(win,AMI_MENU_SAVEAS_IFF);
+               SetAttrs(gwin->objects[OID_MAIN], WINDOW_MenuStrip, NULL, 
TAG_DONE);
+
+               if(gui_menu_count == 0) {
+                       ami_free_menulabs(gui_menu_data);
+                       // if we detach our menu from the window we need to do 
this manually
+                       DisposeObject((Object *)gui_menu);
+                       gui_menu = NULL;
                }
+#endif
+       } else {
+               ami_free_menulabs(gwin->menu_data);
+               FreeMenus(gwin->imenu);
        }
 }
 
+bool ami_gui_menu_quit_selected(void)
+{
+       return menu_quit;
+}
+
+void ami_gui_menu_refresh_hotlist(void)
+{
+#ifdef __amigaos4__
+       ami_menu_refresh(gui_menu, gui_menu_data, M_HOTLIST, 
AMI_MENU_HOTLIST_MAX, ami_menu_scan);
+#endif
+}
+
diff --git a/frontends/amiga/menu.h b/frontends/amiga/gui_menu.h
similarity index 56%
copy from frontends/amiga/menu.h
copy to frontends/amiga/gui_menu.h
index ad0e96d..16fc720 100644
--- a/frontends/amiga/menu.h
+++ b/frontends/amiga/gui_menu.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008,2009,2013 Chris Young <[email protected]>
+ * Copyright 2008-2017 Chris Young <[email protected]>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -16,21 +16,11 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef AMIGA_MENU_H
-#define AMIGA_MENU_H
-
-#include <exec/types.h>
-#include <intuition/intuition.h>
-#include <libraries/gadtools.h>
-
-struct hlcache_handle;
-struct ami_menu_data;
-
-/** empty space */
-#define NSA_SPACE "blankspace.png"
+#ifndef AMIGA_GUI_MENU_H
+#define AMIGA_GUI_MENU_H
 
 /** Maximum number of hotlist items (somewhat arbitrary value) */
-#define AMI_HOTLIST_ITEMS 60
+#define AMI_HOTLIST_ITEMS 200
 
 /** Maximum number of ARexx menu items (somewhat arbitrary value) */
 #define AMI_MENU_AREXX_ITEMS 20
@@ -115,49 +105,21 @@ enum {
  * only used for freeing the UTF-8 converted menu labels */
 #define AMI_MENU_MAX AMI_MENU_AREXX
 
-/* The Intuition menu numbers of some menus we might need to modify */
-#define AMI_MENU_SAVEAS_TEXT FULLMENUNUM(0,4,1)
-#define AMI_MENU_SAVEAS_COMPLETE FULLMENUNUM(0,4,2)
-#define AMI_MENU_SAVEAS_IFF FULLMENUNUM(0,4,3)
-#define AMI_MENU_SAVEAS_PDF FULLMENUNUM(0,4,4)
-#define AMI_MENU_CLOSETAB FULLMENUNUM(0,8,0)
-#define AMI_MENU_CUT FULLMENUNUM(1,0,0)
-#define AMI_MENU_COPY FULLMENUNUM(1,1,0)
-#define AMI_MENU_PASTE FULLMENUNUM(1,2,0)
-#define AMI_MENU_SELECTALL FULLMENUNUM(1,4,0)
-#define AMI_MENU_CLEAR FULLMENUNUM(1,5,0)
-#define AMI_MENU_UNDO FULLMENUNUM(1,8,0)
-#define AMI_MENU_REDO FULLMENUNUM(1,9,0)
-#define AMI_MENU_FIND FULLMENUNUM(2,0,0)
-#define AMI_MENU_FOREIMG FULLMENUNUM(2,8,0)
-#define AMI_MENU_BACKIMG FULLMENUNUM(2,8,1)
-#define AMI_MENU_JS FULLMENUNUM(2,9,0)
-
 struct gui_window;
 struct gui_window_2;
+struct hlcache_handle;
 
-/* cleanup */
-void ami_menu_free_glyphs(void);
-
-/* generic menu alloc/free/layout */
-void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type,
-                       const char *restrict label, char key, const char 
*restrict icon,
-                       void *restrict func, void *restrict hookdata, UWORD 
flags);
-struct Menu *ami_menu_layout(struct ami_menu_data **md, int max);
-void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu 
*imenu);
+ULONG ami_gui_menu_number(int item);
+struct Menu *ami_gui_menu_create(struct gui_window_2 *gwin);
+void ami_gui_menu_free(struct gui_window_2 *gwin);
 
-/* specific to browser windows */
-void ami_free_menulabs(struct ami_menu_data **md);
-struct Menu *ami_menu_create(struct gui_window_2 *gwin);
-void ami_menu_refresh(struct gui_window_2 *gwin);
-void ami_menu_update_checked(struct gui_window_2 *gwin);
-void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c);
-void ami_menu_free(struct gui_window_2 *gwin);
+void ami_gui_menu_update_checked(struct gui_window_2 *gwin);
+void ami_gui_menu_update_disabled(struct gui_window *g, struct hlcache_handle 
*c);
 
 /**
  * Sets that an item linked to a toggle menu item has been changed.
  */
-void ami_menu_set_check_toggled(void);
+void ami_gui_menu_set_check_toggled(void);
 
 /**
  * Gets if the menu needs updating because an item linked
@@ -166,13 +128,30 @@ void ami_menu_set_check_toggled(void);
  *
  * \return true if the menus need refreshing
  */
-bool ami_menu_get_check_toggled(void);
+bool ami_gui_menu_get_check_toggled(void);
+
+/**
+ * Set checked state of a menu item
+ * almost generic, but not quite
+ */
+void ami_gui_menu_set_checked(struct Menu *menu, int item, bool check);
+
+/**
+ * Set disabled state of a menu item
+ * almost generic, but not quite
+ */
+void ami_gui_menu_set_disabled(struct Window *win, struct Menu *menu, int 
item, bool disable);
+
+/**
+ * Refresh the Hotlist menu
+ */
+void ami_gui_menu_refresh_hotlist(void);
 
 /**
  * Gets if NetSurf has been quit from the menu
  *
  * \return true if NetSurf has been quit
  */
-bool ami_menu_quit_selected(void);
+bool ami_gui_menu_quit_selected(void);
 #endif
 
diff --git a/frontends/amiga/gui_options.c b/frontends/amiga/gui_options.c
index 698735b..78dea58 100755
--- a/frontends/amiga/gui_options.c
+++ b/frontends/amiga/gui_options.c
@@ -70,6 +70,7 @@
 #include "amiga/font.h"
 #include "amiga/font_bullet.h"
 #include "amiga/gui.h"
+#include "amiga/gui_menu.h"
 #include "amiga/gui_options.h"
 #include "amiga/help.h"
 #include "amiga/libs.h"
@@ -1726,7 +1727,9 @@ static void ami_gui_opts_use(bool save)
        } else {
                nsoption_set_bool(enable_javascript, false);
        }
-       
+
+       ami_gui_menu_set_checked(NULL, M_JS, nsoption_bool(enable_javascript));
+
        GetAttr(GA_Selected,gow->objects[GID_OPTS_DONOTTRACK],(ULONG *)&data);
        if (data) {
                nsoption_set_bool(do_not_track, true);
@@ -2066,7 +2069,7 @@ static void ami_gui_opts_use(bool save)
                ami_font_savescanner(); /* just in case it has changed and been 
used only */
        }
 
-       ami_menu_set_check_toggled();
+       ami_gui_menu_set_check_toggled();
        ami_update_pointer(gow->win, GUI_POINTER_DEFAULT);
 }
 
diff --git a/frontends/amiga/history.c b/frontends/amiga/history.c
index b2a3cc0..12c306a 100644
--- a/frontends/amiga/history.c
+++ b/frontends/amiga/history.c
@@ -49,6 +49,7 @@
 #include "amiga/file.h"
 #include "amiga/history.h"
 #include "amiga/libs.h"
+#include "amiga/menu.h"
 #include "amiga/theme.h"
 #include "amiga/utf8.h"
 
@@ -308,41 +309,41 @@ HOOKF(void, ami_history_global_menu_item_edit_delete, 
APTR, window, struct Intui
 
 static void ami_history_global_menulabs(struct ami_menu_data **md)
 {
-       ami_menu_alloc_item(md, AMI_HISTORY_M_PROJECT, NM_TITLE, "Tree",       
0, NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPORT,   NM_ITEM, "TreeExport", 
'S', "TBImages:list_save",
+       ami_menu_alloc_item(md, AMI_HISTORY_M_PROJECT, NM_TITLE, "Tree", NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPORT,   NM_ITEM, "TreeExport", 
"S", "TBImages:list_save",
                ami_history_global_menu_item_project_export, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND,   NM_ITEM, "Expand", 0, 
"TBImages:list_folderunfold", NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_ALL,   NM_SUB, "All", '+', 
NULL,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P1, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND,   NM_ITEM, "Expand", 
NULL, "TBImages:list_folderunfold", NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_ALL,   NM_SUB, "All", "+", 
NULL,
                ami_history_global_menu_item_project_expand_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_FOLDERS,   NM_SUB, 
"Folders", 0, NULL,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_FOLDERS,   NM_SUB, 
"Folders", NULL, NULL,
                ami_history_global_menu_item_project_expand_folders, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_LINKS,   NM_SUB, "Links", 
0, NULL,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_EXPAND_LINKS,   NM_SUB, "Links", 
NULL, NULL,
                ami_history_global_menu_item_project_expand_links, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE,   NM_ITEM, "Collapse", 
0, "TBImages:list_folderfold", NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_ALL,   NM_SUB, "All", 
'-', NULL,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE,   NM_ITEM, "Collapse", 
NULL, "TBImages:list_folderfold", NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_ALL,   NM_SUB, "All", 
"-", NULL,
                ami_history_global_menu_item_project_collapse_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_FOLDERS,   NM_SUB, 
"Folders", 0, NULL,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_FOLDERS,   NM_SUB, 
"Folders", NULL, NULL,
                ami_history_global_menu_item_project_collapse_folders, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_LINKS,   NM_SUB, 
"Links", 0, NULL,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_COLLAPSE_LINKS,   NM_SUB, 
"Links", NULL, NULL,
                ami_history_global_menu_item_project_collapse_links, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_SNAPSHOT,   NM_ITEM, 
"SnapshotWindow", 0, "TBImages:list_hold",
+       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P2, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_SNAPSHOT,   NM_ITEM, 
"SnapshotWindow", NULL, "TBImages:list_hold",
                ami_history_global_menu_item_project_snapshot, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_CLOSE,   NM_ITEM, "CloseWindow", 
'K', "TBImages:list_cancel",
+       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_P3, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_CLOSE,   NM_ITEM, "CloseWindow", 
"K", "TBImages:list_cancel",
                ami_history_global_menu_item_project_close, NULL, 0);
 
-       ami_menu_alloc_item(md, AMI_HISTORY_M_EDIT, NM_TITLE, "Edit",       0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_SELECTALL,   NM_ITEM, 
"SelectAllNS", 'A', NSA_SPACE,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_EDIT, NM_TITLE, "Edit", NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_SELECTALL,   NM_ITEM, 
"SelectAllNS", "A", NSA_SPACE,
                ami_history_global_menu_item_edit_select_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_CLEAR,   NM_ITEM, "ClearNS", 0, 
NSA_SPACE,
+       ami_menu_alloc_item(md, AMI_HISTORY_M_CLEAR,   NM_ITEM, "ClearNS", 
NULL, NSA_SPACE,
                ami_history_global_menu_item_edit_clear, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HISTORY_M_DELETE,   NM_ITEM, "TreeDelete", 
0, "TBImages:list_delete",
+       ami_menu_alloc_item(md, AMI_HISTORY_M_BAR_E1, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_DELETE,   NM_ITEM, "TreeDelete", 
"Del", "TBImages:list_delete",
                ami_history_global_menu_item_edit_delete, NULL, 0);
 
-       ami_menu_alloc_item(md, AMI_HISTORY_M_LAST,   NM_END, NULL,     0, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HISTORY_M_LAST,   NM_END, NULL, NULL, NULL, 
NULL, NULL, 0);
 }
 
 static struct Menu *
diff --git a/frontends/amiga/hotlist.c b/frontends/amiga/hotlist.c
index 8aa181b..008e45a 100644
--- a/frontends/amiga/hotlist.c
+++ b/frontends/amiga/hotlist.c
@@ -49,6 +49,7 @@
 #include "amiga/file.h"
 #include "amiga/hotlist.h"
 #include "amiga/libs.h"
+#include "amiga/menu.h"
 #include "amiga/theme.h"
 #include "amiga/utf8.h"
 
@@ -404,49 +405,49 @@ HOOKF(void, ami_hotlist_menu_item_edit_delete, APTR, 
window, struct IntuiMessage
 
 static void ami_hotlist_menulabs(struct ami_menu_data **md)
 {
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_PROJECT, NM_TITLE, "Tree",       
0, NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPORT,   NM_ITEM, "TreeExport", 
'S', "TBImages:list_save",
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_PROJECT, NM_TITLE, "Tree", NULL, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPORT,   NM_ITEM, "TreeExport", 
"S", "TBImages:list_save",
                ami_hotlist_menu_item_project_export, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P1, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND,   NM_ITEM, "Expand", 0, 
"TBImages:list_folderunfold", NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_ALL,   NM_SUB, "All", '+', 
NULL,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P1, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND,   NM_ITEM, "Expand", 
NULL, "TBImages:list_folderunfold", NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_ALL,   NM_SUB, "All", "+", 
NULL,
                ami_hotlist_menu_item_project_expand_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_FOLDERS,   NM_SUB, 
"Folders", 0, NULL,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_FOLDERS,   NM_SUB, 
"Folders", NULL, NULL,
                ami_hotlist_menu_item_project_expand_folders, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_LINKS,   NM_SUB, "Links", 
0, NULL,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_EXPAND_LINKS,   NM_SUB, "Links", 
NULL, NULL,
                ami_hotlist_menu_item_project_expand_links, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE,   NM_ITEM, "Collapse", 
0, "TBImages:list_folderfold", NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_ALL,   NM_SUB, "All", 
'-', NULL,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE,   NM_ITEM, "Collapse", 
NULL, "TBImages:list_folderfold", NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_ALL,   NM_SUB, "All", 
"-", NULL,
                ami_hotlist_menu_item_project_collapse_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_FOLDERS,   NM_SUB, 
"Folders", 0, NULL,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_FOLDERS,   NM_SUB, 
"Folders", NULL, NULL,
                ami_hotlist_menu_item_project_collapse_folders, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_LINKS,   NM_SUB, 
"Links", 0, NULL,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_COLLAPSE_LINKS,   NM_SUB, 
"Links", NULL, NULL,
                ami_hotlist_menu_item_project_collapse_links, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P2, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_SNAPSHOT,   NM_ITEM, 
"SnapshotWindow", 0, "TBImages:list_hold",
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P2, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_SNAPSHOT,   NM_ITEM, 
"SnapshotWindow", NULL, "TBImages:list_hold",
                ami_hotlist_menu_item_project_snapshot, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P3, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_CLOSE,   NM_ITEM, "CloseWindow", 
'K', "TBImages:list_cancel",
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_P3, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_CLOSE,   NM_ITEM, "CloseWindow", 
"K", "TBImages:list_cancel",
                ami_hotlist_menu_item_project_close, NULL, 0);
 
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT, NM_TITLE, "Edit",       0, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT, NM_TITLE, "Edit", NULL, 
NULL, NULL, NULL, 0);
 
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWFOLDER,   NM_ITEM, 
"TreeNewFolder", 'N', "TBImages:list_drawer",
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWFOLDER,   NM_ITEM, 
"TreeNewFolder", "N", "TBImages:list_drawer",
                ami_hotlist_menu_item_edit_newfolder, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWLINK,   NM_ITEM, 
"TreeNewLink", 0, "TBImages:list_favouriteadd",
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_NEWLINK,   NM_ITEM, 
"TreeNewLink", NULL, "TBImages:list_favouriteadd",
                ami_hotlist_menu_item_edit_newlink, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT_EDIT,   NM_ITEM, "TreeEdit", 
'E', "TBImages:list_edit",
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_EDIT_EDIT,   NM_ITEM, "TreeEdit", 
"E", "TBImages:list_edit",
                ami_hotlist_menu_item_edit_edit, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E1, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_SELECTALL,   NM_ITEM, 
"SelectAllNS", 'A', NSA_SPACE,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E1, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_SELECTALL,   NM_ITEM, 
"SelectAllNS", "A", NSA_SPACE,
                ami_hotlist_menu_item_edit_select_all, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_CLEAR,   NM_ITEM, "ClearNS", 0, 
NSA_SPACE,
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_CLEAR,   NM_ITEM, "ClearNS", 
NULL, NSA_SPACE,
                ami_hotlist_menu_item_edit_clear, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E2, NM_ITEM, NM_BARLABEL, 0, 
NULL, NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_DELETE,   NM_ITEM, "TreeDelete", 
0, "TBImages:list_delete",
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_BAR_E2, NM_ITEM, NM_BARLABEL, 
NULL, NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_DELETE,   NM_ITEM, "TreeDelete", 
"Del", "TBImages:list_delete",
                ami_hotlist_menu_item_edit_delete, NULL, 0);
 
-       ami_menu_alloc_item(md, AMI_HOTLIST_M_LAST,   NM_END, NULL,     0, 
NULL, NULL, NULL, 0);
+       ami_menu_alloc_item(md, AMI_HOTLIST_M_LAST,   NM_END, NULL, NULL, NULL, 
NULL, NULL, 0);
 }
 
 static struct Menu *
diff --git a/frontends/amiga/menu.c b/frontends/amiga/menu.c
index c354fef..2d2ec4e 100644
--- a/frontends/amiga/menu.c
+++ b/frontends/amiga/menu.c
@@ -21,18 +21,14 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include <proto/dos.h>
-#include <proto/asl.h>
-#include <proto/exec.h>
 #include <proto/gadtools.h>
+#include <proto/graphics.h>
 #include <proto/intuition.h>
-#include <proto/utility.h>
-#ifdef __amigaos4__
-#include <dos/anchorpath.h>
-#include <dos/obsolete.h> /* Needed for ExAll() */
-#endif
 
 #include <libraries/gadtools.h>
+#ifdef __amigaos4__
+#include <intuition/menuclass.h>
+#endif
 
 #include <classes/window.h>
 #include <proto/label.h>
@@ -42,41 +38,13 @@
 
 #include <reaction/reaction_macros.h>
 
-#include "utils/nsoption.h"
-#include "utils/messages.h"
 #include "utils/log.h"
-#include "utils/utils.h"
-#include "utils/nsurl.h"
-#include "netsurf/browser_window.h"
-#include "netsurf/mouse.h"
-#include "netsurf/window.h"
-#include "netsurf/content.h"
-#include "netsurf/keypress.h"
-#include "desktop/hotlist.h"
-#include "desktop/version.h"
-
-#include "amiga/arexx.h"
-#include "amiga/bitmap.h"
-#include "amiga/clipboard.h"
-#include "amiga/cookies.h"
-#include "amiga/file.h"
-#include "amiga/filetype.h"
+#include "utils/messages.h"
+
 #include "amiga/gui.h"
-#include "amiga/gui_options.h"
-#include "amiga/history.h"
-#include "amiga/history_local.h"
-#include "amiga/hotlist.h"
 #include "amiga/libs.h"
 #include "amiga/menu.h"
-#include "amiga/misc.h"
-#include "amiga/nsoption.h"
-#include "amiga/print.h"
-#include "amiga/search.h"
-#include "amiga/theme.h"
 #include "amiga/utf8.h"
-#include "amiga/schedule.h"
-
-#define NSA_MAX_HOTLIST_MENU_LEN 100
 
 enum {
        NSA_GLYPH_SUBMENU,
@@ -86,518 +54,68 @@ enum {
        NSA_GLYPH_MAX
 };
 
-struct ami_menu_data {
-       char *restrict menulab;
-       Object *restrict menuobj;
-       char menukey;
-       char *restrict menuicon;
-       struct Hook menu_hook;
-       UBYTE menutype;
-       UWORD flags;
-};
+#define NSA_MAX_HOTLIST_MENU_LEN 100
 
-static bool menu_quit = false;
-static bool ami_menu_check_toggled = false;
 static Object *restrict menu_glyph[NSA_GLYPH_MAX];
 static int menu_glyph_width[NSA_GLYPH_MAX];
 static bool menu_glyphs_loaded = false;
 
-const char * const netsurf_version;
-const char * const verdate;
-
-static nserror ami_menu_scan(struct ami_menu_data **md);
-void ami_menu_arexx_scan(struct ami_menu_data **md);
-
-void ami_menu_set_check_toggled(void)
-{
-       ami_menu_check_toggled = true;
-}
-
-bool ami_menu_get_check_toggled(void)
-{
-       bool check_toggled = ami_menu_check_toggled;
-       ami_menu_check_toggled = false;
-       return check_toggled;
-}
-
-bool ami_menu_quit_selected(void)
-{
-       return menu_quit;
-}
-
-/*
- * The below functions are called automatically by window.class when menu 
items are selected.
- */
-
-HOOKF(void, ami_menu_item_project_newwin, APTR, window, struct IntuiMessage *)
-{
-       nsurl *url;
-       nserror error;
-
-       error = nsurl_create(nsoption_charp(homepage_url), &url);
-       if (error == NSERROR_OK) {
-               error = browser_window_create(BW_CREATE_HISTORY,
-                                             url,
-                                             NULL,
-                                             NULL,
-                                             NULL);
-               nsurl_unref(url);
-       }
-       if (error != NSERROR_OK) {
-               amiga_warn_user(messages_get_errorcode(error), 0);
-       }
-}
-
-HOOKF(void, ami_menu_item_project_newtab, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-       ami_gui_new_blank_tab(gwin);
-}
-
-HOOKF(void, ami_menu_item_project_open, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_file_open(gwin);
-}
-
-HOOKF(void, ami_menu_item_project_save, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       ULONG type = (ULONG)hook->h_Data;
-
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_file_save_req(type, gwin, browser_window_get_content(gwin->gw->bw));
-}
-
-HOOKF(void, ami_menu_item_project_closetab, APTR, window, struct IntuiMessage 
*)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       browser_window_destroy(gwin->gw->bw);
-}
-
-HOOKF(void, ami_menu_item_project_closewin, APTR, window, struct IntuiMessage 
*)
+bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg)
 {
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       gwin->closed = true;
-}
-
-HOOKF(void, ami_menu_item_project_print, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_set_pointer(gwin, GUI_POINTER_WAIT, false);
-       ami_print_ui(browser_window_get_content(gwin->gw->bw));
-       ami_reset_pointer(gwin);
-}
-
-HOOKF(void, ami_menu_item_project_about, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       char *temp, *temp2;
-       int sel;
-       nsurl *url = NULL;
-       nserror error = NSERROR_OK;
-
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_set_pointer(gwin, GUI_POINTER_WAIT, false);
-
-       temp = ASPrintf("%s|%s|%s", messages_get("OK"),
-                                                               
messages_get("HelpCredits"),
-                                                               
messages_get("HelpLicence"));
+       bool checked = false;
 
-       temp2 = ami_utf8_easy(temp);
-       FreeVec(temp);
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
 #ifdef __amigaos4__
-       sel = TimedDosRequesterTags(TDR_ImageType,TDRIMAGE_INFO,
-                               TDR_TitleString, messages_get("NetSurf"),
-                               TDR_Window, gwin->win,
-                               TDR_GadgetString, temp2,
-                               TDR_FormatString,"NetSurf %s\nBuild date 
%s\n\nhttp://www.netsurf-browser.org";,
-                               TDR_Arg1,netsurf_version,
-                               TDR_Arg2,verdate,
-                               TAG_DONE);
-#else
-       struct EasyStruct about_req = {
-               sizeof(struct EasyStruct),
-               0,
-               "NetSurf",
-               "NetSurf %s\nBuild date %s\n\nhttp://www.netsurf-browser.org";,
-               temp2,
-       };
-
-       sel = EasyRequest(gwin->win, &about_req, NULL, netsurf_version, 
verdate);
-#endif
-       free(temp2);
+               ULONG state;
+               struct ExtIntuiMessage *emsg = (struct ExtIntuiMessage *)msg;
 
-       if(sel == 2) {
-               error = nsurl_create("about:credits", &url);
-       } else if(sel == 0) {
-               error = nsurl_create("about:licence", &url);
-       }
-
-       if(url) {
-               if (error == NSERROR_OK) {
-                       error = browser_window_create(BW_CREATE_HISTORY,
-                                                         url,
-                                                         NULL,
-                                                         NULL,
-                                                         NULL);
-                       nsurl_unref(url);
-               }
-               if (error != NSERROR_OK) {
-                       amiga_warn_user(messages_get_errorcode(error), 0);
-               }
+               state = IDoMethod((Object *)menu, MM_GETSTATE, 0, 
emsg->eim_LongCode, MS_CHECKED);
+               if(state & MS_CHECKED) checked = true;
+#endif 
+       } else {
+               if(ItemAddress(menu, msg->Code)->Flags & CHECKED) checked = 
true;
        }
 
-       ami_reset_pointer(gwin);
+       return checked;
 }
 
-HOOKF(void, ami_menu_item_project_quit, APTR, window, struct IntuiMessage *)
-{
-       menu_quit = true;
-}
-
-HOOKF(void, ami_menu_item_edit_cut, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       browser_window_key_press(gwin->gw->bw, NS_KEY_CUT_SELECTION);
-}
-
-HOOKF(void, ami_menu_item_edit_copy, APTR, window, struct IntuiMessage *)
-{
-       struct bitmap *bm;
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
+/* menu creation code */
+void ami_menu_free_lab_item(struct ami_menu_data **md, int i)
+{
+       if(md[i] == NULL) return;
+       if(md[i]->menulab &&
+                       (md[i]->menulab != NM_BARLABEL) &&
+                       (md[i]->menulab != ML_SEPARATOR)) {
+               if(md[i]->menutype & MENU_IMAGE) {
+                       if(md[i]->menuobj) DisposeObject(md[i]->menuobj);
+               }
 
-       if(browser_window_can_select(gwin->gw->bw)) {
-               browser_window_key_press(gwin->gw->bw, NS_KEY_COPY_SELECTION);
-               browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION);
-       }
-       else if((bm = 
content_get_bitmap(browser_window_get_content(gwin->gw->bw)))) {
-               /** @todo It should be checked that the lifetime of
-                * the objects containing the values returned (and the
-                * constness cast away) is safe.
-                */
-               ami_bitmap_set_url(bm, browser_window_get_url(gwin->gw->bw));
-               ami_bitmap_set_title(bm, 
browser_window_get_title(gwin->gw->bw));
-               ami_easy_clipboard_bitmap(bm);
+               ami_utf8_free(md[i]->menulab);
        }
-#ifdef WITH_NS_SVG
-       else if(ami_mime_compare(browser_window_get_content(gwin->gw->bw), 
"svg") == true) {
-               
ami_easy_clipboard_svg(browser_window_get_content(gwin->gw->bw));
-       }
-#endif
-}
-
-HOOKF(void, ami_menu_item_edit_paste, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       browser_window_key_press(gwin->gw->bw, NS_KEY_PASTE);
-}
-
-HOOKF(void, ami_menu_item_edit_selectall, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       browser_window_key_press(gwin->gw->bw, NS_KEY_SELECT_ALL);
-       gui_start_selection(gwin->gw);
-}
-
-HOOKF(void, ami_menu_item_edit_clearsel, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       browser_window_key_press(gwin->gw->bw, NS_KEY_CLEAR_SELECTION);
-}
-
-HOOKF(void, ami_menu_item_edit_undo, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       browser_window_key_press(gwin->gw->bw, NS_KEY_UNDO);
-}
-
-HOOKF(void, ami_menu_item_edit_redo, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       browser_window_key_press(gwin->gw->bw, NS_KEY_REDO);
-}
-
-HOOKF(void, ami_menu_item_browser_find, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_search_open(gwin->gw);
-}
-
-HOOKF(void, ami_menu_item_browser_localhistory, APTR, window, struct 
IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_history_open(gwin->gw);
-}
-
-HOOKF(void, ami_menu_item_browser_globalhistory, APTR, window, struct 
IntuiMessage *)
-{
-       ami_history_global_present();
-}
 
-HOOKF(void, ami_menu_item_browser_cookies, APTR, window, struct IntuiMessage *)
-{
-       ami_cookies_present();
-}
-
-HOOKF(void, ami_menu_item_browser_foreimg, APTR, window, struct IntuiMessage *)
-{
-       struct Menu *menustrip;
-       bool checked = false;
+       if(md[i]->menukey != NULL) free(md[i]->menukey);
 
-       GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip);
-       if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true;
-       
-       nsoption_set_bool(foreground_images, checked);
-       ami_menu_set_check_toggled();
+       md[i]->menulab = NULL;
+       md[i]->menuobj = NULL;
+       md[i]->menukey = NULL;
+       md[i]->menutype = 0;
+       free(md[i]);
+       md[i] = NULL;
 }
 
-HOOKF(void, ami_menu_item_browser_backimg, APTR, window, struct IntuiMessage *)
-{
-       struct Menu *menustrip;
-       bool checked = false;
-
-       GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip);
-       if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true;
-       
-       nsoption_set_bool(background_images, checked);
-       ami_menu_set_check_toggled();
-}
-
-HOOKF(void, ami_menu_item_browser_enablejs, APTR, window, struct IntuiMessage 
*)
-{
-       struct Menu *menustrip;
-       bool checked = false;
-
-       GetAttr(WINDOW_MenuStrip, (Object *)window, (ULONG *)&menustrip);
-       if(ItemAddress(menustrip, msg->Code)->Flags & CHECKED) checked = true;
-       
-       nsoption_set_bool(enable_javascript, checked);
-       ami_menu_set_check_toggled();
-}
-
-HOOKF(void, ami_menu_item_browser_scale_decrease, APTR, window, struct 
IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_gui_set_scale(gwin->gw, gwin->gw->scale - 0.1);
-}
-
-HOOKF(void, ami_menu_item_browser_scale_normal, APTR, window, struct 
IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_gui_set_scale(gwin->gw, 1.0);
-}
-
-HOOKF(void, ami_menu_item_browser_scale_increase, APTR, window, struct 
IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_gui_set_scale(gwin->gw, gwin->gw->scale + 0.1);
-}
-
-HOOKF(void, ami_menu_item_browser_redraw, APTR, window, struct IntuiMessage *)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       ami_schedule_redraw(gwin, true);
-       gwin->new_content = true;
-}
-
-HOOKF(void, ami_menu_item_hotlist_add, APTR, window, struct IntuiMessage *)
-{
-       struct browser_window *bw;
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       bw = gwin->gw->bw;
-
-       if (bw == NULL || browser_window_has_content(bw) == false)
-               return;
-
-       hotlist_add_url(browser_window_get_url(bw));
-       ami_gui_update_hotlist_button(gwin);
-}
-
-HOOKF(void, ami_menu_item_hotlist_show, APTR, window, struct IntuiMessage *)
-{
-       ami_hotlist_present();
-}
-
-HOOKF(void, ami_menu_item_hotlist_entries, APTR, window, struct IntuiMessage *)
-{
-       nsurl *url = hook->h_Data;
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       if(url == NULL) return;
-
-       browser_window_navigate(gwin->gw->bw,
-                                       url,
-                                       NULL,
-                                       BW_NAVIGATE_HISTORY,
-                                       NULL,
-                                       NULL,
-                                       NULL);
-}
-
-HOOKF(void, ami_menu_item_settings_edit, APTR, window, struct IntuiMessage *)
-{
-       ami_gui_opts_open();
-}
-
-HOOKF(void, ami_menu_item_settings_snapshot, APTR, window, struct IntuiMessage 
*)
-{
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       nsoption_set_int(window_x, gwin->win->LeftEdge);
-       nsoption_set_int(window_y, gwin->win->TopEdge);
-       nsoption_set_int(window_width, gwin->win->Width);
-       nsoption_set_int(window_height, gwin->win->Height);
-}
-
-HOOKF(void, ami_menu_item_settings_save, APTR, window, struct IntuiMessage *)
-{
-       ami_nsoption_write();
-}
-
-HOOKF(void, ami_menu_item_arexx_execute, APTR, window, struct IntuiMessage *)
-{
-       char *temp;
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       if(AslRequestTags(filereq,
-                                               ASLFR_Window, gwin->win,
-                                               ASLFR_SleepWindow, TRUE,
-                                               ASLFR_TitleText, 
messages_get("NetSurf"),
-                                               ASLFR_Screen, scrn,
-                                               ASLFR_DoSaveMode, FALSE,
-                                               ASLFR_InitialDrawer, 
nsoption_charp(arexx_dir),
-                                               ASLFR_InitialPattern, "#?.nsrx",
-                                               TAG_DONE)) {
-               if((temp = malloc(1024))) {
-                       strlcpy(temp, filereq->fr_Drawer, 1024);
-                       AddPart(temp, filereq->fr_File, 1024);
-                       ami_arexx_execute(temp);
-                       free(temp);
-               }
-       }
-}
-
-HOOKF(void, ami_menu_item_arexx_entries, APTR, window, struct IntuiMessage *)
-{
-       char *script = hook->h_Data;
-       char *temp;
-       struct gui_window_2 *gwin;
-       GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
-
-       if(script) {
-               if((temp = malloc(1024))) {
-                       BPTR lock;
-                       if((lock = Lock(nsoption_charp(arexx_dir), 
SHARED_LOCK))) {
-                               DevNameFromLock(lock, temp, 1024, DN_FULLPATH);
-                               AddPart(temp, script, 1024);
-                               ami_arexx_execute(temp);
-                               free(temp);
-                               UnLock(lock);
-                       }
-               }
-       }
-}
-
-
-/* menu creation code */
 static void ami_menu_free_labs(struct ami_menu_data **md, int max)
 {
        int i;
 
        for(i = 0; i <= max; i++) {
-               if(md[i] == NULL) continue;
-               if(md[i]->menulab && (md[i]->menulab != NM_BARLABEL)) {
-                       if(md[i]->menutype & MENU_IMAGE) {
-                               if(md[i]->menuobj) 
DisposeObject(md[i]->menuobj);
-                       }
-
-                       ami_utf8_free(md[i]->menulab);
-               }
-
-               md[i]->menulab = NULL;
-               md[i]->menuobj = NULL;
-               md[i]->menukey = 0;
-               md[i]->menutype = 0;
-               free(md[i]);
-       }
-}
-
-void ami_free_menulabs(struct ami_menu_data **md)
-{
-       int i;
-
-       for(i=0;i<=AMI_MENU_AREXX_MAX;i++) {
-               if(md[i] == NULL) continue;
-               if(md[i]->menulab && (md[i]->menulab != NM_BARLABEL)) {
-                       if(md[i]->menutype & MENU_IMAGE) {
-                               if(md[i]->menuobj) 
DisposeObject(md[i]->menuobj);
-                       }
-
-                       ami_utf8_free(md[i]->menulab);
-
-                       if(i >= AMI_MENU_AREXX) {
-                               if(md[i]->menu_hook.h_Data) 
free(md[i]->menu_hook.h_Data);
-                               md[i]->menu_hook.h_Data = NULL;
-                       }
-               }
-
-               md[i]->menulab = NULL;
-               md[i]->menuobj = NULL;
-               md[i]->menukey = 0;
-               md[i]->menutype = 0;
-               free(md[i]);
+               ami_menu_free_lab_item(md, i);
        }
 }
 
 void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type,
-                       const char *restrict label, char key, const char 
*restrict icon,
+                       const char *restrict label, const char *restrict key, 
const char *restrict icon,
                        void *restrict func, void *restrict hookdata, UWORD 
flags)
 {
-       char menu_icon[1024];
-
        md[num] = calloc(1, sizeof(struct ami_menu_data));
        md[num]->menutype = type;
        md[num]->flags = flags;
@@ -606,12 +124,9 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int 
num, UBYTE type,
 
        if((label == NM_BARLABEL) || (strcmp(label, "--") == 0)) {
                md[num]->menulab = NM_BARLABEL;
+               icon = NULL;
        } else { /* horrid non-generic stuff */
-               if((num >= AMI_MENU_HOTLIST) && (num <= AMI_MENU_HOTLIST_MAX)) {
-                       utf8_from_local_encoding(label,
-                       (strlen(label) < NSA_MAX_HOTLIST_MENU_LEN) ? 
strlen(label) : NSA_MAX_HOTLIST_MENU_LEN,
-                       (char **)&md[num]->menulab);
-               } else if((num >= AMI_MENU_AREXX) && (num < 
AMI_MENU_AREXX_MAX)) {
+               if((num >= AMI_MENU_AREXX) && (num < AMI_MENU_AREXX_MAX)) {
                        md[num]->menulab = strdup(label);               
                } else {
                        md[num]->menulab = ami_utf8_easy(messages_get(label));
@@ -619,11 +134,13 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int 
num, UBYTE type,
        }
 
        md[num]->menuicon = NULL;
-       if(key) md[num]->menukey = key;
+       if(key) md[num]->menukey = strdup(key);
        if(func) md[num]->menu_hook.h_Entry = (HOOKFUNC)func;
        if(hookdata) md[num]->menu_hook.h_Data = hookdata;
 
 #ifdef __amigaos4__
+       char menu_icon[1024];
+
        if(LIB_IS_AT_LEAST((struct Library *)GadToolsBase, 53, 7)) {
                if(icon) {
                        if(ami_locate_resource(menu_icon, icon) == true) {
@@ -637,154 +154,6 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int 
num, UBYTE type,
 #endif
 }
 
-static void ami_init_menulabs(struct ami_menu_data **md)
-{
-       UWORD js_flags = CHECKIT | MENUTOGGLE;
-       if(nsoption_bool(enable_javascript) == true)
-               js_flags |= CHECKED;
-
-       UWORD imgfore_flags = CHECKIT | MENUTOGGLE;
-       if(nsoption_bool(foreground_images) == true)
-               imgfore_flags |= CHECKED;
-
-       UWORD imgback_flags = CHECKIT | MENUTOGGLE;
-       if(nsoption_bool(background_images) == true)
-               imgback_flags |= CHECKED;
-
-       ami_menu_alloc_item(md, M_PROJECT, NM_TITLE, "Project",       0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_NEWWIN,   NM_ITEM, "NewWindowNS", 'N', 
"TBImages:list_app",
-                       ami_menu_item_project_newwin, NULL, 0);
-       ami_menu_alloc_item(md, M_NEWTAB,   NM_ITEM, "NewTab",      'T', 
"TBImages:list_tab",
-                       ami_menu_item_project_newtab, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_P1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_OPEN,     NM_ITEM, "OpenFile",    'O', 
"TBImages:list_folder_misc",
-                       ami_menu_item_project_open, NULL, 0);
-       ami_menu_alloc_item(md, M_SAVEAS,   NM_ITEM, "SaveAsNS",      0, 
"TBImages:list_saveas", NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SAVESRC,   NM_SUB, "Source",      'S', NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_SOURCE, 
0);
-       ami_menu_alloc_item(md, M_SAVETXT,   NM_SUB, "TextNS",        0, NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_TEXT, 0);
-       ami_menu_alloc_item(md, M_SAVECOMP,  NM_SUB, "SaveCompNS",    0, NULL,
-                       ami_menu_item_project_save, (void 
*)AMINS_SAVE_COMPLETE, 0);
-#ifdef WITH_PDF_EXPORT
-       ami_menu_alloc_item(md, M_SAVEPDF,   NM_SUB, "PDFNS",         0, NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_PDF, 0);
-#endif
-       ami_menu_alloc_item(md, M_SAVEIFF,   NM_SUB, "IFF",           0, NULL,
-                       ami_menu_item_project_save, (void *)AMINS_SAVE_IFF, 0);
-       ami_menu_alloc_item(md, M_BAR_P2,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_PRINT,    NM_ITEM, "PrintNS",     'P', 
"TBImages:list_print",
-                       ami_menu_item_project_print, NULL, NM_ITEMDISABLED);
-       ami_menu_alloc_item(md, M_BAR_P3,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_CLOSETAB, NM_ITEM, "CloseTab",    'K', 
"TBImages:list_remove",
-                       ami_menu_item_project_closetab, NULL, 0);
-       ami_menu_alloc_item(md, M_CLOSEWIN, NM_ITEM, "CloseWindow",   0, 
"TBImages:list_cancel",
-                       ami_menu_item_project_closewin, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_P4,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);                          
-       ami_menu_alloc_item(md, M_ABOUT,    NM_ITEM, "About",       '?', 
"TBImages:list_info",
-                       ami_menu_item_project_about, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_P5,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);                          
-       ami_menu_alloc_item(md, M_QUIT,     NM_ITEM, "Quit",        'Q', 
"TBImages:list_warning",
-                       ami_menu_item_project_quit, NULL, 0);
-
-       ami_menu_alloc_item(md, M_EDIT,    NM_TITLE, "Edit",          0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_CUT,      NM_ITEM, "CutNS",       'X', 
"TBImages:list_cut",
-                       ami_menu_item_edit_cut, NULL, 0);
-       ami_menu_alloc_item(md, M_COPY,     NM_ITEM, "CopyNS",      'C', 
"TBImages:list_copy",
-                       ami_menu_item_edit_copy, NULL, 0);
-       ami_menu_alloc_item(md, M_PASTE,    NM_ITEM, "PasteNS",     'V', 
"TBImages:list_paste",
-                       ami_menu_item_edit_paste, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_E1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SELALL,   NM_ITEM, "SelectAllNS", 'A', 
NSA_SPACE,
-                       ami_menu_item_edit_selectall, NULL, 0);
-       ami_menu_alloc_item(md, M_CLEAR,    NM_ITEM, "ClearNS",       0, 
NSA_SPACE,
-                       ami_menu_item_edit_clearsel, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_E2,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_UNDO,     NM_ITEM, "Undo",        'Z', 
"TBImages:list_undo",
-                       ami_menu_item_edit_undo, NULL, 0);
-       ami_menu_alloc_item(md, M_REDO,     NM_ITEM, "Redo",        'Y', 
"TBImages:list_redo",
-                       ami_menu_item_edit_redo, NULL, 0);
-
-       ami_menu_alloc_item(md, M_BROWSER, NM_TITLE, "Browser",       0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_FIND,     NM_ITEM, "FindTextNS",   'F', 
"TBImages:list_search",
-                       ami_menu_item_browser_find, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_B1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_HISTLOCL, NM_ITEM, "HistLocalNS",   0, 
"TBImages:list_history",
-                       ami_menu_item_browser_localhistory, NULL, 0);
-       ami_menu_alloc_item(md, M_HISTGLBL, NM_ITEM, "HistGlobalNS",  0, 
"TBImages:list_history",
-                       ami_menu_item_browser_globalhistory, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_B2,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_COOKIES,  NM_ITEM, "ShowCookiesNS",   0, 
"TBImages:list_internet",
-                       ami_menu_item_browser_cookies, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_B3,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALE,    NM_ITEM, "ScaleNS",       0, 
"TBImages:list_preview", NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALEDEC,  NM_SUB, "ScaleDec",    '-', 
"TBImages:list_zoom_out",
-                       ami_menu_item_browser_scale_decrease, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALENRM,  NM_SUB, "ScaleNorm",   '=', 
"TBImages:list_zoom_100",
-                       ami_menu_item_browser_scale_normal, NULL, 0);
-       ami_menu_alloc_item(md, M_SCALEINC,  NM_SUB, "ScaleInc",    '+', 
"TBImages:list_zoom_in",
-                       ami_menu_item_browser_scale_increase, NULL, 0);
-       ami_menu_alloc_item(md, M_IMAGES,   NM_ITEM, "Images",        0, 
"TBImages:list_image", NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_IMGFORE,   NM_SUB, "ForeImg",       0, NULL,
-                       ami_menu_item_browser_foreimg, NULL, imgfore_flags);
-       ami_menu_alloc_item(md, M_IMGBACK,   NM_SUB, "BackImg",       0, NULL,
-                       ami_menu_item_browser_backimg, NULL, imgback_flags);
-       ami_menu_alloc_item(md, M_JS,       NM_ITEM, "EnableJS",      0, NULL,
-                       ami_menu_item_browser_enablejs, NULL, js_flags);
-       ami_menu_alloc_item(md, M_BAR_B4,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_REDRAW,   NM_ITEM, "Redraw",        0, 
"TBImages:list_wand",
-                       ami_menu_item_browser_redraw, NULL, 0);
-
-       ami_menu_alloc_item(md, M_HOTLIST, NM_TITLE, "Hotlist",       0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_HLADD,    NM_ITEM, "HotlistAdd",  'B', 
"TBImages:list_favouriteadd",
-                       ami_menu_item_hotlist_add, NULL, 0);
-       ami_menu_alloc_item(md, M_HLSHOW,   NM_ITEM,"HotlistShowNS",'H', 
"TBImages:list_favourite",
-                       ami_menu_item_hotlist_show, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_H1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-
-       ami_menu_alloc_item(md, M_PREFS,   NM_TITLE, "Settings",      0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_PREDIT,   NM_ITEM, "SettingsEdit",  0, 
"TBImages:list_prefs",
-                       ami_menu_item_settings_edit, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_S1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_SNAPSHOT, NM_ITEM, "SnapshotWindow",0, 
"TBImages:list_hold",
-                       ami_menu_item_settings_snapshot, NULL, 0);
-       ami_menu_alloc_item(md, M_PRSAVE,   NM_ITEM, "SettingsSave",  0, 
"TBImages:list_use",
-                       ami_menu_item_settings_save, NULL, 0);
-
-       ami_menu_alloc_item(md, M_AREXX,   NM_TITLE, "ARexx",         0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, M_AREXXEX,  NM_ITEM, "ARexxExecute",'E', 
"TBImages:list_arexx",
-                       ami_menu_item_arexx_execute, NULL, 0);
-       ami_menu_alloc_item(md, M_BAR_A1,   NM_ITEM, NM_BARLABEL,     0, NULL, 
NULL, NULL, 0);
-       ami_menu_alloc_item(md, AMI_MENU_AREXX_MAX,   NM_END, NULL,     0, 
NULL, NULL, NULL, 0);
-}
-
-/* Menu refresh for hotlist */
-void ami_menu_refresh(struct gui_window_2 *gwin)
-{
-       return; /**\todo fix this after migrating to menuclass */
-
-       struct Menu *menu;
-
-       LOG("Clearing MenuStrip");
-       SetAttrs(gwin->objects[OID_MAIN],
-                       WINDOW_MenuStrip, NULL,
-                       TAG_DONE);
-
-       LOG("Freeing menu");
-       ami_menu_free(gwin);
-
-       LOG("Freeing menu labels");
-       ami_free_menulabs(gwin->menu_data);
-
-       LOG("Creating new menu");
-       menu = ami_menu_create(gwin);
-
-       LOG("Attaching MenuStrip %p to %p", menu, gwin->objects[OID_MAIN]);
-       SetAttrs(gwin->objects[OID_MAIN],
-                       WINDOW_MenuStrip, menu,
-                       TAG_DONE);
-}
-
 static void ami_menu_load_glyphs(struct DrawInfo *dri)
 {
 #ifdef __amigaos4__
@@ -836,7 +205,7 @@ static int ami_menu_calc_item_width(struct ami_menu_data 
**md, int j, struct Ras
        item_size += space_width;
 
        if(md[j]->menukey) {
-               item_size += TextLength(rp, &md[j]->menukey, 1);
+               item_size += TextLength(rp, md[j]->menukey, 1);
                item_size += menu_glyph_width[NSA_GLYPH_AMIGAKEY];
                /**TODO: take account of the size of other imagery too
                 */
@@ -853,8 +222,72 @@ static int ami_menu_calc_item_width(struct ami_menu_data 
**md, int j, struct Ras
        return item_size;
 }
 
+#ifdef __amigaos4__
+static int ami_menu_layout_mc_recursive(Object *menu_parent, struct 
ami_menu_data **md, int level, int i, int max)
+{
+       int j;
+       Object *menu_item = menu_parent;
+       
+       for(j = i; j < max; j++) {
+               /* skip empty entries */
+               if(md[j] == NULL) continue;
+               if(md[j]->menutype == NM_IGNORE) continue;
+
+               if(md[j]->menutype == level) {
+                       if(md[j]->menulab == NM_BARLABEL)
+                               md[j]->menulab = ML_SEPARATOR;
+
+                       if(level == NM_TITLE) {
+                               menu_item = NewObject(NULL, "menuclass",
+                                       MA_Type, T_MENU,
+                                       MA_Label, md[j]->menulab,
+                                       TAG_DONE);
+                       } else {
+                               menu_item = NewObject(NULL, "menuclass",
+                                       MA_Type, T_ITEM,
+                                       MA_ID, j,
+                                       MA_Label, md[j]->menulab,
+                                       MA_Image,
+                                               BitMapObj,
+                                                       IA_Scalable, TRUE,
+                                                       BITMAP_Screen, scrn,
+                                                       BITMAP_SourceFile, 
md[j]->menuicon,
+                                                       BITMAP_Masking, TRUE,
+                                               BitMapEnd,
+                                       MA_Key, md[j]->menukey,
+                                       MA_UserData, &md[j]->menu_hook, /* NB: 
Intentionally UserData */
+                                       MA_Disabled, (md[j]->flags & 
NM_ITEMDISABLED),
+                                       MA_Selected, (md[j]->flags & CHECKED),
+                                       MA_Toggle, (md[j]->flags & MENUTOGGLE),
+                                       TAG_DONE);
+                       }
 
-struct Menu *ami_menu_layout(struct ami_menu_data **md, int max)
+                       //LOG("Adding item %p ID %d (%s) to parent %p", 
menu_item, j, md[j]->menulab, menu_parent);
+                       IDoMethod(menu_parent, OM_ADDMEMBER, menu_item);
+                       continue;
+               } else if (md[j]->menutype > level) {
+                       j = ami_menu_layout_mc_recursive(menu_item, md, 
md[j]->menutype, j, max);
+               } else {
+                       break;
+               }
+       }
+       return (j - 1);
+}
+
+static struct Menu *ami_menu_layout_mc(struct ami_menu_data **md, int max)
+{
+       Object *menu_root = NewObject(NULL, "menuclass",
+               MA_Type, T_ROOT,
+               MA_EmbeddedKey, FALSE,
+               TAG_DONE);
+
+       ami_menu_layout_mc_recursive(menu_root, md, NM_TITLE, 0, max);
+
+       return (struct Menu *)menu_root;
+}
+#endif
+
+static struct Menu *ami_menu_layout_gt(struct ami_menu_data **md, int max)
 {
        int i, j;
        int txtlen = 0;
@@ -955,7 +388,9 @@ struct Menu *ami_menu_layout(struct ami_menu_data **md, int 
max)
                else
                        nm[i].nm_Label = md[i]->menulab;
 
-               if(md[i]->menukey) nm[i].nm_CommKey = &md[i]->menukey;
+               if((md[i]->menukey) && (strlen(md[i]->menukey) > 1)) {
+                       nm[i].nm_CommKey = md[i]->menukey;
+               }
                nm[i].nm_Flags = md[i]->flags;
                if(md[i]->menu_hook.h_Entry) nm[i].nm_UserData = 
&md[i]->menu_hook;
 
@@ -977,226 +412,59 @@ struct Menu *ami_menu_layout(struct ami_menu_data **md, 
int max)
        return imenu;
 }
 
-void ami_menu_free(struct gui_window_2 *gwin)
+struct Menu *ami_menu_layout(struct ami_menu_data **md, int max)
 {
-       FreeMenus(gwin->imenu);
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+#ifdef __amigaos4__
+               return ami_menu_layout_mc(md, max);
+#endif 
+       } else {
+               return ami_menu_layout_gt(md, max);
+       }
 }
 
 void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu)
 {
        ami_menu_free_labs(md, max);
-       FreeMenus(imenu);
-}
-
-struct Menu *ami_menu_create(struct gui_window_2 *gwin)
-{
-       ami_init_menulabs(gwin->menu_data);
-       ami_menu_scan(gwin->menu_data); //\todo this needs to be MenuClass 
created
-       ami_menu_arexx_scan(gwin->menu_data);
-       gwin->imenu = ami_menu_layout(gwin->menu_data, AMI_MENU_AREXX_MAX);
-
-       return gwin->imenu;
-}
-
-void ami_menu_arexx_scan(struct ami_menu_data **md)
-{
-       /**\todo Rewrite this to not use ExAll() **/
-       int item = AMI_MENU_AREXX;
-       BPTR lock = 0;
-       UBYTE *buffer;
-       struct ExAllControl *ctrl;
-       char matchpatt[16];
-       LONG cont;
-       struct ExAllData *ead;
-       char *menu_lab;
-
-       if((lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK))) {
-               if((buffer = malloc(1024))) {
-                       if((ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL))) {
-                               ctrl->eac_LastKey = 0;
-
-                               if(ParsePatternNoCase("#?.nsrx",(char 
*)&matchpatt,16) != -1) {
-                                       ctrl->eac_MatchString = (char 
*)&matchpatt;
-                               }
-
-                               do {
-                                       cont = ExAll(lock,(struct ExAllData 
*)buffer,1024,ED_COMMENT,ctrl);
-                                       if((!cont) && (IoErr() != 
ERROR_NO_MORE_ENTRIES)) break;
-                                       if(!ctrl->eac_Entries) continue;
-
-                                       for(ead = (struct ExAllData *)buffer; 
ead; ead = ead->ed_Next) {
-                                               if(item >= AMI_MENU_AREXX_MAX) 
continue;
-                                               if(EAD_IS_FILE(ead)) {
-                                                       if(ead->ed_Comment[0] 
!= '\0')
-                                                               menu_lab = 
ead->ed_Comment;
-                                                       else
-                                                               menu_lab = 
ead->ed_Name;
-
-                                                       ami_menu_alloc_item(md, 
item, NM_ITEM, menu_lab, 0, NSA_SPACE,
-                                                               
ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name), 0);
-
-                                                       item++;
-                                               }
-                                       }
-                               } while(cont);
-                               FreeDosObject(DOS_EXALLCONTROL,ctrl);
-                       }
-                       free(buffer);
-               }
-               UnLock(lock);
-       }
-
-       ami_menu_alloc_item(md, item, NM_END, NULL, 0, NULL, NULL, NULL, 0);
-}
-
-static bool ami_menu_hotlist_add(void *userdata, int level, int item, const 
char *title, nsurl *url, bool is_folder)
-{
-       UBYTE type;
-       STRPTR icon;
-       UWORD flags = 0;
-       struct ami_menu_data **md = (struct ami_menu_data **)userdata;
-
-       if(item >= AMI_MENU_HOTLIST_MAX) return false;
-
-       switch(level) {
-               case 1:
-                       type = NM_ITEM;
-               break;
-               case 2:
-                       type = NM_SUB;
-               break;
-               default:
-                       /* entries not at level 1 or 2 are not able to be added
-                        * \todo construct menus using menuclass instead! */
-                       return false;
-               break;
-       }
-
-       if(is_folder == true) {
-               icon = ASPrintf("icons/directory.png");
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+               DisposeObject((Object *)imenu); // if we detach our menu from 
the window we need to do this manually
        } else {
-               icon = ami_gui_get_cache_favicon_name(url, true);
-               if (icon == NULL) icon = ASPrintf("icons/content.png");
+               FreeMenus(imenu);
        }
-
-       if((is_folder == true) && (type == NM_SUB)) {
-               flags = NM_ITEMDISABLED;
-       }
-
-       ami_menu_alloc_item(md, item, type, title,
-               0, icon, ami_menu_item_hotlist_entries, (void *)url, flags);
-
-       if(icon) FreeVec(icon);
-
-       return true;
-}
-
-static nserror ami_menu_scan(struct ami_menu_data **md)
-{
-       return ami_hotlist_scan((void *)md, AMI_MENU_HOTLIST, 
messages_get("HotlistMenu"), ami_menu_hotlist_add);
 }
 
-void ami_menu_update_checked(struct gui_window_2 *gwin)
+void ami_menu_refresh(struct Menu *menu, struct ami_menu_data **md, int 
menu_item, int max,
+       nserror (*cb)(struct ami_menu_data **md))
 {
-       struct Menu *menustrip;
-
-       GetAttr(WINDOW_MenuStrip, gwin->objects[OID_MAIN], (ULONG *)&menustrip);
-       if(!menustrip) return;
-       if(nsoption_bool(enable_javascript) == true) {
-               if((ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED) == 0)
-                       ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED;
-       } else {
-               if(ItemAddress(menustrip, AMI_MENU_JS)->Flags & CHECKED)
-                       ItemAddress(menustrip, AMI_MENU_JS)->Flags ^= CHECKED;
-       }
-       if(nsoption_bool(foreground_images) == true) {
-               if((ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED) 
== 0)
-                       ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= 
CHECKED;
-       } else {
-               if(ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags & CHECKED)
-                       ItemAddress(menustrip, AMI_MENU_FOREIMG)->Flags ^= 
CHECKED;
-       }
-
-       if(nsoption_bool(background_images) == true) {
-               if((ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED) 
== 0)
-                       ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= 
CHECKED;
-       } else {
-               if(ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags & CHECKED)
-                       ItemAddress(menustrip, AMI_MENU_BACKIMG)->Flags ^= 
CHECKED;
-       }
+#ifdef __amigaos4__
+       Object *restrict obj;
+       Object *restrict menu_item_obj;
+       int i;
 
-       ResetMenuStrip(gwin->win, menustrip);
-}
+       if(menu == NULL) return;
 
-void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c)
-{
-       struct Window *win = g->shared->win;
+       if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
+               /* find the address of the menu */
+               menu_item_obj = (Object *)IDoMethod((Object *)menu, MM_FINDID, 
0, menu_item);
 
-       if(nsoption_bool(kiosk_mode) == true) return;
+               /* remove all children */
+               while((obj = (Object *)IDoMethod(menu_item_obj, MM_NEXTCHILD, 
0, NULL)) != NULL) {
+                       IDoMethod(menu_item_obj, OM_REMMEMBER, obj);
+                       DisposeObject(obj);
+               }
 
-       if(content_get_type(c) <= CONTENT_CSS)
-       {
-               OnMenu(win,AMI_MENU_SAVEAS_TEXT);
-               OnMenu(win,AMI_MENU_SAVEAS_COMPLETE);
-#ifdef WITH_PDF_EXPORT
-               OnMenu(win,AMI_MENU_SAVEAS_PDF);
-#endif
-#if 0
-               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) 
{
-                       OnMenu(win,AMI_MENU_COPY);
-                       OnMenu(win,AMI_MENU_CLEAR);
-               } else {
-                       OffMenu(win,AMI_MENU_COPY);
-                       OffMenu(win,AMI_MENU_CLEAR);    
+               /* free associated data */
+               for(i = (menu_item + 1); i <= max; i++) {
+                       if(md[i] == NULL) continue;
+                       ami_menu_free_lab_item(md, i);
                }
 
-               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_CUT)
-                       OnMenu(win,AMI_MENU_CUT);
-               else
-                       OffMenu(win,AMI_MENU_CUT);              
-               
-               if(browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_PASTE)
-                       OnMenu(win,AMI_MENU_PASTE);
-               else
-                       OffMenu(win,AMI_MENU_PASTE);
-#else
-               OnMenu(win,AMI_MENU_CUT);
-               OnMenu(win,AMI_MENU_COPY);
-               OnMenu(win,AMI_MENU_PASTE);
-               OnMenu(win,AMI_MENU_CLEAR);
-#endif
-               OnMenu(win,AMI_MENU_SELECTALL);
-               OnMenu(win,AMI_MENU_FIND);
-               OffMenu(win,AMI_MENU_SAVEAS_IFF);
-       }
-       else
-       {
-               OffMenu(win,AMI_MENU_CUT);
-               OffMenu(win,AMI_MENU_PASTE);
-               OffMenu(win,AMI_MENU_CLEAR);
-
-               OffMenu(win,AMI_MENU_SAVEAS_TEXT);
-               OffMenu(win,AMI_MENU_SAVEAS_COMPLETE);
-#ifdef WITH_PDF_EXPORT
-               OffMenu(win,AMI_MENU_SAVEAS_PDF);
-#endif
-               OffMenu(win,AMI_MENU_SELECTALL);
-               OffMenu(win,AMI_MENU_FIND);
+               /* get current data */
+               cb(md);
 
-#ifdef WITH_NS_SVG
-               if(content_get_bitmap(c) || (ami_mime_compare(c, "svg") == 
true))
-#else
-               if(content_get_bitmap(c))
-#endif
-               {
-                       OnMenu(win,AMI_MENU_COPY);
-                       OnMenu(win,AMI_MENU_SAVEAS_IFF);
-               }
-               else
-               {
-                       OffMenu(win,AMI_MENU_COPY);
-                       OffMenu(win,AMI_MENU_SAVEAS_IFF);
-               }
+               /* re-add items to menu */
+               ami_menu_layout_mc_recursive(menu_item_obj, md, NM_ITEM, 
(menu_item + 1), max);
        }
+#endif
 }
 
diff --git a/frontends/amiga/menu.h b/frontends/amiga/menu.h
index ad0e96d..358faa4 100644
--- a/frontends/amiga/menu.h
+++ b/frontends/amiga/menu.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008,2009,2013 Chris Young <[email protected]>
+ * Copyright 2017 Chris Young <[email protected]>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -23,156 +23,37 @@
 #include <intuition/intuition.h>
 #include <libraries/gadtools.h>
 
-struct hlcache_handle;
-struct ami_menu_data;
+struct ami_menu_data {
+       char *restrict menulab;
+       Object *restrict menuobj;
+       char *restrict menukey;
+       char *restrict menuicon;
+       struct Hook menu_hook;
+       UBYTE menutype;
+       UWORD flags;
+};
 
 /** empty space */
 #define NSA_SPACE "blankspace.png"
 
-/** Maximum number of hotlist items (somewhat arbitrary value) */
-#define AMI_HOTLIST_ITEMS 60
-
-/** Maximum number of ARexx menu items (somewhat arbitrary value) */
-#define AMI_MENU_AREXX_ITEMS 20
-
-/** enum menu structure, has to be here as we need it below. */
-enum {
-       /* Project menu */
-       M_PROJECT = 0,
-        M_NEWWIN,
-        M_NEWTAB,
-        M_BAR_P1,
-        M_OPEN,
-        M_SAVEAS,
-         M_SAVESRC,
-         M_SAVETXT,
-         M_SAVECOMP,
-         M_SAVEIFF,
-#ifdef WITH_PDF_EXPORT
-         M_SAVEPDF,
-#endif
-        M_BAR_P2,
-        M_PRINT,
-        M_BAR_P3,
-        M_CLOSETAB,
-        M_CLOSEWIN,
-        M_BAR_P4,
-        M_ABOUT,
-        M_BAR_P5,
-        M_QUIT,
-       /* Edit menu */
-       M_EDIT,
-        M_CUT,
-        M_COPY,
-        M_PASTE,
-        M_BAR_E1,
-        M_SELALL,
-        M_CLEAR,
-        M_BAR_E2,
-        M_UNDO,
-        M_REDO,
-       /* Browser menu */
-       M_BROWSER,
-        M_FIND,
-        M_BAR_B1,
-        M_HISTLOCL,
-        M_HISTGLBL,
-        M_BAR_B2,
-        M_COOKIES,
-        M_BAR_B3,
-        M_SCALE,
-         M_SCALEDEC,
-         M_SCALENRM,
-         M_SCALEINC,
-        M_IMAGES,
-         M_IMGFORE,
-         M_IMGBACK,
-        M_JS,
-        M_BAR_B4,
-        M_REDRAW,
-       /* Hotlist menu */
-       M_HOTLIST,
-        M_HLADD,
-        M_HLSHOW,
-        M_BAR_H1, // 47
-        AMI_MENU_HOTLIST, /* Where the hotlist entries start */
-        AMI_MENU_HOTLIST_MAX = AMI_MENU_HOTLIST + AMI_HOTLIST_ITEMS,
-       /* Settings menu */
-       M_PREFS,
-        M_PREDIT,
-        M_BAR_S1,
-        M_SNAPSHOT,
-        M_PRSAVE,
-       /* ARexx menu */
-       M_AREXX,
-        M_AREXXEX,
-        M_BAR_A1,
-        AMI_MENU_AREXX,
-        AMI_MENU_AREXX_MAX = AMI_MENU_AREXX + AMI_MENU_AREXX_ITEMS
-};
-
-/* We can get away with AMI_MENU_MAX falling short as it is
- * only used for freeing the UTF-8 converted menu labels */
-#define AMI_MENU_MAX AMI_MENU_AREXX
-
-/* The Intuition menu numbers of some menus we might need to modify */
-#define AMI_MENU_SAVEAS_TEXT FULLMENUNUM(0,4,1)
-#define AMI_MENU_SAVEAS_COMPLETE FULLMENUNUM(0,4,2)
-#define AMI_MENU_SAVEAS_IFF FULLMENUNUM(0,4,3)
-#define AMI_MENU_SAVEAS_PDF FULLMENUNUM(0,4,4)
-#define AMI_MENU_CLOSETAB FULLMENUNUM(0,8,0)
-#define AMI_MENU_CUT FULLMENUNUM(1,0,0)
-#define AMI_MENU_COPY FULLMENUNUM(1,1,0)
-#define AMI_MENU_PASTE FULLMENUNUM(1,2,0)
-#define AMI_MENU_SELECTALL FULLMENUNUM(1,4,0)
-#define AMI_MENU_CLEAR FULLMENUNUM(1,5,0)
-#define AMI_MENU_UNDO FULLMENUNUM(1,8,0)
-#define AMI_MENU_REDO FULLMENUNUM(1,9,0)
-#define AMI_MENU_FIND FULLMENUNUM(2,0,0)
-#define AMI_MENU_FOREIMG FULLMENUNUM(2,8,0)
-#define AMI_MENU_BACKIMG FULLMENUNUM(2,8,1)
-#define AMI_MENU_JS FULLMENUNUM(2,9,0)
-
-struct gui_window;
-struct gui_window_2;
-
 /* cleanup */
 void ami_menu_free_glyphs(void);
 
 /* generic menu alloc/free/layout */
 void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type,
-                       const char *restrict label, char key, const char 
*restrict icon,
+                       const char *restrict label, const char *restrict key, 
const char *restrict icon,
                        void *restrict func, void *restrict hookdata, UWORD 
flags);
 struct Menu *ami_menu_layout(struct ami_menu_data **md, int max);
 void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu 
*imenu);
+void ami_menu_free_lab_item(struct ami_menu_data **md, int i);
 
-/* specific to browser windows */
-void ami_free_menulabs(struct ami_menu_data **md);
-struct Menu *ami_menu_create(struct gui_window_2 *gwin);
-void ami_menu_refresh(struct gui_window_2 *gwin);
-void ami_menu_update_checked(struct gui_window_2 *gwin);
-void ami_menu_update_disabled(struct gui_window *g, struct hlcache_handle *c);
-void ami_menu_free(struct gui_window_2 *gwin);
+/* refresh a menu's children */
+void ami_menu_refresh(struct Menu *menu, struct ami_menu_data **md, int 
menu_item, int max,
+       nserror (*cb)(struct ami_menu_data **md));
 
 /**
- * Sets that an item linked to a toggle menu item has been changed.
- */
-void ami_menu_set_check_toggled(void);
-
-/**
- * Gets if the menu needs updating because an item linked
- * to a toggle menu item has been changed.
- * NB: This also *clears* the state
- *
- * \return true if the menus need refreshing
- */
-bool ami_menu_get_check_toggled(void);
-
-/**
- * Gets if NetSurf has been quit from the menu
- *
- * \return true if NetSurf has been quit
+ * Get the selected state of a menu item
  */
-bool ami_menu_quit_selected(void);
+bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg);
 #endif
 


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to