--- chimera/MyBrowserView.mm 2002/02/05 00:16:30 1.10 +++ chimera/MyBrowserView.mm 2002/02/11 07:22:13 1.16 @@ -25,6 +25,10 @@ static const char* ioServiceContractID = -(void)dealloc { + printf("My browser view died.\n"); + + [[NSNotificationCenter defaultCenter] removeObserver: self]; + [defaultStatus release]; [loadingStatus release]; @@ -36,27 +40,64 @@ static const char* ioServiceContractID = [browserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone]; } -- (void)awakeFromNib +-(void)disconnectView { - browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease]; - [self addSubview:browserView]; - [browserView setContainer:self]; - [browserView addListener:self]; - + urlbar = nil; + status = nil; + progress = nil; + progressSuper = nil; + mIsPrimary = NO; + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (id)initWithFrame:(NSRect)frameRect +{ + [super initWithFrame: frameRect]; + browserView = [[[NSBrowserView alloc] initWithFrame:[self bounds]] autorelease]; + [self addSubview:browserView]; + [browserView setContainer:self]; + [browserView addListener:self]; + mIsBusy = NO; + return self; +} + +-(void)makePrimaryBrowserView: (NSTabViewItem*)tab urlbar: (id)aUrlbar status: (id)aStatus + progress: (id)aProgress windowController: aWindowController +{ + mTab = tab; + urlbar = aUrlbar; + status = aStatus; + progress = aProgress; + progressSuper = [aProgress superview]; + mWindowController = aWindowController; + + if (!mIsBusy) { + [progress retain]; + [progress removeFromSuperview]; + } + defaultStatus = NULL; loadingStatus = DOCUMENT_DONE_STRING; [status setStringValue:loadingStatus]; - mIsBusy = NO; - - [progress retain]; - [progress removeFromSuperview]; + mIsPrimary = YES; + nsCOMPtr ioService(do_GetService(ioServiceContractID)); if (!ioService) return; PRBool offline = PR_FALSE; ioService->GetOffline(&offline); mOffline = offline; + + if (mWindowController) // Only register if we're the content area. + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(offlineModeChanged:) + name:@"offlineModeChanged" + object:nil]; +} + +- (void)awakeFromNib +{ } - (void)setFrame:(NSRect)frameRect @@ -87,6 +128,8 @@ static const char* ioServiceContractID = [status setStringValue:loadingStatus]; mIsBusy = YES; + [mTab setLabel: LOADING_STRING]; + if (mWindowController) [mWindowController updateToolbarItems]; } @@ -130,6 +173,11 @@ static const char* ioServiceContractID = [mWindowController updateLocationFields:spec]; } +- (void)onStatusChange:(NSString*)aStatusString +{ + [status setStringValue: aStatusString]; +} + - (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type { if (type == NSStatusTypeScriptDefault) { @@ -161,19 +209,50 @@ static const char* ioServiceContractID = - (void)setTitle:(NSString *)title { + if (!mWindowController) + return; // Sidebar panels can't affect the window title. + + // We must be the primary content area. + if (mIsPrimary) { + if (mOffline) { + NSString* newTitle; + if (title && ![title isEqualToString:@""]) + newTitle = [title stringByAppendingString: @" [Working Offline]"]; + else + newTitle = @"Untitled [Working Offline]"; + [[mWindowController window] setTitle: newTitle]; + } + else { + if (title && ![title isEqualToString:@""]) + [[mWindowController window] setTitle:title]; + else + [[mWindowController window] setTitle:@"Untitled"]; + } + } + + // Always set the tab. + if (title && ![title isEqualToString:@""]) + [mTab setLabel:title]; + else + [mTab setLabel:@"Untitled"]; +} + +- (void)offlineModeChanged: (NSNotification*)aNotification +{ + nsCOMPtr ioService(do_GetService(ioServiceContractID)); + if (!ioService) + return; + PRBool offline = PR_FALSE; + ioService->GetOffline(&offline); + mOffline = offline; + if (mOffline) { - NSString* newTitle; - if (title && ![title isEqualToString:@""]) - newTitle = [title stringByAppendingString: @" [Working Offline]"]; - else - newTitle = @"Untitled [Working Offline]"; + NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"]; [[mWindowController window] setTitle: newTitle]; } else { - if (title && ![title isEqualToString:@""]) - [[mWindowController window] setTitle:title]; - else - [[mWindowController window] setTitle:@"Untitled"]; + NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"]; + [[mWindowController window] setTitle: [titleItems objectAtIndex: 0]]; } }