Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOJavaScriptConsoleController Class Reference

#include <OOJavaScriptConsoleController.h>

+ Inheritance diagram for OOJavaScriptConsoleController:
+ Collaboration diagram for OOJavaScriptConsoleController:

Instance Methods

(IBAction) - clearConsole:
 
(IBAction) - showConsole:
 
(IBAction) - toggleShowOnLog:
 
(IBAction) - toggleShowOnWarning:
 
(IBAction) - toggleShowOnError:
 
(IBAction) - consolePerformCommand:
 
(void) - appendMessage:colorKey:emphasisRange:
 
(void) - clearConsole
 
(void) - doShowConsole
 
(void) - noteConfigurationChanged:
 
(void) - setDebugger:
 
(void) - dealloc [implementation]
 
(void) - awakeFromNib [implementation]
 
(void) - applicationWillTerminate: [implementation]
 
(BOOL) - validateMenuItem: [implementation]
 
(void) - splitView:wasResizedFrom:to: [implementation]
 
(NSColor *) - foregroundColorForKey: [implementation]
 
(NSColor *) - backgroundColorForKey: [implementation]
 
(void) - reloadAllSettings [implementation]
 
(void) - setUpFonts [implementation]
 
(void) - saveHistory [implementation]
 
- Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
 
(id) - weakRetain [implementation]
 
(void) - weakRefDied: [implementation]
 
- Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED
 

Private Attributes

IBOutlet NSWindow * consoleWindow
 
IBOutlet NSView * consoleLogHolderView
 
IBOutlet NSView * consoleInputHolderView
 
IBOutlet NSTextView * consoleTextView
 
IBOutlet NSTextField * consoleInputField
 
IBOutlet OOTextFieldHistoryManagerinputHistoryManager
 
RBSplitSubviewinputSplitSubview
 
IBOutlet NSScroller * verticalScroller
 
OOMacDebugger_debugger
 
NSFont * _baseFont
 
NSFont * _boldFont
 
NSMutableDictionary * _fgColors
 
NSMutableDictionary * _bgColors
 

Additional Inherited Members

- Protected Attributes inherited from OOWeakRefObject
OOWeakReferenceweakSelf
 

Detailed Description

Definition at line 38 of file OOJavaScriptConsoleController.h.

Method Documentation

◆ appendMessage:colorKey:emphasisRange:

- (void) appendMessage: (NSString *) string
colorKey: (NSString *) colorKey
emphasisRange: (NSRange) emphasisRange 

Definition at line 1 of file OOJavaScriptConsoleController.m.

192 :(NSString *)string
193 colorKey:(NSString *)colorKey
194 emphasisRange:(NSRange)emphasisRange
195{
197
198 NSMutableAttributedString *mutableStr = nil;
199 NSColor *fgColor = nil,
200 *bgColor = nil;
201 volatile NSRange fullRange;
202 NSTextStorage *textStorage = nil;
203 BOOL doScroll;
204 NSUInteger length;
205
206 mutableStr = [NSMutableAttributedString stringWithString:[string stringByAppendingString:@"\n"]
207 font:_baseFont];
208
209 fullRange = (NSRange){ 0, [mutableStr length] };
210 fgColor = [self foregroundColorForKey:colorKey];
211 if (fgColor != nil)
212 {
213 if ([fgColor alphaComponent] == 0.0) return;
214 [mutableStr addAttribute:NSForegroundColorAttributeName
215 value:fgColor
216 range:fullRange];
217 }
218
219 bgColor = [self backgroundColorForKey:colorKey];
220 if (bgColor != nil)
221 {
222 [mutableStr addAttribute:NSBackgroundColorAttributeName
223 value:bgColor
224 range:fullRange];
225 }
226
227 if (emphasisRange.length != 0)
228 {
229 [mutableStr addAttribute:NSFontAttributeName
230 value:_boldFont
231 range:emphasisRange];
232 }
233
234 doScroll = [verticalScroller floatValue] > 0.980f;
235
236 textStorage = [consoleTextView textStorage];
237 [textStorage appendAttributedString:mutableStr];
238 length = [textStorage length];
239 if (fullRange.length > kConsoleMaxSize)
240 {
241 [textStorage deleteCharactersInRange:(NSRange){ length - kConsoleTrimToSize, kConsoleTrimToSize }];
242 length = kConsoleTrimToSize;
243 }
244
245 // Scroll to end of field
246 if (doScroll) [consoleTextView scrollRangeToVisible:(NSRange){ length, 0 }];
247
249}
#define OOJS_PROFILE_EXIT_VOID
#define OOJS_PROFILE_ENTER
return nil

