* Moved some settings keys into new files SettingsKeys.h/cpp to make it less

likely to introduce erros with spelling settings keys wrong somewhere.
* Introduced new setting for the behavior if tabs should show at all if only
  one page is showing in a window. Defaults to on, i.e. the previous behavior.

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@393 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi
2012-07-03 15:39:51 +02:00
committed by Alexandre Deckner
parent bb68c7f66d
commit d5f0e82b84
7 changed files with 347 additions and 216 deletions
+2 -2
View File
@@ -167,7 +167,7 @@ BrowserApp::ReadyToRun()
delete fLaunchRefsMessage; delete fLaunchRefsMessage;
fLaunchRefsMessage = 0; fLaunchRefsMessage = 0;
} else { } else {
BrowserWindow* window = new BrowserWindow(fLastWindowFrame); BrowserWindow* window = new BrowserWindow(fLastWindowFrame, fSettings);
window->Show(); window->Show();
} }
PostMessage(PRELOAD_BROWSING_HISTORY); PostMessage(PRELOAD_BROWSING_HISTORY);
@@ -327,7 +327,7 @@ BrowserApp::_CreateNewWindow(const BString& url)
if (!BScreen().Frame().Contains(fLastWindowFrame)) if (!BScreen().Frame().Contains(fLastWindowFrame))
fLastWindowFrame.OffsetTo(50, 50); fLastWindowFrame.OffsetTo(50, 50);
BrowserWindow* window = new BrowserWindow(fLastWindowFrame); BrowserWindow* window = new BrowserWindow(fLastWindowFrame, fSettings);
window->Show(); window->Show();
if (url.Length()) if (url.Length())
window->CurrentWebView()->LoadURL(url.String()); window->CurrentWebView()->LoadURL(url.String());
+217 -185
View File
@@ -38,6 +38,8 @@
#include "BrowsingHistory.h" #include "BrowsingHistory.h"
#include "IconButton.h" #include "IconButton.h"
#include "NavMenu.h" #include "NavMenu.h"
#include "SettingsKeys.h"
#include "SettingsMessage.h"
#include "TextControlCompleter.h" #include "TextControlCompleter.h"
#include "WebPage.h" #include "WebPage.h"
#include "WebTabView.h" #include "WebTabView.h"
@@ -257,14 +259,21 @@ private:
// #pragma mark - BrowserWindow // #pragma mark - BrowserWindow
BrowserWindow::BrowserWindow(BRect frame, ToolbarPolicy toolbarPolicy, BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
BWebView* webView) ToolbarPolicy toolbarPolicy, BWebView* webView)
: :
BWebWindow(frame, kApplicationName, BWebWindow(frame, kApplicationName,
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS), B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS),
fZoomTextOnly(true) fAppSettings(appSettings),
fZoomTextOnly(true),
fShowTabsIfSinglePageOpen(true)
{ {
fAppSettings->AddListener(BMessenger(this));
// fZoomTextOnly = fAppSettings->GetValue("zoom text only", fZoomTextOnly);
fShowTabsIfSinglePageOpen = fAppSettings->GetValue(
kSettingsKeyShowTabsIfSinglePageOpen, fShowTabsIfSinglePageOpen);
BMessage* newTabMessage = new BMessage(NEW_TAB); BMessage* newTabMessage = new BMessage(NEW_TAB);
newTabMessage->AddString("url", ""); newTabMessage->AddString("url", "");
newTabMessage->AddPointer("window", this); newTabMessage->AddPointer("window", this);
@@ -461,6 +470,7 @@ BrowserWindow::BrowserWindow(BRect frame, ToolbarPolicy toolbarPolicy,
BrowserWindow::~BrowserWindow() BrowserWindow::~BrowserWindow()
{ {
fAppSettings->RemoveListener(BMessenger(this));
delete fURLAutoCompleter; delete fURLAutoCompleter;
delete fTabManager; delete fTabManager;
} }
@@ -501,199 +511,220 @@ void
BrowserWindow::MessageReceived(BMessage* message) BrowserWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case OPEN_LOCATION: case OPEN_LOCATION:
if (fURLTextControl) { if (fURLTextControl) {
if (fURLTextControl->TextView()->IsFocus()) if (fURLTextControl->TextView()->IsFocus())
fURLTextControl->TextView()->SelectAll(); fURLTextControl->TextView()->SelectAll();
else else
fURLTextControl->MakeFocus(true); fURLTextControl->MakeFocus(true);
} }
break; break;
case RELOAD: case RELOAD:
CurrentWebView()->Reload(); CurrentWebView()->Reload();
break; break;
case GOTO_URL: { case GOTO_URL:
BString url; {
if (message->FindString("url", &url) != B_OK) BString url;
url = fURLTextControl->Text(); if (message->FindString("url", &url) != B_OK)
fTabManager->SetTabIcon(CurrentWebView(), NULL); url = fURLTextControl->Text();
CurrentWebView()->LoadURL(url.String()); fTabManager->SetTabIcon(CurrentWebView(), NULL);
break; CurrentWebView()->LoadURL(url.String());
}
case GO_BACK:
CurrentWebView()->GoBack();
break;
case GO_FORWARD:
CurrentWebView()->GoForward();
break;
case STOP:
CurrentWebView()->StopLoading();
break;
case CLEAR_HISTORY: {
BrowsingHistory* history = BrowsingHistory::DefaultInstance();
if (history->CountItems() == 0)
break; break;
BAlert* alert = new BAlert("Confirmation", "Do you really want to "
"clear the browsing history?", "Clear", "Cancel");
if (alert->Go() == 0)
history->Clear();
break;
}
case CREATE_BOOKMARK:
_CreateBookmark();
break;
case SHOW_BOOKMARKS:
_ShowBookmarks();
break;
case B_REFS_RECEIVED: {
// Currently the only source of these messages is the bookmarks menu.
// Filter refs into URLs, this also gets rid of refs for folders.
// For clicks on sub-folders in the bookmarks menu, we have Tracker
// open the corresponding folder.
entry_ref ref;
uint32 addedCount = 0;
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) {
printf("B_REFS_RECEIVED: %s\n", ref.name);
BEntry entry(&ref);
uint32 addedSubCount = 0;
if (entry.IsDirectory()) {
BDirectory directory(&entry);
printf(" directory ok\n");
_AddBookmarkURLsRecursively(directory, message, addedSubCount);
} else {
BFile file(&ref, B_READ_ONLY);
printf(" file ok\n");
BString url;
if (_ReadURLAttr(file, url)) {
message->AddString("url", url.String());
addedSubCount++;
}
}
if (addedSubCount == 0) {
// Don't know what to do with this entry, just pass it
// on to the system to handle. Note that this may result
// in us opening other supported files via the application
// mechanism.
be_roster->Launch(&ref);
}
addedCount += addedSubCount;
} }
message->RemoveName("refs"); case GO_BACK:
if (addedCount > 10) { CurrentWebView()->GoBack();
BString string; break;
string << "Do you want to open " << addedCount; case GO_FORWARD:
string << " bookmarks all at once?"; CurrentWebView()->GoForward();
BAlert* alert = new BAlert("Open bookmarks confirmation", break;
string.String(), "Cancel", "Open all"); case STOP:
if (alert->Go() == 0) CurrentWebView()->StopLoading();
break;
case CLEAR_HISTORY: {
BrowsingHistory* history = BrowsingHistory::DefaultInstance();
if (history->CountItems() == 0)
break; break;
} BAlert* alert = new BAlert("Confirmation", "Do you really want to "
be_app->PostMessage(message); "clear the browsing history?", "Clear", "Cancel");
break; if (alert->Go() == 0)
} history->Clear();
case B_SIMPLE_DATA: {
// User possibly dropped files on this window.
// If there is more than one entry_ref, let the app handle it (open one
// new page per ref). If there is one ref, open it in this window.
type_code type;
int32 countFound;
if (message->GetInfo("refs", &type, &countFound) != B_OK
|| type != B_REF_TYPE) {
break; break;
} }
if (countFound > 1) {
message->what = B_REFS_RECEIVED; case CREATE_BOOKMARK:
_CreateBookmark();
break;
case SHOW_BOOKMARKS:
_ShowBookmarks();
break;
case B_REFS_RECEIVED:
{
// Currently the only source of these messages is the bookmarks menu.
// Filter refs into URLs, this also gets rid of refs for folders.
// For clicks on sub-folders in the bookmarks menu, we have Tracker
// open the corresponding folder.
entry_ref ref;
uint32 addedCount = 0;
for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) {
BEntry entry(&ref);
uint32 addedSubCount = 0;
if (entry.IsDirectory()) {
BDirectory directory(&entry);
_AddBookmarkURLsRecursively(directory, message,
addedSubCount);
} else {
BFile file(&ref, B_READ_ONLY);
BString url;
if (_ReadURLAttr(file, url)) {
message->AddString("url", url.String());
addedSubCount++;
}
}
if (addedSubCount == 0) {
// Don't know what to do with this entry, just pass it
// on to the system to handle. Note that this may result
// in us opening other supported files via the application
// mechanism.
be_roster->Launch(&ref);
}
addedCount += addedSubCount;
}
message->RemoveName("refs");
if (addedCount > 10) {
BString string;
string << "Do you want to open " << addedCount;
string << " bookmarks all at once?";
BAlert* alert = new BAlert("Open bookmarks confirmation",
string.String(), "Cancel", "Open all");
if (alert->Go() == 0)
break;
}
be_app->PostMessage(message); be_app->PostMessage(message);
break; break;
} }
entry_ref ref; case B_SIMPLE_DATA:
if (message->FindRef("refs", &ref) != B_OK) {
// User possibly dropped files on this window.
// If there is more than one entry_ref, let the app handle it
// (open one new page per ref). If there is one ref, open it in
// this window.
type_code type;
int32 countFound;
if (message->GetInfo("refs", &type, &countFound) != B_OK
|| type != B_REF_TYPE) {
break;
}
if (countFound > 1) {
message->what = B_REFS_RECEIVED;
be_app->PostMessage(message);
break;
}
entry_ref ref;
if (message->FindRef("refs", &ref) != B_OK)
break;
BEntry entry(&ref, true);
BPath path;
if (!entry.Exists() || entry.GetPath(&path) != B_OK)
break;
CurrentWebView()->LoadURL(path.Path());
break; break;
BEntry entry(&ref, true);
BPath path;
if (!entry.Exists() || entry.GetPath(&path) != B_OK)
break;
CurrentWebView()->LoadURL(path.Path());
break;
}
case ZOOM_FACTOR_INCREASE:
CurrentWebView()->IncreaseZoomFactor(fZoomTextOnly);
break;
case ZOOM_FACTOR_DECREASE:
CurrentWebView()->DecreaseZoomFactor(fZoomTextOnly);
break;
case ZOOM_FACTOR_RESET:
CurrentWebView()->ResetZoomFactor();
break;
case ZOOM_TEXT_ONLY:
fZoomTextOnly = !fZoomTextOnly;
fZoomTextOnlyMenuItem->SetMarked(fZoomTextOnly);
// TODO: Would be nice to have an instant update if the page is already
// zoomed.
break;
case TEXT_FIND_NEXT:
CurrentWebView()->FindString(fFindTextControl->Text(), true,
fFindCaseSensitiveCheckBox->Value());
break;
case TEXT_FIND_PREVIOUS:
CurrentWebView()->FindString(fFindTextControl->Text(), false,
fFindCaseSensitiveCheckBox->Value());
break;
case TEXT_SHOW_FIND_GROUP:
if (!fFindGroup->IsVisible())
fFindGroup->SetVisible(true);
fFindTextControl->MakeFocus(true);
break;
case TEXT_HIDE_FIND_GROUP:
if (fFindGroup->IsVisible())
fFindGroup->SetVisible(false);
break;
case SHOW_DOWNLOAD_WINDOW:
case SHOW_SETTINGS_WINDOW:
message->AddUInt32("workspaces", Workspaces());
be_app->PostMessage(message);
break;
case CLOSE_TAB:
if (fTabManager->CountTabs() > 1) {
int32 index;
if (message->FindInt32("tab index", &index) != B_OK)
index = fTabManager->SelectedTabIndex();
_ShutdownTab(index);
_UpdateTabGroupVisibility();
} else
PostMessage(B_QUIT_REQUESTED);
break;
case SELECT_TAB: {
int32 index;
if (message->FindInt32("tab index", &index) == B_OK
&& fTabManager->SelectedTabIndex() != index
&& fTabManager->CountTabs() > index) {
fTabManager->SelectTab(index);
} }
break; case ZOOM_FACTOR_INCREASE:
} CurrentWebView()->IncreaseZoomFactor(fZoomTextOnly);
break;
case ZOOM_FACTOR_DECREASE:
CurrentWebView()->DecreaseZoomFactor(fZoomTextOnly);
break;
case ZOOM_FACTOR_RESET:
CurrentWebView()->ResetZoomFactor();
break;
case ZOOM_TEXT_ONLY:
fZoomTextOnly = !fZoomTextOnly;
fZoomTextOnlyMenuItem->SetMarked(fZoomTextOnly);
// TODO: Would be nice to have an instant update if the page is
// already zoomed.
break;
case TAB_CHANGED: { case TEXT_FIND_NEXT:
// This message may be received also when the last tab closed, i.e. with index == -1. CurrentWebView()->FindString(fFindTextControl->Text(), true,
int32 index; fFindCaseSensitiveCheckBox->Value());
if (message->FindInt32("tab index", &index) != B_OK) break;
index = -1; case TEXT_FIND_PREVIOUS:
_TabChanged(index); CurrentWebView()->FindString(fFindTextControl->Text(), false,
break; fFindCaseSensitiveCheckBox->Value());
} break;
case TEXT_SHOW_FIND_GROUP:
if (!fFindGroup->IsVisible())
fFindGroup->SetVisible(true);
fFindTextControl->MakeFocus(true);
break;
case TEXT_HIDE_FIND_GROUP:
if (fFindGroup->IsVisible())
fFindGroup->SetVisible(false);
break;
default: case SHOW_DOWNLOAD_WINDOW:
BWebWindow::MessageReceived(message); case SHOW_SETTINGS_WINDOW:
break; message->AddUInt32("workspaces", Workspaces());
be_app->PostMessage(message);
break;
case CLOSE_TAB:
if (fTabManager->CountTabs() > 1) {
int32 index;
if (message->FindInt32("tab index", &index) != B_OK)
index = fTabManager->SelectedTabIndex();
_ShutdownTab(index);
_UpdateTabGroupVisibility();
} else
PostMessage(B_QUIT_REQUESTED);
break;
case SELECT_TAB:
{
int32 index;
if (message->FindInt32("tab index", &index) == B_OK
&& fTabManager->SelectedTabIndex() != index
&& fTabManager->CountTabs() > index) {
fTabManager->SelectTab(index);
}
break;
}
case TAB_CHANGED:
{
// This message may be received also when the last tab closed,
// i.e. with index == -1.
int32 index;
if (message->FindInt32("tab index", &index) != B_OK)
index = -1;
_TabChanged(index);
break;
}
case SETTINGS_VALUE_CHANGED:
{
BString name;
if (message->FindString("name", &name) != B_OK)
break;
bool flag;
if (name == kSettingsKeyShowTabsIfSinglePageOpen
&& message->FindBool("value", &flag) == B_OK) {
if (fShowTabsIfSinglePageOpen != flag) {
fShowTabsIfSinglePageOpen = flag;
_UpdateTabGroupVisibility();
}
}
break;
}
default:
BWebWindow::MessageReceived(message);
break;
} }
} }
@@ -898,7 +929,7 @@ BrowserWindow::NewPageCreated(BWebView* view, BRect windowFrame,
bool modalDialog, bool resizable) bool modalDialog, bool resizable)
{ {
if (windowFrame.IsValid()) { if (windowFrame.IsValid()) {
BrowserWindow* window = new BrowserWindow(windowFrame, BrowserWindow* window = new BrowserWindow(windowFrame, fAppSettings,
DoNotHaveToolbar, view); DoNotHaveToolbar, view);
window->Show(); window->Show();
} else } else
@@ -1166,7 +1197,8 @@ void
BrowserWindow::_UpdateTabGroupVisibility() BrowserWindow::_UpdateTabGroupVisibility()
{ {
if (Lock()) { if (Lock()) {
// fTabGroup->SetVisible(fTabManager->CountTabs() > 1); fTabGroup->SetVisible(fShowTabsIfSinglePageOpen
|| fTabManager->CountTabs() > 1);
fTabManager->SetCloseButtonsAvailable(fTabManager->CountTabs() > 1); fTabManager->SetCloseButtonsAvailable(fTabManager->CountTabs() > 1);
Unlock(); Unlock();
} }
+7 -2
View File
@@ -45,10 +45,11 @@ class BPath;
class BStatusBar; class BStatusBar;
class BStringView; class BStringView;
class BTextControl; class BTextControl;
class BWebView;
class IconButton; class IconButton;
class SettingsMessage;
class TabManager; class TabManager;
class TextControlCompleter; class TextControlCompleter;
class BWebView;
enum ToolbarPolicy { enum ToolbarPolicy {
HaveToolbar, HaveToolbar,
@@ -70,6 +71,7 @@ enum {
class BrowserWindow : public BWebWindow { class BrowserWindow : public BWebWindow {
public: public:
BrowserWindow(BRect frame, BrowserWindow(BRect frame,
SettingsMessage* appSettings,
ToolbarPolicy = HaveToolbar, ToolbarPolicy = HaveToolbar,
BWebView* webView = NULL); BWebView* webView = NULL);
virtual ~BrowserWindow(); virtual ~BrowserWindow();
@@ -144,7 +146,6 @@ private:
private: private:
BMenu* fGoMenu; BMenu* fGoMenu;
BMenuItem* fZoomTextOnlyMenuItem; BMenuItem* fZoomTextOnlyMenuItem;
bool fZoomTextOnly;
IconButton* fBackButton; IconButton* fBackButton;
IconButton* fForwardButton; IconButton* fForwardButton;
IconButton* fStopButton; IconButton* fStopButton;
@@ -163,6 +164,10 @@ private:
BTextControl* fFindTextControl; BTextControl* fFindTextControl;
BCheckBox* fFindCaseSensitiveCheckBox; BCheckBox* fFindCaseSensitiveCheckBox;
TabManager* fTabManager; TabManager* fTabManager;
SettingsMessage* fAppSettings;
bool fZoomTextOnly;
bool fShowTabsIfSinglePageOpen;
}; };
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "SettingsKeys.h"
const char* kSettingsKeyDownloadPath = "download path";
const char* kSettingsKeyShowTabsIfSinglePageOpen
= "show tabs if single page open";
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SETTINGS_KEYS_H
#define SETTINGS_KEYS_H
#include <SupportDefs.h>
extern const char* kSettingsKeyDownloadPath;
extern const char* kSettingsKeyShowTabsIfSinglePageOpen;
#endif // SETTINGS_KEYS_H
+50 -27
View File
@@ -27,6 +27,7 @@
#include "SettingsWindow.h" #include "SettingsWindow.h"
#include <Button.h> #include <Button.h>
#include <CheckBox.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <GridLayoutBuilder.h> #include <GridLayoutBuilder.h>
#include <GroupLayout.h> #include <GroupLayout.h>
@@ -48,6 +49,7 @@
#include "BrowserApp.h" #include "BrowserApp.h"
#include "BrowsingHistory.h" #include "BrowsingHistory.h"
#include "FontSelectionView.h" #include "FontSelectionView.h"
#include "SettingsKeys.h"
#include "SettingsMessage.h" #include "SettingsMessage.h"
#include "WebSettings.h" #include "WebSettings.h"
@@ -64,6 +66,7 @@ enum {
MSG_DOWNLOAD_FOLDER_CHANGED = 'dnfc', MSG_DOWNLOAD_FOLDER_CHANGED = 'dnfc',
MSG_NEW_PAGE_BEHAVIOR_CHANGED = 'npbc', MSG_NEW_PAGE_BEHAVIOR_CHANGED = 'npbc',
MSG_GO_MENU_DAYS_CHANGED = 'digm', MSG_GO_MENU_DAYS_CHANGED = 'digm',
MSG_TAB_DISPLAY_BEHAVIOR_CHANGED = 'tdbc',
}; };
static const int32 kDefaultFontSize = 14; static const int32 kDefaultFontSize = 14;
@@ -144,33 +147,39 @@ void
SettingsWindow::MessageReceived(BMessage* message) SettingsWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case MSG_APPLY: case MSG_APPLY:
_ApplySettings(); _ApplySettings();
break; break;
case MSG_CANCEL: case MSG_CANCEL:
_RevertSettings(); _RevertSettings();
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
break; break;
case MSG_REVERT: case MSG_REVERT:
_RevertSettings(); _RevertSettings();
break; break;
case MSG_STANDARD_FONT_SIZE_SELECTED: { case MSG_STANDARD_FONT_SIZE_SELECTED:
int32 size = _SizesMenuValue(fStandardSizesMenu->Menu()); {
fStandardFontView->SetSize(size); int32 size = _SizesMenuValue(fStandardSizesMenu->Menu());
fSerifFontView->SetSize(size); fStandardFontView->SetSize(size);
fSansSerifFontView->SetSize(size); fSerifFontView->SetSize(size);
break; fSansSerifFontView->SetSize(size);
} break;
case MSG_FIXED_FONT_SIZE_SELECTED: { }
int32 size = _SizesMenuValue(fFixedSizesMenu->Menu()); case MSG_FIXED_FONT_SIZE_SELECTED:
fFixedFontView->SetSize(size); {
break; int32 size = _SizesMenuValue(fFixedSizesMenu->Menu());
} fFixedFontView->SetSize(size);
break;
}
default: case MSG_TAB_DISPLAY_BEHAVIOR_CHANGED:
BWindow::MessageReceived(message); // TODO: Some settings could change live, some others not?
break; break;
default:
BWindow::MessageReceived(message);
break;
} }
} }
@@ -236,6 +245,11 @@ fNewPageBehaviorMenu->SetEnabled(false);
for (uchar i = '9' + 1; i <= 128; i++) for (uchar i = '9' + 1; i <= 128; i++)
fDaysInGoMenuControl->TextView()->DisallowChar(i); fDaysInGoMenuControl->TextView()->DisallowChar(i);
fShowTabsIfOnlyOnePage = new BCheckBox("show tabs if only one page",
TR("Show tabs if only page is open."),
new BMessage(MSG_TAB_DISPLAY_BEHAVIOR_CHANGED));
fShowTabsIfOnlyOnePage->SetValue(B_CONTROL_ON);
BView* view = BGridLayoutBuilder(spacing / 2, spacing / 2) BView* view = BGridLayoutBuilder(spacing / 2, spacing / 2)
.Add(fDownloadFolderControl->CreateLabelLayoutItem(), 0, 1) .Add(fDownloadFolderControl->CreateLabelLayoutItem(), 0, 1)
.Add(fDownloadFolderControl->CreateTextViewLayoutItem(), 1, 1) .Add(fDownloadFolderControl->CreateTextViewLayoutItem(), 1, 1)
@@ -246,7 +260,9 @@ fNewPageBehaviorMenu->SetEnabled(false);
.Add(fDaysInGoMenuControl->CreateLabelLayoutItem(), 0, 3) .Add(fDaysInGoMenuControl->CreateLabelLayoutItem(), 0, 3)
.Add(fDaysInGoMenuControl->CreateTextViewLayoutItem(), 1, 3) .Add(fDaysInGoMenuControl->CreateTextViewLayoutItem(), 1, 3)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing), 0, 4, 2) .Add(fShowTabsIfOnlyOnePage, 0, 4, 2)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing), 0, 5, 2)
.SetInsets(spacing, spacing, spacing, spacing) .SetInsets(spacing, spacing, spacing, spacing)
; ;
@@ -323,7 +339,9 @@ SettingsWindow::_ApplySettings()
fDaysInGoMenuControl->SetText(text.String()); fDaysInGoMenuControl->SetText(text.String());
BrowsingHistory::DefaultInstance()->SetMaxHistoryItemAge(maxHistoryAge); BrowsingHistory::DefaultInstance()->SetMaxHistoryItemAge(maxHistoryAge);
fSettings->SetValue("download path", fDownloadFolderControl->Text()); fSettings->SetValue(kSettingsKeyDownloadPath, fDownloadFolderControl->Text());
fSettings->SetValue(kSettingsKeyShowTabsIfSinglePageOpen,
fShowTabsIfOnlyOnePage->Value() == B_CONTROL_ON);
// Store fond settings // Store fond settings
fSettings->SetValue("standard font", fStandardFontView->Font()); fSettings->SetValue("standard font", fStandardFontView->Font());
@@ -354,6 +372,11 @@ SettingsWindow::_ApplySettings()
void void
SettingsWindow::_RevertSettings() SettingsWindow::_RevertSettings()
{ {
fDownloadFolderControl->SetText(
fSettings->GetValue(kSettingsKeyDownloadPath, ""));
fShowTabsIfOnlyOnePage->SetValue(
fSettings->GetValue(kSettingsKeyShowTabsIfSinglePageOpen, true));
int32 defaultFontSize = fSettings->GetValue("standard font size", int32 defaultFontSize = fSettings->GetValue("standard font size",
kDefaultFontSize); kDefaultFontSize);
int32 defaultFixedFontSize = fSettings->GetValue("fixed font size", int32 defaultFixedFontSize = fSettings->GetValue("fixed font size",
+2
View File
@@ -30,6 +30,7 @@
#include <Window.h> #include <Window.h>
class BButton; class BButton;
class BCheckBox;
class BMenu; class BMenu;
class BMenuField; class BMenuField;
class BMenuItem; class BMenuItem;
@@ -73,6 +74,7 @@ private:
BMenuItem* fNewPageBehaviorOpenSearchItem; BMenuItem* fNewPageBehaviorOpenSearchItem;
BMenuItem* fNewPageBehaviorOpenBlankItem; BMenuItem* fNewPageBehaviorOpenBlankItem;
BTextControl* fDaysInGoMenuControl; BTextControl* fDaysInGoMenuControl;
BCheckBox* fShowTabsIfOnlyOnePage;
FontSelectionView* fStandardFontView; FontSelectionView* fStandardFontView;
FontSelectionView* fSerifFontView; FontSelectionView* fSerifFontView;