54@interface OOJavaScriptConsoleController (Private)
60- (NSColor *)foregroundColorForKey:(NSString *)key;
61- (NSColor *)backgroundColorForKey:(NSString *)key;
72@interface NSLayoutManager (Leopard)
73- (void)setAllowsNonContiguousLayout:(BOOL)flag;
81 [consoleWindow release];
82 [inputHistoryManager release];
99 NSView *contentView = [consoleWindow contentView];
102 [contentView addSubview:splitView];
103 [splitView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
111 CGFloat height = [consoleInputHolderView frame].size.height;
114 [inputSplitSubview setMinDimension:30 andMaxDimension:0];
116 NSString *thumbPath = [[NSBundle bundleForClass:[
self class]] pathForResource:@"SplitViewThumb" ofType:@"png"];
117 [splitView
setDivider:[[[NSImage alloc] initWithContentsOfFile:thumbPath] autorelease]];
118 [inputSplitSubview setDimension:height];
121 if ([[consoleTextView layoutManager] respondsToSelector:@selector(setAllowsNonContiguousLayout:)])
123 [[consoleTextView layoutManager] setAllowsNonContiguousLayout:YES];
127 [verticalScroller setFloatValue:1.0];
129 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
130 [inputHistoryManager setHistory:[defaults arrayForKey:@"debug-js-console-scrollback"]];
132 [
self reloadAllSettings];
134 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
138- (void)applicationWillTerminate:(NSNotification *)notification
146- (IBAction) clearConsole:sender
152- (IBAction)showConsole:sender
158- (IBAction)toggleShowOnWarning:sender
160 [_debugger performConsoleCommand:@"console.settings[\"show-console-on-warning\"] = !console.settings[\"show-console-on-warning\"]"];
164- (IBAction)toggleShowOnError:sender
166 [_debugger performConsoleCommand:@"console.settings[\"show-console-on-error\"] = !console.settings[\"show-console-on-error\"]"];
170- (IBAction)toggleShowOnLog:sender
172 [_debugger performConsoleCommand:@"console.settings[\"show-console-on-log\"] = !console.settings[\"show-console-on-log\"]"];
176- (IBAction)consolePerformCommand:sender
178 NSString *command =
nil;
181 command = [consoleInputField stringValue];
182 [consoleInputField setStringValue:@""];
183 [consoleWindow makeFirstResponder:consoleInputField];
185 [inputHistoryManager addToHistory:command];
188 [_debugger performConsoleCommand:command];
192- (void)appendMessage:(NSString *)string
193 colorKey:(NSString *)colorKey
194 emphasisRange:(NSRange)emphasisRange
198 NSMutableAttributedString *mutableStr =
nil;
199 NSColor *fgColor =
nil,
201 volatile NSRange fullRange;
202 NSTextStorage *textStorage =
nil;
206 mutableStr = [NSMutableAttributedString stringWithString:[string stringByAppendingString:@"\n"]
209 fullRange = (NSRange){ 0, [mutableStr length] };
210 fgColor = [
self foregroundColorForKey:colorKey];
213 if ([fgColor alphaComponent] == 0.0)
return;
214 [mutableStr addAttribute:NSForegroundColorAttributeName
219 bgColor = [
self backgroundColorForKey:colorKey];
222 [mutableStr addAttribute:NSBackgroundColorAttributeName
227 if (emphasisRange.length != 0)
229 [mutableStr addAttribute:NSFontAttributeName
231 range:emphasisRange];
234 doScroll = [verticalScroller floatValue] > 0.980f;
236 textStorage = [consoleTextView textStorage];
237 [textStorage appendAttributedString:mutableStr];
238 length = [textStorage length];
241 [textStorage deleteCharactersInRange:(NSRange){ length - kConsoleTrimToSize, kConsoleTrimToSize }];
246 if (doScroll) [consoleTextView scrollRangeToVisible:(NSRange){ length, 0 }];
254 NSTextStorage *textStorage =
nil;
256 textStorage = [consoleTextView textStorage];
257 [textStorage deleteCharactersInRange:(NSRange){ 0, [textStorage length] }];
261- (void) doShowConsole
263 [consoleWindow makeKeyAndOrderFront:nil];
264 [consoleWindow makeFirstResponder:consoleInputField];
268- (void)noteConfigurationChanged:(NSString *)key
270 if ([key hasSuffix:
@"-foreground-color"] || [key hasSuffix:
@"-foreground-colour"])
273 [_fgColors removeAllObjects];
275 else if ([key hasSuffix:
@"-background-color"] || [key hasSuffix:
@"-background-colour"])
278 [_bgColors removeAllObjects];
279 [consoleTextView setBackgroundColor:[
self backgroundColorForKey:nil]];
281 else if ([key hasPrefix:
@"font-"])
290 _debugger = debugger;
291 [
self reloadAllSettings];
297- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
302 action = [menuItem action];
305 if (action ==
@selector(toggleShowOnWarning:))
307 [menuItem setState:[_debugger configurationBoolValueForKey:@"show-console-on-warning"]];
310 if (action ==
@selector(toggleShowOnError:))
312 [menuItem setState:[_debugger configurationBoolValueForKey:@"show-console-on-error"]];
315 if (action ==
@selector(toggleShowOnLog:))
317 [menuItem setState:[_debugger configurationBoolValueForKey:@"show-console-on-log"]];
320 if (action ==
@selector(showConsole:))
325 return [
self respondsToSelector:action];
330- (void)splitView:(
RBSplitView*)sender wasResizedFrom:(
float)oldDimension to:(
float)newDimension
338@implementation OOJavaScriptConsoleController (Private)
340- (NSColor *)foregroundColorForKey:(NSString *)key
342 NSColor *result =
nil;
343 NSString *expandedKey =
nil;
345 if (key ==
nil) key =
@"general";
347 result = [_fgColors objectForKey:key];
351 expandedKey = [key stringByAppendingString:@"-foreground-color"];
352 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
355 expandedKey = [key stringByAppendingString:@"-foreground-colour"];
356 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
358 if (result ==
nil && ![key isEqualToString:
@"general"])
360 result = [
self foregroundColorForKey:nil];
362 if (result ==
nil) result = [NSColor blackColor];
367 if (_fgColors ==
nil) _fgColors = [[NSMutableDictionary alloc] init];
368 [_fgColors setObject:result forKey:key];
376- (NSColor *)backgroundColorForKey:(NSString *)key
378 NSColor *result =
nil;
379 NSString *expandedKey =
nil;
381 if (key ==
nil) key =
@"general";
383 result = [_bgColors objectForKey:key];
387 expandedKey = [key stringByAppendingString:@"-background-color"];
388 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
391 expandedKey = [key stringByAppendingString:@"-background-colour"];
392 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
394 if (result ==
nil && ![key isEqualToString:
@"general"])
396 result = [
self backgroundColorForKey:nil];
398 if (result ==
nil) result = [NSColor whiteColor];
403 if (_bgColors ==
nil) _bgColors = [[NSMutableDictionary alloc] init];
404 [_bgColors setObject:result forKey:key];
412- (void)reloadAllSettings
414 [_fgColors removeAllObjects];
415 [_bgColors removeAllObjects];
416 [consoleTextView setBackgroundColor:[
self backgroundColorForKey:nil]];
423 NSString *fontFace =
nil;
430 fontFace = [_debugger configurationValueForKey:@"font-face"
431 class:[NSString class]
432 defaultValue:@"Courier"];
433 fontSize = (NSInteger)[_debugger configurationIntValueForKey:
@"font-size"
436 _baseFont = [NSFont fontWithName:fontFace size:fontSize];
437 if (_baseFont ==
nil) _baseFont = [NSFont userFixedPitchFontOfSize:0];
441 _boldFont = [[NSFontManager sharedFontManager] convertFont:_baseFont
442 toHaveTrait:NSBoldFontMask];
443 if (_boldFont ==
nil) _boldFont = _baseFont;
450 NSArray *history =
nil;
452 history = [inputHistoryManager history];
455 [[NSUserDefaults standardUserDefaults] setObject:history forKey:@"debug-js-console-scrollback"];
456 [[NSUserDefaults standardUserDefaults] synchronize];
#define OOJS_PROFILE_EXIT_VOID
#define OOJS_PROFILE_ENTER
OODebugMonitor * sharedDebugMonitor()
void setMinDimension:andMaxDimension:(CGFloat newMinDimension,[andMaxDimension] CGFloat newMaxDimension)
RBSplitSubview * subviewAtPosition:(NSUInteger position)
void adjustSubviewsExcepting:(RBSplitSubview *excepting)
void addSubview:atPosition:(NSView *aView,[atPosition] NSUInteger position)
void setDelegate:(id anObject)
void setDivider:(NSImage *image)
void setVertical:(BOOL flag)