From c620610b98ac26afed638fbccabee14d85dea41d Mon Sep 17 00:00:00 2001 From: John Scipione Date: Thu, 24 Apr 2014 20:02:31 -0400 Subject: [PATCH] WebPositive: Add support to show/hide bookmark bar Default is shown, a menu option in the View menu allows you to show or hide the bar. Also move the bookmark bar below the tab frame, it looks better here I think and matches other browsers (e.g. Firefox.) --- src/apps/webpositive/BrowserWindow.cpp | 44 ++++++++++++++++++++++++-- src/apps/webpositive/BrowserWindow.h | 10 ++++-- src/apps/webpositive/SettingsKeys.cpp | 11 ++++++- src/apps/webpositive/SettingsKeys.h | 10 +++++- 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index 0295c01eda..bbb2a915bd 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -5,7 +5,7 @@ * Copyright (C) 2010 Stephan Aßmus * Copyright (C) 2010 Michael Lotz * Copyright (C) 2010 Rene Gollent - * Copyright 2013 Haiku, Inc. All rights reserved. + * Copyright 2013-2014 Haiku, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -101,6 +101,7 @@ enum { HOME = 'home', GOTO_URL = 'goul', RELOAD = 'reld', + SHOW_HIDE_BOOKMARK_BAR = 'shbb', CLEAR_HISTORY = 'clhs', CREATE_BOOKMARK = 'crbm', @@ -572,6 +573,10 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, menu = new BMenu(B_TRANSLATE("View")); menu->AddItem(new BMenuItem(B_TRANSLATE("Reload"), new BMessage(RELOAD), 'R')); + // the label will be replaced with the appropriate text later on + fBookmarkBarMenuItem = new BMenuItem("Show/Hide bookmark bar", + new BMessage(SHOW_HIDE_BOOKMARK_BAR)); + menu->AddItem(fBookmarkBarMenuItem); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Increase size"), new BMessage(ZOOM_FACTOR_INCREASE), '+')); @@ -715,15 +720,23 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, .Add(toggleFullscreenButton, 0.0f) ; + fBookmarkBar = new BookmarkBar("Bookmarks", this, &bookmarkRef); + if (fAppSettings->GetValue(kSettingsShowBookmarkBar, true)) { + // We need to hide the bookmark bar and then show it again + // to save the setting and set the menu item label. + fBookmarkBar->Hide(); + _ShowBookmarkBar(true); + } else + _ShowBookmarkBar(false); + // Layout AddChild(BLayoutBuilder::Group<>(B_VERTICAL, 0.0) #if !INTEGRATE_MENU_INTO_TAB_BAR .Add(menuBarGroup) #endif - .Add(new BookmarkBar(B_TRANSLATE("Bookmarks"), this, - &bookmarkRef)) .Add(fTabManager->TabGroup()) .Add(navigationGroup) + .Add(fBookmarkBar) .Add(fTabManager->ContainerView()) .Add(findGroup) .Add(statusGroup) @@ -917,6 +930,10 @@ BrowserWindow::MessageReceived(BMessage* message) CurrentWebView()->Reload(); break; + case SHOW_HIDE_BOOKMARK_BAR: + _ShowBookmarkBar(fBookmarkBar->IsHidden()); + break; + case GOTO_URL: { BString url; @@ -1229,6 +1246,9 @@ BrowserWindow::MessageReceived(BMessage* message) fHomeButton->Show(); else fHomeButton->Hide(); + } else if (name == kSettingsShowBookmarkBar + && message->FindBool("value", &flag) == B_OK) { + _ShowBookmarkBar(flag); } break; } @@ -2627,3 +2647,21 @@ BrowserWindow::_HandlePageSourceResult(const BMessage* message) alert->Go(NULL); } } + + +void +BrowserWindow::_ShowBookmarkBar(bool show) +{ + if (fBookmarkBar == NULL || fBookmarkBar->IsHidden() != show) + return; + + fAppSettings->SetValue(kSettingsShowBookmarkBar, show); + + fBookmarkBarMenuItem->SetLabel(show + ? B_TRANSLATE("Hide bookmark bar") + : B_TRANSLATE("Show bookmark bar")); + if (show) + fBookmarkBar->Show(); + else + fBookmarkBar->Hide(); +} diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index a2d228f5ff..3defae76a2 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -2,8 +2,7 @@ * Copyright (C) 2007 Ryan Leavengood * Copyright (C) 2009 Maxime Simon * Copyright (C) 2010 Stephan Aßmus - * - * All rights reserved. + * Copyright 2013-2014 Haiku, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -48,6 +47,8 @@ class BStringView; class BTextControl; class BUrlContext; class BWebView; + +class BookmarkBar; class SettingsMessage; class TabManager; class URLInputGroup; @@ -209,6 +210,8 @@ private: void _HandlePageSourceResult( const BMessage* message); + void _ShowBookmarkBar(bool show); + private: BMenu* fHistoryMenu; int32 fHistoryMenuFixedItemCount; @@ -266,6 +269,9 @@ private: uint32 fNewTabPolicy; BString fStartPageURL; BString fSearchPageURL; + + BMenuItem* fBookmarkBarMenuItem; + BookmarkBar* fBookmarkBar; }; diff --git a/src/apps/webpositive/SettingsKeys.cpp b/src/apps/webpositive/SettingsKeys.cpp index c724682654..1cb2a3777b 100644 --- a/src/apps/webpositive/SettingsKeys.cpp +++ b/src/apps/webpositive/SettingsKeys.cpp @@ -1,11 +1,18 @@ /* * Copyright (C) 2010 Stephan Aßmus + * Coptright 2014 Haiku, Inc. All rights reserved. * - * All rights reserved. Distributed under the terms of the MIT License. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus, superstippi@gmx.de + * John Scipione, jscipione@gmail.com */ + #include "SettingsKeys.h" + const char* kSettingsKeyDownloadPath = "download path"; const char* kSettingsKeyShowTabsIfSinglePageOpen = "show tabs if single page open"; @@ -31,3 +38,5 @@ const char* kSettingsKeyProxyPort = "http proxy port"; const char* kSettingsKeyUseProxyAuth = "use http proxy authentication"; const char* kSettingsKeyProxyUsername = "http proxy username"; const char* kSettingsKeyProxyPassword = "http proxy password"; + +const char* kSettingsShowBookmarkBar = "show bookmarks bar"; \ No newline at end of file diff --git a/src/apps/webpositive/SettingsKeys.h b/src/apps/webpositive/SettingsKeys.h index 71a0999504..21cbeb95c0 100644 --- a/src/apps/webpositive/SettingsKeys.h +++ b/src/apps/webpositive/SettingsKeys.h @@ -1,11 +1,17 @@ /* * Copyright (C) 2010 Stephan Aßmus + * Coptright 2014 Haiku, Inc. All rights reserved. * - * All rights reserved. Distributed under the terms of the MIT License. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus, superstippi@gmx.de + * John Scipione, jscipione@gmail.com */ #ifndef SETTINGS_KEYS_H #define SETTINGS_KEYS_H + #include @@ -31,4 +37,6 @@ extern const char* kSettingsKeyUseProxyAuth; extern const char* kSettingsKeyProxyUsername; extern const char* kSettingsKeyProxyPassword; +extern const char* kSettingsShowBookmarkBar; + #endif // SETTINGS_KEYS_H