blob: ec5bbe84c8c03a954ccf894b096fac8fd677b5ba [file] [log] [blame]
Ronald Oussorenc629be82006-06-07 18:58:01 +00001#import "PreferencesWindowController.h"
2
3@implementation PreferencesWindowController
4
5+ getPreferencesWindow
6{
7 static PreferencesWindowController *_singleton;
Ronald Oussorencc879a02013-07-07 09:49:23 +02008
Ronald Oussorenc629be82006-06-07 18:58:01 +00009 if (!_singleton)
10 _singleton = [[PreferencesWindowController alloc] init];
11 [_singleton showWindow: _singleton];
12 return _singleton;
13}
14
15- (id) init
16{
17 self = [self initWithWindowNibName: @"PreferenceWindow"];
18 return self;
19}
20
21- (void)load_defaults
22{
23 NSString *title = [filetype titleOfSelectedItem];
Ronald Oussorencc879a02013-07-07 09:49:23 +020024
Ronald Oussorenc629be82006-06-07 18:58:01 +000025 settings = [FileSettings getDefaultsForFileType: title];
26}
27
28- (void)update_display
29{
Ronald Oussorencc879a02013-07-07 09:49:23 +020030 [interpreter reloadData];
Ronald Oussorenc629be82006-06-07 18:58:01 +000031 [interpreter setStringValue: [settings interpreter]];
32 [honourhashbang setState: [settings honourhashbang]];
33 [debug setState: [settings debug]];
34 [verbose setState: [settings verbose]];
35 [inspect setState: [settings inspect]];
36 [optimize setState: [settings optimize]];
37 [nosite setState: [settings nosite]];
38 [tabs setState: [settings tabs]];
39 [others setStringValue: [settings others]];
40 [with_terminal setState: [settings with_terminal]];
41 // Not scriptargs, it isn't for preferences
Ronald Oussorenc629be82006-06-07 18:58:01 +000042 [commandline setStringValue: [settings commandLineForScript: @"<your script here>"]];
43}
44
45- (void) windowDidLoad
46{
47 [super windowDidLoad];
48 [self load_defaults];
49 [self update_display];
50}
51
52- (void)update_settings
53{
54 [settings updateFromSource: self];
55}
56
57- (IBAction)do_filetype:(id)sender
58{
59 [self load_defaults];
60 [self update_display];
61}
62
63- (IBAction)do_reset:(id)sender
64{
65 [settings reset];
66 [self update_display];
67}
68
69- (IBAction)do_apply:(id)sender
70{
71 [self update_settings];
72 [self update_display];
73}
74
Ronald Oussorencc879a02013-07-07 09:49:23 +020075// FileSettingsSource protocol
Ronald Oussorenc629be82006-06-07 18:58:01 +000076- (NSString *) interpreter { return [interpreter stringValue];};
77- (BOOL) honourhashbang { return [honourhashbang state]; };
78- (BOOL) debug { return [debug state];};
79- (BOOL) verbose { return [verbose state];};
80- (BOOL) inspect { return [inspect state];};
81- (BOOL) optimize { return [optimize state];};
82- (BOOL) nosite { return [nosite state];};
83- (BOOL) tabs { return [tabs state];};
84- (NSString *) others { return [others stringValue];};
85- (BOOL) with_terminal { return [with_terminal state];};
86- (NSString *) scriptargs { return @"";};
87
88// Delegates
89- (void)controlTextDidChange:(NSNotification *)aNotification
90{
91 [self update_settings];
92 [self update_display];
93};
94
95// NSComboBoxDataSource protocol
96- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString
97{
Ronald Oussorencc879a02013-07-07 09:49:23 +020098 NSArray *interp_list = [settings interpreters];
Ronald Oussorenc629be82006-06-07 18:58:01 +000099 unsigned int rv = [interp_list indexOfObjectIdenticalTo: aString];
Ronald Oussorencc879a02013-07-07 09:49:23 +0200100 return rv;
Ronald Oussorenc629be82006-06-07 18:58:01 +0000101}
102
103- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index
104{
Ronald Oussorencc879a02013-07-07 09:49:23 +0200105 NSArray *interp_list = [settings interpreters];
Ronald Oussorenc629be82006-06-07 18:58:01 +0000106 id rv = [interp_list objectAtIndex: index];
Ronald Oussorencc879a02013-07-07 09:49:23 +0200107 return rv;
Ronald Oussorenc629be82006-06-07 18:58:01 +0000108}
109
110- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
111{
Ronald Oussorencc879a02013-07-07 09:49:23 +0200112 NSArray *interp_list = [settings interpreters];
Ronald Oussorenc629be82006-06-07 18:58:01 +0000113 int rv = [interp_list count];
Ronald Oussorencc879a02013-07-07 09:49:23 +0200114 return rv;
Ronald Oussorenc629be82006-06-07 18:58:01 +0000115}
116
117
118@end