File: WrapperDocumentController.m

package info (click to toggle)
wrapperfactory.app 0.1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: objc: 3,094; sh: 176; makefile: 33
file content (533 lines) | stat: -rw-r--r-- 14,568 bytes parent folder | download | duplicates (6)
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/* Copyright (C) 2003 Raffael Herzog
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: WrapperDocumentController.m 103 2004-08-09 16:30:51Z rherzog $
 * $HeadURL: file:///home/rherzog/Subversion/GNUstep/GSWrapper/tags/release-0.1.0/WrapperFactory/WrapperDocumentController.m $
 */

#include <AppKit/AppKit.h>

#include "WrapperDocumentController.h"
#include "WrapperDocument.h"
#include "Icon.h"


static NSString *emptyString = @"";


@interface WrapperDocumentController (Notifications)

- (void)wrapperDocumentChangedNotification: (NSNotification *)not;

@end


@implementation WrapperDocumentController

- (id)init
{
    self = [super init];
    if ( self ) {
//         textCursor = [NSCursor IBeamCursor];
//         defaultCursor = [NSCursor arrowCursor];
//         [textCursor setOnMouseEntered: YES];
//         [defaultCursor setOnMouseExited: YES];
        settingValue = NO;
    }
    return self;
}

- (void)awakeFromNib
{
//     if ( currentScript ) {
//         NSLog(@"Setting cursor");
//         [currentScript addCursorRect: [currentScript bounds]
//                        cursor: (textCursor)];
//         [currentScript addCursorRect: [currentScript bounds]
//                        cursor: (defaultCursor)];
//     }
//    [self setCurrentScriptId: StartScript];
}



/*
 * delegate methods
 */

- (void)controlTextDidChange: (NSNotification *)not
{
    [self textDidChange: not];
}

- (void)textDidChange: (NSNotification *)not
{
    if ( settingValue ) {
        return;
    }
    id src = [not object];
    settingValue = YES;
    if ( src == name ) {
        [document setName: AUTORELEASE([[name stringValue] copyWithZone: NSDefaultMallocZone()])];
    }
    else if ( src == version ) {
        [document setVersion: AUTORELEASE([[version stringValue] copyWithZone: NSDefaultMallocZone()])];
    }
    else if ( src == fullVersion ) {
        [document setFullVersion: AUTORELEASE([[fullVersion stringValue] copyWithZone: NSDefaultMallocZone()])];
    }
    else if ( src == description ) {
        [document setDescription: AUTORELEASE([[description stringValue] copyWithZone: NSDefaultMallocZone()])];
    }
    else if ( src == url ) {
        [document setUrl: AUTORELEASE([[url stringValue] copyWithZone: NSDefaultMallocZone()])];
    }
    else if ( src == authors ) {
        [document setAuthors: AUTORELEASE([[authors stringValue] copyWithZone: NSDefaultMallocZone()])];
    }
    else if ( src == currentScriptShell ) {
        NSString *shell = AUTORELEASE([[currentScriptShell stringValue] copyWithZone: NSDefaultMallocZone()]);
        switch ( currentScriptId ) {
        case StartScript:
            [document setStartScriptShell: shell];
            break;
        case StartOpenScript:
            [document setStartOpenScriptShell: shell];
            break;
        case OpenScript:
            [document setOpenScriptShell: shell];
            break;
        default:
            NSLog(@"Unknown script ID: %d", currentScriptId);
        }
    }
    else if ( src == currentScript ) {
        NSString *script = AUTORELEASE([[currentScript string] copyWithZone: NSDefaultMallocZone()]);
        switch ( currentScriptId ) {
        case StartScript:
            [document setStartScript: script];
            break;
        case StartOpenScript:
            [document setStartOpenScript: script];
            break;
        case OpenScript:
            [document setOpenScript: script];
            break;
        default:
            NSLog(@"Unknown script ID: %d", currentScriptId);
        }
    }
    else {
        NSLog(@"Received textDidChange notification from unknown control: %@", src);
    }
    settingValue = NO;
}

- (void)iconViewDidChangeIcon: (NSNotification *)not
{
    if ( settingValue ) {
        return;
    }
    settingValue = YES;
    if ( [not object] == appIcon ) {
        [document setAppIcon: [(IconView *)[not object] icon]];
    }
    else {
        NSLog(@"Received iconViewImageChanged notification from unknown ImageView: %@", [not object]);
    }
    settingValue = NO;
}


/*
 * actions
 */

- (IBAction)setCurrentScriptToStart: (id)sender
{
    [self setCurrentScriptId: StartScript];
}

- (IBAction)setCurrentScriptToStartOpen: (id)sender
{
    [self setCurrentScriptId: StartOpenScript];
}

- (IBAction)setCurrentScriptToOpen: (id)sender
{
    [self setCurrentScriptId: OpenScript];
}

