Complete context menu items for links

This commit is contained in:
Chris Young 2015-09-04 23:38:04 +01:00
parent 41f219192c
commit a15e5a7869
4 changed files with 69 additions and 34 deletions

View File

@ -327,7 +327,7 @@ void ami_drag_selection(struct gui_window *g)
}
}
bool ami_easy_clipboard(char *text)
bool ami_easy_clipboard(const char *text)
{
gui_set_clipboard(text, strlen(text), NULL, 0);
return true;

View File

@ -34,7 +34,7 @@ void gui_start_selection(struct gui_window *g);
void ami_clipboard_init(void);
void ami_clipboard_free(void);
void ami_drag_selection(struct gui_window *g);
bool ami_easy_clipboard(char *text);
bool ami_easy_clipboard(const char *text);
bool ami_easy_clipboard_bitmap(struct bitmap *bitmap);
#ifdef WITH_NS_SVG
bool ami_easy_clipboard_svg(struct hlcache_handle *c);

View File

@ -34,6 +34,7 @@
#include <intuition/menuclass.h>
#include <reaction/reaction_macros.h>
#include "amiga/clipboard.h"
#include "amiga/ctxmenu.h"
#include "amiga/gui.h"
#include "amiga/libs.h"
@ -49,31 +50,19 @@
#include "utils/nsoption.h"
enum {
AMI_CTX_ID_TEST = 1,
AMI_CTX_ID_URLOPEN,
AMI_CTX_ID_URLOPENWIN,
AMI_CTX_ID_DUMMY = 0,
/* Links */
AMI_CTX_ID_URLOPENTAB,
AMI_CTX_ID_URLOPENWIN,
AMI_CTX_ID_URLDOWNLOAD,
AMI_CTX_ID_URLCOPY,
/* History */
AMI_CTX_ID_HISTORY,
AMI_CTX_ID_HISTORY0,
AMI_CTX_ID_HISTORY1,
AMI_CTX_ID_HISTORY2,
AMI_CTX_ID_HISTORY3,
AMI_CTX_ID_HISTORY4,
AMI_CTX_ID_HISTORY5,
AMI_CTX_ID_HISTORY6,
AMI_CTX_ID_HISTORY7,
AMI_CTX_ID_HISTORY8,
AMI_CTX_ID_HISTORY9,
AMI_CTX_ID_HISTORY0F,
AMI_CTX_ID_HISTORY1F,
AMI_CTX_ID_HISTORY2F,
AMI_CTX_ID_HISTORY3F,
AMI_CTX_ID_HISTORY4F,
AMI_CTX_ID_HISTORY5F,
AMI_CTX_ID_HISTORY6F,
AMI_CTX_ID_HISTORY7F,
AMI_CTX_ID_HISTORY8F,
AMI_CTX_ID_HISTORY9F,
AMI_CTX_ID_HISTORY9F = AMI_CTX_ID_HISTORY0 + 19,
AMI_CTX_ID_MAX
};
@ -83,6 +72,10 @@ static struct Hook ctxmenu_item_hook[AMI_CTX_ID_MAX];
static char *ctxmenu_item_label[AMI_CTX_ID_MAX];
static Object *ctxmenu_item_image[AMI_CTX_ID_MAX];
/****************************
* Menu item hook functions *
****************************/
/** Menu functions - called automatically by RA_HandleInput **/
HOOKF(void, ami_ctxmenu_item_urlopentab, APTR, window, struct IntuiMessage *)
{
@ -118,6 +111,29 @@ HOOKF(void, ami_ctxmenu_item_urlopenwin, APTR, window, struct IntuiMessage *)
warn_user(messages_get_errorcode(error), 0);
}
HOOKF(void, ami_ctxmenu_item_urldownload, APTR, window, struct IntuiMessage *)
{
nsurl *url = (nsurl *)hook->h_Data;
struct gui_window_2 *gwin;
GetAttr(WINDOW_UserData, (Object *)window, (ULONG *)&gwin);
browser_window_navigate(gwin->gw->bw,
url,
browser_window_get_url(gwin->gw->bw),
BW_NAVIGATE_DOWNLOAD,
NULL,
NULL,
NULL);
}
HOOKF(void, ami_ctxmenu_item_urlcopy, APTR, window, struct IntuiMessage *)
{
nsurl *url = (nsurl *)hook->h_Data;
ami_easy_clipboard(nsurl_access(url));
}
/** Hook for history context menu entries **/
HOOKF(void, ami_ctxmenu_item_history, APTR, window, struct IntuiMessage *)
{
struct gui_window_2 *gwin;
@ -128,6 +144,9 @@ HOOKF(void, ami_ctxmenu_item_history, APTR, window, struct IntuiMessage *)
}
/*************************
* Browser context menus *
*************************/
/** Add an initialised item to a context menu **/
static void ami_ctxmenu_add_item(Object *root_menu, int id, APTR data)
@ -181,6 +200,8 @@ static uint32 ami_ctxmenu_hook_func(struct Hook *hook, struct Window *window, st
if(ccdata.link) {
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLOPENTAB, ccdata.link);
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLOPENWIN, ccdata.link);
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLDOWNLOAD, ccdata.link);
ami_ctxmenu_add_item(root_menu, AMI_CTX_ID_URLCOPY, ccdata.link);
ctxmenu_has_content = true;
}
@ -229,13 +250,6 @@ void ami_ctxmenu_release_hook(struct Hook *hook)
FreeSysObject(ASOT_HOOK, hook);
}
/** Exported interface documented in ctxmenu.h **/
void ami_ctxmenu_init(void)
{
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLOPENWIN, "LinkNewWin", "TBImages:list_app", ami_ctxmenu_item_urlopenwin);
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLOPENTAB, "LinkNewTab", "TBImages:list_add", ami_ctxmenu_item_urlopentab);
}
/** Exported interface documented in ctxmenu.h **/
void ami_ctxmenu_free(void)
{
@ -255,7 +269,23 @@ void ami_ctxmenu_free(void)
ctxmenu_obj = NULL;
}
/** Exported interface documented in ctxmenu.h **/
void ami_ctxmenu_init(void)
{
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLOPENTAB, "LinkNewTab", "TBImages:list_tab",
ami_ctxmenu_item_urlopentab);
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLOPENWIN, "LinkNewWin", "TBImages:list_app",
ami_ctxmenu_item_urlopenwin);
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLDOWNLOAD, "LinkDload", "TBImages:list_saveas",
ami_ctxmenu_item_urldownload);
ami_ctxmenu_alloc_item(AMI_CTX_ID_URLCOPY, "CopyURL", "TBImages:list_copy",
ami_ctxmenu_item_urlcopy);
}
/********************************
* History button context menus *
********************************/
/** Create menu entries from browser history **/
static bool ami_ctxmenu_history(int direction, struct gui_window_2 *gwin, const struct history_entry *entry)

View File

@ -59,17 +59,22 @@ struct Hook *ami_ctxmenu_get_hook(APTR data);
void ami_ctxmenu_release_hook(struct Hook *hook);
/**
* Create history context menu. First run sets up the menu, next creates entries.
* Create history context menu
* The first time this is run it will create an empty menu,
* Subsequent runs will (re-)populate with the history.
* This is to allow the pointer to be obtained before the browser_winodw is opened.
*
* \param direction AMI_CTXMENU_HISTORY_(BACK|FORWARD)
* \param gwin struct gui_window_2 *
* \returns pointer to menu
* \returns pointer to menu (for convenience, is also stored in gwin structure)
* The returned pointer MUST be disposed of with DisposeObject before program exit.
*/
struct Menu *ami_ctxmenu_history_create(int direction, struct gui_window_2 *gwin);
#else
inline void ami_ctxmenu_init(void) {}
inline void ami_ctxmenu_free(void) {}
inline struct Hook *ami_ctxmenu_get_hook(APTR data) {return NULL;}
inline void ami_ctxmenu_release_hook(struct Hook *hook) {}
inline struct Menu *ami_ctxmenu_history_create(int direction, struct gui_window_2 *gwin) {return NULL;}
#endif