~ubuntu-branches/ubuntu/karmic/terminal.app/karmic

« back to all changes in this revision

Viewing changes to TerminalWindowPrefs.m

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2005-11-25 15:35:20 UTC
  • Revision ID: james.westby@ubuntu.com-20051125153520-98yiw1zatalh7t1j
Tags: upstream-0.9.4+cvs20051125
Import upstream version 0.9.4+cvs20051125

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
copyright 2002, 2003 Alexander Malmberg <alexander@malmberg.org>
 
3
 
 
4
This file is a part of Terminal.app. Terminal.app is free software; you
 
5
can redistribute it and/or modify it under the terms of the GNU General
 
6
Public License as published by the Free Software Foundation; version 2
 
7
of the License. See COPYING or main.m for more information.
 
8
*/
 
9
 
 
10
#include <Foundation/NSBundle.h>
 
11
#include <Foundation/NSString.h>
 
12
#include <Foundation/NSUserDefaults.h>
 
13
#include <AppKit/NSBox.h>
 
14
#include <AppKit/NSButton.h>
 
15
#include <AppKit/NSMatrix.h>
 
16
#include <AppKit/NSTextField.h>
 
17
#include <GNUstepGUI/GSTable.h>
 
18
#include <GNUstepGUI/GSVbox.h>
 
19
#include "Label.h"
 
20
 
 
21
#include "TerminalWindowPrefs.h"
 
22
 
 
23
 
 
24
static NSUserDefaults *ud;
 
25
 
 
26
 
 
27
static NSString
 
28
        *WindowCloseBehaviorKey=@"WindowCloseBehavior",
 
29
        *WindowHeightKey=@"WindowHeight",
 
30
        *WindowWidthKey=@"WindowWidth",
 
31
        *AddYBordersKey=@"AddYBorders";
 
32
 
 
33
 
 
34
static int windowCloseBehavior;
 
35
static int windowWidth,windowHeight;
 
36
static BOOL addYBorders;
 
37
 
 
38
 
 
39
@implementation TerminalWindowPrefs
 
40
 
 
41
+(void) initialize
 
42
{
 
43
        if (!ud)
 
44
        {
 
45
                ud=[NSUserDefaults standardUserDefaults];
 
46
 
 
47
                windowCloseBehavior=[ud integerForKey: WindowCloseBehaviorKey];
 
48
                windowWidth=[ud integerForKey: WindowWidthKey];
 
49
                windowHeight=[ud integerForKey: WindowHeightKey];
 
50
                addYBorders=[ud boolForKey: AddYBordersKey];
 
51
 
 
52
                if (windowWidth<=0)
 
53
                        windowWidth=80;
 
54
                if (windowHeight<=0)
 
55
                        windowHeight=25;
 
56
        }
 
57
}
 
58
 
 
59
+(int) windowCloseBehavior
 
60
{
 
61
        return windowCloseBehavior;
 
62
}
 
63
 
 
64
+(int) defaultWindowWidth
 
65
{
 
66
        return windowWidth;
 
67
}
 
68
+(int) defaultWindowHeight
 
69
{
 
70
        return windowHeight;
 
71
}
 
72
 
 
73
+(BOOL) addYBorders
 
74
{
 
75
        return addYBorders;
 
76
}
 
77
 
 
78
 
 
79
-(void) save
 
80
{
 
81
        if (!top) return;
 
82
 
 
83
        windowCloseBehavior=[[m_close selectedCell] tag];
 
84
        [ud setInteger: windowCloseBehavior  forKey: WindowCloseBehaviorKey];
 
85
 
 
86
        addYBorders=[b_addYBorders state];
 
87
        [ud setBool: addYBorders  forKey: AddYBordersKey];
 
88
 
 
89
        windowWidth=[tf_width intValue];
 
90
        windowHeight=[tf_height intValue];
 
91
 
 
92
        if (windowWidth<=0)
 
93
                windowWidth=80;
 
94
        if (windowHeight<=0)
 
95
                windowHeight=25;
 
96
 
 
97
        [ud setInteger: windowWidth  forKey: WindowWidthKey];
 
98
        [ud setInteger: windowHeight  forKey: WindowHeightKey];
 
99
}
 
100
 
 
101
-(void) revert
 
102
{
 
103
        [m_close selectCellWithTag: windowCloseBehavior];
 
104
 
 
105
        [tf_width setIntValue: windowWidth];
 
106
        [tf_height setIntValue: windowHeight];
 
107
 
 
108
        [b_addYBorders setState: addYBorders];
 
109
}
 
110
 
 
111
 
 
112
-(NSString *) name
 
113
{
 
114
        return _(@"Terminal Window");
 
115
}
 
116
 
 
117
-(void) setupButton: (NSButton *)b
 
118
{
 
119
        [b setTitle: _(@"Terminal\nWindow")];
 
120
        [b sizeToFit];
 
121
}
 
