Save object

svn path=/trunk/netsurf/; revision=5909
This commit is contained in:
Chris Young 2008-12-13 23:26:10 +00:00
parent 0951de5c0e
commit 689f2e4232
2 changed files with 36 additions and 10 deletions

View File

@ -30,6 +30,7 @@
#include <proto/dos.h> #include <proto/dos.h>
#include <string.h> #include <string.h>
#include "utils/utils.h" #include "utils/utils.h"
#include <proto/asl.h>
uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved); uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved);
@ -41,17 +42,10 @@ void ami_context_menu_init(void)
ctxmenulab[CMID_COPYURL] = ami_utf8_easy((char *)messages_get("CopyURL")); ctxmenulab[CMID_COPYURL] = ami_utf8_easy((char *)messages_get("CopyURL"));
ctxmenulab[CMID_SHOWOBJ] = ami_utf8_easy((char *)messages_get("ObjShow")); ctxmenulab[CMID_SHOWOBJ] = ami_utf8_easy((char *)messages_get("ObjShow"));
ctxmenulab[CMID_COPYOBJ] = ami_utf8_easy((char *)messages_get("CopyURL")); ctxmenulab[CMID_COPYOBJ] = ami_utf8_easy((char *)messages_get("CopyURL"));
ctxmenulab[CMID_SAVEOBJ] = ami_utf8_easy((char *)messages_get("ObjSave"));
if(!option_force_tabs) ctxmenulab[CMID_URLOPENWIN] = ami_utf8_easy((char *)messages_get("LinkNewWin"));
{ ctxmenulab[CMID_URLOPENTAB] = ami_utf8_easy((char *)messages_get("LinkNewTab"));
ctxmenulab[CMID_URLOPENWIN] = ami_utf8_easy((char *)messages_get("LinkNewWin"));
ctxmenulab[CMID_URLOPENTAB] = ami_utf8_easy((char *)messages_get("LinkNewTab"));
}
else
{
ctxmenulab[CMID_URLOPENWIN] = ami_utf8_easy((char *)messages_get("LinkNewTab"));
ctxmenulab[CMID_URLOPENTAB] = ami_utf8_easy((char *)messages_get("LinkNewWin"));
}
ctxmenulab[CMSUB_OBJECT] = ami_utf8_easy((char *)messages_get("Object")); ctxmenulab[CMSUB_OBJECT] = ami_utf8_easy((char *)messages_get("Object"));
ctxmenulab[CMSUB_URL] = ami_utf8_easy((char *)messages_get("Link")); ctxmenulab[CMSUB_URL] = ami_utf8_easy((char *)messages_get("Link"));
@ -131,6 +125,11 @@ void ami_context_menu_show(struct gui_window_2 *gwin,int x,int y)
PMIA_ID,CMID_COPYOBJ, PMIA_ID,CMID_COPYOBJ,
PMIA_UserData,curbox->object->url, PMIA_UserData,curbox->object->url,
TAG_DONE), TAG_DONE),
PMA_AddItem,NewObject(POPUPMENU_GetItemClass(), NULL,
PMIA_Title, (ULONG)ctxmenulab[CMID_SAVEOBJ],
PMIA_ID,CMID_SAVEOBJ,
PMIA_UserData,curbox->object,
TAG_DONE),
TAG_DONE), TAG_DONE),
TAG_DONE), TAG_DONE),
~0); ~0);
@ -163,6 +162,7 @@ uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved)
struct gui_window_2 *gwin = hook->h_Data; struct gui_window_2 *gwin = hook->h_Data;
APTR userdata = NULL; APTR userdata = NULL;
struct browser_window *bw; struct browser_window *bw;
struct content *object;
if(GetAttrs(item,PMIA_ID,&itemid, if(GetAttrs(item,PMIA_ID,&itemid,
PMIA_UserData,&userdata, PMIA_UserData,&userdata,
@ -217,6 +217,31 @@ uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved)
case CMID_SHOWOBJ: case CMID_SHOWOBJ:
browser_window_go(gwin->bw,userdata,gwin->bw->current_content->url,true); browser_window_go(gwin->bw,userdata,gwin->bw->current_content->url,true);
break; break;
case CMID_SAVEOBJ:
object = (struct content *)userdata;
if(AslRequestTags(filereq,
ASLFR_TitleText,messages_get("NetSurf"),
ASLFR_Screen,scrn,
ASLFR_DoSaveMode,TRUE,
ASLFR_InitialFile,FilePart(object->url),
TAG_DONE))
{
BPTR fh = 0;
char fname[1024];
strlcpy(&fname,filereq->fr_Drawer,1024);
AddPart(fname,filereq->fr_File,1024);
ami_update_pointer(gwin->win,GUI_POINTER_WAIT);
if(fh = FOpen(fname,MODE_NEWFILE,0))
{
FWrite(fh,object->source_data,1,object->source_size);
FClose(fh);
SetComment(fname,object->url);
}
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
break;
} }
} }

View File

@ -27,6 +27,7 @@ enum {
CMID_URLOPENTAB, CMID_URLOPENTAB,
CMID_SHOWOBJ, CMID_SHOWOBJ,
CMID_COPYOBJ, CMID_COPYOBJ,
CMID_SAVEOBJ,
CMSUB_OBJECT, CMSUB_OBJECT,
CMSUB_URL, CMSUB_URL,
CMID_LAST CMID_LAST