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

« back to all changes in this revision

Viewing changes to TerminalViewPrefs.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/NSNotification.h>
 
11
#include <Foundation/NSString.h>
 
12
#include <Foundation/NSUserDefaults.h>
 
13
#include <AppKit/NSBox.h>
 
14
#include <AppKit/NSColor.h>
 
15
#include <AppKit/NSColorPanel.h>
 
16
#include <AppKit/NSColorWell.h>
 
17
#include <AppKit/NSFont.h>
 
18
#include <AppKit/NSGraphics.h>
 
19
#include <AppKit/NSImage.h>
 
20
#include <AppKit/NSTextField.h>
 
21
#include <GNUstepGUI/GSVbox.h>
 
22
#include <GNUstepGUI/GSHbox.h>
 
23
#include "Label.h"
 
24
 
 
25
#include "TerminalViewPrefs.h"
 
26
 
 
27
 
 
28
NSString *TerminalViewDisplayPrefsDidChangeNotification=
 
29
        @"TerminalViewDisplayPrefsDidChangeNotification";
 
30
 
 
31
static NSUserDefaults *ud;
 
32
 
 
33
 
 
34
static NSString
 
35
        *TerminalFontKey=@"TerminalFont",
 
36
        *TerminalFontSizeKey=@"TerminalFontSize",
 
37
        *BoldTerminalFontKey=@"BoldTerminalFont",
 
38
        *BoldTerminalFontSizeKey=@"BoldTerminalFontSize",
 
39
        *UseMultiCellGlyphsKey=@"UseMultiCellGlyphs",
 
40
        *CursorStyleKey=@"CursorStyle",
 
41
        *ScrollBackLinesKey=@"ScrollBackLines",
 
42
 
 
43
        *CursorColorRKey=@"CursorColorR",
 
44
        *CursorColorGKey=@"CursorColorG",
 
45
        *CursorColorBKey=@"CursorColorB",
 
46
        *CursorColorAKey=@"CursorColorA";
 
47
 
 
48
 
 
49
static NSFont *terminalFont,*boldTerminalFont;
 
50
 
 
51
static BOOL useMultiCellGlyphs;
 
52
 
 
53
static float brightness[3]={0.6,0.8,1.0};
 
54
static float saturation[3]={1.0,1.0,0.75};
 
55
 
 
56
static int cursorStyle;
 
57
static NSColor *cursorColor;
 
58
 
 
59
static int scrollBackLines;
 
60
 
 
61
 
 
62
@implementation TerminalViewDisplayPrefs
 
63
 
 
64
+(void) initialize
 
65
{
 
66
        if (!ud)
 
67
                ud=[NSUserDefaults standardUserDefaults];
 
68
 
 
69
        if (!cursorColor)
 
70
        {
 
71
                NSString *s;
 
72
                float size;
 
73
 
 
74
 
 
75
                size=[ud floatForKey: TerminalFontSizeKey];
 
76
                s=[ud stringForKey: TerminalFontKey];
 
77
                if (!s)
 
78
                        terminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
 
79
                else
 
80
                {
 
81
                        terminalFont=[[NSFont fontWithName: s  size: size] retain];
 
82
                        if (!terminalFont)
 
83
                                terminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
 
84
                }
 
85
 
 
86
                size=[ud floatForKey: BoldTerminalFontSizeKey];
 
87
                s=[ud stringForKey: BoldTerminalFontKey];
 
88
                if (!s)
 
89
                        boldTerminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
 
90
                else
 
91
                {
 
92
                        boldTerminalFont=[[NSFont fontWithName: s  size: size] retain];
 
93
                        if (!boldTerminalFont)
 
94
                                boldTerminalFont=[[NSFont userFixedPitchFontOfSize: size] retain];
 
95
                }
 
96
 
 
97
                useMultiCellGlyphs=[ud boolForKey: UseMultiCellGlyphsKey];
 
98
 
 
99
                cursorStyle=[ud integerForKey: CursorStyleKey];
 
100
                if ([ud objectForKey: CursorColorRKey])
 
101
                {
 
102
                        float r,g,b,a;
 
103
                        r=[ud floatForKey: CursorColorRKey];
 
104
                        g=[ud floatForKey: CursorColorGKey];
 
105
                        b=[ud floatForKey: CursorColorBKey];
 
106
                        a=[ud floatForKey: CursorColorAKey];
 
107
                        cursorColor=[[NSColor colorWithCalibratedRed: r
 
108
                                green: g
 
109
                                blue: b
 
110
                                alpha: a] retain];
 
111
                }
 
112
                else
 
113
                {
 
114
                        cursorColor=[[NSColor whiteColor] retain];
 
115
                }
 
116
 
 
117
                scrollBackLines=[ud integerForKey: ScrollBackLinesKey];
 
118
                if (scrollBackLines<=0)
 
119
                        scrollBackLines=256;
 
120
        }
 
121
}
 
