File: setMacroWatcher.m

package info (click to toggle)
gtamsanalyzer.app 0.42-6
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 6,112 kB
  • ctags: 866
  • sloc: objc: 34,338; ansic: 8,762; cpp: 384; makefile: 59; sh: 47
file content (545 lines) | stat: -rwxr-xr-x 17,132 bytes parent folder | download | duplicates (7)
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
534
535
536
537
538
539
540
541
542
543
544
545
#import "myResults.h"
#import "prefBoss.h"
#import "setMacroWatcher.h"
#import "utils.h"

@implementation setMacroWatcher
-(id) init
{
    currMacro = nil;
    return self;
}

-(IBAction) addAutoHistory: (id) sender
{
    NSMutableArray *pr;
    if(!currMacro) currMacro = [[NSMutableDictionary alloc] init];
    if((pr = [currMacro objectForKey: @"program"]) == nil)
    {
        pr = [[NSMutableArray alloc] init];
        [currMacro setObject: pr forKey: @"program"];
    }
    [pr addObjectsFromArray: [myOverLord autoHistory]];
    if([startMenu indexOfItemWithTitle: [myOverLord autoHistoryStart]] >= 0)
        [startMenu selectItemWithTitle: [myOverLord autoHistoryStart]];
    [macroView reloadData];
}
- (IBAction) addCodeSetStep: (id)sender
{
    BOOL ex;
    NSMutableDictionary *aa;
    NSMutableArray *pr;
    
    if(!currMacro) currMacro = [[NSMutableDictionary alloc] init];
    if((pr = [currMacro objectForKey: @"program"]) == nil)
    {
        pr = [[NSMutableArray alloc] init];
        [currMacro setObject: pr forKey: @"program"];
    }
    if([codeSetExact state] == NSOnState) 
        ex = YES;
    else
        ex = NO;
    aa = [[NSMutableDictionary alloc] init];
    [aa setObject: @"sel" forKey: @"stepType"];
    [aa setObject: [NSNumber numberWithInt: SELECTCODESET]
           forKey: @"mode"];
    [aa setObject: [NSNumber numberWithInt: [[codeSetSelMenu selectedItem] tag]] forKey: @"type"];
    [aa setObject: [[[codeSetMenu titleOfSelectedItem] copy] autorelease] forKey: @"name"];
    [aa setObject: [NSNumber numberWithBool: ex] forKey: @"exact"];
    [pr addObject: [aa autorelease]];
    [macroView reloadData];
    
}
- (IBAction)addSelectStep:(id)sender
{
    NSMutableDictionary *aa;
    NSMutableArray *pr;
    if(!currMacro) currMacro = [[NSMutableDictionary alloc] init];
    if((pr = [currMacro objectForKey: @"program"]) == nil)
    {
        pr = [[NSMutableArray alloc] init];
        [currMacro setObject: pr forKey: @"program"];
    }
    
    aa = [[NSMutableDictionary alloc] init];
    [aa setObject: @"sel" forKey: @"stepType"];
    [aa setObject: [NSNumber numberWithInt: [[selectModeMenu selectedItem] tag]]
        forKey: @"mode"];
    [aa setObject: [NSNumber numberWithInt: [[selectTypeMenu selectedItem] tag]] 
        forKey: @"type"];
    [aa setObject: [[[selectStringView stringValue] copy] autorelease]
        forKey: @"searchValue"];
    [aa setObject: [[[columnMenu titleOfSelectedItem] copy] autorelease] forKey: @"col"];
    [aa setObject: [NSNumber numberWithInt: [fpOption intValue]] forKey: @"float"];
    [aa setObject: [NSNumber numberWithInt: [regexOption intValue]] forKey: @"regex"];
    [pr addObject: [aa autorelease]];
    [macroView reloadData];
        
}
-(IBAction) addAutosetStep: (id) sender
{
    NSMutableDictionary *aa;
    NSMutableArray *pr;
    if([localAutosetMenu numberOfItems] == 0) 
    {
        NSWARNING(@"No defined sets.");
        return;
    }
    if(!currMacro) currMacro = [[NSMutableDictionary alloc] init];
    if((pr = [currMacro objectForKey: @"program"]) == nil)
    {
        pr = [[NSMutableArray alloc] init];
        [currMacro setObject: pr forKey: @"program"];
    }
    
    aa = [[NSMutableDictionary alloc] init];
    [aa setObject: @"autoset" forKey: @"stepType"];
    [aa setObject: [[[localAutosetMenu titleOfSelectedItem] copy] autorelease]
           forKey: @"name"];
    [pr addObject: [aa autorelease]];
    [macroView reloadData];
    
    
}

