Annotation of chimera/BrowserWindowController.mm, revision 1.18
1.2 macserv 1: /*
2: * BrowserWindowController.mm
3: */
1.1 hyatt 4:
5: #import "BrowserWindowController.h"
6: #import "MyBrowserView.h"
7:
8: static NSString *BrowserToolbarIdentifier = @"Browser Window Toolbar";
9: static NSString *BackToolbarItemIdentifier = @"Back Toolbar Item";
10: static NSString *ForwardToolbarItemIdentifier = @"Forward Toolbar Item";
11: static NSString *ReloadToolbarItemIdentifier = @"Reload Toolbar Item";
12: static NSString *StopToolbarItemIdentifier = @"Stop Toolbar Item";
13: static NSString *HomeToolbarItemIdentifier = @"Home Toolbar Item";
14: static NSString *LocationToolbarItemIdentifier = @"Location Toolbar Item";
15: static NSString *SidebarToolbarItemIdentifier = @"Sidebar Toolbar Item";
1.11 macserv 16: static NSString *PrintToolbarItemIdentifier = @"Print Toolbar Item";
1.1 hyatt 17:
18: @interface BrowserWindowController(Private)
19: - (void)setupToolbar;
20: @end
21:
22: @implementation BrowserWindowController
23:
1.4 hyatt 24: - (id)init
25: {
26: mInitialized = NO;
27: return [super init];
28: }
29:
1.17 hyatt 30: - (void)windowWillClose:(NSNotification *)notification
31: {
32: [self autorelease];
33: }
34:
1.7 hyatt 35: - (void)dealloc
36: {
1.10 hyatt 37: [mBrowserView windowClosed];
1.7 hyatt 38: [super dealloc];
39: }
40:
1.1 hyatt 41: - (void)windowDidLoad
42: {
1.4 hyatt 43: mInitialized = YES;
1.1 hyatt 44: [self setupToolbar];
1.4 hyatt 45:
46: if (mURL) {
47: [self loadURL: mURL];
48: [mURL release];
49: }
1.18 ! hyatt 50:
! 51: [mSidebarDrawer setDelegate: self];
! 52: }
! 53:
! 54: - (void)drawerDidOpen:(NSNotification *)aNotification
! 55: {
! 56: [[mSidebarBrowserView getBrowserView] loadURI: [NSURL URLWithString: @"http://tinderbox.mozilla.org/SeaMonkey/panel.html"] flags:NSLoadFlagsNone];
1.1 hyatt 57: }
58:
59: - (void)setupToolbar
60: {
61: NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier:BrowserToolbarIdentifier] autorelease];
62:
63: [toolbar setDisplayMode:NSToolbarDisplayModeDefault];
64: [toolbar setAllowsUserCustomization:YES];
65: [toolbar setAutosavesConfiguration:YES];
66: [toolbar setDelegate:self];
67: [[self window] setToolbar:toolbar];
68: }
69:
70:
71: - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
72: {
73: return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
74: ForwardToolbarItemIdentifier,
75: ReloadToolbarItemIdentifier,
76: StopToolbarItemIdentifier,
77: HomeToolbarItemIdentifier,
78: LocationToolbarItemIdentifier,
79: SidebarToolbarItemIdentifier,
1.11 macserv 80: PrintToolbarItemIdentifier,
1.1 hyatt 81: NSToolbarCustomizeToolbarItemIdentifier,
82: NSToolbarFlexibleSpaceItemIdentifier,
83: NSToolbarSpaceItemIdentifier,
84: NSToolbarSeparatorItemIdentifier,
85: nil];
86: }
87:
88: - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
89: {
90: return [NSArray arrayWithObjects: BackToolbarItemIdentifier,
91: ForwardToolbarItemIdentifier,
92: ReloadToolbarItemIdentifier,
93: StopToolbarItemIdentifier,
94: HomeToolbarItemIdentifier,
95: LocationToolbarItemIdentifier,
96: SidebarToolbarItemIdentifier,
97: nil];
98: }
99:
100: - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
101: itemForItemIdentifier:(NSString *)itemIdent
102: willBeInsertedIntoToolbar:(BOOL)willBeInserted
103: {
104: NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdent] autorelease];
105: if ( [itemIdent isEqual:BackToolbarItemIdentifier] ) {
106: [toolbarItem setLabel:@"Back"];
107: [toolbarItem setPaletteLabel:@"Go Back"];
108: [toolbarItem setToolTip:@"Go back one page"];
109: [toolbarItem setImage:[NSImage imageNamed:@"back"]];
110: [toolbarItem setTarget:self];
111: [toolbarItem setAction:@selector(back:)];
112: } else if ( [itemIdent isEqual:ForwardToolbarItemIdentifier] ) {
113: [toolbarItem setLabel:@"Forward"];
114: [toolbarItem setPaletteLabel:@"Go Forward"];
115: [toolbarItem setToolTip:@"Go forward one page"];
116: [toolbarItem setImage:[NSImage imageNamed:@"forward"]];
117: [toolbarItem setTarget:self];
118: [toolbarItem setAction:@selector(forward:)];
119: } else if ( [itemIdent isEqual:ReloadToolbarItemIdentifier] ) {
120: [toolbarItem setLabel:@"Reload"];
121: [toolbarItem setPaletteLabel:@"Reload Page"];
122: [toolbarItem setToolTip:@"Reload current page"];
123: [toolbarItem setImage:[NSImage imageNamed:@"reload"]];
124: [toolbarItem setTarget:self];
125: [toolbarItem setAction:@selector(reload:)];
126: } else if ( [itemIdent isEqual:StopToolbarItemIdentifier] ) {
127: [toolbarItem setLabel:@"Stop"];
128: [toolbarItem setPaletteLabel:@"Stop Loading"];
129: [toolbarItem setToolTip:@"Stop loading this page"];
130: [toolbarItem setImage:[NSImage imageNamed:@"stop"]];
131: [toolbarItem setTarget:self];
132: [toolbarItem setAction:@selector(stop:)];
133: } else if ( [itemIdent isEqual:HomeToolbarItemIdentifier] ) {
134: [toolbarItem setLabel:@"Home"];
135: [toolbarItem setPaletteLabel:@"Go Home"];
136: [toolbarItem setToolTip:@"Go to home page"];
137: [toolbarItem setImage:[NSImage imageNamed:@"home"]];
138: [toolbarItem setTarget:self];
139: [toolbarItem setAction:@selector(home:)];
140: } else if ( [itemIdent isEqual:SidebarToolbarItemIdentifier] ) {
141: [toolbarItem setLabel:@"Sidebar"];
142: [toolbarItem setPaletteLabel:@"Toggle Sidebar"];
143: [toolbarItem setToolTip:@"Show or hide the Sidebar"];
144: [toolbarItem setImage:[NSImage imageNamed:@"sidebar"]];
145: [toolbarItem setTarget:self];
146: [toolbarItem setAction:@selector(toggleSidebar:)];
147: } else if ( [itemIdent isEqual:LocationToolbarItemIdentifier] ) {
148:
149: NSMenuItem *menuFormRep = [[[NSMenuItem alloc] init] autorelease];
150:
151: [toolbarItem setLabel:@"Location"];
152: [toolbarItem setPaletteLabel:@"Location"];
153: [toolbarItem setImage:[NSImage imageNamed:@"Enter a web location."]];
154: [toolbarItem setView:mLocationToolbarView];
155: [toolbarItem setMinSize:NSMakeSize(128,32)];
156: [toolbarItem setMaxSize:NSMakeSize(2560,32)];
157:
158: [menuFormRep setTarget:self];
1.5 macserv 159: [menuFormRep setAction:@selector(performAppropriateLocationAction)];
1.1 hyatt 160: [menuFormRep setTitle:[toolbarItem label]];
161:
162: [toolbarItem setMenuFormRepresentation:menuFormRep];
1.5 macserv 163: mLocationToolbarItem = toolbarItem;
1.11 macserv 164:
165: } else if ( [itemIdent isEqual:PrintToolbarItemIdentifier] ) {
166: [toolbarItem setLabel:@"Print"];
167: [toolbarItem setPaletteLabel:@"Print"];
168: [toolbarItem setToolTip:@"Print this page"];
169: [toolbarItem setImage:[NSImage imageNamed:@"print"]];
170: [toolbarItem setTarget:self];
171: [toolbarItem setAction:@selector(printDocument)];
1.1 hyatt 172: } else {
173: toolbarItem = nil;
174: }
175:
176: return toolbarItem;
177: }
178:
179: // This method handles the enabling/disabling of the toolbar buttons.
180: - (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
181: {
182: // Check the action and see if it matches.
183: SEL action = [theItem action];
184: if (action == @selector(back:))
185: return [[mBrowserView getBrowserView] canGoBack];
186: else if (action == @selector(forward:))
187: return [[mBrowserView getBrowserView] canGoForward];
188: else if (action == @selector(reload:))
189: return [mBrowserView isBusy] == NO;
190: else if (action == @selector(stop:))
191: return [mBrowserView isBusy];
192: else
193: return YES;
194: }
195:
1.5 macserv 196: - (void)updateToolbarItems
1.1 hyatt 197: {
198: [[[self window] toolbar] validateVisibleItems];
199: }
200:
1.5 macserv 201: - (void)performAppropriateLocationAction
202: {
203: if ( [[[self window] toolbar] isVisible] ) {
204: if ( ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconAndLabel) ||
205: ([[[self window] toolbar] displayMode] == NSToolbarDisplayModeIconOnly) ) {
206: [self focusURLBar];
207: } else {
208: [self beginLocationSheet];
209: }
210: } else {
211: [self beginLocationSheet];
212: }
213: }
214:
215: - (void)focusURLBar
1.3 hyatt 216: {
217: [mURLBar selectText: self];
218: }
219:
1.5 macserv 220: - (void)beginLocationSheet
221: {
222: [NSApp beginSheet: mLocationSheetWindow
223: modalForWindow: [self window]
224: modalDelegate: nil
225: didEndSelector: nil
226: contextInfo: nil];
227: }
228:
229: - (IBAction)endLocationSheet:(id)sender
230: {
231: [mLocationSheetWindow orderOut:self];
232: [NSApp endSheet:mLocationSheetWindow returnCode:1];
233: [self loadURL:[NSURL URLWithString:[mLocationSheetURLField stringValue]]];
234: }
235:
236: - (IBAction)goToLocationFromToolbarURLField:(id)sender
237: {
238: [self loadURL:[NSURL URLWithString:[sender stringValue]]];
239: }
240:
1.7 hyatt 241: - (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
1.6 hyatt 242: {
1.7 hyatt 243: [[mBrowserView getBrowserView] saveDocument: aFilterView filterList: aFilterList];
1.6 hyatt 244: }
245:
1.12 hyatt 246: - (void)printDocument
247: {
248: [[mBrowserView getBrowserView] printDocument];
249: }
250:
1.15 hyatt 251: - (void)printPreview
252: {
253: [[mBrowserView getBrowserView] printPreview];
254: }
255:
1.16 hyatt 256: - (void)findInPage
257: {
258: [[mBrowserView getBrowserView] findInPage];
259: }
260:
261: - (void)findAgain
262: {
263: [[mBrowserView getBrowserView] findAgain];
264: }
265:
1.5 macserv 266: - (IBAction)back:(id)aSender
1.1 hyatt 267: {
268: [[mBrowserView getBrowserView] goBack];
269: }
270:
1.5 macserv 271: - (IBAction)forward:(id)aSender
1.1 hyatt 272: {
273: [[mBrowserView getBrowserView] goForward];
274: }
275:
1.5 macserv 276: - (IBAction)reload:(id)aSender
1.1 hyatt 277: {
278: [[mBrowserView getBrowserView] reload: 0];
279: }
280:
1.5 macserv 281: - (IBAction)stop:(id)aSender
1.1 hyatt 282: {
283: [[mBrowserView getBrowserView] stop: 0];
284: }
285:
1.5 macserv 286: - (IBAction)home:(id)aSender
1.1 hyatt 287: {
1.5 macserv 288: [[mBrowserView getBrowserView] loadURI:[NSURL URLWithString:@"about:blank"] flags:NSLoadFlagsNone];
1.1 hyatt 289: }
290:
1.5 macserv 291: - (IBAction)toggleSidebar:(id)aSender
1.1 hyatt 292: {
293: if ( ([mSidebarDrawer state] == NSDrawerClosedState) || ([mSidebarDrawer state] == NSDrawerClosingState) ) {
294: [mSidebarDrawer open];
295: } else {
296: [mSidebarDrawer close];
297: }
298: }
299:
1.4 hyatt 300: -(void)loadURL:(NSURL*)aURL
1.1 hyatt 301: {
1.4 hyatt 302: if (mInitialized)
303: [[mBrowserView getBrowserView] loadURI:aURL flags:NSLoadFlagsNone];
304: else {
305: mURL = aURL;
306: [mURL retain];
307: }
1.1 hyatt 308: }
1.5 macserv 309:
310: - (void)updateLocationFields:(NSString *)locationString
311: {
312: /* //commenting this out because it doesn't work right yet.
313: if ( [locationString length] > 30 ) {
314: [[mLocationToolbarItem menuFormRepresentation] setTitle:
315: [NSString stringWithFormat:@"Location: %@...", [locationString substringToIndex:31]]];
316: } else {
317: [[mLocationToolbarItem menuFormRepresentation] setTitle:
318: [NSString stringWithFormat:@"Location: %@", locationString]];
319: }
320: */
321:
322: [mURLBar setStringValue:locationString];
323: [mLocationSheetURLField setStringValue:locationString];
324:
325: [[self window] update];
326: [[self window] display];
1.8 hyatt 327: }
1.1 hyatt 328: @end
329:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>