122
 
 
123
+(NSFont *) terminalFont
 
124
{
 
125
        NSFont *f=[terminalFont screenFont];
 
126
        if (f)
 
127
                return f;
 
128
        return terminalFont;
 
129
}
 
130
 
 
131
+(NSFont *) boldTerminalFont
 
132
{
 
133
        NSFont *f=[boldTerminalFont screenFont];
 
134
        if (f)
 
135
                return f;
 
136
        return boldTerminalFont;
 
137
}
 
138
 
 
139
+(BOOL) useMultiCellGlyphs
 
140
{
 
141
        return useMultiCellGlyphs;
 
142
}
 
143
 
 
144
+(const float *) brightnessForIntensities
 
145
{
 
146
        return brightness;
 
147
}
 
148
+(const float *) saturationForIntensities
 
149
{
 
150
        return saturation;
 
151
}
 
152
 
 
153
+(int) cursorStyle
 
154
{
 
155
        return cursorStyle;
 
156
}
 
157
 
 
158
+(NSColor *) cursorColor
 
159
{
 
160
        return cursorColor;
 
161
}
 
162
 
 
163
+(int) scrollBackLines
 
164
{
 
165
        return scrollBackLines;
 
166
}
 
167
 
 
168
 
 
169
-(void) save
 
170
{
 
171
        if (!top) return;
 
172
 
 
173
        cursorStyle=[[m_cursorStyle selectedCell] tag];
 
174
        [ud setInteger: cursorStyle
 
175
                forKey: CursorStyleKey];
 
176
 
 
177
        {
 
178
                DESTROY(cursorColor);
 
179
                cursorColor=[w_cursorColor color];
 
180
                cursorColor=[[cursorColor colorUsingColorSpaceName: NSCalibratedRGBColorSpace] retain];
 
181
                [ud setFloat: [cursorColor redComponent]
 
182
                        forKey: CursorColorRKey];
 
183
                [ud setFloat: [cursorColor greenComponent]
 
184
                        forKey: CursorColorGKey];
 
185
                [ud setFloat: [cursorColor blueComponent]
 
186
                        forKey: CursorColorBKey];
 
187
                [ud setFloat: [cursorColor alphaComponent]
 
188
                        forKey: CursorColorAKey];
 
189
        }
 
190
 
 
191
        ASSIGN(terminalFont,[f_terminalFont font]);
 
192
        [ud setFloat: [terminalFont pointSize]
 
193
                forKey: TerminalFontSizeKey];
 
194
        [ud setObject: [terminalFont fontName]
 
195
                forKey: TerminalFontKey];
 
196
 
 
197
        ASSIGN(boldTerminalFont,[f_boldTerminalFont font]);
 
198
        [ud setFloat: [boldTerminalFont pointSize]
 
199
                forKey: BoldTerminalFontSizeKey];
 
200
        [ud setObject: [boldTerminalFont fontName]
 
201
                forKey: BoldTerminalFontKey];
 
202
 
 
203
        scrollBackLines=[f_scrollBackLines intValue];
 
204
        [ud setInteger: scrollBackLines
 
205
                forKey: ScrollBackLinesKey];
 
206
 
 
207
        useMultiCellGlyphs=!![b_useMultiCellGlyphs state];
 
208
        [ud setBool: useMultiCellGlyphs
 
209
                forKey: UseMultiCellGlyphsKey];
 
210
 
 
211
        [[NSNotificationCenter defaultCenter]
 
212
                postNotificationName: TerminalViewDisplayPrefsDidChangeNotification
 
213
                object: self];
 
214
}
 
