From 65a271e837571872e7e537133c3ffbb41bb75298 Mon Sep 17 00:00:00 2001 From: "stuart.morgan%alumni.case.edu" Date: Wed, 27 Dec 2006 18:16:40 +0000 Subject: [PATCH] Camino only - Bug 181721: Disable menu commands when sheets or dialogs are frontmost. r=cl sr=pink --- camino/src/application/MainController.mm | 80 +++++++++++++------ camino/src/bookmarks/BookmarkManager.mm | 10 +++ camino/src/bookmarks/BookmarkToolbar.mm | 4 + .../src/bookmarks/BookmarkViewController.mm | 4 + camino/src/browser/BrowserWindowController.mm | 16 +++- camino/src/browser/GoMenu.mm | 15 ++++ camino/src/embedding/CHBrowserView.mm | 4 + .../src/history/HistoryOutlineViewDelegate.mm | 4 + 8 files changed, 110 insertions(+), 27 deletions(-) diff --git a/camino/src/application/MainController.mm b/camino/src/application/MainController.mm index 50f9831f2db..521d18c1997 100644 --- a/camino/src/application/MainController.mm +++ b/camino/src/application/MainController.mm @@ -118,6 +118,7 @@ const int kReuseWindowOnAE = 2; - (void)menuWillDisplay:(NSNotification*)inNotification; - (void)showCertificatesNotification:(NSNotification*)inNotification; - (void)openPanelDidEnd:(NSOpenPanel*)inOpenPanel returnCode:(int)inReturnCode contextInfo:(void*)inContextInfo; +- (void)loadApplicationPage:(NSString*)pageURL; - (NSArray*)browserWindows; + (NSURL*)decodeLocalFileURL:(NSURL*)url; @@ -630,6 +631,17 @@ const int kReuseWindowOnAE = 2; controller = [self openBrowserWindowWithURL:inURLString andReferrer:aReferrer behind:nil allowPopups:NO]; } +// Convenience function for loading application pages either in a new window or a new +// tab as appropriate for the user prefs and the current browser state. +- (void)loadApplicationPage:(NSString*)pageURL +{ + BrowserWindowController* browserController = [self getMainWindowBrowserController]; + if (browserController && [[browserController window] attachedSheet]) + [self openBrowserWindowWithURL:pageURL andReferrer:nil behind:nil allowPopups:NO]; + else + [self openNewWindowOrTabWithURL:pageURL andReferrer:nil alwaysInFront:YES]; +} + - (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)filename { // We can get called before -applicationDidFinishLaunching, so make sure gecko @@ -808,7 +820,7 @@ const int kReuseWindowOnAE = 2; { NSString* pageToLoad = NSLocalizedStringFromTable(@"FeedbackPageDefault", @"WebsiteDefaults", nil); if (![pageToLoad isEqualToString:@"FeedbackPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:pageToLoad]; } - (IBAction)displayPreferencesWindow:(id)sender @@ -1397,7 +1409,7 @@ const int kReuseWindowOnAE = 2; { NSString* pageToLoad = NSLocalizedStringFromTable(@"RendezvousPageDefault", @"WebsiteDefaults", nil); if (![pageToLoad isEqualToString:@"RendezvousPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:pageToLoad]; } - (IBAction)connectToServer:(id)aSender @@ -1446,40 +1458,40 @@ const int kReuseWindowOnAE = 2; { NSString* pageToLoad = NSLocalizedStringFromTable(@"SupportPageDefault", @"WebsiteDefaults", nil); if (![pageToLoad isEqualToString:@"SupportPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:pageToLoad]; } - (IBAction)infoLink:(id)aSender { NSString* pageToLoad = NSLocalizedStringFromTable(@"InfoPageDefault", @"WebsiteDefaults", nil); if (![pageToLoad isEqualToString:@"InfoPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:pageToLoad]; } - (IBAction)aboutPlugins:(id)aSender { - [self openNewWindowOrTabWithURL:@"about:plugins" andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:@"about:plugins"]; } - (IBAction)releaseNoteLink:(id)aSender { NSString* pageToLoad = NSLocalizedStringFromTable(@"ReleaseNotesDefault", @"WebsiteDefaults", nil); if (![pageToLoad isEqualToString:@"ReleaseNotesDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:pageToLoad]; } - (IBAction)tipsTricksLink:(id)aSender { NSString* pageToLoad = NSLocalizedStringFromTable(@"TipsTricksPageDefault", @"WebsiteDefaults", nil); if (![pageToLoad isEqualToString:@"TipsTricksPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:pageToLoad]; } - (IBAction)searchCustomizeLink:(id)aSender { NSString* pageToLoad = NSLocalizedStringFromTable(@"SearchCustomPageDefault", @"WebsiteDefaults", nil); if (![pageToLoad isEqualToString:@"SearchCustomPageDefault"]) - [self openNewWindowOrTabWithURL:pageToLoad andReferrer:nil alwaysInFront:YES]; + [self loadApplicationPage:pageToLoad]; } #pragma mark - @@ -1492,19 +1504,34 @@ const int kReuseWindowOnAE = 2; // NSLog(@"MainController validateMenuItem for %@ (%s)", [aMenuItem title], action); + // disable window-related menu items if a sheet is up + if (browserController && [[browserController window] attachedSheet] && + (action == @selector(openFile:) || + action == @selector(openLocation:) || + action == @selector(savePage:) || + action == @selector(newTab:) || + action == @selector(doSearch:) || + action == @selector(toggleBookmarksToolbar:) || + action == @selector(goHome:) || + action == @selector(showHistory:) || + action == @selector(manageBookmarks:) || + action == @selector(openMenuBookmark:) || + action == @selector(connectToServer:))) + { + return NO; + } + // check what the state of the personal toolbar should be, but only if there is a browser // window open. Popup windows that have the personal toolbar removed should always gray // out this menu. if (action == @selector(toggleBookmarksToolbar:)) { if (browserController) { - NSView* bookmarkToolbar = [browserController bookmarkToolbar]; + BookmarkToolbar* bookmarkToolbar = [browserController bookmarkToolbar]; if (bookmarkToolbar) { - float height = [bookmarkToolbar frame].size.height; - BOOL toolbarShowing = (height > 0); - if (toolbarShowing) - [mBookmarksToolbarMenuItem setTitle:NSLocalizedString(@"Hide Bookmarks Toolbar",@"")]; + if ([bookmarkToolbar isVisible]) + [mBookmarksToolbarMenuItem setTitle:NSLocalizedString(@"Hide Bookmarks Toolbar", nil)]; else - [mBookmarksToolbarMenuItem setTitle:NSLocalizedString(@"Show Bookmarks Toolbar",@"")]; + [mBookmarksToolbarMenuItem setTitle:NSLocalizedString(@"Show Bookmarks Toolbar", nil)]; return YES; } } @@ -1527,12 +1554,6 @@ const int kReuseWindowOnAE = 2; [aMenuItem setTitle:NSLocalizedString(@"Open in Tabs in New Window", nil)]; } - // disable open menu items if a sheet is up (maybe disable others too) - if (action == @selector(openFile:) || - action == @selector(openLocation:)) { - return (!browserController || [[browserController window] attachedSheet] == nil); - } - // only enable newTab if there is a browser window frontmost, or if there is no window // (i.e., disable it for non-browser windows). if (action == @selector(newTab:)) @@ -1550,7 +1571,17 @@ const int kReuseWindowOnAE = 2; // BrowserWindowController decides about actions that are just sent on to // the front window's BrowserWindowController. This works because the selectors // of these actions are the same here and in BrowserWindowController. + + // goBack: and goForward: don't match; for now we translate them, but eventually + // BrowserWindowController's methods should be renamed. + if (action == @selector(goBack:)) + action = @selector(back:); + if (action == @selector(goForward:)) + action = @selector(forward:); + if (action == @selector(stop:) || + action == @selector(back:) || + action == @selector(forward:) || action == @selector(reload:) || action == @selector(reloadAllTabs:) || action == @selector(nextTab:) || @@ -1564,14 +1595,10 @@ const int kReuseWindowOnAE = 2; action == @selector(printDocument:) || action == @selector(pageSetup:)) { + if (browserController && [[browserController window] attachedSheet]) + return NO; return (browserController && [browserController validateActionBySelector:action]); } - // goBack: and goForward: don't match; for now we translate them, but eventually - // BrowserWindowController's methods should be renamed. - if (action == @selector(goBack:)) - return (browserController && [browserController validateActionBySelector:@selector(back:)]); - if (action == @selector(goForward:)) - return (browserController && [browserController validateActionBySelector:@selector(forward:)]); // default return return YES; @@ -1589,6 +1616,7 @@ const int kReuseWindowOnAE = 2; { BrowserWindowController* browserController = [self getMainWindowBrowserController]; if (browserController && ![browserController bookmarkManagerIsVisible] && + ![[browserController window] attachedSheet] && [[[browserController getBrowserWrapper] getBrowserView] isTextBasedContent]) { // enable all items diff --git a/camino/src/bookmarks/BookmarkManager.mm b/camino/src/bookmarks/BookmarkManager.mm index ac496a566ca..01afc2980a8 100644 --- a/camino/src/bookmarks/BookmarkManager.mm +++ b/camino/src/bookmarks/BookmarkManager.mm @@ -920,6 +920,16 @@ static BookmarkManager* gBookmarkManager = nil; [contextMenu setSubmenu:arrangeSubmenu forItem:menuItem]; } + // Disable context menu items if the parent window is currently showing a sheet. + if ((outlineView && [[outlineView window] attachedSheet]) || + (target && [target respondsToSelector:@selector(window)] && [[target window] attachedSheet])) + { + NSArray* menuArray = [contextMenu itemArray]; + for (unsigned i = 0; i < [menuArray count]; i++) { + [[menuArray objectAtIndex:i] setEnabled:NO]; + } + } + return contextMenu; } diff --git a/camino/src/bookmarks/BookmarkToolbar.mm b/camino/src/bookmarks/BookmarkToolbar.mm index b8934e5b265..234b46010fa 100644 --- a/camino/src/bookmarks/BookmarkToolbar.mm +++ b/camino/src/bookmarks/BookmarkToolbar.mm @@ -482,6 +482,10 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa // - (BOOL)validateMenuItem:(NSMenuItem*)aMenuItem { + // Window actions are disabled while a sheet is showing + if ([[self window] attachedSheet]) + return NO; + return YES; } diff --git a/camino/src/bookmarks/BookmarkViewController.mm b/camino/src/bookmarks/BookmarkViewController.mm index f313471ae3b..11ce341b8c1 100644 --- a/camino/src/bookmarks/BookmarkViewController.mm +++ b/camino/src/bookmarks/BookmarkViewController.mm @@ -1595,6 +1595,10 @@ const int kOutlineViewLeftMargin = 19; // determined empirically, since it doesn - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { + // Window actions are disabled while a sheet is showing + if ([[mBrowserWindowController window] attachedSheet]) + return NO; + SEL action = [menuItem action]; if ([self activeOutlineView] == mBookmarksOutlineView) { diff --git a/camino/src/browser/BrowserWindowController.mm b/camino/src/browser/BrowserWindowController.mm index fb27493eaa2..1c4ba69903e 100644 --- a/camino/src/browser/BrowserWindowController.mm +++ b/camino/src/browser/BrowserWindowController.mm @@ -1676,10 +1676,16 @@ enum BWCOpenDest { #pragma mark - --(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem +- (BOOL)validateMenuItem:(NSMenuItem*)aMenuItem { SEL action = [aMenuItem action]; + // Disable all window-specific menu items while a sheet is showing. + // We don't do this in validateActionBySelector: because toolbar items shouldn't + // suddenly get a disabled look when a sheet appears (they aren't clickable anyway). + if ([[self window] attachedSheet]) + return NO; + if (action == @selector(reloadSendersTab:)) { BrowserTabViewItem* sendersTab = [[self getTabBrowser] itemWithTag:[aMenuItem tag]]; return [[sendersTab view] canReload]; @@ -4137,6 +4143,14 @@ enum BWCOpenDest { } } + // Disable context menu items if the window is currently showing a sheet. + if ([[self window] attachedSheet]) { + NSArray* menuArray = [result itemArray]; + for (unsigned i = 0; i < [menuArray count]; i++) { + [[menuArray objectAtIndex:i] setEnabled:NO]; + } + } + return result; } diff --git a/camino/src/browser/GoMenu.mm b/camino/src/browser/GoMenu.mm index 4525bab8596..9abfea7b738 100644 --- a/camino/src/browser/GoMenu.mm +++ b/camino/src/browser/GoMenu.mm @@ -422,6 +422,21 @@ static const unsigned int kMaxTitleLength = 50; [self rebuildHistoryItems]; } +- (BOOL)validateMenuItem:(NSMenuItem*)aMenuItem +{ + BrowserWindowController* browserController = [(MainController *)[NSApp delegate] getMainWindowBrowserController]; + SEL action = [aMenuItem action]; + + // disable history if a sheet is up + if (browserController && [[browserController window] attachedSheet] && + (action == @selector(openHistoryItem:))) + { + return NO; + } + + return YES; +} + - (void)openHistoryItem:(id)sender { id repObject = [sender representedObject]; diff --git a/camino/src/embedding/CHBrowserView.mm b/camino/src/embedding/CHBrowserView.mm index c6c8ca33488..81c4c783eac 100644 --- a/camino/src/embedding/CHBrowserView.mm +++ b/camino/src/embedding/CHBrowserView.mm @@ -1285,6 +1285,10 @@ const char kDirServiceContractID[] = "@mozilla.org/file/directory_service;1"; -(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem { + // Window actions are disabled while a sheet is showing + if ([[self window] attachedSheet]) + return NO; + // update first responder items based on the selection SEL action = [aMenuItem action]; if (action == @selector(cut:)) diff --git a/camino/src/history/HistoryOutlineViewDelegate.mm b/camino/src/history/HistoryOutlineViewDelegate.mm index b27db660290..5c1b75bcd8f 100644 --- a/camino/src/history/HistoryOutlineViewDelegate.mm +++ b/camino/src/history/HistoryOutlineViewDelegate.mm @@ -470,6 +470,10 @@ static NSString* const kExpandedHistoryStatesDefaultsKey = @"history_expand_stat - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { + // Window actions are disabled while a sheet is showing + if ([[mBrowserWindowController window] attachedSheet]) + return NO; + SEL action = [menuItem action]; if (action == @selector(openHistoryItem:) ||