OSDN Git Service

MacGui: Remove x264 opt field from the preferences.
[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 #define TextStorageUpperSizeLimit 20000
13
14 /// When old output is removed, this is the amount of characters that will be
15 /// left in outputTextStorage.
16 #define TextStorageLowerSizeLimit 15000
17
18 @implementation HBOutputPanelController
19
20 /**
21  * Initializes the object, creates outputTextStorage and starts redirection of stderr.
22  */
23 - (id)init
24 {
25         if (self = [super init])
26         {
27                 outputTextStorage = [[NSTextStorage alloc] init];
28                 [[HBOutputRedirect stderrRedirect] addListener:self];
29                 [[HBOutputRedirect stdoutRedirect] addListener:self];
30         }
31         return self;
32 }
33
34 /**
35  * Stops redirection of stderr and releases resources.
36  */
37 - (void)dealloc
38 {
39         [[HBOutputRedirect stderrRedirect] removeListener:self];
40         [[HBOutputRedirect stdoutRedirect] removeListener:self];        
41         [outputTextStorage release];
42         [outputPanel release];
43         [super dealloc];
44 }
45
46 /**
47  * Loads output panel from OutputPanel.nib and shows it.
48  */
49 - (IBAction)showOutputPanel:(id)sender
50 {
51         if (!outputPanel)
52         {
53                 BOOL loadSucceeded = [NSBundle loadNibNamed:@"OutputPanel" owner:self] && outputPanel;
54                 NSAssert(loadSucceeded, @"Could not open nib file");
55                 
56                 [outputPanel setFrameAutosaveName:@"OutputPanelFrame"];
57                 [[textView layoutManager] replaceTextStorage:outputTextStorage];
58         }
59                 
60     [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)];
61         [outputPanel orderFront:nil];
62
63     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"OutputPanelIsOpen"];
64 }
65
66 /**
67  * Displays text received from HBOutputRedirect in the text view.
68  */
69 - (void)stderrRedirect:(NSString *)text
70 {
71         NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text];
72         [outputTextStorage appendAttributedString:attributedString];
73         [attributedString release];
74
75         if ([outputTextStorage length] > TextStorageUpperSizeLimit)
76                 [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length] - TextStorageLowerSizeLimit)];
77
78     [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)];
79 }
80 - (void)stdoutRedirect:(NSString *)text { [self stderrRedirect:text]; }
81
82 /**
83  * Clears the output window.
84  */
85 - (IBAction)clearOutput:(id)sender
86 {
87         [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length])];
88 }
89
90 /**
91  * Copies all text in the output window to pasteboard.
92  */
93 - (IBAction)copyAllOutputToPasteboard:(id)sender
94 {
95         NSPasteboard *pboard = [NSPasteboard generalPasteboard];
96         [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
97         [pboard setString:[outputTextStorage string] forType:NSStringPboardType];
98 }
99
100 - (void)windowWillClose:(NSNotification *)aNotification
101 {
102     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"OutputPanelIsOpen"];
103 }
104
105
106 @end