Attempt hotlist menu refresh

This commit is contained in:
Chris Young 2017-01-15 17:51:55 +00:00
parent b8640956d4
commit b78d6f458e
6 changed files with 79 additions and 16 deletions

View File

@ -3327,6 +3327,8 @@ void ami_gui_hotlist_update_all(void)
if(IsMinListEmpty(window_list)) return;
ami_gui_menu_refresh_hotlist();
node = (struct nsObject *)GetHead((struct List *)window_list);
do {
@ -3336,7 +3338,6 @@ void ami_gui_hotlist_update_all(void)
if(node->Type == AMINS_WINDOW)
{
ami_gui_hotlist_toolbar_update(gwin);
//ami_gui_menu_refresh_hotlist(gwin);
}
} while((node = nnode));
}

View File

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

View File

@ -80,8 +80,11 @@
#include "amiga/utf8.h"
#include "amiga/schedule.h"
#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 ami_menu_check_toggled = false;
static bool menu_quit = false;
@ -900,6 +903,12 @@ 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);
}
@ -1002,11 +1011,7 @@ static void ami_init_menulabs(struct ami_menu_data **md)
ami_menu_item_browser_redraw, NULL, 0);
ami_menu_alloc_item(md, M_HOTLIST, NM_TITLE, "Hotlist", NULL, 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, 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",
@ -1027,21 +1032,25 @@ static void ami_init_menulabs(struct ami_menu_data **md)
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);
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);
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
gui_menu = gwin->imenu;
gui_menu_count++;
#endif
} else {
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);
}
return gwin->imenu;
@ -1081,14 +1090,16 @@ static void ami_free_menulabs(struct ami_menu_data **md)
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--;
if(gui_menu_count == 0) {
ami_free_menulabs(gwin->menu_data);
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);
@ -1100,3 +1111,10 @@ 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
}

View File

@ -142,6 +142,10 @@ void ami_gui_menu_set_checked(struct Menu *menu, int item, bool check);
*/
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

View File

@ -80,7 +80,7 @@ bool ami_menu_get_selected(struct Menu *menu, struct IntuiMessage *msg)
}
/* menu creation code */
static void ami_menu_free_lab_item(struct ami_menu_data **md, int i)
void ami_menu_free_lab_item(struct ami_menu_data **md, int i)
{
if(md[i] == NULL) return;
if(md[i]->menulab &&
@ -435,3 +435,38 @@ void ami_menu_free_menu(struct ami_menu_data **md, int max, struct Menu *imenu)
}
}
void ami_menu_refresh(struct Menu *menu, struct ami_menu_data **md, int menu_item, int max,
nserror (*cb)(struct ami_menu_data **md))
{
#ifdef __amigaos4__
Object *restrict obj;
Object *restrict menu_item_obj;
int i;
if(menu == NULL) return;
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);
/* remove all children */
while((obj = (Object *)IDoMethod(menu_item_obj, MM_NEXTCHILD, 0, NULL)) != NULL) {
IDoMethod(menu_item_obj, OM_REMMEMBER, obj);
/* do we need to disposeobject? */
}
/* free associated data */
for(i = (menu_item + 1); i <= max; i++) {
if(md[i] == NULL) continue;
ami_menu_free_lab_item(md, i);
}
/* get current data */
cb(md);
/* re-add items to menu */
ami_menu_layout_mc_recursive(menu_item_obj, md, NM_ITEM, (menu_item + 1), max);
}
#endif
}

View File

@ -45,6 +45,11 @@ void ami_menu_alloc_item(struct ami_menu_data **md, int num, UBYTE type,
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);
/* 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));
/**
* Get the selected state of a menu item