215
 
 
216
-(void) revert
 
217
{
 
218
        NSFont *f;
 
219
 
 
220
        [b_useMultiCellGlyphs setState: useMultiCellGlyphs];
 
221
 
 
222
        [m_cursorStyle selectCellWithTag: [[self class] cursorStyle]];
 
223
        [w_cursorColor setColor: [[self class] cursorColor]];
 
224
 
 
225
        f=[isa terminalFont];
 
226
        [f_terminalFont setStringValue: [NSString stringWithFormat: @"%@ %0.1f",[f fontName],[f pointSize]]];
 
227
        [f_terminalFont setFont: f];
 
228
 
 
229
        f=[isa boldTerminalFont];
 
230
        [f_boldTerminalFont setStringValue: [NSString stringWithFormat: @"%@ %0.1f",[f fontName],[f pointSize]]];
 
231
        [f_boldTerminalFont setFont: f];
 
232
 
 
233
        [f_scrollBackLines setIntValue: scrollBackLines];
 
234
}
 
235
 
 
236
 
 
237
-(NSString *) name
 
238
{
 
239
        return _(@"Display");
 
240
}
 
241
 
 
242
-(void) setupButton: (NSButton *)b
 
243
{
 
244
        [b setTitle: _(@"Display")];
 
245
        [b sizeToFit];
 
246
}
 
247
 
 
248
-(void) willHide
 
249
{
 
250
}
 
251
 
 
252
-(NSView *) willShow
 
