1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/*
copyright 2002, 2003 Alexander Malmberg <alexander@malmberg.org>
This file is a part of Terminal.app. Terminal.app is free software; you
can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; version 2
of the License. See COPYING or main.m for more information.
*/
#include <AppKit/AppKit.h>
#include <GNUstepGUI/GSTable.h>
#include <GNUstepGUI/GSVbox.h>
#include "Label.h"
#include "TerminalParser_LinuxPrefs.h"
static NSUserDefaults *ud;
NSString
*TerminalParser_LinuxPrefsDidChangeNotification=
@"TerminalParser_LinuxPrefsDidChangeNotification";
static NSString *CharacterSetKey=@"Linux_CharacterSet";
static NSString *characterSet;
typedef struct
{
NSString *name;
NSString *display_name;
} character_set_choice_t;
static character_set_choice_t cs_choices[]={
{@"utf-8" ,__(@"UTF-8")},
{@"iso-8859-1" ,__(@"West Europe, latin1")},
{@"iso-8859-2" ,__(@"East Europe, latin2")},
{@"big-5" ,__(@"Chinese")},
{nil ,__(@"Custom, leave unchanged")},
{nil,nil}
};
@implementation TerminalParser_LinuxPrefs
+(void) initialize
{
if (!ud)
{
ud=[NSUserDefaults standardUserDefaults];
characterSet=[[ud stringForKey: CharacterSetKey] retain];
if (!characterSet)
characterSet=@"iso-8859-1";
}
}
+(const char *) characterSet
{
return [characterSet cString];
}
-(void) save
{
int i;
if (!top) return;
i=[pb_characterSet indexOfSelectedItem];
if (cs_choices[i].name!=nil)
{
ASSIGN(characterSet,cs_choices[i].name);
[ud setObject: characterSet forKey: CharacterSetKey];
[[NSNotificationCenter defaultCenter]
postNotificationName: TerminalParser_LinuxPrefsDidChangeNotification
object: self];
}
}
-(void) revert
{
int i;
character_set_choice_t *c;
for (i=0,c=cs_choices;c->name;i++,c++)
{
if (c->name &&
[c->name caseInsensitiveCompare: characterSet]==NSOrderedSame)
break;
}
[pb_characterSet selectItemAtIndex: i];
}
-(NSString *) name
{
return _(@"'linux' terminal parser");
}
-(void) setupButton: (NSButton *)b
{
[b setTitle: _(@"'linux'\nparser")];
[b sizeToFit];
}
-(void) willHide
{
}
-(NSView *) willShow
{
if (!top)
{
GSVbox *top2;
top2=[[GSVbox alloc] init];
top=[[GSVbox alloc] init];
[top setAutoresizingMask: NSViewMinXMargin|NSViewMaxXMargin|NSViewMinYMargin|NSViewMaxYMargin];
[top setDefaultMinYMargin: 2];
{
NSTextField *f;
NSPopUpButton *pb;
int i;
character_set_choice_t *c;
pb_characterSet=pb=[[NSPopUpButton alloc] init];
[pb setAutoresizingMask: NSViewMinXMargin|NSViewMaxXMargin];
[pb setAutoenablesItems: NO];
for (i=0,c=cs_choices;c->display_name;i++,c++)
{
NSString *name;
if (c->name)
name=[NSString stringWithFormat: @"%@ (%@)",
_(c->display_name),c->name];
else
name=_(c->display_name);
[pb addItemWithTitle: name];
}
[pb sizeToFit];
[top addView: pb enablingYResizing: NO];
DESTROY(pb);
f=[NSTextField newLabel: _(@"Character set:")];
[top addView: f enablingYResizing: NO];
DESTROY(f);
}
[top2 addView: top enablingYResizing: YES];
DESTROY(top);
top=top2;
[self revert];
}
return top;
}
-(void) dealloc
{
DESTROY(top);
[super dealloc];
}
@end
|