The R Project SVN R-packages

Rev

Rev 5973 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1051 urbaneks 1
#import "../RGUI.h"
815 urbaneks 2
#import "PrefWindowController.h"
5721 urbaneks 3
#import "../PreferenceKeys.h"
4
#import "../AMPrefs/AMPreferenceWindowController.h"
815 urbaneks 5
 
6
@implementation PrefWindowController
7
 
8
- (id) init
9
{
10
	self = [super initWithAutosaveName:@"PreferencesWindow"];
11
	return self;
12
}
13
 
14
- (void) awakeFromNib
15
{
1051 urbaneks 16
	quartzPrefPane = [[[QuartzPrefPane alloc] initWithIdentifier:@"Quartz" label:NLSC(@"PrefP-Quartz",@"Quartz preference pane") category:NLSC(@"PrefG-Views",@"Views preference group") ] autorelease];
815 urbaneks 17
	[self addPane:quartzPrefPane withIdentifier:[quartzPrefPane identifier]];
18
 
1051 urbaneks 19
	miscPrefPane = [[[MiscPrefPane alloc] initWithIdentifier:@"Misc" label:NLSC(@"PrefP-Startup",@"Startup preference pane") category:NLSC(@"PrefG-General",@"General preference group")] autorelease];
815 urbaneks 20
	[self addPane:miscPrefPane withIdentifier:[miscPrefPane identifier]];
21
 
1051 urbaneks 22
	colorsPrefPane = [[[ColorsPrefPane alloc] initWithIdentifier:@"Colors" label:NLSC(@"PrefP-Colors",@"Colors preference pane") category:NLSC(@"PrefG-Views",@"Views preference group")] autorelease];
815 urbaneks 23
	[self addPane:colorsPrefPane withIdentifier:[colorsPrefPane identifier]];
24
 
1084 urbaneks 25
	syntaxColorsPrefPane = [[[SyntaxColorsPrefPane alloc] initWithIdentifier:@"Syntax Colors" label:NLSC(@"PrefP-Syntax",@"Syntax colors preference pane") category:NLSC(@"PrefG-Editor",@"Editor preference group")] autorelease];
1077 urbaneks 26
	[self addPane:syntaxColorsPrefPane withIdentifier:[syntaxColorsPrefPane identifier]];
27
 
1084 urbaneks 28
	editorPrefPane = [[[EditorPrefPane alloc] initWithIdentifier:@"Editor" label:NLSC(@"PrefP-Editor",@"Editor preference pane") category:NLSC(@"PrefG-Editor",@"Editor preference group")] autorelease];
815 urbaneks 29
	[self addPane:editorPrefPane withIdentifier:[editorPrefPane identifier]];
5741 urbaneks 30
 
31
	[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:RScriptEditorDefaultFont options:NSKeyValueObservingOptionNew context:NULL];
6063 bibiko 32
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:NSApp];
5741 urbaneks 33
 
815 urbaneks 34
	// set up some configuration options
35
	[self setUsesConfigurationPane:YES];
36
	[self setSortByCategory:YES];
37
	// select prefs pane for display
38
	[self selectPaneWithIdentifier:@"All"];
5973 bibiko 39
	[[self window] setExcludedFromWindowsMenu:YES];
815 urbaneks 40
}
41
 
5741 urbaneks 42
- (void)dealloc
43
{
44
	[[NSNotificationCenter defaultCenter] removeObserver:self];
45
	[super dealloc];
46
}
47
 
48
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
49
{
50
	if ([keyPath isEqualToString:RScriptEditorDefaultFont]) {
51
		[[editorPrefPane valueForKeyPath:@"editorFont"] setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
52
	}
53
}
54
 
815 urbaneks 55
- (IBAction)showPrefsWindow:(id)sender
56
{
57
	[self showWindow:self];
58
	[[self window] makeKeyAndOrderFront:self];
59
}
60
 
61
- (IBAction)sortByAlphabet:(id)sender
62
{
63
	[self setSortByCategory:NO];
64
	[self selectIconViewPane];
65
}
66
 
67
- (IBAction)sortByCategory:(id)sender
68
{
69
	[self setSortByCategory:YES];
70
	[self selectIconViewPane];
71
}
72
 
73
- (BOOL)shouldLoadPreferencePane:(NSString *)identifier
74
{
75
	//	NSLog(@"shouldLoadPreferencePane: %@", identifier);
76
	return YES;
77
}
78
 
79
- (void)willSelectPreferencePane:(NSString *)identifier
80
{
81
	//	NSLog(@"willSelectPreferencePane: %@", identifier);
82
}
83
 
84
- (void)didUnselectPreferencePane:(NSString *)identifier
85
{
86
	//	NSLog(@"didUnselectPreferencePane: %@", identifier);
87
}
88
 
89
- (NSString *)displayNameForCategory:(NSString *)category
90
{
91
	return category;
92
}
93
 
5721 urbaneks 94
/**
95
 * Trap window close notifications and use them to ensure changes are saved.
96
 */
97
- (void)windowWillClose:(NSNotification *)notification
98
{
99
	[[NSColorPanel sharedColorPanel] close];
100
	[[NSFontPanel sharedFontPanel] close];
101
 
102
	// Mark the currently selected field in the window as having finished editing, to trigger saves.
103
	if ([[self window] firstResponder]) {
104
		[[self window] endEditingFor:[[self window] firstResponder]];
105
	}
106
}
107
 
108
- (void)changeFont:(id)sender
109
{
110
 
111
	if([self activePane] == (AMPreferencePane*)editorPrefPane) {
112
 
113
		NSFont *font;
114
		NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
115
 
116
		font = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:RScriptEditorDefaultFont]]];
117
 
118
		[prefs setObject:[NSArchiver archivedDataWithRootObject:font] forKey:RScriptEditorDefaultFont];
119
 
120
		[[editorPrefPane valueForKeyPath:@"editorFont"] setFont:font];
121
	}
122
 
123
}
124
 
125
 
815 urbaneks 126
@end