- (IBAction)setRole: (id)sender
{
    int tag = [[sender selectedItem] tag];
    settingValue = YES;
    switch ( tag ) {
    case NoneRole:
        [document setRole: NoneRole];
        break;
    case ViewerRole:
        [document setRole: ViewerRole];
        break;
    case EditorRole:
        [document setRole: EditorRole];
        break;
    default:
        NSLog(@"Unknown role: %d", tag);
    }
    settingValue = NO;
}

- (IBAction)setCurrentScriptAction: (id)sender
{
    int tag = [[sender selectedItem] tag];
    settingValue = YES;
    switch ( currentScriptId ) {
    case StartScript:
        [document setStartScriptAction: tag];
        break;
    case StartOpenScript:
        [document setStartOpenScriptAction: tag];
        break;
    case OpenScript:
        [document setOpenScriptAction: tag];
        break;
    }
}


/*
 * outlets
 */

- (void)setWindowController: (NSWindowController *)controller
{
    windowController = controller;
    [self setDocument: [controller document]];
}

- (void)setDocument: (WrapperDocument *)d
{
    if ( document ) {
        [[NSNotificationCenter defaultCenter] removeObserver: self
                                              name: (WrapperChangedNotification)
                                              object: (document)];
    }

    document = d;

    settingValue = YES;
    if ( ! d ) {
        NSLog(@"Document set to null");
    }
    if ( appIcon ) {
        [appIcon setIcon: [d appIcon]];
    }
    else {
        NSLog(@"No appIcon image view");
    }
    if ( name ) {
        [name setStringValue: d ? [d name] : emptyString];
    }
    else {
        NSLog(@"No name text field");
    }
    if ( version ) {
        [version setStringValue: d ? [d version] : emptyString];
    }
    else {
        NSLog(@"No version text field");
    }
    if ( fullVersion ) {
        [fullVersion setStringValue: d ? [d fullVersion] : emptyString];
    }
    else {
        NSLog(@"No fullVersion text field");
    }
    if ( description ) {
        [description setStringValue: d ? [d description] : emptyString];
    }
    else {
        NSLog(@"No description text field");
    }
    if ( url ) {
        [url setStringValue: d ? [d url] : emptyString];
    }
    else {
        NSLog(@"No url text field");
    }
    if ( authors ) {
        [authors setStringValue: d ? [d authors] : emptyString];
    }
    else {
        NSLog(@"No authors text field");
    }
    [self setCurrentScriptId: currentScriptId];
    settingValue = NO;

    if ( document ) {
        [[NSNotificationCenter defaultCenter] addObserver: self
                                              selector: @selector(wrapperDocumentChangedNotification:)
                                              name: (WrapperChangedNotification)
                                              object: (document)];
    }
}

- (void)setAppIcon: (IconView *)i
{
    if ( appIcon) {
        [[NSNotificationCenter defaultCenter] removeObserver: self
                                              name: (IconViewDidChangeIconNotification)
                                              object: (self)];
    }
    appIcon = i;
    if ( appIcon ) {
        [[NSNotificationCenter defaultCenter] addObserver: self
                                              selector: @selector(iconViewDidChangeIcon:)
                                              name: (IconViewDidChangeIconNotification)
                                              object: (appIcon)];
    }
}
- (IconView *)appIcon
{
    return appIcon;
}

- (void)setName: (NSTextField *)n
{
    name = n;
}
- (NSTextField *)name
{
    return name;
}

- (void)setVersion: (NSTextField *)v
{
    version = v;
}
- (NSTextField *)version
{
    return version;
}

- (void)setFullVersion: (NSTextField *)v
{
    fullVersion = v;
}
- (NSTextField *)fullVersion
{
    return fullVersion;
}

- (void)setDescription: (NSTextField *)d
{
    description = d;
}
- (NSTextField *)description
{
    return description;
}

- (void)setUrl: (NSTextField *)u
{
    url = u;
}
- (NSTextField *)url
{
    return url;
}

- (void)setAuthors: (NSTextField *)a
{
    authors = a;
}
- (NSTextField *)authors
{
    return authors;
}

- (NSPopUpButton *)rolePopUp
{
    return rolePopUp;
}
- (void)setRolePopUp: (NSPopUpButton *)role
{
    ASSIGN(rolePopUp, role);
}

- (NSPopUpButton *)currentScriptActionPopUp
{
    return currentScriptActionPopUp;
}
- (void)setCurrentScriptActionPopUp: (NSPopUpButton *)actionPopUp;
{
    ASSIGN(currentScriptActionPopUp, actionPopUp);
}