253
{
 
254
        if (!top)
 
255
        {
 
256
                top=[[GSVbox alloc] init];
 
257
                [top setDefaultMinYMargin: 2];
 
258
 
 
259
                [top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
 
260
 
 
261
                {
 
262
                        NSTextField *f;
 
263
                        NSButton *b;
 
264
                        GSHbox *hb;
 
265
 
 
266
                        hb=[[GSHbox alloc] init];
 
267
                        [hb setDefaultMinXMargin: 4];
 
268
                        [hb setAutoresizingMask: NSViewWidthSizable];
 
269
 
 
270
                        f=[NSTextField newLabel: _(@"Scroll-back length in lines:")];
 
271
                        [f setAutoresizingMask: 0];
 
272
                        [hb addView: f  enablingXResizing: NO];
 
273
                        DESTROY(f);
 
274
 
 
275
                        f_scrollBackLines=f=[[NSTextField alloc] init];
 
276
                        [f setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
 
277
                        [f sizeToFit];
 
278
                        [hb addView: f  enablingXResizing: YES];
 
279
                        DESTROY(f);
 
280
 
 
281
                        [top addView: hb enablingYResizing: NO];
 
282
                        DESTROY(hb);
 
283
 
 
284
                        [top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
 
285
 
 
286
                        {
 
287
                                NSBox *b;
 
288
                                GSTable *t;
 
289
                                NSColorWell *w;
 
290
 
 
291
                                b=[[NSBox alloc] init];
 
292
                                [b setAutoresizingMask: NSViewMinXMargin|NSViewMaxXMargin];
 
293
                                [b setTitle: _(@"Cursor")];
 
294
 
 
295
                                t=[[GSTable alloc] initWithNumberOfRows: 2 numberOfColumns: 2];
 
296
                                [t setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
 
297
 
 
298
                                f=[NSTextField newLabel: _(@"Style:")];
 
299
                                [f setAutoresizingMask: NSViewMinXMargin|NSViewMinYMargin|NSViewMaxYMargin];
 
300
                                [t putView: f  atRow: 0 column: 0  withXMargins: 2 yMargins: 2];
 
301
                                DESTROY(f);
 
302
 
 
303
                                {
 
304
                                        NSMatrix *m;
 
305
                                        NSButtonCell *b=[NSButtonCell new];
 
306
                                        NSSize s;
 
307
 
 
308
                                        [b setImagePosition: NSImageOnly];
 
309
                                        [b setHighlightsBy: NSChangeBackgroundCellMask];
 
310
                                        [b setShowsStateBy: NSChangeBackgroundCellMask];
 
311
 
 
312
                                        m=m_cursorStyle=[[NSMatrix alloc] initWithFrame: NSMakeRect(0,0,1,1)
 
313
                                                mode: NSRadioModeMatrix
 
314
                                                prototype: b
 
315
                                                numberOfRows: 1
 
316
                                                numberOfColumns: 4];
 
317
 
 
318
                                        [[m cellAtRow: 0 column: 0] setImage: [NSImage imageNamed: @"cursor_line"]];
 
319
                                        [[m cellAtRow: 0 column: 1] setImage: [NSImage imageNamed: @"cursor_stroked"]];
 
320
                                        [[m cellAtRow: 0 column: 2] setImage: [NSImage imageNamed: @"cursor_filled"]];
 
321
                                        [[m cellAtRow: 0 column: 3] setImage: [NSImage imageNamed: @"cursor_inverted"]];
 
322
                                        [[m cellAtRow: 0 column: 0] setTag: 0];
 
323
                                        [[m cellAtRow: 0 column: 1] setTag: 1];
 
324
                                        [[m cellAtRow: 0 column: 2] setTag: 2];
 
325
                                        [[m cellAtRow: 0 column: 3] setTag: 3];
 
326
 
 
327
                                        s=[[m cellAtRow: 0 column: 0] cellSize];
 
328
                                        s.width+=6;
 
329
                                        s.height+=6;
 
330
                                        [m setCellSize: s];
 
331
                                        [m sizeToCells];
 
332
 
 
333
                                        [t putView: m  atRow: 0 column: 1  withXMargins: 2 yMargins: 2];
 
334
                                        DESTROY(m);
 
335
                                }
 
336
 
 
337
 
 
338
                                f=[NSTextField newLabel: _(@"Color:")];
 
339
                                [f setAutoresizingMask: NSViewMinXMargin|NSViewMinYMargin|NSViewMaxYMargin];
 
340
                                [t putView: f  atRow: 1 column: 0  withXMargins: 2 yMargins: 2];
 
341
                                DESTROY(f);
 
342
 
 
343
                                w_cursorColor=w=[[NSColorWell alloc] initWithFrame: NSMakeRect(0,0,40,30)];
 
344
                                [t putView: w  atRow: 1 column: 1  withXMargins: 2 yMargins: 2];
 
345
                                DESTROY(w);
 
346
 
 
347
                                [[NSColorPanel sharedColorPanel] setShowsAlpha: YES];
 
348
 
 
349
 
 
350
                                [t sizeToFit];
 
351
                                [b setContentView: t];
 
352
                                [b sizeToFit];
 
353
                                [top addView: b enablingYResizing: NO];
 
354
                                DESTROY(b);
 
355
                        }
 
356
 
 
357
                        [top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
 
358
 
 
359
 
 
360
                        b=b_useMultiCellGlyphs=[[NSButton alloc] init];
 
361
                        [b setTitle: _(@"Handle wide (multi-cell) glyphs")];
 
362
                        [b setButtonType: NSSwitchButton];
 
363
                        [b sizeToFit];
 
364
                        [top addView: b enablingYResizing: NO];
 
365
                        DESTROY(b);
 
366
 
 
367
 
 
368
                        hb=[[GSHbox alloc] init];
 
369
                        [hb setDefaultMinXMargin: 4];
 
370
                        [hb setAutoresizingMask: NSViewWidthSizable];
 
371
 
 
372
                        f=[NSTextField newLabel: _(@"Bold font:")];
 
373
                        [f setAutoresizingMask: 0];
 
374
                        [hb addView: f  enablingXResizing: NO];
 
375
                        DESTROY(f);
 
376
 
 
377
                        f_boldTerminalFont=f=[[NSTextField alloc] init];
 
378
                        [f setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
 
379
                        [f setEditable: NO];
 
380
                        [hb addView: f  enablingXResizing: YES];
 
381
                        DESTROY(f);
 
382
 
 
383
                        b=[[NSButton alloc] init];
 
384
                        [b setTitle: _(@"Pick font...")];
 
385
                        [b setTarget: self];
 
386
                        [b setAction: @selector(_pickBoldTerminalFont:)];
 
387
                        [b sizeToFit];
 
388
                        [hb addView: b  enablingXResizing: NO];
 
389
                        DESTROY(b);
 
390
 
 
391
                        [top addView: hb enablingYResizing: NO];
 
392
                        DESTROY(hb);
 
393
 
 
394
 
 
395
                        hb=[[GSHbox alloc] init];
 
396
                        [hb setDefaultMinXMargin: 4];
 
397
                        [hb setAutoresizingMask: NSViewWidthSizable];
 
398
 
 
399
                        f=[NSTextField newLabel: _(@"Normal font:")];
 
400
                        [f setAutoresizingMask: 0];
 
401
                        [hb addView: f  enablingXResizing: NO];
 
402
                        DESTROY(f);
 
403
 
 
404
                        f_terminalFont=f=[[NSTextField alloc] init];
 
405
                        [f setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
 
406
                        [f setEditable: NO];
 
407
                        [hb addView: f  enablingXResizing: YES];
 
408
                        DESTROY(f);
 
409
 
 
410
                        b=[[NSButton alloc] init];
 
411
                        [b setTitle: _(@"Pick font...")];
 
412
                        [b setTarget: self];
 
413
                        [b setAction: @selector(_pickTerminalFont:)];
 
414
                        [b sizeToFit];
 
415
                        [hb addView: b  enablingXResizing: NO];
 
416
                        DESTROY(b);
 
417
 
 
418
                        [top addView: hb enablingYResizing: NO];
 
419
                        DESTROY(hb);
 
420
 
 
421
 
 
422
                        [top addView: [[[NSView alloc] init] autorelease] enablingYResizing: YES];
 
423
                }
 
424
 
 
425
                [self revert];
 
426
        }
 
427
        return top;
 
428
}
 
429
 
 
430
-(void) dealloc
 
431
{
 
432
        DESTROY(top);
 
433
        [super dealloc];
 
434
}
 
435
 
 
436
 
 
437
-(void) _pickFont
 
438
{
 
439
        NSFontManager *fm=[NSFontManager sharedFontManager];
 
440
        [fm setSelectedFont: [f_cur font] isMultiple: NO];
 
441
        [fm orderFrontFontPanel: self];
 
442
}
 
443
 
 
444
-(void) _pickTerminalFont: (id)sender
 
445
{
 
446
        f_cur=f_terminalFont;
 
447
        [self _pickFont];
 
448
}
 
449
 
 
450
-(void) _pickBoldTerminalFont: (id)sender
 
451
{
 
452
        f_cur=f_boldTerminalFont;
 
453
        [self _pickFont];
 
454
}
 
455
 
 
456
/*
 
457
TODO: The return type here should be (void), but due to forwarding issues in
 
458
-base, it has to be (id) to avoid a return type mismatch error
 
459
*/
 
460
-(id) changeFont: (id)sender
 
461
{
 
462
        NSFont *f;
 
463
 
 
464
        if (!f_cur) return nil;
 
465
        f=[sender convertFont: [f_cur font]];
 
466
        if (!f) return nil;
 
467
 
 
468
        [f_cur setStringValue: [NSString stringWithFormat: @"%@ %0.1f",[f fontName],[f pointSize]]];
 
469
        [f_cur setFont: f];
 
470
 
 
471
        return nil;
 
472
}
 
473
 
 
474
@end
 
475
 
 
476
 
 
477
static NSString
 
478
        *LoginShellKey=@"LoginShell",
 
479
        *ShellKey=@"Shell";
 
480
 
 
481
static NSString *shell;
 
482
static BOOL loginShell;
 
483
 
 
484
@implementation TerminalViewShellPrefs
 
485
 
 
486
+(void) initialize
 
487
{
 
488
        if (!ud)
 
489
                ud=[NSUserDefaults standardUserDefaults];
 
490
 
 
491
        if (!shell)
 
492
        {
 
493
                loginShell=[ud boolForKey: LoginShellKey];
 
494
                shell=[ud stringForKey: ShellKey];
 
495
                if (!shell && getenv("SHELL"))
 
496
                        shell=[NSString stringWithCString: getenv("SHELL")];
 
497
                if (!shell)
 
498
                        shell=@"/bin/sh";
 
499
                shell=[shell retain];
 
500
        }
 
501
}
 
502
 
 
503
+(NSString *) shell
 
504
{
 
505
        return shell;
 
506
}
 
507
 
 
508
+(BOOL) loginShell
 
509
{
 
510
        return loginShell;
 
511
}
 
512
 
 
513
 
 
514
-(void) save
 
515
{
 
516
        if (!top) return;
 
517
 
 
518
        if ([b_loginShell state])
 
519
                loginShell=YES;
 
520
        else
 
521
                loginShell=NO;
 
522
        [ud setBool: loginShell forKey: LoginShellKey];
 
523
 
 
524
        DESTROY(shell);
 
525
        shell=[[tf_shell stringValue] copy];
 
526
        [ud setObject: shell forKey: ShellKey];
 
527
}
 
528
 
 
529
-(void) revert
 
530
{
 
531
        [b_loginShell setState: loginShell];
 
532
        [tf_shell setStringValue: shell];
 
533
}
 
534
 
 
535
 
 
536
-(NSString *) name
 
537
{
 
538
        return _(@"Shell");
 
539
}
 
540
 
 
541
-(void) setupButton: (NSButton *)b
 
542
{
 
543
        [b setTitle: _(@"Shell")];
 
544
        [b sizeToFit];
 
545
}
 
546
 
 
547
-(void) willHide
 
548
{
 
549
}
 
550
 
 
551
-(NSView *) willShow
 
552
{
 
553
        if (!top)
 
554
        {
 
555
                top=[[GSVbox alloc] init];
 
556
                [top setDefaultMinYMargin: 4];
 
557
 
 
558
                {
 
559
                        NSTextField *f;
 
560
                        NSButton *b;
 
561
 
 
562
                        b=b_loginShell=[[NSButton alloc] init];
 
563
                        [b setAutoresizingMask: NSViewMinYMargin];
 
564
                        [b setTitle: _(@"Start as login-shell")];
 
565
                        [b setButtonType: NSSwitchButton];
 
566
                        [b sizeToFit];
 
567
                        [top addView: b enablingYResizing: YES];
 
568
                        DESTROY(b);
 
569
 
 
570
                        tf_shell=f=[[NSTextField alloc] init];
 
571
                        [f sizeToFit];
 
572
                        [f setAutoresizingMask: NSViewWidthSizable];
 
573
                        [top addView: f enablingYResizing: NO];
 
574
                        DESTROY(f);
 
575
 
 
576
                        f=[NSTextField newLabel: _(@"Shell:")];
 
577
                        [f setAutoresizingMask: NSViewMaxYMargin];
 
578
                        [f sizeToFit];
 
579
                        [top addView: f enablingYResizing: YES];
 
580
                        DESTROY(f);
 
581
                }
 
582
 
 
583
                [self revert];
 
584
        }
 
585
        return top;
 
586
}
 
587
 
 
588
-(void) dealloc
 
589
{
 
590
        DESTROY(top);
 
591
        [super dealloc];
 
592
}
 
593
 
 
594
@end
 
595
 
 
596
 
 
597
static NSString
 
598
        *CommandAsMetaKey=@"CommandAsMeta",
 
599
        *DoubleEscapeKey=@"DoubleEscape";
 
600
 
 
601
static BOOL commandAsMeta,doubleEscape;
 
602
 
 
603
@implementation TerminalViewKeyboardPrefs
 
604
 
 
605
+(void) initialize
 
606
{
 
607
        if (!ud)
 
608
                ud=[NSUserDefaults standardUserDefaults];
 
609
 
 
610
        commandAsMeta=[ud boolForKey: CommandAsMetaKey];
 
611
        doubleEscape=[ud boolForKey: DoubleEscapeKey];
 
612
}
 
613
 
 
614
+(BOOL) commandAsMeta
 
615
{
 
616
        return commandAsMeta;
 
617
}
 
618
 
 
619
+(BOOL) doubleEscape
 
620
{
 
621
        return doubleEscape;
 
622
}
 
623
 
 
624
 
 
625
-(void) save
 
626
{
 
627
        if (!top) return;
 
628
 
 
629
        if ([b_commandAsMeta state])
 
630
                commandAsMeta=YES;
 
631
        else
 
632
                commandAsMeta=NO;
 
633
        [ud setBool: commandAsMeta forKey: CommandAsMetaKey];
 
634
 
 
635
        if ([b_doubleEscape state])
 
636
                doubleEscape=YES;
 
637
        else
 
638
                doubleEscape=NO;
 
639
        [ud setBool: doubleEscape forKey: DoubleEscapeKey];
 
640
}
 
641
 
 
642
-(void) revert
 
643
{
 
644
        [b_commandAsMeta setState: commandAsMeta];
 
645
        [b_doubleEscape setState: doubleEscape];
 
646
}
 
647
 
 
648
 
 
649
-(NSString *) name
 
650
{
 
651
        return _(@"Keyboard");
 
652
}
 
653
 
 
654
-(void) setupButton: (NSButton *)b
 
655
{
 
656
        [b setTitle: _(@"Keyboard")];
 
657
        [b sizeToFit];
 
658
}
 
659
 
 
660
-(void) willHide
 
661
{
 
662
}
 
663
 
 
664
-(NSView *) willShow
 
665
{
 
666
        if (!top)
 
667
        {
 
668
                top=[[GSVbox alloc] init];
 
669
                [top setDefaultMinYMargin: 8];
 
670
 
 
671
                {
 
672
                        NSButton *b;
 
673
 
 
674
                        b=b_commandAsMeta=[[NSButton alloc] init];
 
675
                        [b setAutoresizingMask: NSViewMinYMargin|NSViewMaxYMargin|NSViewWidthSizable];
 
676
                        [b setTitle:
 
677
                                _(@"Treat the command key as meta.\n"
 
678
                                  @"\n"
 
679
                                  @"Note that with this enabled, you won't be\n"
 
680
                                  @"able to access menu entries with the\n"
 
681
                                  @"keyboard.")];
 
682
                        [b setButtonType: NSSwitchButton];
 
683
                        [b sizeToFit];
 
684
                        [top addView: b enablingYResizing: YES];
 
685
                        DESTROY(b);
 
686
 
 
687
                        [top addSeparator];
 
688
 
 
689
                        b=b_doubleEscape=[[NSButton alloc] init];
 
690
                        [b setAutoresizingMask: NSViewMinYMargin|NSViewMaxYMargin|NSViewWidthSizable];
 
691
                        [b setTitle:
 
692
                                _(@"Send a double escape for the escape key.\n"
 
693
                                  @"\n"
 
694
                                  @"This means that the escape key will be\n"
 
695
                                  @"recognized faster by many programs, but\n"
 
696
                                  @"you can't use it as a substitute for meta.")];
 
697
                        [b setButtonType: NSSwitchButton];
 
698
                        [b sizeToFit];
 
699
                        [top addView: b enablingYResizing: YES];
 
700
                        DESTROY(b);
 
701
                }
 
702
 
 
703
                [self revert];
 
704
        }
 
705
        return top;
 
706
}
 
707
 
 
708
-(void) dealloc
 
709
{
 
710
        DESTROY(top);
 
711
        [super dealloc];
 
712
}
 
713
 
 
714
@end
 
715