5 * Implementation of class HBOutputPanelController.
8 #import "HBOutputPanelController.h"
9 #import "HBOutputRedirect.h"
11 /// Maximum amount of characters that can be shown in the view.
12 // Original value used by cleaner
13 //#define TextStorageUpperSizeLimit 20000
14 // lets use this higher value for now for better gui debugging
15 #define TextStorageUpperSizeLimit 40000
17 /// When old output is removed, this is the amount of characters that will be
18 /// left in outputTextStorage.
19 // Original value used by cleaner
20 //#define TextStorageLowerSizeLimit 15000
21 // lets use this higher value for now for better gui debugging
22 #define TextStorageLowerSizeLimit 35000
24 @implementation HBOutputPanelController
27 * Initializes the object, creates outputTextStorage and starts redirection of stderr.
31 if (self = [super init])
33 outputTextStorage = [[NSTextStorage alloc] init];
34 [[HBOutputRedirect stderrRedirect] addListener:self];
35 [[HBOutputRedirect stdoutRedirect] addListener:self];
41 * Stops redirection of stderr and releases resources.
45 [[HBOutputRedirect stderrRedirect] removeListener:self];
46 [[HBOutputRedirect stdoutRedirect] removeListener:self];
47 [outputTextStorage release];
48 [outputPanel release];
53 * Loads output panel from OutputPanel.nib and shows it.
55 - (IBAction)showOutputPanel:(id)sender
59 BOOL loadSucceeded = [NSBundle loadNibNamed:@"OutputPanel" owner:self] && outputPanel;
60 NSAssert(loadSucceeded, @"Could not open nib file");
62 [outputPanel setFrameAutosaveName:@"OutputPanelFrame"];
63 [[textView layoutManager] replaceTextStorage:outputTextStorage];
64 [[textView enclosingScrollView] setLineScroll:10];
65 [[textView enclosingScrollView] setPageScroll:20];
68 [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)];
69 [outputPanel orderFront:nil];
71 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"OutputPanelIsOpen"];
75 * Displays text received from HBOutputRedirect in the text view.
77 - (void)stderrRedirect:(NSString *)text
79 NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text];
80 [outputTextStorage appendAttributedString:attributedString];
81 [attributedString release];
83 if ([outputTextStorage length] > TextStorageUpperSizeLimit)
84 [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length] - TextStorageLowerSizeLimit)];
86 [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)];
88 - (void)stdoutRedirect:(NSString *)text { [self stderrRedirect:text]; }
91 * Clears the output window.
93 - (IBAction)clearOutput:(id)sender
95 [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length])];
99 * Copies all text in the output window to pasteboard.
101 - (IBAction)copyAllOutputToPasteboard:(id)sender
103 NSPasteboard *pboard = [NSPasteboard generalPasteboard];
104 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
105 [pboard setString:[outputTextStorage string] forType:NSStringPboardType];
108 - (void)windowWillClose:(NSNotification *)aNotification
110 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"OutputPanelIsOpen"];