Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/parts/statusbar/statusbarActions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { localize, localize2 } from '../../../../nls.js';
7
import { IStatusbarService } from '../../../services/statusbar/browser/statusbar.js';
8
import { Action } from '../../../../base/common/actions.js';
9
import { Parts, IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js';
10
import { KeyCode } from '../../../../base/common/keyCodes.js';
11
import { KeybindingsRegistry, KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
12
import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js';
13
import { Action2, registerAction2 } from '../../../../platform/actions/common/actions.js';
14
import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';
15
import { IEditorService } from '../../../services/editor/common/editorService.js';
16
import { StatusbarViewModel } from './statusbarModel.js';
17
import { StatusBarFocused } from '../../../common/contextkeys.js';
18
import { getActiveWindow } from '../../../../base/browser/dom.js';
19
import { ICommandService } from '../../../../platform/commands/common/commands.js';
20
21
export class ToggleStatusbarEntryVisibilityAction extends Action {
22
23
constructor(id: string, label: string, private model: StatusbarViewModel) {
24
super(id, label, undefined, true);
25
26
this.checked = !model.isHidden(id);
27
}
28
29
override async run(): Promise<void> {
30
if (this.model.isHidden(this.id)) {
31
this.model.show(this.id);
32
} else {
33
this.model.hide(this.id);
34
}
35
}
36
}
37
38
export class HideStatusbarEntryAction extends Action {
39
40
constructor(id: string, name: string, private model: StatusbarViewModel) {
41
super(id, localize('hide', "Hide '{0}'", name), undefined, true);
42
}
43
44
override async run(): Promise<void> {
45
this.model.hide(this.id);
46
}
47
}
48
49
export class ManageExtensionAction extends Action {
50
51
constructor(
52
private readonly extensionId: string,
53
@ICommandService private readonly commandService: ICommandService
54
) {
55
super('statusbar.manage.extension', localize('manageExtension', "Manage Extension"));
56
}
57
58
override run(): Promise<void> {
59
return this.commandService.executeCommand('_extensions.manage', this.extensionId);
60
}
61
}
62
63
KeybindingsRegistry.registerCommandAndKeybindingRule({
64
id: 'workbench.statusBar.focusPrevious',
65
weight: KeybindingWeight.WorkbenchContrib,
66
primary: KeyCode.LeftArrow,
67
secondary: [KeyCode.UpArrow],
68
when: StatusBarFocused,
69
handler: (accessor: ServicesAccessor) => {
70
const statusBarService = accessor.get(IStatusbarService);
71
statusBarService.focusPreviousEntry();
72
}
73
});
74
75
KeybindingsRegistry.registerCommandAndKeybindingRule({
76
id: 'workbench.statusBar.focusNext',
77
weight: KeybindingWeight.WorkbenchContrib,
78
primary: KeyCode.RightArrow,
79
secondary: [KeyCode.DownArrow],
80
when: StatusBarFocused,
81
handler: (accessor: ServicesAccessor) => {
82
const statusBarService = accessor.get(IStatusbarService);
83
statusBarService.focusNextEntry();
84
}
85
});
86
87
KeybindingsRegistry.registerCommandAndKeybindingRule({
88
id: 'workbench.statusBar.focusFirst',
89
weight: KeybindingWeight.WorkbenchContrib,
90
primary: KeyCode.Home,
91
when: StatusBarFocused,
92
handler: (accessor: ServicesAccessor) => {
93
const statusBarService = accessor.get(IStatusbarService);
94
statusBarService.focus(false);
95
statusBarService.focusNextEntry();
96
}
97
});
98
99
KeybindingsRegistry.registerCommandAndKeybindingRule({
100
id: 'workbench.statusBar.focusLast',
101
weight: KeybindingWeight.WorkbenchContrib,
102
primary: KeyCode.End,
103
when: StatusBarFocused,
104
handler: (accessor: ServicesAccessor) => {
105
const statusBarService = accessor.get(IStatusbarService);
106
statusBarService.focus(false);
107
statusBarService.focusPreviousEntry();
108
}
109
});
110
111
KeybindingsRegistry.registerCommandAndKeybindingRule({
112
id: 'workbench.statusBar.clearFocus',
113
weight: KeybindingWeight.WorkbenchContrib,
114
primary: KeyCode.Escape,
115
when: StatusBarFocused,
116
handler: (accessor: ServicesAccessor) => {
117
const statusBarService = accessor.get(IStatusbarService);
118
const editorService = accessor.get(IEditorService);
119
if (statusBarService.isEntryFocused()) {
120
statusBarService.focus(false);
121
} else if (editorService.activeEditorPane) {
122
editorService.activeEditorPane.focus();
123
}
124
}
125
});
126
127
class FocusStatusBarAction extends Action2 {
128
129
constructor() {
130
super({
131
id: 'workbench.action.focusStatusBar',
132
title: localize2('focusStatusBar', 'Focus Status Bar'),
133
category: Categories.View,
134
f1: true
135
});
136
}
137
138
async run(accessor: ServicesAccessor): Promise<void> {
139
const layoutService = accessor.get(IWorkbenchLayoutService);
140
layoutService.focusPart(Parts.STATUSBAR_PART, getActiveWindow());
141
}
142
}
143
144
registerAction2(FocusStatusBarAction);
145
146