◆ applicationWillTerminate:

- (void) applicationWillTerminate: (NSNotification *) notification
implementation

Definition at line 1 of file OOJavaScriptConsoleController.m.

138 :(NSNotification *)notification
139{
140 [self saveHistory];
141}

◆ awakeFromNib

- (void) awakeFromNib
implementation

Definition at line 1 of file OOJavaScriptConsoleController.m.

95{
97
98 // Build RBSplitView programmatically to avoid issues with IB plug-in.
99 NSView *contentView = [consoleWindow contentView];
100 RBSplitView *splitView = [[RBSplitView alloc] initWithFrame:[contentView frame]];
101
102 [contentView addSubview:splitView];
103 [splitView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
104
105 [splitView setVertical:NO];
106 [splitView setDelegate:self];
107
108 [splitView addSubview:consoleLogHolderView atPosition:0];
110
111 CGFloat height = [consoleInputHolderView frame].size.height;
112 [splitView addSubview:consoleInputHolderView atPosition:1];
113 inputSplitSubview = [splitView subviewAtPosition:1];
114 [inputSplitSubview setMinDimension:30 andMaxDimension:0];
115
116 NSString *thumbPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SplitViewThumb" ofType:@"png"];
117 [splitView setDivider:[[[NSImage alloc] initWithContentsOfFile:thumbPath] autorelease]];
118 [inputSplitSubview setDimension:height];
119
120 // Free performance boost in Leopard.
121 if ([[consoleTextView layoutManager] respondsToSelector:@selector(setAllowsNonContiguousLayout:)])
122 {
123 [[consoleTextView layoutManager] setAllowsNonContiguousLayout:YES];
124 }
125
126 // Ensure auto-scrolling will work.
127 [verticalScroller setFloatValue:1.0];
128
129 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
130 [inputHistoryManager setHistory:[defaults arrayForKey:@"debug-js-console-scrollback"]];
131
132 [self reloadAllSettings];
133
134 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
135}
void setMinDimension:andMaxDimension:(CGFloat newMinDimension,[andMaxDimension] CGFloat newMaxDimension)
RBSplitSubview * subviewAtPosition:(NSUInteger position)
void addSubview:atPosition:(NSView *aView,[atPosition] NSUInteger position)
void setDelegate:(id anObject)
void setDivider:(NSImage *image)
void setVertical:(BOOL flag)

◆ backgroundColorForKey:

- (NSColor *) backgroundColorForKey: (NSString *) key
implementation

Provided by category OOJavaScriptConsoleController(Private).

Definition at line 1 of file OOJavaScriptConsoleController.m.

376 :(NSString *)key
377{
378 NSColor *result = nil;
379 NSString *expandedKey = nil;
380
381 if (key == nil) key = @"general";
382
383 result = [_bgColors objectForKey:key];
384 if (result == nil)
385 {
386 // No cached colour; load colour description from config file
387 expandedKey = [key stringByAppendingString:@"-background-color"];
388 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
389 if (result == nil)
390 {
391 expandedKey = [key stringByAppendingString:@"-background-colour"];
392 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
393 }
394 if (result == nil && ![key isEqualToString:@"general"])
395 {
396 result = [self backgroundColorForKey:nil];
397 }
398 if (result == nil) result = [NSColor whiteColor];
399
400 // Store loaded colour in cache
401 if (result != nil)
402 {
403 if (_bgColors == nil) _bgColors = [[NSMutableDictionary alloc] init];
404 [_bgColors setObject:result forKey:key];
405 }
406 }
407
408 return result;
409}

◆ clearConsole

- (void) clearConsole

Definition at line 1 of file OOJavaScriptConsoleController.m.

253{
254 NSTextStorage *textStorage = nil;
255
256 textStorage = [consoleTextView textStorage];
257 [textStorage deleteCharactersInRange:(NSRange){ 0, [textStorage length] }];
258}

◆ clearConsole:

- (IBAction) clearConsole: (id) sender

Definition at line 1 of file OOJavaScriptConsoleController.m.

146 :sender
147{
148 [self clearConsole];
149}

◆ consolePerformCommand:

- (IBAction) consolePerformCommand: (id) sender

Definition at line 1 of file OOJavaScriptConsoleController.m.

176 :sender
177{
178 NSString *command = nil;
179
180 // Use consoleInputField rather than sender so we can, e.g., add a button.
181 command = [consoleInputField stringValue];
182 [consoleInputField setStringValue:@""];
183 [consoleWindow makeFirstResponder:consoleInputField]; // Is unset if an empty string is entered otherwise.
184
185 [inputHistoryManager addToHistory:command];
186 [self saveHistory];
187
188 [_debugger performConsoleCommand:command];
189}

◆ dealloc

- (void) dealloc
implementation

Reimplemented from OOWeakRefObject.

Definition at line 1 of file OOJavaScriptConsoleController.m.

80{
81 [consoleWindow release];
82 [inputHistoryManager release];
83
84 [_baseFont release];
85 [_boldFont release];
86
87 [_fgColors release];
88 [_bgColors release];
89
90 [super dealloc];
91}

◆ doShowConsole

- (void) doShowConsole

Definition at line 1 of file OOJavaScriptConsoleController.m.

262{
263 [consoleWindow makeKeyAndOrderFront:nil];
264 [consoleWindow makeFirstResponder:consoleInputField];
265}

◆ foregroundColorForKey:

- (NSColor *) foregroundColorForKey: (NSString *) key
implementation

Provided by category OOJavaScriptConsoleController(Private).

Definition at line 1 of file OOJavaScriptConsoleController.m.

340 :(NSString *)key
341{
342 NSColor *result = nil;
343 NSString *expandedKey = nil;
344
345 if (key == nil) key = @"general";
346
347 result = [_fgColors objectForKey:key];
348 if (result == nil)
349 {
350 // No cached colour; load colour description from config file
351 expandedKey = [key stringByAppendingString:@"-foreground-color"];
352 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
353 if (result == nil)
354 {
355 expandedKey = [key stringByAppendingString:@"-foreground-colour"];
356 result = [NSColor colorWithOOColorDescription:[_debugger configurationValueForKey:expandedKey]];
357 }
358 if (result == nil && ![key isEqualToString:@"general"])
359 {
360 result = [self foregroundColorForKey:nil];
361 }
362 if (result == nil) result = [NSColor blackColor];
363
364 // Store loaded colour in cache
365 if (result != nil)
366 {
367 if (_fgColors == nil) _fgColors = [[NSMutableDictionary alloc] init];
368 [_fgColors setObject:result forKey:key];
369 }
370 }
371
372 return result;
373}

◆ noteConfigurationChanged:

- (void) noteConfigurationChanged: (NSString *) key

Definition at line 1 of file OOJavaScriptConsoleController.m.

268 :(NSString *)key
269{
270 if ([key hasSuffix:@"-foreground-color"] || [key hasSuffix:@"-foreground-colour"])
271 {
272 // Flush foreground colour cache
273 [_fgColors removeAllObjects];
274 }
275 else if ([key hasSuffix:@"-background-color"] || [key hasSuffix:@"-background-colour"])
276 {
277 // Flush background colour cache
278 [_bgColors removeAllObjects];
279 [consoleTextView setBackgroundColor:[self backgroundColorForKey:nil]];
280 }
281 else if ([key hasPrefix:@"font-"])
282 {
283 [self setUpFonts];
284 }
285}

◆ reloadAllSettings

- (void) reloadAllSettings
implementation

Provided by category OOJavaScriptConsoleController(Private).

Definition at line 1 of file OOJavaScriptConsoleController.m.

413{
414 [_fgColors removeAllObjects];
415 [_bgColors removeAllObjects];
416 [consoleTextView setBackgroundColor:[self backgroundColorForKey:nil]];
417 [self setUpFonts];
418}

◆ saveHistory

- (void) saveHistory
implementation

Provided by category OOJavaScriptConsoleController(Private).

Definition at line 1 of file OOJavaScriptConsoleController.m.

449{
450 NSArray *history = nil;
451
452 history = [inputHistoryManager history];
453 if (history != nil)
454 {
455 [[NSUserDefaults standardUserDefaults] setObject:history forKey:@"debug-js-console-scrollback"];
456 [[NSUserDefaults standardUserDefaults] synchronize];
457 }
458}

◆ setDebugger:

- (void) setDebugger: (OOMacDebugger *) debugger

Definition at line 1 of file OOJavaScriptConsoleController.m.

288 :(OOMacDebugger *)debugger
289{
290 _debugger = debugger;
291 [self reloadAllSettings];
292}

Referenced by OOMacDebugger::configurationBoolValueForKey:.

+ Here is the caller graph for this function:

◆ setUpFonts

- (void) setUpFonts
implementation

Provided by category OOJavaScriptConsoleController(Private).

Definition at line 1 of file OOJavaScriptConsoleController.m.

422{
423 NSString *fontFace = nil;
424 NSInteger fontSize;
425
426 DESTROY(_baseFont);
427 DESTROY(_boldFont);
428
429 // Set font.
430 fontFace = [_debugger configurationValueForKey:@"font-face"
431 class:[NSString class]
432 defaultValue:@"Courier"];
433 fontSize = (NSInteger)[_debugger configurationIntValueForKey:@"font-size"
434 defaultValue:12];
435
436 _baseFont = [NSFont fontWithName:fontFace size:fontSize];
437 if (_baseFont == nil) _baseFont = [NSFont userFixedPitchFontOfSize:0];
438 [_baseFont retain];
439
440 // Get bold variant of font.
441 _boldFont = [[NSFontManager sharedFontManager] convertFont:_baseFont
442 toHaveTrait:NSBoldFontMask];
443 if (_boldFont == nil) _boldFont = _baseFont;
444 [_boldFont retain];
445}
#define DESTROY(x)
Definition OOCocoa.h:77

◆ showConsole:

- (IBAction) showConsole: (id) sender

Definition at line 1 of file OOJavaScriptConsoleController.m.

152 :sender
153{
155}
OODebugMonitor * sharedDebugMonitor()

◆ splitView:wasResizedFrom:to:

- (void) splitView: (RBSplitView*) sender
wasResizedFrom: (float) oldDimension
to: (float) newDimension 
implementation

Definition at line 1 of file OOJavaScriptConsoleController.m.

330 :(RBSplitView*)sender wasResizedFrom:(float)oldDimension to:(float)newDimension
331{
332 [sender adjustSubviewsExcepting:inputSplitSubview];
333}
void adjustSubviewsExcepting:(RBSplitSubview *excepting)

◆ toggleShowOnError:

- (IBAction) toggleShowOnError: (id) sender

Definition at line 1 of file OOJavaScriptConsoleController.m.

164 :sender
165{
166 [_debugger performConsoleCommand:@"console.settings[\"show-console-on-error\"] = !console.settings[\"show-console-on-error\"]"];
167}

◆ toggleShowOnLog:

- (IBAction) toggleShowOnLog: (id) sender

Definition at line 1 of file OOJavaScriptConsoleController.m.

170 :sender
171{
172 [_debugger performConsoleCommand:@"console.settings[\"show-console-on-log\"] = !console.settings[\"show-console-on-log\"]"];
173}

◆ toggleShowOnWarning:

- (IBAction) toggleShowOnWarning: (id) sender

Definition at line 1 of file OOJavaScriptConsoleController.m.

158 :sender
159{
160 [_debugger performConsoleCommand:@"console.settings[\"show-console-on-warning\"] = !console.settings[\"show-console-on-warning\"]"];
161}

◆ validateMenuItem:

- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
implementation

Definition at line 1 of file OOJavaScriptConsoleController.m.

297 :(NSMenuItem *)menuItem
298{
299 SEL action = NULL;
300 OODebugMonitor *monitor = nil;
301
302 action = [menuItem action];
304
305 if (action == @selector(toggleShowOnWarning:))
306 {
307 [menuItem setState:[_debugger configurationBoolValueForKey:@"show-console-on-warning"]];
308 return [monitor debuggerConnected];
309 }
310 if (action == @selector(toggleShowOnError:))
311 {
312 [menuItem setState:[_debugger configurationBoolValueForKey:@"show-console-on-error"]];
313 return [monitor debuggerConnected];
314 }
315 if (action == @selector(toggleShowOnLog:))
316 {
317 [menuItem setState:[_debugger configurationBoolValueForKey:@"show-console-on-log"]];
318 return [monitor debuggerConnected];
319 }
320 if (action == @selector(showConsole:))
321 {
322 return [monitor debuggerConnected];
323 }
324
325 return [self respondsToSelector:action];
326}

Member Data Documentation

◆ _baseFont

- (NSFont*) _baseFont
private

Definition at line 57 of file OOJavaScriptConsoleController.h.

◆ _bgColors

- (NSMutableDictionary *) _bgColors
private

Definition at line 62 of file OOJavaScriptConsoleController.h.

◆ _boldFont

- (NSFont *) _boldFont
private

Definition at line 58 of file OOJavaScriptConsoleController.h.

◆ _debugger

- (OOMacDebugger*) _debugger
private

Definition at line 55 of file OOJavaScriptConsoleController.h.

◆ _fgColors

- (NSMutableDictionary*) _fgColors
private

Definition at line 61 of file OOJavaScriptConsoleController.h.

◆ consoleInputField

- (IBOutlet NSTextField*) consoleInputField
private

Definition at line 49 of file OOJavaScriptConsoleController.h.

◆ consoleInputHolderView

- (IBOutlet NSView*) consoleInputHolderView
private

Definition at line 45 of file OOJavaScriptConsoleController.h.

◆ consoleLogHolderView

- (IBOutlet NSView*) consoleLogHolderView
private

Definition at line 44 of file OOJavaScriptConsoleController.h.

◆ consoleTextView

- (IBOutlet NSTextView*) consoleTextView
private

Definition at line 48 of file OOJavaScriptConsoleController.h.

◆ consoleWindow

- (IBOutlet NSWindow*) consoleWindow
private

Definition at line 41 of file OOJavaScriptConsoleController.h.

◆ inputHistoryManager

- (IBOutlet OOTextFieldHistoryManager*) inputHistoryManager
private

Definition at line 51 of file OOJavaScriptConsoleController.h.

◆ inputSplitSubview

- (RBSplitSubview*) inputSplitSubview
private

Definition at line 52 of file OOJavaScriptConsoleController.h.

◆ verticalScroller

- (IBOutlet NSScroller*) verticalScroller
private

Definition at line 53 of file OOJavaScriptConsoleController.h.


The documentation for this class was generated from the following files: