-
Notifications
You must be signed in to change notification settings - Fork 29.6k
/
scm.contribution.ts
190 lines (173 loc) · 8.65 KB
/
scm.contribution.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
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { DirtyDiffWorkbenchController } from './dirtydiffDecorator';
import { ShowViewletAction } from 'vs/workbench/browser/viewlet';
import { VIEWLET_ID, ISCMRepository, ISCMService } from 'vs/workbench/contrib/scm/common/scm';
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { SCMStatusController } from './activity';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { SCMService } from 'vs/workbench/contrib/scm/common/scmService';
import { IViewContainersRegistry, ViewContainerLocation, Extensions as ViewContainerExtensions } from 'vs/workbench/common/views';
import { SCMViewPaneContainer } from 'vs/workbench/contrib/scm/browser/scmViewlet';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
import { Codicon } from 'vs/base/common/codicons';
class OpenSCMViewletAction extends ShowViewletAction {
static readonly ID = VIEWLET_ID;
static readonly LABEL = localize('toggleSCMViewlet', "Show SCM");
constructor(id: string, label: string, @IViewletService viewletService: IViewletService, @IEditorGroupsService editorGroupService: IEditorGroupsService, @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService) {
super(id, label, VIEWLET_ID, viewletService, editorGroupService, layoutService);
}
}
ModesRegistry.registerLanguage({
id: 'scminput',
extensions: [],
mimetypes: ['text/x-scm-input']
});
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(DirtyDiffWorkbenchController, LifecyclePhase.Restored);
Registry.as<IViewContainersRegistry>(ViewContainerExtensions.ViewContainersRegistry).registerViewContainer({
id: VIEWLET_ID,
name: localize('source control', "Source Control"),
ctorDescriptor: new SyncDescriptor(SCMViewPaneContainer),
storageId: 'workbench.scm.views.state',
icon: Codicon.sourceControl.classNames,
alwaysUseContainerInfo: true,
order: 2
}, ViewContainerLocation.Sidebar);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(SCMStatusController, LifecyclePhase.Restored);
// Register Action to Open Viewlet
Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions).registerWorkbenchAction(
SyncActionDescriptor.from(OpenSCMViewletAction, {
primary: 0,
win: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G },
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_G },
mac: { primary: KeyMod.WinCtrl | KeyMod.Shift | KeyCode.KEY_G }
}),
'View: Show SCM',
localize('view', "View")
);
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
id: 'scm',
order: 5,
title: localize('scmConfigurationTitle', "SCM"),
type: 'object',
scope: ConfigurationScope.RESOURCE,
properties: {
'scm.alwaysShowProviders': {
type: 'boolean',
description: localize('alwaysShowProviders', "Controls whether to show the Source Control Provider section even when there's only one Provider registered."),
default: false
},
'scm.providers.visible': {
type: 'number',
description: localize('providersVisible', "Controls how many providers are visible in the Source Control Provider section. Set to `0` to be able to manually resize the view."),
default: 10
},
'scm.diffDecorations': {
type: 'string',
enum: ['all', 'gutter', 'overview', 'minimap', 'none'],
enumDescriptions: [
localize('scm.diffDecorations.all', "Show the diff decorations in all available locations."),
localize('scm.diffDecorations.gutter', "Show the diff decorations only in the editor gutter."),
localize('scm.diffDecorations.overviewRuler', "Show the diff decorations only in the overview ruler."),
localize('scm.diffDecorations.minimap', "Show the diff decorations only in the minimap."),
localize('scm.diffDecorations.none', "Do not show the diff decorations.")
],
default: 'all',
description: localize('diffDecorations', "Controls diff decorations in the editor.")
},
'scm.diffDecorationsGutterWidth': {
type: 'number',
enum: [1, 2, 3, 4, 5],
default: 3,
description: localize('diffGutterWidth', "Controls the width(px) of diff decorations in gutter (added & modified).")
},
'scm.diffDecorationsGutterVisibility': {
type: 'string',
enum: ['always', 'hover'],
enumDescriptions: [
localize('scm.diffDecorationsGutterVisibility.always', "Show the diff decorator in the gutter at all times."),
localize('scm.diffDecorationsGutterVisibility.hover', "Show the diff decorator in the gutter only on hover.")
],
description: localize('scm.diffDecorationsGutterVisibility', "Controls the visibility of the Source Control diff decorator in the gutter."),
default: 'always'
},
'scm.alwaysShowActions': {
type: 'boolean',
description: localize('alwaysShowActions', "Controls whether inline actions are always visible in the Source Control view."),
default: false
},
'scm.countBadge': {
type: 'string',
enum: ['all', 'focused', 'off'],
enumDescriptions: [
localize('scm.countBadge.all', "Show the sum of all Source Control Providers count badges."),
localize('scm.countBadge.focused', "Show the count badge of the focused Source Control Provider."),
localize('scm.countBadge.off', "Disable the Source Control count badge.")
],
description: localize('scm.countBadge', "Controls the Source Control count badge."),
default: 'all'
},
'scm.defaultViewMode': {
type: 'string',
enum: ['tree', 'list'],
enumDescriptions: [
localize('scm.defaultViewMode.tree', "Show the repository changes as a tree."),
localize('scm.defaultViewMode.list', "Show the repository changes as a list.")
],
description: localize('scm.defaultViewMode', "Controls the default Source Control repository view mode."),
default: 'list'
},
'scm.autoReveal': {
type: 'boolean',
description: localize('autoReveal', "Controls whether the SCM view should automatically reveal and select files when opening them."),
default: true
},
}
});
// View menu
MenuRegistry.appendMenuItem(MenuId.MenubarViewMenu, {
group: '3_views',
command: {
id: VIEWLET_ID,
title: localize({ key: 'miViewSCM', comment: ['&& denotes a mnemonic'] }, "S&&CM")
},
order: 3
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'scm.acceptInput',
description: { description: localize('scm accept', "SCM: Accept Input"), args: [] },
weight: KeybindingWeight.WorkbenchContrib,
when: ContextKeyExpr.has('scmRepository'),
primary: KeyMod.CtrlCmd | KeyCode.Enter,
handler: accessor => {
const contextKeyService = accessor.get(IContextKeyService);
const context = contextKeyService.getContext(document.activeElement);
const repository = context.getValue<ISCMRepository>('scmRepository');
if (!repository || !repository.provider.acceptInputCommand) {
return Promise.resolve(null);
}
const id = repository.provider.acceptInputCommand.id;
const args = repository.provider.acceptInputCommand.arguments;
const commandService = accessor.get(ICommandService);
return commandService.executeCommand(id, ...(args || []));
}
});
registerSingleton(ISCMService, SCMService);