mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-18 08:39:50 +03:00
Move the hotlist menu creator into hotlist.c and make it more generic
This commit is contained in:
parent
177b46e873
commit
fda365fb2d
@ -19,6 +19,17 @@
|
||||
#include <proto/exec.h>
|
||||
#include "amiga/hotlist.h"
|
||||
#include "amiga/tree.h"
|
||||
#include "desktop/hotlist.h"
|
||||
|
||||
struct ami_hotlist_ctx {
|
||||
struct gui_window_2 *gw;
|
||||
int level;
|
||||
int item;
|
||||
const char *folder; /* folder we're interested in */
|
||||
bool in_menu; /* set if we are in that folder */
|
||||
bool (*cb)(struct gui_window_2 *gw, int level, int item, const char *title, nsurl *url, bool folder);
|
||||
};
|
||||
|
||||
|
||||
void ami_hotlist_initialise(const char *hotlist_file)
|
||||
{
|
||||
@ -33,3 +44,61 @@ void ami_hotlist_free(const char *hotlist_file)
|
||||
ami_tree_destroy(hotlist_window);
|
||||
hotlist_window = NULL;
|
||||
}
|
||||
|
||||
|
||||
static nserror ami_hotlist_folder_enter_cb(void *ctx, const char *title)
|
||||
{
|
||||
struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
|
||||
|
||||
if(menu_ctx->in_menu == true) {
|
||||
if(menu_ctx->cb(menu_ctx->gw, menu_ctx->level, menu_ctx->item, title, NULL, true) == true)
|
||||
menu_ctx->item++;
|
||||
} else {
|
||||
if((menu_ctx->level == 0) && (strcmp(title, menu_ctx->folder) == 0))
|
||||
menu_ctx->in_menu = true;
|
||||
}
|
||||
menu_ctx->level++;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static nserror ami_hotlist_address_cb(void *ctx, nsurl *url, const char *title)
|
||||
{
|
||||
struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
|
||||
|
||||
if(menu_ctx->in_menu == true) {
|
||||
if(menu_ctx->cb(menu_ctx->gw, menu_ctx->level, menu_ctx->item, title, url, false) == true)
|
||||
menu_ctx->item++;
|
||||
}
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static nserror ami_hotlist_folder_leave_cb(void *ctx)
|
||||
{
|
||||
struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
|
||||
|
||||
menu_ctx->level--;
|
||||
|
||||
if((menu_ctx->in_menu == true) && (menu_ctx->level == 0))
|
||||
menu_ctx->in_menu = false;
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
nserror ami_hotlist_scan(struct gui_window_2 *gwin, int first_item, const char *folder,
|
||||
bool (*cb_add_item)(struct gui_window_2 *gw, int level, int item, const char *title, nsurl *url, bool folder))
|
||||
{
|
||||
struct ami_hotlist_ctx ctx;
|
||||
|
||||
ctx.level = 0;
|
||||
ctx.item = first_item;
|
||||
ctx.folder = folder;
|
||||
ctx.in_menu = false;
|
||||
ctx.gw = gwin;
|
||||
ctx.cb = cb_add_item;
|
||||
|
||||
return hotlist_iterate(&ctx,
|
||||
ami_hotlist_folder_enter_cb,
|
||||
ami_hotlist_address_cb,
|
||||
ami_hotlist_folder_leave_cb);
|
||||
}
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
void ami_hotlist_initialise(const char *hotlist_file);
|
||||
void ami_hotlist_free(const char *hotlist_file);
|
||||
nserror ami_hotlist_scan(struct gui_window_2 *gwin, int first_item, const char *folder,
|
||||
bool (*cb_add_item)(struct gui_window_2 *gw, int level, int item, const char *title, nsurl *url, bool folder));
|
||||
|
||||
struct treeview_window *hotlist_window;
|
||||
#endif
|
||||
|
73
amiga/menu.c
73
amiga/menu.c
@ -73,14 +73,6 @@ enum {
|
||||
NSA_GLYPH_MAX
|
||||
};
|
||||
|
||||
struct ami_hotlist_ctx {
|
||||
struct gui_window_2 *gw;
|
||||
int level;
|
||||
int item;
|
||||
bool in_menu;
|
||||
};
|
||||
|
||||
|
||||
BOOL menualreadyinit;
|
||||
const char * const netsurf_version;
|
||||
const char * const verdate;
|
||||
@ -543,15 +535,14 @@ void ami_menu_arexx_scan(struct gui_window_2 *gwin)
|
||||
gwin->menu[item].nm_Label = NULL;
|
||||
}
|
||||
|
||||
static nserror ami_menu_hotlist_add(void *ctx, const char *title, nsurl *url, bool is_folder)
|
||||
static bool ami_menu_hotlist_add(struct gui_window_2 *gw, int level, int item, const char *title, nsurl *url, bool is_folder)
|
||||
{
|
||||
struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
|
||||
UBYTE type;
|
||||
char *icon;
|
||||
|
||||
if(menu_ctx->item >= AMI_MENU_HOTLIST_MAX) return NSERROR_OK;
|
||||
if(item >= AMI_MENU_HOTLIST_MAX) return false;
|
||||
|
||||
switch(menu_ctx->level) {
|
||||
switch(level) {
|
||||
case 1:
|
||||
type = NM_ITEM;
|
||||
break;
|
||||
@ -560,7 +551,7 @@ static nserror ami_menu_hotlist_add(void *ctx, const char *title, nsurl *url, bo
|
||||
break;
|
||||
default:
|
||||
/* entries not at level 1 or 2 are not able to be added */
|
||||
return NSERROR_OK;
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -570,65 +561,17 @@ static nserror ami_menu_hotlist_add(void *ctx, const char *title, nsurl *url, bo
|
||||
icon = "icons/content.png";
|
||||
}
|
||||
|
||||
ami_menu_alloc_item(menu_ctx->gw, menu_ctx->item, type, title,
|
||||
ami_menu_alloc_item(gw, item, type, title,
|
||||
0, icon, ami_menu_item_hotlist_entries, (void *)url);
|
||||
if((is_folder == true) && (type == NM_SUB))
|
||||
menu_ctx->gw->menu[menu_ctx->item].nm_Flags = NM_ITEMDISABLED;
|
||||
gw->menu[item].nm_Flags = NM_ITEMDISABLED;
|
||||
|
||||
menu_ctx->item++;
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static nserror ami_menu_hotlist_folder_enter_cb(void *ctx, const char *title)
|
||||
{
|
||||
struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
|
||||
|
||||
if(menu_ctx->in_menu == true) {
|
||||
ami_menu_hotlist_add(menu_ctx, title, NULL, true);
|
||||
} else {
|
||||
if((menu_ctx->level == 0) && (strcmp(title, messages_get("HotlistMenu")) == 0))
|
||||
menu_ctx->in_menu = true;
|
||||
}
|
||||
menu_ctx->level++;
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static nserror ami_menu_hotlist_address_cb(void *ctx, nsurl *url, const char *title)
|
||||
{
|
||||
struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
|
||||
|
||||
if(menu_ctx->in_menu == true)
|
||||
ami_menu_hotlist_add(menu_ctx, title, url, false);
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
static nserror ami_menu_hotlist_folder_leave_cb(void *ctx)
|
||||
{
|
||||
struct ami_hotlist_ctx *menu_ctx = (struct ami_hotlist_ctx *)ctx;
|
||||
|
||||
menu_ctx->level--;
|
||||
|
||||
if((menu_ctx->in_menu == true) && (menu_ctx->level == 0))
|
||||
menu_ctx->in_menu = false;
|
||||
|
||||
return NSERROR_OK;
|
||||
return true;
|
||||
}
|
||||
|
||||
static nserror ami_menu_scan(struct tree *tree, struct gui_window_2 *gwin)
|
||||
{
|
||||
struct ami_hotlist_ctx ctx;
|
||||
|
||||
ctx.level = 0;
|
||||
ctx.item = AMI_MENU_HOTLIST;
|
||||
ctx.in_menu = false;
|
||||
ctx.gw = gwin;
|
||||
|
||||
return hotlist_iterate(&ctx,
|
||||
ami_menu_hotlist_folder_enter_cb,
|
||||
ami_menu_hotlist_address_cb,
|
||||
ami_menu_hotlist_folder_leave_cb);
|
||||
return ami_hotlist_scan(gwin, AMI_MENU_HOTLIST, messages_get("HotlistMenu"), ami_menu_hotlist_add);
|
||||
}
|
||||
|
||||
void ami_menu_update_checked(struct gui_window_2 *gwin)
|
||||
|
Loading…
Reference in New Issue
Block a user