122
 
 
123
-(void) willHide
 
124
{
 
125
}
 
126
 
 
127
-(NSView *) willShow
 
128
{
 
129
        if (!top)
 
130
        {
 
131
                top=[[GSVbox alloc] init];
 
132
                [top setDefaultMinYMargin: 1];
 
133
 
 
134
                {
 
135
                        NSTextField *f;
 
136
 
 
137
                        {
 
138
                                NSMatrix *m;
 
139
                                NSButtonCell *b=[NSButtonCell new];
 
140
                                NSSize s,s2;
 
141
 
 
142
                                [b setButtonType: NSRadioButton];
 
143
 
 
144
                                m=m_close=[[NSMatrix alloc] initWithFrame: NSMakeRect(0,0,1,1)
 
145
                                        mode: NSRadioModeMatrix
 
146
                                        prototype: b
 
147
                                        numberOfRows: 2
 
148
                                        numberOfColumns: 1];
 
149
                                [m setAutoresizingMask: NSViewMinXMargin|NSViewMaxXMargin|
 
150
                                        NSViewMinYMargin|NSViewMaxYMargin];
 
151
 
 
152
                                [[m cellAtRow: 0 column: 0] setTitle: _(@"Close new windows when idle")];
 
153
                                [[m cellAtRow: 1 column: 0] setTitle: _(@"Don't close new windows")];
 
154
                                [[m cellAtRow: 0 column: 0] setTag: 0];
 
155
                                [[m cellAtRow: 1 column: 0] setTag: 1];
 
156
 
 
157
                                s=[[m cellAtRow: 0 column: 0] cellSize];
 
158
                                s2=[[m cellAtRow: 0 column: 0] cellSize];
 
159
                                if (s2.width>s.width) s.width=s2.width;
 
160
                                
 
161
                                [m setCellSize: s];
 
162
                                [m setIntercellSpacing: NSMakeSize(0,3)];
 
163
                                [m sizeToCells];
 
164
 
 
165
                                [top addView: m enablingYResizing: YES];
 
166
                                DESTROY(m);
 
167
                        }
 
168
 
 
169
                        {
 
170
                                NSBox *b;
 
171
                                GSTable *t;
 
172
 
 
173
                                b=[[NSBox alloc] init];
 
174
                                [b setAutoresizingMask:
 
175
                                        NSViewWidthSizable|NSViewMinYMargin|NSViewMaxYMargin];
 
176
                                [b setTitle: _(@"Default size")];
 
177
 
 
178
                                t=[[GSTable alloc] initWithNumberOfRows: 2 numberOfColumns: 2];
 
179
 
 
180
                                f=[NSTextField newLabel: _(@"Width:")];
 
181
                                [f setAutoresizingMask: NSViewMinXMargin|NSViewMinYMargin|NSViewMaxYMargin];
 
182
                                [t putView: f atRow: 1 column: 0
 
183
                                        withXMargins: 2 yMargins: 2];
 
184
                                tf_width=f=[[NSTextField alloc] init];
 
185
                                [f setAutoresizingMask: NSViewWidthSizable];
 
186
                                [f sizeToFit];
 
187
                                [t putView: f atRow: 1 column: 1];
 
188
 
 
189
                                f=[NSTextField newLabel: _(@"Height:")];
 
190
                                [f setAutoresizingMask: NSViewMinXMargin|NSViewMinYMargin|NSViewMaxYMargin];
 
191
                                [t putView: f atRow: 0 column: 0
 
192
                                        withXMargins: 2 yMargins: 2];
 
193
                                tf_height=f=[[NSTextField alloc] init];
 
194
                                [f setAutoresizingMask: NSViewWidthSizable];
 
195
                                [f sizeToFit];
 
196
                                [t putView: f atRow: 0 column: 1];
 
197
 
 
198
                                [b setContentView: t];
 
199
                                [b sizeToFit];
 
200
                                DESTROY(t);
 
201
 
 
202
                                [top addView: b enablingYResizing: YES];
 
203
                                DESTROY(b);
 
204
                        }
 
205
 
 
206
                        {
 
207
                                NSButton *b;
 
208
 
 
209
                                b=b_addYBorders=[[NSButton alloc] init];
 
210
                                [b setAutoresizingMask: NSViewMinXMargin|NSViewMaxXMargin|NSViewMinYMargin|NSViewMaxYMargin];
 
211
                                [b setButtonType: NSSwitchButton];
 
212
                                [b setTitle: _(@"Add top and bottom border")];
 
213
                                [b sizeToFit];
 
214
                                [top addView: b enablingYResizing: YES];
 
215
                        }
 
216
                }
 
217
 
 
218
                [self revert];
 
219
        }
 
220
        return top;
 
221
}
 
222
 
 
223
-(void) dealloc
 
224
{
 
225
        DESTROY(top);
 
226
        [super dealloc];
 
227
}
 
228
 
 
229
@end
 
230