Bug 315697, UI hangs when "are you sure you want to quit?" download sheet is displayed and the pref to close the download window is set. Be careful about putting the sheet up and closing the window. Patch by Nick Kreeger <nick.kreeger@park.edu>. Camion-only-npotdb. r=smfr

This commit is contained in:
mark%moxienet.com 2005-12-01 16:28:20 +00:00
parent cf0d53a926
commit fada42bd48
3 changed files with 43 additions and 10 deletions

View File

@ -87,6 +87,8 @@
NSMutableArray *mProgressViewControllers; // the downloads we manage, STRONG ref
int mNumActiveDownloads;
int mSelectionPivotIndex;
BOOL mShouldCloseWindow; // true when a download completes when termination modal sheet is up
BOOL mAwaitingTermination; // true when we are waiting for users termination modal sheet
}
+(ProgressDlgController *)sharedDownloadController; // creates if necessary

View File

@ -64,7 +64,7 @@ static NSString* const kProgressWindowFrameSaveName = @"ProgressWindow";
-(BOOL)shouldAllowPauseAction;
-(BOOL)shouldAllowResumeAction;
-(BOOL)fileExistsForSelectedItems;
-(void)maybeCloseWindow;
@end
@ -95,6 +95,11 @@ static id gSharedProgressController = nil;
// mess with it before setting it.
[[self window] setFrameUsingName:kProgressWindowFrameSaveName];
// these 2 bools prevent the app from locking up when the termination modal sheet
// is running and a download completes
mAwaitingTermination = NO;
mShouldCloseWindow = NO;
// We provide the views for the stack view, from mProgressViewControllers
[mStackView setDataSource:self];
mSelectionPivotIndex = -1;
@ -502,13 +507,10 @@ static id gSharedProgressController = nil;
// close the window if user has set pref to close when all downloads complete
if (completedOK)
{
BOOL gotPref;
BOOL keepDownloadsOpen = [[PreferenceManager sharedInstance] getBooleanPref:"browser.download.progressDnldDialog.keepAlive" withSuccess:&gotPref];
if (!keepDownloadsOpen && ([self numDownloadsInProgress] == 0))
{
[self close]; // don't call -performClose: on the window, because we don't want Cocoa to look
// for the option key and try to close all windows
}
if (!mAwaitingTermination)
[self maybeCloseWindow];
else
mShouldCloseWindow = YES;
}
else if (NS_FAILED(status) && status != NS_BINDING_ABORTED) // if it's an error, and not just canceled, show sheet
{
@ -518,6 +520,22 @@ static id gSharedProgressController = nil;
[self saveProgressViewControllers];
}
-(void)maybeCloseWindow
{
// only check if there are zero downloads running
if ([self numDownloadsInProgress] == 0)
{
BOOL gotPref;
BOOL keepDownloadsOpen = [[PreferenceManager sharedInstance] getBooleanPref:"browser.download.progressDnldDialog.keepAlive" withSuccess:&gotPref];
if (gotPref && !keepDownloadsOpen)
{
// don't call -performClose: on the window, because we don't want Cocoa to look
// for the option key and try to close all windows
[self close];
}
}
}
-(void)showErrorSheetForDownload:(id <CHDownloadProgressDisplay>)progressDisplay withStatus:(nsresult)inStatus
{
NSString* errorMsgFmt = NSLocalizedString(@"DownloadErrorMsgFmt", @"");
@ -654,6 +672,9 @@ static id gSharedProgressController = nil;
// downloads continue (PLEvents being processed)
id panel = NSGetAlertPanel(alert, message, okButton, altButton, nil, message);
// set this bool to true so that if a download finishes while the modal sheet is up we don't lock
mAwaitingTermination = YES;
[NSApp beginSheet:panel
modalForWindow:[self window]
modalDelegate:self
@ -665,7 +686,19 @@ static id gSharedProgressController = nil;
NSReleaseAlertPanel(panel);
if (sheetResult == NSAlertDefaultReturn)
{
mAwaitingTermination = NO;
// Check to see if a request to close the download window was made while the modal sheet was running.
// If so, close the download window according to the user's pref.
if (mShouldCloseWindow)
{
[self maybeCloseWindow];
mShouldCloseWindow = NO;
}
return NSTerminateCancel;
}
else {
// need to save here because downloads that were downloading aren't

View File

@ -170,8 +170,6 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void
if ((self = [self init]))
{
[self setProgressViewFromDictionary:aDict];
// since we are creating a progressview from a dict, the file
// will not be restarted, so setup file system notifications here
}
return self;