- (void)setCurrentScriptId: (int)i
{
    NSString *shell;
    NSString *script;
    int action;
    switch ( i ) {
    case StartScript:
        shell = [document startScriptShell];
        script = [document startScript];
        action = [document startScriptAction];
        break;
    case StartOpenScript:
        shell = [document startOpenScriptShell];
        script = [document startOpenScript];
        action = [document startOpenScriptAction];
        break;
    case OpenScript:
        shell = [document openScriptShell];
        script = [document openScript];
        action = [document openScriptAction];
        break;
    default:
        NSLog(@"Unknown script ID: %d", currentScriptId);
        return;
    }
    [currentScriptActionPopUp selectItemAtIndex: [currentScriptActionPopUp indexOfItemWithTag: action]];
    currentScriptId = i;
    if ( !script ) {
        script = @"";
    }
    if ( !shell ) {
        shell = @"/bin/sh";
    }
    if ( currentScriptShell ) {
        [currentScriptShell setStringValue: shell];
    }
    if ( currentScript ) {
        [currentScript setString: script];
    }
}
- (int)currentScriptId
{
    return currentScriptId;
}

- (void)setCurrentScriptShell: (NSTextField *)s
{
    currentScriptShell = s;
}
- (NSTextField *)currentScriptShell
{
    return currentScriptShell;
}

- (void)setCurrentScript: (NSTextView *)s
{
    currentScript = s;
}
- (NSTextView *)currentScript
{
    return currentScript;
}

@end



@implementation WrapperDocumentController (Notifications)

- (void)wrapperDocumentChangedNotification: (NSNotification *)not
{
    if ( settingValue ) {
        return;
    }
    settingValue = YES;
    NSString *attr = [[not userInfo] objectForKey: WrapperChangedAttributeName];
    id val = [[not userInfo] objectForKey: WrapperChangedAttributeValue];
    if ( [attr isEqualToString: @"appIcon"] && appIcon ) {
        [appIcon setIcon: [Icon iconWithImage: val]];
    }
    else if ( [attr isEqualToString: @"name"] && name ) {
        [name setStringValue: val];
    }
    else if ( [attr isEqualToString: @"version"] && version ) {
        [version setStringValue: val];
    }
    else if ( [attr isEqualToString: @"fullVersion"] && fullVersion ) {
        [fullVersion setStringValue: val];
    }
    else if ( [attr isEqualToString: @"description"] && description ) {
        [description setStringValue: val];
    }
    else if ( [attr isEqualToString: @"url"] && url ) {
        [url setStringValue: val];
    }
    else if ( [attr isEqualToString: @"authors"] && authors ) {
        [authors setStringValue: val];
    }
    else if ( [attr isEqualToString: @"role"] && rolePopUp ) {
        [rolePopUp selectItemAtIndex: [rolePopUp indexOfItemWithTag: [val intValue]]];
    }
    else if ( [attr isEqualToString: @"startScript"] && currentScript) {
        if ( currentScriptId == StartScript ) {
            [currentScript setString: val];
        }
    }
    else if ( [attr isEqualToString: @"startScriptShell"] && currentScriptShell ) {
        if ( currentScriptId == StartScript ) {
            [currentScriptShell setStringValue: val];
        }
    }
    else if ( [attr isEqualToString: @"startScriptAction"] && currentScriptActionPopUp ) {
        if ( currentScriptId == StartScript ) {
            [currentScriptActionPopUp selectItemAtIndex: [currentScriptActionPopUp indexOfItemWithTag: [val intValue]]];
        }
    }
    else if ( [attr isEqualToString: @"startOpenScript"] && currentScriptActionPopUp ) {
        if ( currentScriptId == StartOpenScript ) {
            [currentScriptActionPopUp selectItemAtIndex: [currentScriptActionPopUp indexOfItemWithTag: [val intValue]]];
        }
    }
    else if ( [attr isEqualToString: @"startOpenScriptShell"] && currentScriptShell ) {
        if ( currentScriptId == StartOpenScript ) {
            [currentScriptShell setStringValue: val];
        }
    }
    else if ( [attr isEqualToString: @"startOpenScriptAction"] && currentScriptActionPopUp ) {
        if ( currentScriptId == StartOpenScript ) {
            [currentScriptActionPopUp selectItemAtIndex: [currentScriptActionPopUp indexOfItemWithTag: [val intValue]]];
        }
    }
    else if ( [attr isEqualToString: @"openScript"] && currentScript ) {
        if ( currentScriptId == OpenScript ) {
            [currentScript setString: val];
        }
    }
    else if ( [attr isEqualToString: @"openScriptAction"] && currentScriptActionPopUp ) {
        if ( currentScriptId == OpenScript ) {
            [currentScriptActionPopUp selectItemAtIndex: [currentScriptActionPopUp indexOfItemWithTag: [val intValue]]];
        }
    }
    else if ( [attr isEqualToString: @"openScriptShell"] && currentScriptShell ) {
        if ( currentScriptId == OpenScript ) {
            [currentScriptShell setStringValue: val];
        }
    }
    else {
        NSLog(@"Received WrapperChangedNotification for unknown attribute %@", attr);
    }
    settingValue = NO;
}

@end