- (IBAction)addSetStep:(id)sender
{
    NSMutableDictionary *aa;
    NSMutableArray *pr;
    if([setObjectMenu numberOfItems] == 0) 
    {
        NSWARNING(@"No defined sets.");
        return;
    }
    if(!currMacro) currMacro = [[NSMutableDictionary alloc] init];
    if((pr = [currMacro objectForKey: @"program"]) == nil)
    {
        pr = [[NSMutableArray alloc] init];
        [currMacro setObject: pr forKey: @"program"];
    }
    
    aa = [[NSMutableDictionary alloc] init];
    [aa setObject: @"set" forKey: @"stepType"];
    [aa setObject: [NSNumber numberWithInt: [[setOpMenu selectedItem] tag]]
        forKey: @"op"];
    [aa setObject: [[[setObjectMenu titleOfSelectedItem] copy] autorelease]
        forKey: @"obj"];
    [pr addObject: [aa autorelease]];
    [macroView reloadData];

}
- (IBAction)cancelMacro:(id)sender
{
    [macroSheet orderOut: sender];
    [NSApp endSheet: macroSheet returnCode: 0];

}


- (IBAction)deleteAllSteps:(id)sender
{
    NSMutableArray *pr;
    if(!currMacro) currMacro = [[NSMutableDictionary alloc] init];
    if((pr = [currMacro objectForKey: @"program"]) == nil)
    {
        pr = [[NSMutableArray alloc] init];
        [currMacro setObject: pr forKey: @"program"];
    }
    else
        [pr removeAllObjects];
    [macroView reloadData];
}

- (IBAction)deleteStep:(id)sender
{
    int n;

    if((n = [macroView selectedRow]) >= 0 && [currMacro objectForKey: @"program"] != nil)
    {
        [[currMacro objectForKey: @"program"] removeObjectAtIndex: n];
    }
    [macroView reloadData];
}

- (IBAction)loadMacro:(id)sender
{
    NSMutableArray *revProg;
    int n;
    if([macroMenu numberOfItems] == 0) return;
    //need to do memory mgmt here
    //[self zeroEditor: self];
    [currMacro removeAllObjects];
    revProg = [NSMutableArray array];
    [currMacro addEntriesFromDictionary: [myOverLord autoSetForName: [macroMenu titleOfSelectedItem]]];
    //[[myOverLord autoSets] objectForKey: [macroMenu titleOfSelectedItem]]];
    [revProg setArray: [currMacro objectForKey: @"program"]];
    n = [revProg count];
    [currMacro setObject: revProg forKey: @"program"];
    [nameView setStringValue: [macroMenu titleOfSelectedItem]];
    [startMenu selectItemWithTitle: [currMacro objectForKey: @"start"]];
    [globalScope setIntValue: [[currMacro objectForKey: @"global"] intValue]];
    if([currMacro objectForKey: @"sort"] != nil)
        [sortSwitch setState: NSOnState];
    else
        [sortSwitch setState: NSOffState];
    [macroView reloadData];
}

- (IBAction)moveDown:(id)sender
{
    int n, m;
    NSMutableArray *where;
    n=0;
    if ((where = [currMacro objectForKey: @"program"]) != nil)
    {
        m = [where count];
        n = [macroView selectedRow];
        if(n < m - 1)
        {	
            [where exchangeObjectAtIndex: n
                withObjectAtIndex: n+1];

        }
    }
    [macroView reloadData];
    [macroView selectRow: n + 1 byExtendingSelection: NO];
}

- (IBAction)moveUp:(id)sender
{
    int n;
    NSMutableArray *where;
    if((n = [macroView selectedRow]) >= 0 && 
        (where = [currMacro objectForKey: @"program"]) != nil)
    {
        if(n > 0)
        {	
            [where exchangeObjectAtIndex: n
                withObjectAtIndex: n-1];
        }
    }
    [macroView reloadData];
    [macroView selectRow: n - 1  byExtendingSelection: NO];
}
- (IBAction) deleteMacro: (id) sender
{
    if([macroMenu numberOfItems] == 0) return;
    if(NSYESNOQUESTION(@"Delete auto set?") == NO) return;
    //need to do memory mgmt here
    [myOverLord removeAutoSetForName: [macroMenu titleOfSelectedItem]];
    [myOverLord rebuildAutoSetMenu];
    [self zeroEditor: nil];
}
- (IBAction)runMacro:(id)sender
{
    
    
    [macroSheet orderOut: sender];
    [NSApp endSheet: macroSheet returnCode: 1];

}

