-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiTermProfileWindowController.m
1393 lines (1178 loc) · 45.1 KB
/
iTermProfileWindowController.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
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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** iTermProfileWindowController.h
**
** Copyright (c) 2002, 2003, 2004
**
** Author: Ujwal S. Setlur
**
** Project: iTerm
**
** Description: window controller for profile editors.
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import <iTerm/iTermController.h>
#import <iTerm/iTermKeyBindingMgr.h>
#import <iTerm/iTermDisplayProfileMgr.h>
#import <iTerm/iTermTerminalProfileMgr.h>
#import <iTerm/iTermProfileWindowController.h>
@implementation iTermProfileWindowController
static NSArray *profileCategories;
static BOOL addingKBEntry;
+ (iTermProfileWindowController*)sharedInstance
{
static iTermProfileWindowController* shared = nil;
if (!shared)
{
shared = [[self alloc] init];
}
profileCategories = [[NSArray arrayWithObjects:[NSNumber numberWithInt: 0],[NSNumber numberWithInt: 1],[NSNumber numberWithInt: 2],nil] retain];
return shared;
}
- (id) init
{
NSMutableDictionary *profilesDictionary, *keybindingProfiles, *displayProfiles, *terminalProfiles;
NSString *plistFile;
if ((self = [super init]) == nil)
return nil;
_prefs = [NSUserDefaults standardUserDefaults];
// load saved profiles or default if we don't have any
keybindingProfiles = [_prefs objectForKey: @"KeyBindings"];
displayProfiles = [_prefs objectForKey: @"Displays"];
terminalProfiles = [_prefs objectForKey: @"Terminals"];
// if we got no profiles, load from our embedded plist
plistFile = [[NSBundle bundleForClass: [self class]] pathForResource:@"Profiles" ofType:@"plist"];
profilesDictionary = [NSDictionary dictionaryWithContentsOfFile: plistFile];
if([keybindingProfiles count] == 0)
keybindingProfiles = [profilesDictionary objectForKey: @"KeyBindings"];
if([displayProfiles count] == 0)
displayProfiles = [profilesDictionary objectForKey: @"Displays"];
if([terminalProfiles count] == 0)
terminalProfiles = [profilesDictionary objectForKey: @"Terminals"];
[[iTermKeyBindingMgr singleInstance] setProfiles: keybindingProfiles];
[[iTermDisplayProfileMgr singleInstance] setProfiles: displayProfiles];
[[iTermTerminalProfileMgr singleInstance] setProfiles: terminalProfiles];
selectedProfile = nil;
return self;
}
- (IBAction) showProfilesWindow: (id) sender
{
// load nib if we haven't already
if([self window] == nil)
[self initWithWindowNibName: @"ProfilesWindow"];
[[self window] setDelegate: self]; // also forces window to load
[self tableViewSelectionDidChange: nil];
// add list of encodings
NSEnumerator *anEnumerator;
NSNumber *anEncoding;
[terminalEncoding removeAllItems];
anEnumerator = [[[iTermController sharedInstance] sortedEncodingList] objectEnumerator];
while((anEncoding = [anEnumerator nextObject]) != NULL)
{
[terminalEncoding addItemWithTitle: [NSString localizedNameOfStringEncoding: [anEncoding unsignedIntValue]]];
[[terminalEncoding lastItem] setTag: [anEncoding unsignedIntValue]];
}
[profileOutline deselectAll:nil];
[deleteButton setEnabled:NO];
[duplicateButton setEnabled:NO];
[kbEntryTableView setDoubleAction:@selector(kbEntryEdit:)];
[self showWindow: self];
}
- (IBAction)closeWindow:(id)sender
{
[[self window] close];
}
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
// Post a notification
[[NSNotificationCenter defaultCenter] postNotificationName: @"nonTerminalWindowBecameKey" object: nil userInfo: nil];
}
- (void)windowWillClose:(NSNotification *)aNotification
{
id prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject: [[iTermKeyBindingMgr singleInstance] profiles] forKey: @"KeyBindings"];
[prefs setObject: [[iTermDisplayProfileMgr singleInstance] profiles] forKey: @"Displays"];
[prefs setObject: [[iTermTerminalProfileMgr singleInstance] profiles] forKey: @"Terminals"];
[prefs synchronize];
[[NSColorPanel sharedColorPanel] close];
[[NSFontPanel sharedFontPanel] close];
}
// Profile editing
- (IBAction) profileAdd: (id) sender
{
// Check if duplicate button is hit, and there is a profile chosen
if ([sender tag] == 1 && selectedProfile == nil) {
return;
}
[NSApp beginSheet: addProfile
modalForWindow: [self window]
modalDelegate: self
didEndSelector: @selector(_addProfileSheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
// duplicate button?
if ([sender tag]) {
[profileName setStringValue: [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"%@ copy",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles"),
selectedProfile]];
[addProfileCategory selectItemAtIndex: [profileTabView indexOfTabViewItem:[profileTabView selectedTabViewItem]]];
[addProfileCategory setEnabled: NO];
}
else {
[profileName setStringValue: NSLocalizedStringFromTableInBundle(@"Untitled",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles")];
[addProfileCategory setEnabled: YES];
}
}
- (IBAction) profileDelete: (id) sender
{
NSBeginAlertSheet(NSLocalizedStringFromTableInBundle(@"Delete Profile",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles"),
NSLocalizedStringFromTableInBundle(@"Delete",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles"),
NSLocalizedStringFromTableInBundle(@"Cancel",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles"),
nil, [self window], self,
@selector(_deleteProfileSheetDidEnd:returnCode:contextInfo:),
NULL, NULL,
[NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"Are you sure that you want to delete %@? There is no way to undo this action.",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles"),
selectedProfile]);
}
- (IBAction) profileAddConfirm: (id) sender
{
//NSLog(@"%s", __PRETTY_FUNCTION__);
id profileMgr;
int categoryChosen = [addProfileCategory indexOfSelectedItem];
if(categoryChosen == KEYBOARD_PROFILE_TAB)
{
profileMgr = [iTermKeyBindingMgr singleInstance];
}
else if(categoryChosen == TERMINAL_PROFILE_TAB)
{
profileMgr = [iTermTerminalProfileMgr singleInstance];
}
else if(categoryChosen == DISPLAY_PROFILE_TAB)
{
profileMgr = [iTermDisplayProfileMgr singleInstance];
}
else
return;
// make sure this profile does not already exist
if([[profileName stringValue] length] <= 0 || [[profileMgr profiles] objectForKey: [profileName stringValue]] != nil)
{
NSBeep();
// find a non-duplicated name
NSString *aString = [NSString stringWithFormat:@"%@ new", [profileName stringValue]];
int i = 1;
for(; [[profileMgr profiles] objectForKey: aString] != nil; i++)
aString = [NSString stringWithFormat:@"%@ new %d", [profileName stringValue], i];
[profileName setStringValue: aString];
}
[NSApp endSheet:addProfile returnCode:NSOKButton];
}
- (IBAction) profileAddCancel: (id) sender
{
//NSLog(@"%s", __PRETTY_FUNCTION__);
[NSApp endSheet:addProfile returnCode:NSCancelButton];
}
- (IBAction) profileDuplicate: (id) sender
{
int selectedTabViewItem;
id profileMgr;
selectedTabViewItem = [profileTabView indexOfTabViewItem: [profileTabView selectedTabViewItem]];
if(selectedTabViewItem == KEYBOARD_PROFILE_TAB)
{
profileMgr = [iTermKeyBindingMgr singleInstance];
}
else if(selectedTabViewItem == TERMINAL_PROFILE_TAB)
{
profileMgr = [iTermTerminalProfileMgr singleInstance];
}
else if(selectedTabViewItem == DISPLAY_PROFILE_TAB)
{
profileMgr = [iTermDisplayProfileMgr singleInstance];
}
else
return;
// find a non-duplicated name
NSString *aString = [NSString stringWithFormat:@"%@ copy", selectedProfile];
int i = 1;
for(; [[profileMgr profiles] objectForKey: aString] != nil; i++)
aString = [NSString stringWithFormat:@"%@ copy %d", selectedProfile, i];
[profileMgr addProfileWithName: aString
copyProfile: selectedProfile];
[profileOutline reloadData];
[self selectProfile:aString withInCategory: selectedTabViewItem];
}
// Keybinding profile UI
- (void) kbOptionKeyChanged: (id) sender
{
[[iTermKeyBindingMgr singleInstance] setOptionKey: [kbOptionKey selectedColumn]
forProfile: selectedProfile];
}
- (void) kbProfileChangedTo: (NSString *) selectedKBProfile
{
//NSLog(@"%s; %@", __PRETTY_FUNCTION__, sender);
[deleteButton setEnabled: ![[iTermKeyBindingMgr singleInstance] isGlobalProfile: selectedKBProfile]];
[duplicateButton setEnabled:YES];
[kbOptionKey selectCellAtRow:0 column:[[iTermKeyBindingMgr singleInstance] optionKeyForProfile: selectedKBProfile]];
[kbEntryTableView reloadData];
}
- (IBAction) kbEntryAdd: (id) sender
{
int i;
addingKBEntry = YES;
//NSLog(@"%s", __PRETTY_FUNCTION__);
[kbEntryKeyCode setStringValue: @""];
[kbEntryText setStringValue: @""];
[kbEntryKeyModifierOption setState: NSOffState];
[kbEntryKeyModifierControl setState: NSOffState];
[kbEntryKeyModifierShift setState: NSOffState];
[kbEntryKeyModifierCommand setState: NSOffState];
[kbEntryKeyModifierOption setEnabled: YES];
[kbEntryKeyModifierControl setEnabled: YES];
[kbEntryKeyModifierShift setEnabled: YES];
[kbEntryKeyModifierCommand setEnabled: YES];
if ([kbEntryKeyCode respondsToSelector: @selector(setHidden:)] == YES)
{
[kbEntryKeyCode setHidden: YES];
[kbEntryText setHidden: YES];
}
[kbEntryKey selectItemAtIndex: 0];
[kbEntryKey setTarget: self];
[kbEntryKey setAction: @selector(kbEntrySelectorChanged:)];
[kbEntryAction selectItemAtIndex: 0];
[kbEntryAction setTarget: self];
[kbEntryAction setAction: @selector(kbEntrySelectorChanged:)];
if([[iTermKeyBindingMgr singleInstance] isGlobalProfile: selectedProfile])
{
for (i = KEY_ACTION_NEXT_SESSION; i < KEY_ACTION_ESCAPE_SEQUENCE; i++)
{
[[kbEntryAction itemAtIndex: i] setEnabled: YES];
[[kbEntryAction itemAtIndex: i] setAction: @selector(kbEntrySelectorChanged:)];
[[kbEntryAction itemAtIndex: i] setTarget: self];
}
}
else
{
for (i = KEY_ACTION_NEXT_SESSION; i < KEY_ACTION_ESCAPE_SEQUENCE; i++)
{
[[kbEntryAction itemAtIndex: i] setEnabled: NO];
[[kbEntryAction itemAtIndex: i] setAction: nil];
}
[kbEntryAction selectItemAtIndex: KEY_ACTION_ESCAPE_SEQUENCE];
}
[kbEntryHighPriority setState: NSOffState];
[self kbEntrySelectorChanged: kbEntryAction];
[NSApp beginSheet: addKBEntry
modalForWindow: [self window]
modalDelegate: self
didEndSelector: @selector(_addKBEntrySheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
- (IBAction) kbEntryEdit: (id) sender
{
int index;
int selectedRow = [kbEntryTableView selectedRow];
NSMutableDictionary *keyMappings;
NSArray *allKeys;
NSString *theKeyCombination;
unsigned int keyCode, keyModifiers;
int action;
NSString *auxText;
BOOL priority;
//NSLog(@"%s: %@", __PRETTY_FUNCTION__, profile);
keyMappings = [[[[iTermKeyBindingMgr singleInstance] profiles] objectForKey: selectedProfile] objectForKey: @"Key Mappings"];
allKeys = [[keyMappings allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
if(selectedRow >= 0 && selectedRow < [allKeys count])
{
theKeyCombination = [allKeys objectAtIndex: selectedRow];
action = [[[keyMappings objectForKey: [allKeys objectAtIndex: selectedRow]] objectForKey: @"Action"] intValue];
auxText = [[keyMappings objectForKey: [allKeys objectAtIndex: selectedRow]] objectForKey: @"Text"];
priority = [[keyMappings objectForKey: [allKeys objectAtIndex: selectedRow]] objectForKey: @"Priority"] ? [[[keyMappings objectForKey: [allKeys objectAtIndex: selectedRow]] objectForKey: @"Priority"] boolValue] : NO;
}
else
return;
addingKBEntry = NO;
sscanf([theKeyCombination UTF8String], "%x-%x", &keyCode, &keyModifiers);
[kbEntryKey setTarget: self];
[kbEntryKey setAction: @selector(kbEntrySelectorChanged:)];
[kbEntryAction setTarget: self];
[kbEntryAction setAction: @selector(kbEntrySelectorChanged:)];
switch (keyCode)
{
case NSDownArrowFunctionKey:
index = KEY_CURSOR_DOWN;
break;
case NSLeftArrowFunctionKey:
index = KEY_CURSOR_LEFT;
break;
case NSRightArrowFunctionKey:
index = KEY_CURSOR_RIGHT;
break;
case NSUpArrowFunctionKey:
index = KEY_CURSOR_UP;
break;
case NSDeleteFunctionKey:
index = KEY_DEL;
break;
case 0x7f:
index = KEY_DELETE;
break;
case NSEndFunctionKey:
index = KEY_END;
break;
case NSF1FunctionKey:
case NSF2FunctionKey:
case NSF3FunctionKey:
case NSF4FunctionKey:
case NSF5FunctionKey:
case NSF6FunctionKey:
case NSF7FunctionKey:
case NSF8FunctionKey:
case NSF9FunctionKey:
case NSF10FunctionKey:
case NSF11FunctionKey:
case NSF12FunctionKey:
case NSF13FunctionKey:
case NSF14FunctionKey:
case NSF15FunctionKey:
case NSF16FunctionKey:
case NSF17FunctionKey:
case NSF18FunctionKey:
case NSF19FunctionKey:
case NSF20FunctionKey:
index = KEY_F1 + keyCode - NSF1FunctionKey;
break;
case NSHelpFunctionKey:
index = KEY_HELP;
break;
case NSHomeFunctionKey:
index = KEY_HOME;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (keyModifiers & NSNumericPadKeyMask)
index = KEY_NUMERIC_0 + keyCode - '0';
else {
index = KEY_HEX_CODE;
[kbEntryKeyCode setStringValue: [NSString stringWithFormat:@"0x%x", keyCode]];
}
break;
case '=':
index = KEY_NUMERIC_EQUAL;
break;
case '/':
index = KEY_NUMERIC_DIVIDE;
break;
case '*':
index = KEY_NUMERIC_MULTIPLY;
break;
case '-':
index = KEY_NUMERIC_MINUS;
break;
case '+':
index = KEY_NUMERIC_PLUS;
break;
case '.':
index = KEY_NUMERIC_PERIOD;
break;
case NSClearLineFunctionKey:
index = KEY_NUMLOCK;
break;
case NSPageDownFunctionKey:
index = KEY_PAGE_DOWN;
break;
case NSPageUpFunctionKey:
index = KEY_PAGE_UP;
break;
case 0x3: // 'enter' on numeric key pad
index = KEY_NUMERIC_ENTER;
break;
default:
index = KEY_HEX_CODE;
[kbEntryKeyCode setStringValue: [NSString stringWithFormat:@"0x%x", keyCode]];
break;
}
[kbEntryKey selectItemAtIndex:index];
[self kbEntrySelectorChanged: kbEntryKey];
[kbEntryKeyModifierCommand setState: (keyModifiers & NSCommandKeyMask)];
[kbEntryKeyModifierOption setState: (keyModifiers & NSAlternateKeyMask)];
[kbEntryKeyModifierControl setState: (keyModifiers & NSControlKeyMask)];
[kbEntryKeyModifierShift setState: (keyModifiers & NSShiftKeyMask)];
//NSLog(@"%s", __PRETTY_FUNCTION__);
[kbEntryKeyModifierOption setEnabled: YES];
[kbEntryKeyModifierControl setEnabled: YES];
[kbEntryKeyModifierShift setEnabled: YES];
[kbEntryKeyModifierCommand setEnabled: YES];
if (action == KEY_ACTION_HEX_CODE || action == KEY_ACTION_ESCAPE_SEQUENCE || action == KEY_ACTION_TEXT)
{
[kbEntryText setStringValue: auxText];
}
else
{
[kbEntryText setStringValue: @""];
}
[kbEntryAction selectItemAtIndex: action];
[self kbEntrySelectorChanged: kbEntryAction];
int i;
if([[iTermKeyBindingMgr singleInstance] isGlobalProfile: selectedProfile])
{
for (i = KEY_ACTION_NEXT_SESSION; i < KEY_ACTION_ESCAPE_SEQUENCE; i++)
{
[[kbEntryAction itemAtIndex: i] setEnabled: YES];
[[kbEntryAction itemAtIndex: i] setAction: @selector(kbEntrySelectorChanged:)];
[[kbEntryAction itemAtIndex: i] setTarget: self];
}
}
else
{
for (i = KEY_ACTION_NEXT_SESSION; i < KEY_ACTION_ESCAPE_SEQUENCE; i++)
{
[[kbEntryAction itemAtIndex: i] setEnabled: NO];
[[kbEntryAction itemAtIndex: i] setAction: nil];
}
}
[kbEntryHighPriority setState: priority ? NSOnState : NSOffState];
[self kbEntrySelectorChanged: kbEntryAction];
[NSApp beginSheet: addKBEntry
modalForWindow: [self window]
modalDelegate: self
didEndSelector: @selector(_addKBEntrySheetDidEnd:returnCode:contextInfo:)
contextInfo: nil];
}
- (IBAction) kbEntryAddConfirm: (id) sender
{
[NSApp endSheet:addKBEntry returnCode:NSOKButton];
}
- (IBAction) kbEntryAddCancel: (id) sender
{
[NSApp endSheet:addKBEntry returnCode:NSCancelButton];
}
- (IBAction) kbEntryDelete: (id) sender
{
//NSLog(@"%s", __PRETTY_FUNCTION__);
if([kbEntryTableView selectedRow] >= 0)
{
[[iTermKeyBindingMgr singleInstance] deleteEntryAtIndex: [kbEntryTableView selectedRow]
inProfile: selectedProfile];
[kbEntryTableView reloadData];
}
else
NSBeep();
}
- (IBAction) kbEntrySelectorChanged: (id) sender
{
if(sender == kbEntryKey)
{
if([kbEntryKey indexOfSelectedItem] == KEY_HEX_CODE && [kbEntryKeyCode respondsToSelector: @selector(setHidden:)] == YES)
{
[kbEntryKeyCode setHidden: NO];
}
else
{
[kbEntryKeyCode setStringValue: @""];
if ([kbEntryKeyCode respondsToSelector: @selector(setHidden:)] == YES)
[kbEntryKeyCode setHidden: YES];
}
}
else if(sender == kbEntryAction)
{
if([kbEntryAction indexOfSelectedItem] == KEY_ACTION_HEX_CODE ||
[kbEntryAction indexOfSelectedItem] == KEY_ACTION_ESCAPE_SEQUENCE ||
[kbEntryAction indexOfSelectedItem] == KEY_ACTION_TEXT)
{
[kbEntryText setHidden: NO];
[kbEntryHint setHidden: NO];
switch ([kbEntryAction indexOfSelectedItem]) {
case KEY_ACTION_HEX_CODE:
[kbEntryHint setStringValue: NSLocalizedStringFromTableInBundle(@"eg. 7F for backward delete.",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles")];
break;
case KEY_ACTION_ESCAPE_SEQUENCE:
[kbEntryHint setStringValue: NSLocalizedStringFromTableInBundle(@"eg. [OC for ESC [OC.",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles")];
break;
case KEY_ACTION_TEXT:
[kbEntryHint setStringValue: NSLocalizedStringFromTableInBundle(@"use \\n for new-line, etc",@"iTerm", [NSBundle bundleForClass: [self class]], @"Profiles")];
break;
}
}
else
{
[kbEntryText setStringValue: @""];
[kbEntryText setHidden: YES];
[kbEntryHint setHidden: YES];
}
}
}
// NSTableView data source
- (int) numberOfRowsInTableView: (NSTableView *)aTableView
{
if([[[iTermKeyBindingMgr singleInstance] profiles] count] == 0 || selectedProfile == nil)
return (0);
return([[iTermKeyBindingMgr singleInstance] numberOfEntriesInProfile: selectedProfile]);
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
//NSLog(@"%s: %@", __PRETTY_FUNCTION__, aTableView);
if([[aTableColumn identifier] intValue] == 0)
{
return ([[iTermKeyBindingMgr singleInstance] keyCombinationAtIndex: rowIndex
inProfile: selectedProfile]);
}
else
{
return ([[iTermKeyBindingMgr singleInstance] actionForKeyCombinationAtIndex: rowIndex
inProfile: selectedProfile]);
}
}
// NSTableView delegate
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
//NSLog(@"%s", __PRETTY_FUNCTION__);
if([kbEntryTableView selectedRow] < 0)
[kbEntryDeleteButton setEnabled: NO];
else
[kbEntryDeleteButton setEnabled: YES];
}
// Display profile UI
- (void) displayProfileChangedTo: (NSString *) theProfile
{
NSString *backgroundImagePath;
// load the colors
[displayFGColor setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_FOREGROUND_COLOR
forProfile: theProfile]];
[displayBGColor setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_BACKGROUND_COLOR
forProfile: theProfile]];
[displayBoldColor setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_BOLD_COLOR
forProfile: theProfile]];
[displaySelectionColor setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_SELECTION_COLOR
forProfile: theProfile]];
[displaySelectedTextColor setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_SELECTED_TEXT_COLOR
forProfile: theProfile]];
[displayCursorColor setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_CURSOR_COLOR
forProfile: theProfile]];
[displayCursorTextColor setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_CURSOR_TEXT_COLOR
forProfile: theProfile]];
[displayAnsi0Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_0_COLOR
forProfile: theProfile]];
[displayAnsi1Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_1_COLOR
forProfile: theProfile]];
[displayAnsi2Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_2_COLOR
forProfile: theProfile]];
[displayAnsi3Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_3_COLOR
forProfile: theProfile]];
[displayAnsi4Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_4_COLOR
forProfile: theProfile]];
[displayAnsi5Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_5_COLOR
forProfile: theProfile]];
[displayAnsi6Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_6_COLOR
forProfile: theProfile]];
[displayAnsi7Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_7_COLOR
forProfile: theProfile]];
[displayAnsi8Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_8_COLOR
forProfile: theProfile]];
[displayAnsi9Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_9_COLOR
forProfile: theProfile]];
[displayAnsi10Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_10_COLOR
forProfile: theProfile]];
[displayAnsi11Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_11_COLOR
forProfile: theProfile]];
[displayAnsi12Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_12_COLOR
forProfile: theProfile]];
[displayAnsi13Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_13_COLOR
forProfile: theProfile]];
[displayAnsi14Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_14_COLOR
forProfile: theProfile]];
[displayAnsi15Color setColor: [[iTermDisplayProfileMgr singleInstance] color: TYPE_ANSI_15_COLOR
forProfile: theProfile]];
// background image
backgroundImagePath = [[iTermDisplayProfileMgr singleInstance] backgroundImageForProfile: theProfile];
if([backgroundImagePath length] > 0)
{
NSImage *anImage = [[NSImage alloc] initWithContentsOfFile: backgroundImagePath];
if(anImage != nil)
{
[displayBackgroundImage setImage: anImage];
[anImage release];
[displayUseBackgroundImage setState: NSOnState];
}
else
{
[displayBackgroundImage setImage: nil];
[displayUseBackgroundImage setState: NSOffState];
}
}
else
{
[displayBackgroundImage setImage: nil];
[displayUseBackgroundImage setState: NSOffState];
}
// transparency
[displayTransparency setStringValue: [NSString stringWithFormat: @"%d",
(int)(100*[[iTermDisplayProfileMgr singleInstance] transparencyForProfile: theProfile])]];
// disable bold
[displayDisableBold setState: [[iTermDisplayProfileMgr singleInstance] disableBoldForProfile: theProfile]];
// fonts
[self _updateFontsDisplay];
// anti-alias
[displayAntiAlias setState: [[iTermDisplayProfileMgr singleInstance] windowAntiAliasForProfile: theProfile]];
// blur
[displayBlur setState: [[iTermDisplayProfileMgr singleInstance] windowBlurForProfile: theProfile]];
// window size
[displayColTextField setStringValue: [NSString stringWithFormat: @"%d",
[[iTermDisplayProfileMgr singleInstance] windowColumnsForProfile: theProfile]]];
[displayRowTextField setStringValue: [NSString stringWithFormat: @"%d",
[[iTermDisplayProfileMgr singleInstance] windowRowsForProfile: theProfile]]];
[deleteButton setEnabled: ![[iTermDisplayProfileMgr singleInstance] isDefaultProfile: theProfile]];
[duplicateButton setEnabled:YES];
}
- (IBAction) displaySetDisableBold: (id) sender
{
if(sender == displayDisableBold)
{
[[iTermDisplayProfileMgr singleInstance] setDisableBold: [sender state]
forProfile: selectedProfile];
}
}
- (IBAction) displaySetAntiAlias: (id) sender
{
if(sender == displayAntiAlias)
{
[[iTermDisplayProfileMgr singleInstance] setWindowAntiAlias: [sender state]
forProfile: selectedProfile];
}
}
- (IBAction) displaySetBlur: (id) sender
{
if(sender == displayBlur)
{
[[iTermDisplayProfileMgr singleInstance] setWindowBlur: [sender state]
forProfile: selectedProfile];
}
}
- (IBAction) displayBackgroundImage: (id) sender
{
if (sender == displayUseBackgroundImage)
{
if ([sender state] == NSOffState)
{
[displayBackgroundImage setImage: nil];
[[iTermDisplayProfileMgr singleInstance] setBackgroundImage: @"" forProfile: selectedProfile];
}
else
[self _chooseBackgroundImageForProfile: selectedProfile];
}
}
- (IBAction) displayChangeColor: (id) sender
{
int type;
type = [sender tag];
[[iTermDisplayProfileMgr singleInstance] setColor: [sender color]
forType: type
forProfile: selectedProfile];
// update fonts display
[self _updateFontsDisplay];
}
// sent by NSFontManager
- (void)changeFont:(id)fontManager
{
NSFont *aFont;
//NSLog(@"%s", __PRETTY_FUNCTION__);
if(changingNAFont)
{
aFont = [fontManager convertFont: [displayNAFontTextField font]];
[[iTermDisplayProfileMgr singleInstance] setWindowNAFont: aFont forProfile: selectedProfile];
}
else
{
aFont = [fontManager convertFont: [displayFontTextField font]];
[[iTermDisplayProfileMgr singleInstance] setWindowFont: aFont forProfile: selectedProfile];
}
[self _updateFontsDisplay];
}
- (IBAction) displaySelectFont: (id) sender
{
NSFont *aFont;
NSFontPanel *aFontPanel;
changingNAFont = NO;
aFont = [[iTermDisplayProfileMgr singleInstance] windowFontForProfile: selectedProfile];
// make sure we get the messages from the NSFontManager
[[self window] makeFirstResponder:self];
aFontPanel = [[NSFontManager sharedFontManager] fontPanel: YES];
[aFontPanel setAccessoryView: displayFontAccessoryView];
[[NSFontManager sharedFontManager] setSelectedFont:aFont isMultiple:NO];
[[NSFontManager sharedFontManager] orderFrontFontPanel:self];
}
- (IBAction) displaySelectNAFont: (id) sender
{
NSFont *aFont;
NSFontPanel *aFontPanel;
changingNAFont = YES;
aFont = [[iTermDisplayProfileMgr singleInstance] windowNAFontForProfile: selectedProfile];
// make sure we get the messages from the NSFontManager
[[self window] makeFirstResponder:self];
aFontPanel = [[NSFontManager sharedFontManager] fontPanel: YES];
[aFontPanel setAccessoryView: displayFontAccessoryView];
[[NSFontManager sharedFontManager] setSelectedFont:aFont isMultiple:NO];
[[NSFontManager sharedFontManager] orderFrontFontPanel:self];
}
- (IBAction) displaySetFontSpacing: (id) sender
{
if(sender == displayFontSpacingWidth)
[[iTermDisplayProfileMgr singleInstance] setWindowHorizontalCharSpacing: [sender floatValue]
forProfile: selectedProfile];
else if(sender == displayFontSpacingHeight)
[[iTermDisplayProfileMgr singleInstance] setWindowVerticalCharSpacing: [sender floatValue]
forProfile: selectedProfile];
}
// NSTextField delegate
- (void)controlTextDidChange:(NSNotification *)aNotification
{
int iVal;
float fVal;
id sender;
//NSLog(@"%s: %@", __PRETTY_FUNCTION__, [aNotification object]);
sender = [aNotification object];
iVal = [sender intValue];
fVal = [sender floatValue];
if(sender == displayColTextField)
[[iTermDisplayProfileMgr singleInstance] setWindowColumns: iVal forProfile: selectedProfile];
else if(sender == displayRowTextField)
[[iTermDisplayProfileMgr singleInstance] setWindowRows: iVal forProfile: selectedProfile];
else if(sender == displayTransparency)
[[iTermDisplayProfileMgr singleInstance] setTransparency: fVal/100 forProfile: selectedProfile];
else if(sender == terminalScrollback)
[[iTermTerminalProfileMgr singleInstance] setScrollbackLines: iVal forProfile: selectedProfile];
else if(sender == terminalIdleChar)
[[iTermTerminalProfileMgr singleInstance] setIdleChar: iVal forProfile: selectedProfile];
}
// Terminal profile UI
- (void) terminalProfileChangedTo: (NSString *)theProfile
{
//NSLog(@"Terminal Profile changed to: %@", theProfile);
[terminalType setStringValue: [[iTermTerminalProfileMgr singleInstance] typeForProfile: theProfile]];
[terminalEncoding setTitle: [NSString localizedNameOfStringEncoding:
[[iTermTerminalProfileMgr singleInstance] encodingForProfile: theProfile]]];
[terminalScrollback setStringValue: [NSString stringWithFormat: @"%d",
[[iTermTerminalProfileMgr singleInstance] scrollbackLinesForProfile: theProfile]]];
[terminalSilenceBell setState: [[iTermTerminalProfileMgr singleInstance] silenceBellForProfile: theProfile]];
[terminalShowBell setState: [[iTermTerminalProfileMgr singleInstance] showBellForProfile: theProfile]];
[terminalEnableGrowl setState: [[iTermTerminalProfileMgr singleInstance] growlForProfile: theProfile]];
[terminalBlink setState: [[iTermTerminalProfileMgr singleInstance] blinkCursorForProfile: theProfile]];
[terminalCloseOnSessionEnd setState: [[iTermTerminalProfileMgr singleInstance] closeOnSessionEndForProfile: theProfile]];
[terminalDoubleWidth setState: [[iTermTerminalProfileMgr singleInstance] doubleWidthForProfile: theProfile]];
[terminalSendIdleChar setState: [[iTermTerminalProfileMgr singleInstance] sendIdleCharForProfile: theProfile]];
[terminalIdleChar setStringValue: [NSString stringWithFormat: @"%d",
[[iTermTerminalProfileMgr singleInstance] idleCharForProfile: theProfile]]];
[xtermMouseReporting setState: [[iTermTerminalProfileMgr singleInstance] xtermMouseReportingForProfile: theProfile]];
[terminalAppendTitle setState: [[iTermTerminalProfileMgr singleInstance] appendTitleForProfile: theProfile]];
[terminalNoResizing setState: [[iTermTerminalProfileMgr singleInstance] noResizingForProfile: theProfile]];
[deleteButton setEnabled: ![[iTermTerminalProfileMgr singleInstance] isDefaultProfile: theProfile]];
[duplicateButton setEnabled: YES];
}
- (IBAction) terminalSetType: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setType: [sender stringValue]
forProfile: selectedProfile];
}
- (IBAction) terminalSetEncoding: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setEncoding: [[terminalEncoding selectedItem] tag]
forProfile: selectedProfile];
}
- (IBAction) terminalSetSilenceBell: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setSilenceBell: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetShowBell: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setShowBell: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetEnableGrowl: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setGrowl: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetBlink: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setBlinkCursor: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetCloseOnSessionEnd: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setCloseOnSessionEnd: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetDoubleWidth: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setDoubleWidth: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetSendIdleChar: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setSendIdleChar: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetXtermMouseReporting: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setXtermMouseReporting: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetAppendTitle: (id) sender
{
[[iTermTerminalProfileMgr singleInstance] setAppendTitle: [sender state]
forProfile: selectedProfile];
}
- (IBAction) terminalSetNoResizing: (id) sender
{