* Improved the layout of the Settings window general page.

* Allow specifying a start and a search page in the Settings window.
* Separated the "New page" policy into "New window" and "New tab" policies.
  For a new window, the user can chose to "Open start page", "Open search page"
  and "Open blank page". The default changed to "Open start page" and the
  default start page points to the "Welcome" readme. For new tabs, there is
  an additional choice "Clone current page". The default stayed with opening
  a blank page.
* Implemented the new page policies in BrowserWindow.
* Listen for changes of the new settings in BrowserWindow.
* Added the new settings keys and default values to SettingsKeys.

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@456 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi 2010-04-23 15:07:53 +00:00 committed by Alexandre Deckner
parent a8d1c85daa
commit 1547f92b8e
6 changed files with 236 additions and 46 deletions

View File

@ -166,11 +166,22 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
fZoomTextOnly(true),
fShowTabsIfSinglePageOpen(true)
{
// Begin listening to settings changes and read some current values.
fAppSettings->AddListener(BMessenger(this));
// fZoomTextOnly = fAppSettings->GetValue("zoom text only", fZoomTextOnly);
fShowTabsIfSinglePageOpen = fAppSettings->GetValue(
kSettingsKeyShowTabsIfSinglePageOpen, fShowTabsIfSinglePageOpen);
fNewWindowPolicy = fAppSettings->GetValue(kSettingsKeyNewWindowPolicy,
(uint32)OpenStartPage);
fNewTabPolicy = fAppSettings->GetValue(kSettingsKeyNewTabPolicy,
(uint32)OpenBlankPage);
fStartPageURL = fAppSettings->GetValue(kSettingsKeyStartPageURL,
kDefaultStartPageURL);
fSearchPageURL = fAppSettings->GetValue(kSettingsKeySearchPageURL,
kDefaultSearchPageURL);
// Create the interface elements
BMessage* newTabMessage = new BMessage(NEW_TAB);
newTabMessage->AddString("url", "");
newTabMessage->AddPointer("window", this);
@ -672,12 +683,26 @@ BrowserWindow::MessageReceived(BMessage* message)
if (message->FindString("name", &name) != B_OK)
break;
bool flag;
BString string;
uint32 value;
if (name == kSettingsKeyShowTabsIfSinglePageOpen
&& message->FindBool("value", &flag) == B_OK) {
if (fShowTabsIfSinglePageOpen != flag) {
fShowTabsIfSinglePageOpen = flag;
_UpdateTabGroupVisibility();
}
} else if (name == kSettingsKeyStartPageURL
&& message->FindString("value", &string) == B_OK) {
fStartPageURL = string;
} else if (name == kSettingsKeySearchPageURL
&& message->FindString("value", &string) == B_OK) {
fSearchPageURL = string;
} else if (name == kSettingsKeyNewWindowPolicy
&& message->FindUInt32("value", &value) == B_OK) {
fNewWindowPolicy = value;
} else if (name == kSettingsKeyNewTabPolicy
&& message->FindUInt32("value", &value) == B_OK) {
fNewTabPolicy = value;
}
break;
}
@ -716,15 +741,38 @@ BrowserWindow::MenusBeginning()
void
BrowserWindow::CreateNewTab(const BString& url, bool select, BWebView* webView)
BrowserWindow::CreateNewTab(const BString& _url, bool select, BWebView* webView)
{
// Executed in app thread (new BWebPage needs to be created in app thread).
if (!webView)
webView = new BWebView("web view");
bool isNewWindow = fTabManager->CountTabs() == 0;
fTabManager->AddTab(webView, "New tab");
if (url.Length())
BString url(_url);
if (url.Length() == 0) {
uint32 policy = isNewWindow ? fNewWindowPolicy : fNewTabPolicy;
// Implement new page policy
switch (policy) {
case OpenStartPage:
url = fStartPageURL;
break;
case OpenSearchPage:
url = fSearchPageURL;
break;
case CloneCurrentPage:
if (CurrentWebView() != NULL)
url = CurrentWebView()->MainFrameURL();
break;
default:
case OpenBlankPage:
break;
}
}
if (url.Length() > 0)
webView->LoadURL(url.String());
if (select) {

View File

@ -56,6 +56,13 @@ enum ToolbarPolicy {
DoNotHaveToolbar
};
enum NewPagePolicy {
OpenBlankPage = 0,
OpenStartPage = 1,
OpenSearchPage = 2,
CloneCurrentPage = 3
};
enum {
NEW_WINDOW = 'nwnd',
NEW_TAB = 'ntab',
@ -176,9 +183,14 @@ private:
BCheckBox* fFindCaseSensitiveCheckBox;
TabManager* fTabManager;
// cached settings
SettingsMessage* fAppSettings;
bool fZoomTextOnly;
bool fShowTabsIfSinglePageOpen;
uint32 fNewWindowPolicy;
uint32 fNewTabPolicy;
BString fStartPageURL;
BString fSearchPageURL;
};

View File

@ -30,3 +30,15 @@
const char* kSettingsKeyDownloadPath = "download path";
const char* kSettingsKeyShowTabsIfSinglePageOpen
= "show tabs if single page open";
const char* kSettingsKeyNewWindowPolicy = "new window policy";
const char* kSettingsKeyNewTabPolicy = "new tab policy";
const char* kSettingsKeyStartPageURL = "start page url";
const char* kSettingsKeySearchPageURL = "search page url";
const char* kDefaultDownloadPath = "/boot/home/Desktop/";
const char* kDefaultStartPageURL
= "file:///boot/system/documentation/welcome/welcome_en.html";
const char* kDefaultSearchPageURL = "http://www.google.com";

View File

@ -33,5 +33,13 @@
extern const char* kSettingsKeyDownloadPath;
extern const char* kSettingsKeyShowTabsIfSinglePageOpen;
extern const char* kSettingsKeyNewWindowPolicy;
extern const char* kSettingsKeyNewTabPolicy;
extern const char* kSettingsKeyStartPageURL;
extern const char* kSettingsKeySearchPageURL;
extern const char* kDefaultDownloadPath;
extern const char* kDefaultStartPageURL;
extern const char* kDefaultSearchPageURL;
#endif // SETTINGS_KEYS_H

View File

@ -48,6 +48,7 @@
#include "BrowserApp.h"
#include "BrowsingHistory.h"
#include "BrowserWindow.h"
#include "FontSelectionView.h"
#include "SettingsKeys.h"
#include "SettingsMessage.h"
@ -63,9 +64,12 @@ enum {
MSG_REVERT = 'rvrt',
MSG_STANDARD_FONT_SIZE_SELECTED = 'sfss',
MSG_FIXED_FONT_SIZE_SELECTED = 'ffss',
MSG_START_PAGE_CHANGED = 'hpch',
MSG_SEARCH_PAGE_CHANGED = 'spch',
MSG_DOWNLOAD_FOLDER_CHANGED = 'dnfc',
MSG_NEW_PAGE_BEHAVIOR_CHANGED = 'npbc',
MSG_GO_MENU_DAYS_CHANGED = 'digm',
MSG_NEW_WINDOWS_BEHAVIOR_CHANGED = 'nwbc',
MSG_NEW_TABS_BEHAVIOR_CHANGED = 'ntbc',
MSG_HISTORY_MENU_DAYS_CHANGED = 'digm',
MSG_TAB_DISPLAY_BEHAVIOR_CHANGED = 'tdbc',
};
@ -209,61 +213,94 @@ SettingsWindow::Show()
BView*
SettingsWindow::_CreateGeneralPage(float spacing)
{
fStartPageControl = new BTextControl("start page",
TR("Start page:"), "", new BMessage(MSG_START_PAGE_CHANGED));
fStartPageControl->SetText(
fSettings->GetValue(kSettingsKeyStartPageURL, kDefaultStartPageURL));
fSearchPageControl = new BTextControl("search page",
TR("Search page:"), "", new BMessage(MSG_SEARCH_PAGE_CHANGED));
fSearchPageControl->SetText(
fSettings->GetValue(kSettingsKeySearchPageURL, kDefaultSearchPageURL));
fDownloadFolderControl = new BTextControl("download folder",
TR("Download folder:"), "", new BMessage(MSG_DOWNLOAD_FOLDER_CHANGED));
fDownloadFolderControl->SetText(
fSettings->GetValue(kSettingsKeyDownloadPath, ""));
fSettings->GetValue(kSettingsKeyDownloadPath, kDefaultDownloadPath));
fNewPageBehaviorCloneCurrentItem = new BMenuItem(TR("Clone current page"),
fNewWindowBehaviorOpenHomeItem = new BMenuItem(TR("Open start page"),
NULL);
fNewPageBehaviorCloneCurrentItem->SetEnabled(false);
fNewPageBehaviorOpenHomeItem = new BMenuItem(TR("Open home page"), NULL);
fNewPageBehaviorOpenHomeItem->SetEnabled(false);
fNewPageBehaviorOpenSearchItem = new BMenuItem(TR("Open search page"),
fNewWindowBehaviorOpenSearchItem = new BMenuItem(TR("Open search page"),
NULL);
fNewWindowBehaviorOpenBlankItem = new BMenuItem(TR("Open blank page"),
NULL);
fNewPageBehaviorOpenSearchItem->SetEnabled(false);
fNewPageBehaviorOpenBlankItem = new BMenuItem(TR("Open blank page"), NULL);
fNewPageBehaviorOpenBlankItem->SetMarked(true);
BPopUpMenu* newPageBehaviorMenu = new BPopUpMenu("New pages");
newPageBehaviorMenu->AddItem(fNewPageBehaviorCloneCurrentItem);
newPageBehaviorMenu->AddItem(fNewPageBehaviorOpenHomeItem);
newPageBehaviorMenu->AddItem(fNewPageBehaviorOpenSearchItem);
newPageBehaviorMenu->AddItem(fNewPageBehaviorOpenBlankItem);
fNewPageBehaviorMenu = new BMenuField("new page behavior",
TR("New pages:"), newPageBehaviorMenu,
new BMessage(MSG_NEW_PAGE_BEHAVIOR_CHANGED));
fNewPageBehaviorMenu->SetEnabled(false);
fNewTabBehaviorCloneCurrentItem = new BMenuItem(TR("Clone current page"),
NULL);
fNewTabBehaviorOpenHomeItem = new BMenuItem(TR("Open start page"), NULL);
fNewTabBehaviorOpenSearchItem = new BMenuItem(TR("Open search page"),
NULL);
fNewTabBehaviorOpenBlankItem = new BMenuItem(TR("Open blank page"), NULL);
fDaysInGoMenuControl = new BTextControl("days in go menu",
TR("Number of days to keep links in Go menu:"), "",
new BMessage(MSG_GO_MENU_DAYS_CHANGED));
fNewWindowBehaviorOpenHomeItem->SetMarked(true);
fNewTabBehaviorOpenBlankItem->SetMarked(true);
BPopUpMenu* newWindowBehaviorMenu = new BPopUpMenu("New windows");
newWindowBehaviorMenu->AddItem(fNewWindowBehaviorOpenHomeItem);
newWindowBehaviorMenu->AddItem(fNewWindowBehaviorOpenSearchItem);
newWindowBehaviorMenu->AddItem(fNewWindowBehaviorOpenBlankItem);
fNewWindowBehaviorMenu = new BMenuField("new window behavior",
TR("New windows:"), newWindowBehaviorMenu,
new BMessage(MSG_NEW_WINDOWS_BEHAVIOR_CHANGED));
BPopUpMenu* newTabBehaviorMenu = new BPopUpMenu("New tabs");
newTabBehaviorMenu->AddItem(fNewTabBehaviorOpenBlankItem);
newTabBehaviorMenu->AddItem(fNewTabBehaviorOpenHomeItem);
newTabBehaviorMenu->AddItem(fNewTabBehaviorOpenSearchItem);
newTabBehaviorMenu->AddItem(fNewTabBehaviorCloneCurrentItem);
fNewTabBehaviorMenu = new BMenuField("new tab behavior",
TR("New tabs:"), newTabBehaviorMenu,
new BMessage(MSG_NEW_TABS_BEHAVIOR_CHANGED));
fDaysInHistoryMenuControl = new BTextControl("days in history",
TR("Number of days to keep links in History menu:"), "",
new BMessage(MSG_HISTORY_MENU_DAYS_CHANGED));
BString maxHistoryAge;
maxHistoryAge << BrowsingHistory::DefaultInstance()->MaxHistoryItemAge();
fDaysInGoMenuControl->SetText(maxHistoryAge.String());
fDaysInHistoryMenuControl->SetText(maxHistoryAge.String());
for (uchar i = 0; i < '0'; i++)
fDaysInGoMenuControl->TextView()->DisallowChar(i);
fDaysInHistoryMenuControl->TextView()->DisallowChar(i);
for (uchar i = '9' + 1; i <= 128; i++)
fDaysInGoMenuControl->TextView()->DisallowChar(i);
fDaysInHistoryMenuControl->TextView()->DisallowChar(i);
fShowTabsIfOnlyOnePage = new BCheckBox("show tabs if only one page",
TR("Show tabs if only one page is open."),
new BMessage(MSG_TAB_DISPLAY_BEHAVIOR_CHANGED));
fShowTabsIfOnlyOnePage->SetValue(B_CONTROL_ON);
BView* view = BGridLayoutBuilder(spacing / 2, spacing / 2)
.Add(fDownloadFolderControl->CreateLabelLayoutItem(), 0, 1)
.Add(fDownloadFolderControl->CreateTextViewLayoutItem(), 1, 1)
BView* view = BGroupLayoutBuilder(B_VERTICAL, spacing / 2)
.Add(BGridLayoutBuilder(spacing / 2, spacing / 2)
.Add(fStartPageControl->CreateLabelLayoutItem(), 0, 0)
.Add(fStartPageControl->CreateTextViewLayoutItem(), 1, 0)
.Add(fNewPageBehaviorMenu->CreateLabelLayoutItem(), 0, 2)
.Add(fNewPageBehaviorMenu->CreateMenuBarLayoutItem(), 1, 2)
.Add(fSearchPageControl->CreateLabelLayoutItem(), 0, 1)
.Add(fSearchPageControl->CreateTextViewLayoutItem(), 1, 1)
.Add(fDaysInGoMenuControl->CreateLabelLayoutItem(), 0, 3)
.Add(fDaysInGoMenuControl->CreateTextViewLayoutItem(), 1, 3)
.Add(fDownloadFolderControl->CreateLabelLayoutItem(), 0, 2)
.Add(fDownloadFolderControl->CreateTextViewLayoutItem(), 1, 2)
.Add(fShowTabsIfOnlyOnePage, 0, 4, 2)
.Add(fNewWindowBehaviorMenu->CreateLabelLayoutItem(), 0, 3)
.Add(fNewWindowBehaviorMenu->CreateMenuBarLayoutItem(), 1, 3)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing), 0, 5, 2)
.Add(fNewTabBehaviorMenu->CreateLabelLayoutItem(), 0, 4)
.Add(fNewTabBehaviorMenu->CreateMenuBarLayoutItem(), 1, 4)
)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing))
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing))
.Add(fShowTabsIfOnlyOnePage)
.Add(fDaysInHistoryMenuControl)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing))
.SetInsets(spacing, spacing, spacing, spacing)
;
@ -330,20 +367,42 @@ void
SettingsWindow::_ApplySettings()
{
// Store general settings
int32 maxHistoryAge = atoi(fDaysInGoMenuControl->Text());
int32 maxHistoryAge = atoi(fDaysInHistoryMenuControl->Text());
if (maxHistoryAge <= 0)
maxHistoryAge = 1;
if (maxHistoryAge >= 35)
maxHistoryAge = 35;
BString text;
text << maxHistoryAge;
fDaysInGoMenuControl->SetText(text.String());
fDaysInHistoryMenuControl->SetText(text.String());
BrowsingHistory::DefaultInstance()->SetMaxHistoryItemAge(maxHistoryAge);
fSettings->SetValue(kSettingsKeyStartPageURL, fStartPageControl->Text());
fSettings->SetValue(kSettingsKeySearchPageURL, fSearchPageControl->Text());
fSettings->SetValue(kSettingsKeyDownloadPath, fDownloadFolderControl->Text());
fSettings->SetValue(kSettingsKeyShowTabsIfSinglePageOpen,
fShowTabsIfOnlyOnePage->Value() == B_CONTROL_ON);
// New window policy
uint32 newWindowPolicy = OpenStartPage;
BMenuItem* markedItem = fNewWindowBehaviorMenu->Menu()->FindMarked();
if (markedItem == fNewWindowBehaviorOpenSearchItem)
newWindowPolicy = OpenSearchPage;
else if (markedItem == fNewWindowBehaviorOpenBlankItem)
newWindowPolicy = OpenBlankPage;
fSettings->SetValue(kSettingsKeyNewWindowPolicy, newWindowPolicy);
// New tab policy
uint32 newTabPolicy = OpenBlankPage;
markedItem = fNewTabBehaviorMenu->Menu()->FindMarked();
if (markedItem == fNewTabBehaviorCloneCurrentItem)
newTabPolicy = CloneCurrentPage;
else if (markedItem == fNewTabBehaviorOpenHomeItem)
newTabPolicy = OpenStartPage;
else if (markedItem == fNewTabBehaviorOpenSearchItem)
newTabPolicy = OpenSearchPage;
fSettings->SetValue(kSettingsKeyNewTabPolicy, newTabPolicy);
// Store fond settings
fSettings->SetValue("standard font", fStandardFontView->Font());
fSettings->SetValue("serif font", fSerifFontView->Font());
@ -373,11 +432,53 @@ SettingsWindow::_ApplySettings()
void
SettingsWindow::_RevertSettings()
{
fStartPageControl->SetText(
fSettings->GetValue(kSettingsKeyStartPageURL, kDefaultStartPageURL));
fSearchPageControl->SetText(
fSettings->GetValue(kSettingsKeySearchPageURL, kDefaultSearchPageURL));
fDownloadFolderControl->SetText(
fSettings->GetValue(kSettingsKeyDownloadPath, ""));
fSettings->GetValue(kSettingsKeyDownloadPath, kDefaultDownloadPath));
fShowTabsIfOnlyOnePage->SetValue(
fSettings->GetValue(kSettingsKeyShowTabsIfSinglePageOpen, true));
// New window policy
uint32 newWindowPolicy = fSettings->GetValue(kSettingsKeyNewWindowPolicy,
(uint32)OpenStartPage);
switch (newWindowPolicy) {
default:
case OpenStartPage:
fNewWindowBehaviorOpenHomeItem->SetMarked(true);
break;
case OpenSearchPage:
fNewWindowBehaviorOpenSearchItem->SetMarked(true);
break;
case OpenBlankPage:
fNewWindowBehaviorOpenBlankItem->SetMarked(true);
break;
}
// New tab policy
uint32 newTabPolicy = fSettings->GetValue(kSettingsKeyNewTabPolicy,
(uint32)OpenBlankPage);
switch (newTabPolicy) {
default:
case OpenBlankPage:
fNewTabBehaviorOpenBlankItem->SetMarked(true);
break;
case OpenStartPage:
fNewTabBehaviorOpenHomeItem->SetMarked(true);
break;
case OpenSearchPage:
fNewTabBehaviorOpenSearchItem->SetMarked(true);
break;
case CloneCurrentPage:
fNewTabBehaviorCloneCurrentItem->SetMarked(true);
break;
}
// Font settings
int32 defaultFontSize = fSettings->GetValue("standard font size",
kDefaultFontSize);
int32 defaultFixedFontSize = fSettings->GetValue("fixed font size",

View File

@ -67,13 +67,22 @@ private:
private:
SettingsMessage* fSettings;
BTextControl* fStartPageControl;
BTextControl* fSearchPageControl;
BTextControl* fDownloadFolderControl;
BMenuField* fNewPageBehaviorMenu;
BMenuItem* fNewPageBehaviorCloneCurrentItem;
BMenuItem* fNewPageBehaviorOpenHomeItem;
BMenuItem* fNewPageBehaviorOpenSearchItem;
BMenuItem* fNewPageBehaviorOpenBlankItem;
BTextControl* fDaysInGoMenuControl;
BMenuField* fNewWindowBehaviorMenu;
BMenuItem* fNewWindowBehaviorOpenHomeItem;
BMenuItem* fNewWindowBehaviorOpenSearchItem;
BMenuItem* fNewWindowBehaviorOpenBlankItem;
BMenuField* fNewTabBehaviorMenu;
BMenuItem* fNewTabBehaviorCloneCurrentItem;
BMenuItem* fNewTabBehaviorOpenHomeItem;
BMenuItem* fNewTabBehaviorOpenSearchItem;
BMenuItem* fNewTabBehaviorOpenBlankItem;
BTextControl* fDaysInHistoryMenuControl;
BCheckBox* fShowTabsIfOnlyOnePage;
FontSelectionView* fStandardFontView;