Fix the menu title and enabled state of the Show/Hide bookmarks item when toggling bookmarks. No bug.

This commit is contained in:
smfr%smfr.org 2005-03-06 06:32:07 +00:00
parent e35d06c35e
commit cff8ff9bf3
5 changed files with 56 additions and 10 deletions

View File

@ -725,7 +725,38 @@ Otherwise, we return the URL we originally got. Right now this supports .url and
[mAddBookmarkMenuItem setEnabled:inBrowserWindowFrontmost]; [mAddBookmarkMenuItem setEnabled:inBrowserWindowFrontmost];
[mCreateBookmarksFolderMenuItem setEnabled:inBrowserWindowFrontmost]; [mCreateBookmarksFolderMenuItem setEnabled:inBrowserWindowFrontmost];
[mCreateBookmarksSeparatorMenuItem setEnabled:YES]; [mCreateBookmarksSeparatorMenuItem setEnabled:YES];
[mShowAllBookmarksMenuItem setEnabled:YES]; // always enabled.
// We need the frontmost browser for the case of the dl/about window
// is the main so we can ensure the "show/hide all bookmarks" has the correct
// state for that window. Unfortunately, we can't rely on |-getFrontmostBrowserWindow| in all
// cases, such as when a window has just been opened. As a result, first
// try |-getMainWindowBrowserController| and if that fails use fFBW as a fallback.
BrowserWindowController* browserController = [self getMainWindowBrowserController];
if (!browserController)
browserController = (BrowserWindowController*)[[self getFrontmostBrowserWindow] windowController];
BOOL showBookmarksEnabled = YES;
BOOL useShowLabel = YES;
if (browserController)
{
if ([browserController bookmarkManagerIsVisible])
{
useShowLabel = NO;
showBookmarksEnabled = [browserController canHideBookmarks];
}
else
{
useShowLabel = YES;
}
}
NSString* showBMLabel = useShowLabel ? NSLocalizedString(@"Show All Bookmarks", @"")
: NSLocalizedString(@"Hide All Bookmarks", @"");
[mShowAllBookmarksMenuItem setTitle:showBMLabel];
[mShowAllBookmarksMenuItem setEnabled:showBookmarksEnabled];
} }
- (NSView*)getSavePanelView - (NSView*)getSavePanelView

View File

@ -251,6 +251,7 @@ typedef enum
- (IBAction)manageHistory: (id)aSender; - (IBAction)manageHistory: (id)aSender;
- (BOOL)bookmarkManagerIsVisible; - (BOOL)bookmarkManagerIsVisible;
- (BOOL)canHideBookmarks;
- (BOOL)singleBookmarkIsSelected; - (BOOL)singleBookmarkIsSelected;
- (void)createNewTab:(ENewTabContents)contents; - (void)createNewTab:(ENewTabContents)contents;

View File

@ -1311,6 +1311,12 @@ enum BWCOpenDest {
return [mURLBar userHasTyped]; return [mURLBar userHasTyped];
} }
- (void)contentViewChangedTo:(NSView*)inView forURL:(NSString*)inURL
{
// update bookmarks menu
[[NSApp delegate] adjustBookmarksMenuItemsEnabling:[[self window] isMainWindow]];
}
- (void)updateFromFrontmostTab - (void)updateFromFrontmostTab
{ {
[[self window] setTitle: [mBrowserView windowTitle]]; [[self window] setTitle: [mBrowserView windowTitle]];
@ -1466,7 +1472,9 @@ enum BWCOpenDest {
if ([self bookmarkManagerIsVisible]) if ([self bookmarkManagerIsVisible])
[self back:aSender]; [self back:aSender];
else else
[self loadURL:@"about:bookmarks" referrer:nil activate:YES allowPopups:YES]; [self loadURL:@"about:bookmarks" referrer:nil activate:YES allowPopups:NO];
[[NSApp delegate] adjustBookmarksMenuItemsEnabling:[[self window] isMainWindow]];
} }
// //
@ -1847,6 +1855,11 @@ enum BWCOpenDest {
return [currentURL isEqualToString:@"about:bookmarks"] || [currentURL isEqualToString:@"about:history"]; return [currentURL isEqualToString:@"about:bookmarks"] || [currentURL isEqualToString:@"about:history"];
} }
- (BOOL)canHideBookmarks
{
return [self bookmarkManagerIsVisible] && [[mBrowserView getBrowserView] canGoBack];
}
- (BOOL)singleBookmarkIsSelected - (BOOL)singleBookmarkIsSelected
{ {
if (![self bookmarkManagerIsVisible]) if (![self bookmarkManagerIsVisible])

View File

@ -68,6 +68,8 @@ class nsISupportsArray;
- (BOOL)userChangedLocationField; - (BOOL)userChangedLocationField;
- (void)contentViewChangedTo:(NSView*)inView forURL:(NSString*)inURL;
@end @end

View File

@ -391,15 +391,14 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged";
- (void)checkForCustomViewOnLoad:(NSString*)inURL - (void)checkForCustomViewOnLoad:(NSString*)inURL
{ {
NSView* newView = [self contentProviderViewForURL:inURL]; NSView* newContentView = [self contentProviderViewForURL:inURL];
if (newView) if (!newContentView)
newContentView = mBrowserView; // put the browser view back
if ([self firstSubview] != newContentView)
{ {
[self swapFirstSubview:newView]; [self swapFirstSubview:newContentView];
} [mDelegate contentViewChangedTo:newContentView forURL:inURL];
else
{
// put the browser view back
[self swapFirstSubview:mBrowserView];
} }
} }