-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMiscElement.m
228 lines (203 loc) · 5.85 KB
/
MiscElement.m
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* MiscElement.m
*
* Copyright (C) 2006-2013 Free Software Foundation, Inc.
*
* Author: Richard Frith-Macdonald <[email protected]>
* Riccardo Mottola <[email protected]>
* Date: 2006
*
* This file is part of GNUstep.
*
* This program 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; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
*/
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <GNUstepGUI/GSTheme.h>
#import "AppController.h"
#import "ThemeDocument.h"
#import "MiscElement.h"
@implementation MiscElement
- (void) any: (NSNotification*)o
{
NSLog(@"Notified: %@", o);
}
- (void) didEndEditing: (id)o
{
NSNotification *n;
/* We must record any editing changes because we have lost keyboard focus
* or somesuch.
*/
n = [NSNotification notificationWithName: @"dummy"
object: authors
userInfo: nil];
[self textDidEndEditing: n];
n = [NSNotification notificationWithName: @"dummy"
object: license
userInfo: nil];
[self textDidEndEditing: n];
n = [NSNotification notificationWithName: @"dummy"
object: details
userInfo: nil];
[self textDidEndEditing: n];
}
- (void) dealloc
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver: self];
[super dealloc];
}
- (void) deselect
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
AppController *ctl = [AppController sharedController];
[nc removeObserver: self
name: NSWindowDidResignKeyNotification
object: [ctl inspector]];
[self didEndEditing: nil];
[super deselect];
}
- (void) selectAt: (NSPoint)mouse
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
AppController *ctl = [AppController sharedController];
ThemeDocument *doc = [ctl selectedDocument];
NSDictionary *info = [doc infoDictionary];
NSArray *arr;
NSString *str;
int fsize = 32;
[nc addObserver: self
selector: @selector(didEndEditing:)
name: NSWindowDidResignKeyNotification
object: [ctl inspector]];
arr = [info objectForKey: @"GSThemeAuthors"];
if ([arr count] > 0)
{
str = [arr componentsJoinedByString: @"\n"];
[authors setString: str];
}
str = [info objectForKey: @"GSThemeLicense"];
if ([str length] > 0)
{
[license setString: str];
}
str = [info objectForKey: @"GSThemeDetails"];
if ([str length] > 0)
{
[details setString: str];
}
[iconView setImage: [[GSTheme theme] icon]];
do
{
[themeName setFont: [NSFont boldSystemFontOfSize: fsize]];
fsize -= 2;
[themeName sizeToFit];
}
while ([themeName frame].size.width > 200 && fsize > 8);
[themeName setStringValue: [[doc name] stringByDeletingPathExtension]];
str = [doc versionIncrementMajor: NO incrementMinor: NO];
[themeVersion setStringValue: str];
[super selectAt: mouse];
}
- (void) newVersion: (id)sender
{
ThemeDocument *doc = [[AppController sharedController] selectedDocument];
NSString *ver = [doc versionIncrementMajor: YES incrementMinor: NO];
[themeVersion setStringValue: ver];
}
- (void) takeIcon: (id)sender
{
ThemeDocument *doc = [[AppController sharedController] selectedDocument];
NSArray *fileTypes = [NSImage imageFileTypes];
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
int result;
[oPanel setAllowsMultipleSelection: NO];
[oPanel setCanChooseFiles: YES];
[oPanel setCanChooseDirectories: NO];
result = [oPanel runModalForDirectory: NSHomeDirectory()
file: nil
types: fileTypes];
if (result == NSOKButton)
{
NSString *path = [oPanel filename];
NSImage *image = nil;
NS_DURING
{
image = [[NSImage alloc] initWithContentsOfFile: path];
}
NS_HANDLER
{
NSString *message = [localException reason];
NSRunAlertPanel(_(@"Problem loading theme icon image"),
message, nil, nil, nil);
}
NS_ENDHANDLER
if (image != nil)
{
NSSize s = [image size];
float scale = 1.0;
if (s.height > 48.0)
scale = 48.0 / s.height;
if (48.0 / s.width < scale)
scale = 48.0 / s.width;
if (scale != 1.0)
{
[image setScalesWhenResized: YES];
s.height *= scale;
s.width *= scale;
[image setSize: s];
}
[doc setResource: path forKey: @"GSThemeIcon"];
[iconView setImage: image];
RELEASE(image);
}
}
}
- (void) textDidEndEditing: (NSNotification*)aNotification
{
ThemeDocument *doc = [[AppController sharedController] selectedDocument];
NSTextView *sender = [aNotification object];
NSString *s = [[sender string] stringByTrimmingSpaces];
// NSLog(@"End editing %@", aNotification);
if (sender == details)
{
[doc setInfo: s forKey: @"GSThemeDetails"];
}
else if (sender == license)
{
[doc setInfo: s forKey: @"GSThemeLicense"];
}
else if (sender == authors)
{
NSMutableArray *a;
unsigned count;
a = [[s componentsSeparatedByString: @"\n"] mutableCopy];
count = [a count];
while (count-- > 0)
{
NSString *line = [a objectAtIndex: count];
if ([[line stringByTrimmingSpaces] length] == 0)
{
[a removeObjectAtIndex: count];
}
}
[doc setInfo: a forKey: @"GSThemeAuthors"];
RELEASE(a);
}
}
- (NSString*) title
{
return @"Miscellaneous";
}
@end