-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathtabContextMenu.ts
87 lines (80 loc) · 3.31 KB
/
tabContextMenu.ts
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
import { Inject, Injectable, Optional } from '@angular/core'
import { ConfigService, BaseTabComponent, TabContextMenuItemProvider, MenuItemOptions, ProfilesService, TranslateService } from 'tabby-core'
import { TerminalTabComponent } from './components/terminalTab.component'
import { TerminalService } from './services/terminal.service'
import { LocalProfile, UACService } from './api'
/** @hidden */
@Injectable()
export class NewTabContextMenu extends TabContextMenuItemProvider {
weight = 10
constructor (
public config: ConfigService,
private profilesService: ProfilesService,
private terminalService: TerminalService,
@Optional() @Inject(UACService) private uac: UACService|undefined,
private translate: TranslateService,
) {
super()
}
async getItems (tab: BaseTabComponent, tabHeader?: boolean): Promise<MenuItemOptions[]> {
const profiles = (await this.profilesService.getProfiles()).filter(x => x.type === 'local') as LocalProfile[]
const items: MenuItemOptions[] = [
{
label: this.translate.instant('New terminal'),
click: () => {
if (tab instanceof TerminalTabComponent) {
this.profilesService.openNewTabForProfile(tab.profile)
} else {
this.terminalService.openTab()
}
},
},
{
label: this.translate.instant('New with profile'),
submenu: profiles.map(profile => ({
label: profile.name,
click: async () => {
let workingDirectory = profile.options.cwd
if (!workingDirectory && tab instanceof TerminalTabComponent) {
workingDirectory = await tab.session?.getWorkingDirectory() ?? undefined
}
await this.terminalService.openTab(profile, workingDirectory)
},
})),
},
]
if (this.uac?.isAvailable) {
items.push({
label: this.translate.instant('New admin tab'),
submenu: profiles.map(profile => ({
label: profile.name,
click: () => {
this.profilesService.openNewTabForProfile({
...profile,
options: {
...profile.options,
runAsAdministrator: true,
},
})
},
})),
})
}
if (tab instanceof TerminalTabComponent && tabHeader && this.uac?.isAvailable) {
const terminalTab = tab
items.push({
label: this.translate.instant('Duplicate as administrator'),
click: () => {
this.profilesService.openNewTabForProfile({
...terminalTab.profile,
options: {
...terminalTab.profile.options,
runAsAdministrator: true,
},
})
},
})
}
return items
}
}