From 6563b112643871b3a1d35cdf5127f7766b46be8a Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 16 Jun 2014 10:12:50 +0200 Subject: [PATCH] Add menu entry to save pages as MHTML. Fixes #9570. --- src/apps/webpositive/BrowserWindow.cpp | 31 ++++++++++++++++++++++++++ src/apps/webpositive/BrowserWindow.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index b25e18016e..eb1bd9e97d 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index 3defae76a2..f51a5b5d9f 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -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; };