WebPositive: improve "show bookmark bar" menu item
* Disable the menu item when the folder doesn't exist, as the bar won't show in that case. * Use a mark on the item to tell wether the bar is visible, rather than changing its label * Simplify the logic for hiding and showing the bar. It is safe to call _ShowBookmarkBar even if the bar doesn't exist, so no need to check for it everywhere. Fixes #11199.
This commit is contained in:
parent
21f8e588da
commit
2c8da96546
@ -455,7 +455,7 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
|
|||||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Reload"), new BMessage(RELOAD),
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Reload"), new BMessage(RELOAD),
|
||||||
'R'));
|
'R'));
|
||||||
// the label will be replaced with the appropriate text later on
|
// the label will be replaced with the appropriate text later on
|
||||||
fBookmarkBarMenuItem = new BMenuItem("Show/Hide bookmark bar",
|
fBookmarkBarMenuItem = new BMenuItem(B_TRANSLATE("Show bookmark bar"),
|
||||||
new BMessage(SHOW_HIDE_BOOKMARK_BAR));
|
new BMessage(SHOW_HIDE_BOOKMARK_BAR));
|
||||||
menu->AddItem(fBookmarkBarMenuItem);
|
menu->AddItem(fBookmarkBarMenuItem);
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
@ -500,8 +500,11 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
|
|||||||
BEntry bookmarkBar(&barDir, "Bookmark bar");
|
BEntry bookmarkBar(&barDir, "Bookmark bar");
|
||||||
entry_ref bookmarkBarRef;
|
entry_ref bookmarkBarRef;
|
||||||
// TODO we could also check if the folder is empty here.
|
// TODO we could also check if the folder is empty here.
|
||||||
if (bookmarkBar.Exists() && bookmarkBar.GetRef(&bookmarkBarRef) == B_OK)
|
if (bookmarkBar.Exists() && bookmarkBar.GetRef(&bookmarkBarRef) == B_OK) {
|
||||||
fBookmarkBar = new BookmarkBar("Bookmarks", this, &bookmarkBarRef);
|
fBookmarkBar = new BookmarkBar("Bookmarks", this, &bookmarkBarRef);
|
||||||
|
fBookmarkBarMenuItem->SetEnabled(true);
|
||||||
|
} else
|
||||||
|
fBookmarkBarMenuItem->SetEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Back, Forward, Stop & Home buttons
|
// Back, Forward, Stop & Home buttons
|
||||||
@ -608,15 +611,10 @@ BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
|
|||||||
.Add(toggleFullscreenButton, 0.0f)
|
.Add(toggleFullscreenButton, 0.0f)
|
||||||
;
|
;
|
||||||
|
|
||||||
if (fBookmarkBar != NULL) {
|
if (fAppSettings->GetValue(kSettingsShowBookmarkBar, true))
|
||||||
if (fAppSettings->GetValue(kSettingsShowBookmarkBar, true)) {
|
_ShowBookmarkBar(true);
|
||||||
// We need to hide the bookmark bar and then show it again
|
else
|
||||||
// to save the setting and set the menu item label.
|
_ShowBookmarkBar(false);
|
||||||
fBookmarkBar->Hide();
|
|
||||||
_ShowBookmarkBar(true);
|
|
||||||
} else
|
|
||||||
_ShowBookmarkBar(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
|
fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this), NULL, 0,
|
||||||
false);
|
false);
|
||||||
@ -827,8 +825,7 @@ BrowserWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SHOW_HIDE_BOOKMARK_BAR:
|
case SHOW_HIDE_BOOKMARK_BAR:
|
||||||
if (fBookmarkBar != NULL)
|
_ShowBookmarkBar(fBookmarkBar->IsHidden());
|
||||||
_ShowBookmarkBar(fBookmarkBar->IsHidden());
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GOTO_URL:
|
case GOTO_URL:
|
||||||
@ -2606,16 +2603,16 @@ BrowserWindow::_HandlePageSourceResult(const BMessage* message)
|
|||||||
void
|
void
|
||||||
BrowserWindow::_ShowBookmarkBar(bool show)
|
BrowserWindow::_ShowBookmarkBar(bool show)
|
||||||
{
|
{
|
||||||
|
fBookmarkBarMenuItem->SetMarked(show);
|
||||||
|
|
||||||
if (fBookmarkBar == NULL || fBookmarkBar->IsHidden() != show)
|
if (fBookmarkBar == NULL || fBookmarkBar->IsHidden() != show)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fAppSettings->SetValue(kSettingsShowBookmarkBar, show);
|
fAppSettings->SetValue(kSettingsShowBookmarkBar, show);
|
||||||
|
|
||||||
fBookmarkBarMenuItem->SetLabel(show
|
if (show) {
|
||||||
? B_TRANSLATE("Hide bookmark bar")
|
|
||||||
: B_TRANSLATE("Show bookmark bar"));
|
|
||||||
if (show)
|
|
||||||
fBookmarkBar->Show();
|
fBookmarkBar->Show();
|
||||||
else
|
} else {
|
||||||
fBookmarkBar->Hide();
|
fBookmarkBar->Hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user