-
Notifications
You must be signed in to change notification settings - Fork 23
/
TerminalTabSwitching.m
70 lines (60 loc) · 2.38 KB
/
TerminalTabSwitching.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
#import "JRSwizzle.h"
@implementation NSWindowController (Mine)
- (void)updateTabListMenu
{
NSMenu* windowsMenu = [[NSApplication sharedApplication] windowsMenu];
for(NSMenuItem* menuItem in [windowsMenu itemArray])
{
if([menuItem action] == @selector(selectRepresentedTabViewItem:))
[windowsMenu removeItem:menuItem];
}
NSArray* tabViewItems = [[self valueForKey:@"tabView"] tabViewItems];
for(size_t tabIndex = 0; tabIndex < [tabViewItems count]; ++tabIndex)
{
NSString* keyEquivalent = (tabIndex < 10) ? [NSString stringWithFormat:@"%d", (tabIndex+1)%10] : @"";
NSTabViewItem* tabViewItem = [tabViewItems objectAtIndex:tabIndex];
NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:[tabViewItem label]
action:@selector(selectRepresentedTabViewItem:)
keyEquivalent:keyEquivalent];
[menuItem setRepresentedObject:tabViewItem];
[windowsMenu addItem:menuItem];
[menuItem release];
}
}
- (void)TerminalTabSwitching_windowDidBecomeMain:(id)fp8;
{
[self TerminalTabSwitching_windowDidBecomeMain:fp8];
[self updateTabListMenu];
}
- (void)tabViewDidChangeNumberOfTabViewItems:(NSTabView*)aTabView
{
[self updateTabListMenu];
}
- (void)TerminalTabSwitching_awakeFromNib;
{
[[NSApplication sharedApplication] removeWindowsItem:[self window]];
[[self window] setExcludedFromWindowsMenu:YES];
[self TerminalTabSwitching_awakeFromNib];
}
- (void)TerminalTabSwitching_newTab:(id)fp8;
{
[self TerminalTabSwitching_newTab:fp8];
[self updateTabListMenu];
}
- (void)selectRepresentedTabViewItem:(NSMenuItem*)item
{
NSTabViewItem* tabViewItem = [item representedObject];
[[tabViewItem tabView] selectTabViewItem:tabViewItem];
}
@end
@interface TerminalTabSwitching : NSObject
@end
@implementation TerminalTabSwitching
+ (void)load
{
[[[NSApplication sharedApplication] windowsMenu] addItem:[NSMenuItem separatorItem]];
[NSClassFromString(@"TTWindowController") jr_swizzleMethod:@selector(windowDidBecomeMain:) withMethod:@selector(TerminalTabSwitching_windowDidBecomeMain:) error:NULL];
[NSClassFromString(@"TTWindowController") jr_swizzleMethod:@selector(awakeFromNib) withMethod:@selector(TerminalTabSwitching_awakeFromNib) error:NULL];
[NSClassFromString(@"TTWindowController") jr_swizzleMethod:@selector(newTab:) withMethod:@selector(TerminalTabSwitching_newTab:) error:NULL];
}
@end