Add menu entry to save pages as MHTML.

Fixes #9570.
This commit is contained in:
Adrien Destugues 2014-06-16 10:12:50 +02:00
parent 9b738c321b
commit 6563b11264
2 changed files with 33 additions and 0 deletions

View File

@ -43,6 +43,7 @@
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <FindDirectory.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
@ -96,6 +97,7 @@
enum {
OPEN_LOCATION = 'open',
SAVE_PAGE = 'save',
GO_BACK = 'goba',
GO_FORWARD = 'gofo',
STOP = 'stop',
@ -398,6 +400,8 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
new BMessage(B_QUIT_REQUESTED), 'W', B_SHIFT_KEY));
menu->AddItem(new BMenuItem(B_TRANSLATE("Close tab"),
new BMessage(CLOSE_TAB), 'W'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Save page"),
new BMessage(SAVE_PAGE), 'S'));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("Downloads"),
new BMessage(SHOW_DOWNLOAD_WINDOW), 'D'));
@ -594,6 +598,9 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
} else
_ShowBookmarkBar(false);
fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
false);
// Layout
AddChild(BLayoutBuilder::Group<>(B_VERTICAL, 0.0)
#if !INTEGRATE_MENU_INTO_TAB_BAR
@ -665,6 +672,7 @@ BrowserWindow::~BrowserWindow()
fAppSettings->RemoveListener(BMessenger(this));
delete fTabManager;
delete fPulseRunner;
delete fSavePanel;
}
@ -811,6 +819,29 @@ BrowserWindow::MessageReceived(BMessage* message)
break;
}
case SAVE_PAGE:
{
fSavePanel->SetSaveText(CurrentWebView()->MainFrameTitle());
fSavePanel->Show();
break;
}
case B_SAVE_REQUESTED:
{
entry_ref ref;
BString name;
if (message->FindRef("directory", &ref) == B_OK &&
message->FindString("name", &name) == B_OK) {
BDirectory dir(&ref);
BFile output(&dir, name,
B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
CurrentWebView()->WebPage()->GetContentsAsMHTML(output);
}
break;
}
case GO_BACK:
CurrentWebView()->GoBack();
break;

View File

@ -37,6 +37,7 @@ class BButton;
class BCheckBox;
class BDirectory;
class BFile;
class BFilePanel;
class BLayoutItem;
class BMenu;
class BMenuItem;
@ -272,6 +273,7 @@ private:
BMenuItem* fBookmarkBarMenuItem;
BookmarkBar* fBookmarkBar;
BFilePanel* fSavePanel;
};