Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 182 lines (141 sloc) 5.442 kb
4deff4d Initial check-in.
uli authored
1 //
2 // UKSCTDUserIdentifiersPrefsController.m
3 // UKSyntaxColoredDocument
4 //
5 // Created by Uli Kusterer on Sat May 15 2004.
6f2d874 @uliwitness Updated the license to zlib license.
authored
6 // Copyright (c) 2004 Uli Kusterer.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
4deff4d Initial check-in.
uli authored
26 //
27
28 // -----------------------------------------------------------------------------
29 // Headers:
30 // -----------------------------------------------------------------------------
31
32 #import "UKSCTDUserIdentifiersPrefsController.h"
deefb99 @uliwitness Make helpers depend on view controller, not document.
authored
33 #import "UKSyntaxColoredTextViewController.h"
4deff4d Initial check-in.
uli authored
34
35
36 @implementation UKSCTDUserIdentifiersPrefsController
37
38 // -----------------------------------------------------------------------------
39 // * CONSTRUCTOR:
40 //
41 // REVISIONS:
42 // 2004-05-18 witness Documented.
43 // -----------------------------------------------------------------------------
44
45 -(id) init
46 {
47 self = [super init];
48 if( self )
49 {
50 identifiers = nil; // Is instantiated lazily when we need it.
51 }
52
53 return self;
54 }
55
56
57 // -----------------------------------------------------------------------------
58 // * DESTRUCTOR:
59 //
60 // REVISIONS:
61 // 2004-05-18 witness Documented.
62 // -----------------------------------------------------------------------------
63
64 -(void) dealloc
65 {
66 [identifiers release];
67 identifiers = nil;
68
69 [super dealloc];
70 }
71
72
73 // -----------------------------------------------------------------------------
74 // awakeFromNib:
75 // Make sure GUI looks right after it's been loaded.
76 //
77 // REVISIONS:
78 // 2004-05-18 witness Documented.
79 // -----------------------------------------------------------------------------
80
81 -(void) awakeFromNib
82 {
83 [self tableViewSelectionDidChange:nil]; // Make sure "remove" button looks right.
84 }
85
86
87 // -----------------------------------------------------------------------------
88 // createNewIdentifier:
89 // Action for "Add Identifier" button. Creates a new untitled identifier
90 // entry that the user can then edit.
91 //
92 // REVISIONS:
93 // 2004-05-18 witness Documented.
94 // -----------------------------------------------------------------------------
95
96 -(IBAction) createNewIdentifier: (id)sender
97 {
98 [[self identifiers] addObject: NSLocalizedString(@"untitled", nil)];
d3bb0c9 @uliwitness More correct and probably also more 64-bit-y.
authored
99 NSUInteger theRow = [[self identifiers] count] -1;
4deff4d Initial check-in.
uli authored
100
101 [identifiersList noteNumberOfRowsChanged];
102
d3bb0c9 @uliwitness More correct and probably also more 64-bit-y.
authored
103 [identifiersList selectRowIndexes: [NSIndexSet indexSetWithIndex: theRow] byExtendingSelection: NO];
4deff4d Initial check-in.
uli authored
104 [identifiersList editColumn: 0 row: theRow withEvent: nil select: YES];
105 }
106
107
108 // -----------------------------------------------------------------------------
109 // deleteIdentifier:
110 // Action for "Remove Identifier" button. Removes the selected identifier
111 // from the list and the user defaults.
112 //
113 // REVISIONS:
114 // 2004-05-18 witness Documented.
115 // -----------------------------------------------------------------------------
116
117 -(IBAction) deleteIdentifier: (id)sender
118 {
119 [identifiers removeObjectAtIndex: [identifiersList selectedRow]];
120 [identifiersList noteNumberOfRowsChanged];
121
122 [[NSUserDefaults standardUserDefaults] setObject: [self identifiers]
123 forKey: TD_USER_DEFINED_IDENTIFIERS];
124 }
125
126
127 // -----------------------------------------------------------------------------
128 // identifiers:
129 // Return and, if needed, lazily instantiate our array of user-defined
130 // identifiers.
131 //
132 // REVISIONS:
133 // 2004-05-18 witness Documented.
134 // -----------------------------------------------------------------------------
135
136 -(NSMutableArray*) identifiers
137 {
138 if( !identifiers )
139 {
140 identifiers = [[[NSUserDefaults standardUserDefaults] objectForKey: TD_USER_DEFINED_IDENTIFIERS] mutableCopy];
141 if( !identifiers )
142 identifiers = [[NSMutableArray alloc] init];
143 }
144
145 return identifiers;
146 }
147
148
149 // -----------------------------------------------------------------------------
150 // Table view data source methods:
151 // -----------------------------------------------------------------------------
152
2504ceb @uliwitness Less warnings on 64 bit.
authored
153 -(NSUInteger) numberOfRowsInTableView: (NSTableView *)tableView
4deff4d Initial check-in.
uli authored
154 {
155 return [[self identifiers] count];
156 }
157
158
2504ceb @uliwitness Less warnings on 64 bit.
authored
159 -(void) tableViewSelectionDidChange: (NSNotification *)notification
4deff4d Initial check-in.
uli authored
160 {
161 [removeButton setEnabled: ([identifiersList selectedRow] != -1)]; // Make sure "remove" button is only enabled if we have a selection.
162 }
163
164
2504ceb @uliwitness Less warnings on 64 bit.
authored
165 -(id) tableView: (NSTableView *)tableView objectValueForTableColumn: (NSTableColumn *)tableColumn row: (NSUInteger)row
4deff4d Initial check-in.
uli authored
166 {
167 return [[self identifiers] objectAtIndex: row];
168 }
169
170
2504ceb @uliwitness Less warnings on 64 bit.
authored
171 -(void) tableView: (NSTableView *)tableView setObjectValue: (id)object forTableColumn: (NSTableColumn *)tableColumn row: (NSUInteger)row
4deff4d Initial check-in.
uli authored
172 {
173 [identifiers replaceObjectAtIndex: row withObject: object];
174
175 [[NSUserDefaults standardUserDefaults] setObject: [self identifiers]
176 forKey: TD_USER_DEFINED_IDENTIFIERS];
177 }
178
179
180
181 @end
Something went wrong with that request. Please try again.