-(void) rebuildMenus
{
    int i, n, m;
    NSMutableDictionary *macros;
    NSArray *macroNames;
    
    macros = [myOverLord autoSets];
    macroNames = [myOverLord allAutoSetNames];
    //build menus
    
    //start menu
    n = [startMenu numberOfItems];
    if(n >= 2)
        for(i = 2; i < n; i++)
        {
            [startMenu removeItemAtIndex: 2];
        }
            
    m = [macroNames count];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [startMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
        //if(m>0)[startMenu selectItemAtIndex: 0];
    
    
    //macro names
    [macroMenu removeAllItems];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [macroMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
            if(m>0) [macroMenu selectItemAtIndex: 0];
    
    
    //set Objects
    [setObjectMenu removeAllItems];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [setObjectMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
            if(m>0) [setObjectMenu selectItemAtIndex: 0];
    //set autosets
    [localAutosetMenu removeAllItems];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [localAutosetMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
            if(m>0) [localAutosetMenu selectItemAtIndex: 0];
    //column names
    [columnMenu removeAllItems];
    m = [[myOverLord columns] count];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [columnMenu addItemWithTitle: [[myOverLord columns] objectAtIndex: i]];
        }
            if(m>0) [columnMenu selectItemAtIndex: 0];
    
    
    [setOpMenu  selectItemAtIndex: 0];
    [selectTypeMenu  selectItemAtIndex: 0];
    [selectModeMenu  selectItemAtIndex: 0];    
}
-(IBAction) zeroEditor: (id) sender
{
    int i, n, m;
    NSMutableDictionary *macros;
    NSArray *macroNames;
    
    macros = [myOverLord autoSets];
    macroNames = [myOverLord allAutoSetNames];
    currMacro = [[NSMutableDictionary alloc] init];
    [nameView setStringValue: @""];
    [selectStringView setStringValue: @""];
    [fpOption setState: NSOffState];
    [regexOption setState: NSOffState];
    
    
    //build menus
    
    //start menu
    n = [startMenu numberOfItems];
    if(n >= 2)
        for(i = 2; i < n; i++)
        {
            [startMenu removeItemAtIndex: 2];
        }
    
    m = [macroNames count];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [startMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
    if(m>0)[startMenu selectItemAtIndex: 0];

    
    //macro names
    [macroMenu removeAllItems];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [macroMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
    if(m>0) [macroMenu selectItemAtIndex: 0];
    
    //code sets
    [codeSetSelMenu selectItemAtIndex: 0];
    [codeSetExact setState: NSOnState];
    [codeSetMenu removeAllItems];
    [codeSetMenu addItemsWithTitles: [[myOverLord getGWorkBench: nil] allCodeSetNames]];
    if([codeSetMenu numberOfItems] >= 1) [codeSetMenu selectItemAtIndex: 0];
    //set Objects
    [setObjectMenu removeAllItems];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [setObjectMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
    if(m>0) [setObjectMenu selectItemAtIndex: 0];
    //set autosets
    [localAutosetMenu removeAllItems];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [localAutosetMenu addItemWithTitle: [macroNames objectAtIndex: i]];
        }
        if(m>0) [localAutosetMenu selectItemAtIndex: 0];
    //column names
    [columnMenu removeAllItems];
    m = [[myOverLord columns] count];
    if(m > 0)
        for(i = 0; i < m; i++)
        {
            [columnMenu addItemWithTitle: [[myOverLord columns] objectAtIndex: i]];
        }
    if(m>0) [columnMenu selectItemAtIndex: 0];
    

    [setOpMenu  selectItemAtIndex: 0];
    [selectTypeMenu  selectItemAtIndex: 0];
    [selectModeMenu  selectItemAtIndex: 0];
    [macroView reloadData];
    
    
}
-(void) saveMacro: (id) sender
{
    if([[nameView stringValue] isEqualToString: @""] == YES )
    {
        NSWARNING(@"You need to give the auto set a unique name");
        return;
    }
    if([myOverLord validAutoSetName: [nameView stringValue]] == NO)
    {
        if( NSYESNOQUESTION(@"Write on top of existing auto set with that name?") == YES)
        {
            [myOverLord removeAutoSetForName:  [nameView stringValue]];
        }
        else
            return;
    }
    [currMacro setObject: [[[startMenu titleOfSelectedItem] copy] autorelease]
                  forKey: @"start"];
    [currMacro setObject: [NSNumber numberWithInt: [globalScope intValue]] forKey: @"global"];
    if([sortSwitch state] == NSOnState)
        [currMacro setObject: [myOverLord sortStackCopy] forKey: @"sort"];
    [myOverLord addAutoSet: [[currMacro copy] autorelease] withName: [nameView stringValue]];
    [self rebuildMenus];
    [macroMenu selectItemWithTitle: [nameView stringValue]];
    if([startMenu indexOfItemWithTitle: [currMacro objectForKey: @"start"]] >= 0)
        [startMenu selectItemWithTitle: [currMacro objectForKey: @"start"]];
    [myOverLord rebuildAutoSetMenu];
    

}
-(void) macroEditorDidEnd: (NSWindow *) mySheet returnCode: (int) returnCode contextInfo: (void *) contextInfo
{
    if(returnCode == 0) return;
    //put in runningstuff
    [myOverLord doAutoSet: [macroMenu selectedItem]];
    [myOverLord rebuildAutoSetMenu];


}
-(void) runMacroEditor
{
    NSWindow *who;
    
    [self zeroEditor: self];
    if([gPrefBoss detachedSheetValue])
        who = nil;
    else
        who = [myOverLord myWindow];
    
     [NSApp beginSheet: macroSheet
        modalForWindow: who
	modalDelegate: self
	didEndSelector: @selector(macroEditorDidEnd:returnCode:contextInfo:)
	contextInfo: nil];

}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
    if(currMacro)
        return [[currMacro objectForKey: @"program"] count];
    else
        return 0;
}

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
    NSArray *arr;
    NSMutableDictionary *md;
    if(currMacro)
    {
        arr = [currMacro objectForKey: @"program"];
        md = [arr objectAtIndex: rowIndex];
        if([[md objectForKey: @"stepType"] isEqualToString: @"sel"] == YES)
        {
            NSMutableString *flagStr = [NSMutableString string];
            int ff;
            ff = 0;
            if([[md objectForKey: @"mode"] intValue] == SELECTCODESET)
            {
                NSString *csItem;
                if([md objectForKey: @"type"] == nil)
                    [md setObject: [NSNumber numberWithInt: SELECT] forKey: @"type"];
                if([md objectForKey: @"exact"] == nil)
                    [md setObject: [NSNumber numberWithBool: YES] forKey: @"exact"];
                switch([[md objectForKey: @"type"] intValue])
                {
                    case SELECT:
                        csItem = [NSString stringWithFormat: @"%d %@: %@", rowIndex+1, @"Code set", 
                            [md objectForKey: @"name"]];
                        break;
                    case SELECTFEWER:
                        csItem = [NSString stringWithFormat: @"%d %@: %@", rowIndex+1, @"-Code set", 
                            [md objectForKey: @"name"]];
                        break;
                    case SELECTADDITIONAL:
                        csItem = [NSString stringWithFormat: @"%d %@: %@", rowIndex+1, @"+Code set", 
                            [md objectForKey: @"name"]];
                        break;
                }
                if([[md objectForKey: @"exact"] boolValue] == YES)
                    return [NSString stringWithFormat: @"%@ (x)", csItem];
                return csItem;
            }
            if([[md objectForKey: @"mode"] intValue] == SELECTREVERSE)
            {
                return [NSString stringWithFormat: @"%d %@", rowIndex+1, @"Select reverse"];
            }
            [flagStr setString: @"("];
            if([[md objectForKey: @"float"] intValue] == 1)
            {
                ff++;
                [flagStr appendString: @"float"];
            }
            if([[md objectForKey: @"regex"] intValue] == 1)
            {
                if(ff) [flagStr appendString: @", "];
                [flagStr appendString: @"regex"];
                ff++;
            }
            if(ff)
                [flagStr appendString: @")"];
            else
                [flagStr setString: @""];
            
            return [NSString stringWithFormat: @"%d %@: \"%@\" in %@ %@", rowIndex + 1,
                [[selectModeMenu itemAtIndex: [selectModeMenu indexOfItemWithTag: [[md objectForKey: @"mode"] intValue]]]  title],
                [md objectForKey: @"searchValue"],
                [md objectForKey: @"col"],
                flagStr];
        }
        else if ([[md objectForKey: @"stepType"] isEqualToString: @"set"] == YES)
        {
            return [NSString stringWithFormat: @"%d %@: \"%@\" with %@", rowIndex + 1,
                [md objectForKey: @"stepType"],
                [[setOpMenu itemAtIndex: [setOpMenu indexOfItemWithTag: [[md objectForKey: @"op"] intValue]]] title],
                [md objectForKey: @"obj"]
                ];
        }
        else if([[md objectForKey: @"stepType"] isEqualToString: @"autoset"] == YES)
        {
            return [NSString stringWithFormat: @"%d %@: %@", rowIndex + 1,
                [md objectForKey: @"stepType"],
                [md objectForKey: @"name"]
                ];
            
        }
    }
    return @"";

}
@end