OSDN Git Service

A line went missing from Controller.mm in the reorg of that file, you
[handbrake-jp/handbrake-jp-git.git] / macosx / HBOutputPanelController.m
1 /**
2  * @file
3  * @date 18.5.2007
4  *
5  * Implementation of class HBOutputPanelController.
6  */
7
8 #import "HBOutputPanelController.h"
9 #import "HBOutputRedirect.h"
10
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
16
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
23
24 @implementation HBOutputPanelController
25
26 /**
27  * Initializes the object, creates outputTextStorage and starts redirection of stderr.
28  */
29 - (id)init
30 {
31         if (self = [super init])
32         {
33                 outputTextStorage = [[NSTextStorage alloc] init];
34                 [[HBOutputRedirect stderrRedirect] addListener:self];
35                 [[HBOutputRedirect stdoutRedirect] addListener:self];
36         }
37         return self;
38 }
39
40 /**
41  * Stops redirection of stderr and releases resources.
42  */
43 - (void)dealloc
44 {
45         [[HBOutputRedirect stderrRedirect] removeListener:self];
46         [[HBOutputRedirect stdoutRedirect] removeListener:self];        
47         [outputTextStorage release];
48         [outputPanel release];
49         [super dealloc];
50 }
51
52 /**
53  * Loads output panel from OutputPanel.nib and shows it.
54  */
55 - (IBAction)showOutputPanel:(id)sender
56 {
57         if (!outputPanel)
58         {
59                 BOOL loadSucceeded = [NSBundle loadNibNamed:@"OutputPanel" owner:self] && outputPanel;
60                 NSAssert(loadSucceeded, @"Could not open nib file");
61                 
62                 [outputPanel setFrameAutosaveName:@"OutputPanelFrame"];
63                 [[textView layoutManager] replaceTextStorage:outputTextStorage];
64                 [[textView enclosingScrollView] setLineScroll:10];
65                 [[textView enclosingScrollView] setPageScroll:20];
66         }
67                 
68     [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)];
69         [outputPanel orderFront:nil];
70
71     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"OutputPanelIsOpen"];
72 }
73
74 /**
75  * Displays text received from HBOutputRedirect in the text view.
76  */
77 - (void)stderrRedirect:(NSString *)text
78 {
79         NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text];
80         [outputTextStorage appendAttributedString:attributedString];
81         [attributedString release];
82
83         if ([outputTextStorage length] > TextStorageUpperSizeLimit)
84                 [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length] - TextStorageLowerSizeLimit)];
85
86     [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)];
87 }
88 - (void)stdoutRedirect:(NSString *)text { [self stderrRedirect:text]; }
89
90 /**
91  * Clears the output window.
92  */
93 - (IBAction)clearOutput:(id)sender
94 {
95         [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length])];
96 }
97
98 /**
99  * Copies all text in the output window to pasteboard.
100  */
101 - (IBAction)copyAllOutputToPasteboard:(id)sender
102 {
103         NSPasteboard *pboard = [NSPasteboard generalPasteboard];
104         [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
105         [pboard setString:[outputTextStorage string] forType:NSStringPboardType];
106 }
107
108 - (void)windowWillClose:(NSNotification *)aNotification
109 {
110     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"OutputPanelIsOpen"];
111 }
112
113
114 @end