repositoryPane.ts 36.3 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import 'vs/css!./media/scmViewlet';
J
Joao Moreno 已提交
7
import { Event, Emitter } from 'vs/base/common/event';
J
Joao Moreno 已提交
8
import { domEvent } from 'vs/base/browser/event';
J
Joao Moreno 已提交
9
import { basename, isEqual } from 'vs/base/common/resources';
10
import { IDisposable, Disposable, DisposableStore, combinedDisposable } from 'vs/base/common/lifecycle';
S
SteVen Batten 已提交
11
import { ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPaneContainer';
J
Joao Moreno 已提交
12
import { append, $, addClass, toggleClass, trackFocus, removeClass } from 'vs/base/browser/dom';
13
import { IListVirtualDelegate, IIdentityProvider } from 'vs/base/browser/ui/list/list';
14
import { ISCMRepository, ISCMResourceGroup, ISCMResource, InputValidationType } from 'vs/workbench/contrib/scm/common/scm';
J
Joao Moreno 已提交
15 16 17 18 19 20 21 22 23
import { ResourceLabels, IResourceLabel } from 'vs/workbench/browser/labels';
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { MenuItemAction, IMenuService } from 'vs/platform/actions/common/actions';
J
Joao Moreno 已提交
24
import { IAction, IActionViewItem, ActionRunner, Action } from 'vs/base/common/actions';
J
Joao Moreno 已提交
25 26 27 28 29 30 31 32 33 34
import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { SCMMenus } from './menus';
import { ActionBar, IActionViewItemProvider } from 'vs/base/browser/ui/actionbar/actionbar';
import { IThemeService, LIGHT } from 'vs/platform/theme/common/themeService';
import { isSCMResource, isSCMResourceGroup, connectPrimaryMenuToInlineActionBar } from './util';
import { attachBadgeStyler, attachInputBoxStyler } from 'vs/platform/theme/common/styler';
import { InputBox, MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
import { format } from 'vs/base/common/strings';
import { WorkbenchCompressibleObjectTree } from 'vs/platform/list/browser/listService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
J
Joao Moreno 已提交
35
import { ThrottledDelayer, disposableTimeout } from 'vs/base/common/async';
J
Joao Moreno 已提交
36 37
import { INotificationService } from 'vs/platform/notification/common/notification';
import * as platform from 'vs/base/common/platform';
38
import { ITreeNode, ITreeFilter, ITreeSorter, ITreeContextMenuEvent } from 'vs/base/browser/ui/tree/tree';
39
import { ResourceTree, IResourceNode } from 'vs/base/common/resourceTree';
40
import { ISequence, ISplice } from 'vs/base/common/sequence';
J
Joao Moreno 已提交
41
import { ICompressibleTreeRenderer, ICompressibleKeyboardNavigationLabelProvider } from 'vs/base/browser/ui/tree/objectTree';
J
Joao Moreno 已提交
42 43 44 45 46 47 48
import { Iterator } from 'vs/base/common/iterator';
import { ICompressedTreeNode, ICompressedTreeElement } from 'vs/base/browser/ui/tree/compressedObjectTreeModel';
import { URI } from 'vs/base/common/uri';
import { FileKind } from 'vs/platform/files/common/files';
import { compareFileNames } from 'vs/base/common/comparers';
import { FuzzyScore, createMatches } from 'vs/base/common/filters';
import { IViewDescriptor } from 'vs/workbench/common/views';
J
Joao Moreno 已提交
49
import { localize } from 'vs/nls';
J
Joao Moreno 已提交
50
import { flatten, find } from 'vs/base/common/arrays';
J
Joao Moreno 已提交
51
import { memoize } from 'vs/base/common/decorators';
52
import { IWorkbenchThemeService, IFileIconTheme } from 'vs/workbench/services/themes/common/workbenchThemeService';
J
Joao Moreno 已提交
53
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
J
Joao Moreno 已提交
54
import { toResource, SideBySideEditor } from 'vs/workbench/common/editor';
J
Joao Moreno 已提交
55
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
J
Joao Moreno 已提交
56
import { Hasher } from 'vs/base/common/hash';
S
Sandeep Somavarapu 已提交
57
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
J
Joao Moreno 已提交
58

59
type TreeElement = ISCMResourceGroup | IResourceNode<ISCMResource, ISCMResourceGroup> | ISCMResource;
J
Joao Moreno 已提交
60

J
Joao Moreno 已提交
61
interface ResourceGroupTemplate {
J
Joao Moreno 已提交
62 63 64
	readonly name: HTMLElement;
	readonly count: CountBadge;
	readonly actionBar: ActionBar;
J
Joao Moreno 已提交
65
	elementDisposables: IDisposable;
J
Joao Moreno 已提交
66
	readonly disposables: IDisposable;
J
Joao Moreno 已提交
67 68 69 70
}

class ResourceGroupRenderer implements ICompressibleTreeRenderer<ISCMResourceGroup, FuzzyScore, ResourceGroupTemplate> {

71
	static readonly TEMPLATE_ID = 'resource group';
J
Joao Moreno 已提交
72 73 74 75 76 77 78 79 80
	get templateId(): string { return ResourceGroupRenderer.TEMPLATE_ID; }

	constructor(
		private actionViewItemProvider: IActionViewItemProvider,
		private themeService: IThemeService,
		private menus: SCMMenus
	) { }

	renderTemplate(container: HTMLElement): ResourceGroupTemplate {
81 82 83
		// hack
		addClass(container.parentElement!.parentElement!.querySelector('.monaco-tl-twistie')! as HTMLElement, 'force-twistie');

J
Joao Moreno 已提交
84 85 86 87 88 89 90
		const element = append(container, $('.resource-group'));
		const name = append(element, $('.name'));
		const actionsContainer = append(element, $('.actions'));
		const actionBar = new ActionBar(actionsContainer, { actionViewItemProvider: this.actionViewItemProvider });
		const countContainer = append(element, $('.count'));
		const count = new CountBadge(countContainer);
		const styler = attachBadgeStyler(count, this.themeService);
J
Joao Moreno 已提交
91 92
		const elementDisposables = Disposable.None;
		const disposables = combinedDisposable(actionBar, styler);
J
Joao Moreno 已提交
93

J
Joao Moreno 已提交
94
		return { name, count, actionBar, elementDisposables, disposables };
J
Joao Moreno 已提交
95 96 97
	}

	renderElement(node: ITreeNode<ISCMResourceGroup, FuzzyScore>, index: number, template: ResourceGroupTemplate): void {
J
Joao Moreno 已提交
98
		template.elementDisposables.dispose();
J
Joao Moreno 已提交
99 100 101 102 103

		const group = node.element;
		template.name.textContent = group.label;
		template.actionBar.clear();
		template.actionBar.context = group;
J
Joao Moreno 已提交
104
		template.count.setCount(group.elements.length);
J
Joao Moreno 已提交
105 106 107 108

		const disposables = new DisposableStore();
		disposables.add(connectPrimaryMenuToInlineActionBar(this.menus.getResourceGroupMenu(group), template.actionBar));

J
Joao Moreno 已提交
109
		template.elementDisposables = disposables;
J
Joao Moreno 已提交
110 111 112 113 114 115 116
	}

	renderCompressedElements(node: ITreeNode<ICompressedTreeNode<ISCMResourceGroup>, FuzzyScore>, index: number, templateData: ResourceGroupTemplate, height: number | undefined): void {
		throw new Error('Should never happen since node is incompressible');
	}

	disposeElement(group: ITreeNode<ISCMResourceGroup, FuzzyScore>, index: number, template: ResourceGroupTemplate): void {
J
Joao Moreno 已提交
117
		template.elementDisposables.dispose();
J
Joao Moreno 已提交
118 119 120
	}

	disposeTemplate(template: ResourceGroupTemplate): void {
J
Joao Moreno 已提交
121
		template.elementDisposables.dispose();
J
Joao Moreno 已提交
122
		template.disposables.dispose();
J
Joao Moreno 已提交
123 124 125 126 127 128 129 130 131
	}
}

interface ResourceTemplate {
	element: HTMLElement;
	name: HTMLElement;
	fileLabel: IResourceLabel;
	decorationIcon: HTMLElement;
	actionBar: ActionBar;
J
Joao Moreno 已提交
132 133
	elementDisposables: IDisposable;
	disposables: IDisposable;
J
Joao Moreno 已提交
134 135 136 137
}

class MultipleSelectionActionRunner extends ActionRunner {

138
	constructor(private getSelectedResources: () => (ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>)[]) {
J
Joao Moreno 已提交
139 140 141
		super();
	}

142
	runAction(action: IAction, context: ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>): Promise<any> {
J
Joao Moreno 已提交
143 144 145 146 147
		if (!(action instanceof MenuItemAction)) {
			return super.runAction(action, context);
		}

		const selection = this.getSelectedResources();
148 149
		const contextIsSelected = selection.some(s => s === context);
		const actualContext = contextIsSelected ? selection : [context];
150
		const args = flatten(actualContext.map(e => ResourceTree.isResourceNode(e) ? ResourceTree.collect(e) : [e]));
151
		return action.run(...args);
J
Joao Moreno 已提交
152 153 154
	}
}

155
class ResourceRenderer implements ICompressibleTreeRenderer<ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore, ResourceTemplate> {
J
Joao Moreno 已提交
156

157
	static readonly TEMPLATE_ID = 'resource';
J
Joao Moreno 已提交
158 159 160
	get templateId(): string { return ResourceRenderer.TEMPLATE_ID; }

	constructor(
J
Joao Moreno 已提交
161
		private viewModelProvider: () => ViewModel,
J
Joao Moreno 已提交
162 163
		private labels: ResourceLabels,
		private actionViewItemProvider: IActionViewItemProvider,
164
		private getSelectedResources: () => (ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>)[],
J
Joao Moreno 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
		private themeService: IThemeService,
		private menus: SCMMenus
	) { }

	renderTemplate(container: HTMLElement): ResourceTemplate {
		const element = append(container, $('.resource'));
		const name = append(element, $('.name'));
		const fileLabel = this.labels.create(name, { supportHighlights: true });
		const actionsContainer = append(fileLabel.element, $('.actions'));
		const actionBar = new ActionBar(actionsContainer, {
			actionViewItemProvider: this.actionViewItemProvider,
			actionRunner: new MultipleSelectionActionRunner(this.getSelectedResources)
		});

		const decorationIcon = append(element, $('.decoration-icon'));
J
Joao Moreno 已提交
180
		const disposables = combinedDisposable(actionBar, fileLabel);
J
Joao Moreno 已提交
181

J
Joao Moreno 已提交
182
		return { element, name, fileLabel, decorationIcon, actionBar, elementDisposables: Disposable.None, disposables };
J
Joao Moreno 已提交
183 184
	}

185
	renderElement(node: ITreeNode<ISCMResource, FuzzyScore> | ITreeNode<ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore>, index: number, template: ResourceTemplate): void {
J
Joao Moreno 已提交
186
		template.elementDisposables.dispose();
J
Joao Moreno 已提交
187

J
Joao Moreno 已提交
188
		const elementDisposables = new DisposableStore();
J
Joao Moreno 已提交
189
		const resourceOrFolder = node.element;
J
Joao Moreno 已提交
190
		const theme = this.themeService.getTheme();
J
Joao Moreno 已提交
191 192
		const iconResource = ResourceTree.isResourceNode(resourceOrFolder) ? resourceOrFolder.element : resourceOrFolder;
		const icon = iconResource && (theme.type === LIGHT ? iconResource.decorations.icon : iconResource.decorations.iconDark);
J
Joao Moreno 已提交
193

194 195
		const uri = ResourceTree.isResourceNode(resourceOrFolder) ? resourceOrFolder.uri : resourceOrFolder.sourceUri;
		const fileKind = ResourceTree.isResourceNode(resourceOrFolder) ? FileKind.FOLDER : FileKind.FILE;
J
Joao Moreno 已提交
196 197
		const viewModel = this.viewModelProvider();

J
Joao Moreno 已提交
198 199
		template.fileLabel.setFile(uri, {
			fileDecorations: { colors: false, badges: !icon },
J
Joao Moreno 已提交
200
			hidePath: viewModel.mode === ViewModelMode.Tree,
J
Joao Moreno 已提交
201 202 203
			fileKind,
			matches: createMatches(node.filterData)
		});
J
Joao Moreno 已提交
204

J
Joao Moreno 已提交
205
		template.actionBar.clear();
J
Joao Moreno 已提交
206
		template.actionBar.context = resourceOrFolder;
J
Joao Moreno 已提交
207

208
		if (ResourceTree.isResourceNode(resourceOrFolder)) {
J
Joao Moreno 已提交
209 210 211 212 213 214 215 216 217
			if (resourceOrFolder.element) {
				elementDisposables.add(connectPrimaryMenuToInlineActionBar(this.menus.getResourceMenu(resourceOrFolder.element.resourceGroup), template.actionBar));
				toggleClass(template.name, 'strike-through', resourceOrFolder.element.decorations.strikeThrough);
				toggleClass(template.element, 'faded', resourceOrFolder.element.decorations.faded);
			} else {
				elementDisposables.add(connectPrimaryMenuToInlineActionBar(this.menus.getResourceFolderMenu(resourceOrFolder.context), template.actionBar));
				removeClass(template.name, 'strike-through');
				removeClass(template.element, 'faded');
			}
J
Joao Moreno 已提交
218
		} else {
J
Joao Moreno 已提交
219 220 221
			elementDisposables.add(connectPrimaryMenuToInlineActionBar(this.menus.getResourceMenu(resourceOrFolder.resourceGroup), template.actionBar));
			toggleClass(template.name, 'strike-through', resourceOrFolder.decorations.strikeThrough);
			toggleClass(template.element, 'faded', resourceOrFolder.decorations.faded);
J
Joao Moreno 已提交
222 223
		}

224
		const tooltip = !ResourceTree.isResourceNode(resourceOrFolder) && resourceOrFolder.decorations.tooltip || '';
J
Joao Moreno 已提交
225 226 227 228 229 230 231 232

		if (icon) {
			template.decorationIcon.style.display = '';
			template.decorationIcon.style.backgroundImage = `url('${icon}')`;
			template.decorationIcon.title = tooltip;
		} else {
			template.decorationIcon.style.display = 'none';
			template.decorationIcon.style.backgroundImage = '';
J
Joao Moreno 已提交
233
			template.decorationIcon.title = '';
J
Joao Moreno 已提交
234 235 236
		}

		template.element.setAttribute('data-tooltip', tooltip);
J
Joao Moreno 已提交
237
		template.elementDisposables = elementDisposables;
J
Joao Moreno 已提交
238 239
	}

240
	disposeElement(resource: ITreeNode<ISCMResource, FuzzyScore> | ITreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>, FuzzyScore>, index: number, template: ResourceTemplate): void {
J
Joao Moreno 已提交
241
		template.elementDisposables.dispose();
J
Joao Moreno 已提交
242
	}
J
Joao Moreno 已提交
243

244
	renderCompressedElements(node: ITreeNode<ICompressedTreeNode<ISCMResource> | ICompressedTreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>>, FuzzyScore>, index: number, template: ResourceTemplate, height: number | undefined): void {
J
Joao Moreno 已提交
245 246 247
		template.elementDisposables.dispose();

		const elementDisposables = new DisposableStore();
248
		const compressed = node.element as ICompressedTreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>>;
J
Joao Moreno 已提交
249
		const folder = compressed.elements[compressed.elements.length - 1];
J
Joao Moreno 已提交
250 251 252

		const label = compressed.elements.map(e => e.name).join('/');
		const fileKind = FileKind.FOLDER;
J
Joao Moreno 已提交
253

J
Joao Moreno 已提交
254
		template.fileLabel.setResource({ resource: folder.uri, name: label }, {
J
Joao Moreno 已提交
255 256 257 258
			fileDecorations: { colors: false, badges: true },
			fileKind,
			matches: createMatches(node.filterData)
		});
J
Joao Moreno 已提交
259

J
Joao Moreno 已提交
260
		template.actionBar.clear();
J
Joao Moreno 已提交
261
		template.actionBar.context = folder;
J
Joao Moreno 已提交
262

J
Joao Moreno 已提交
263
		elementDisposables.add(connectPrimaryMenuToInlineActionBar(this.menus.getResourceFolderMenu(folder.context), template.actionBar));
J
Joao Moreno 已提交
264

J
Joao Moreno 已提交
265 266
		removeClass(template.name, 'strike-through');
		removeClass(template.element, 'faded');
J
Joao Moreno 已提交
267 268 269
		template.decorationIcon.style.display = 'none';
		template.decorationIcon.style.backgroundImage = '';

J
Joao Moreno 已提交
270 271
		template.element.setAttribute('data-tooltip', '');
		template.elementDisposables = elementDisposables;
J
Joao Moreno 已提交
272 273
	}

274
	disposeCompressedElements(node: ITreeNode<ICompressedTreeNode<ISCMResource> | ICompressedTreeNode<IResourceNode<ISCMResource, ISCMResourceGroup>>, FuzzyScore>, index: number, template: ResourceTemplate, height: number | undefined): void {
J
Joao Moreno 已提交
275
		template.elementDisposables.dispose();
J
Joao Moreno 已提交
276 277 278
	}

	disposeTemplate(template: ResourceTemplate): void {
J
Joao Moreno 已提交
279 280
		template.elementDisposables.dispose();
		template.disposables.dispose();
J
Joao Moreno 已提交
281 282 283 284 285 286 287 288
	}
}

class ProviderListDelegate implements IListVirtualDelegate<TreeElement> {

	getHeight() { return 22; }

	getTemplateId(element: TreeElement) {
289
		if (ResourceTree.isResourceNode(element) || isSCMResource(element)) {
J
Joao Moreno 已提交
290 291 292 293 294 295 296 297 298 299
			return ResourceRenderer.TEMPLATE_ID;
		} else {
			return ResourceGroupRenderer.TEMPLATE_ID;
		}
	}
}

class SCMTreeFilter implements ITreeFilter<TreeElement> {

	filter(element: TreeElement): boolean {
300
		if (ResourceTree.isResourceNode(element)) {
J
Joao Moreno 已提交
301 302 303 304 305 306 307 308 309 310 311
			return true;
		} else if (isSCMResourceGroup(element)) {
			return element.elements.length > 0 || !element.hideWhenEmpty;
		} else {
			return true;
		}
	}
}

export class SCMTreeSorter implements ITreeSorter<TreeElement> {

J
Joao Moreno 已提交
312 313 314 315 316
	@memoize
	private get viewModel(): ViewModel { return this.viewModelProvider(); }

	constructor(private viewModelProvider: () => ViewModel) { }

J
Joao Moreno 已提交
317
	compare(one: TreeElement, other: TreeElement): number {
J
Joao Moreno 已提交
318 319 320 321
		if (this.viewModel.mode === ViewModelMode.List) {
			return 0;
		}

J
Joao Moreno 已提交
322 323 324 325
		if (isSCMResourceGroup(one) && isSCMResourceGroup(other)) {
			return 0;
		}

326 327
		const oneIsDirectory = ResourceTree.isResourceNode(one);
		const otherIsDirectory = ResourceTree.isResourceNode(other);
J
Joao Moreno 已提交
328 329 330 331 332

		if (oneIsDirectory !== otherIsDirectory) {
			return oneIsDirectory ? -1 : 1;
		}

333 334
		const oneName = ResourceTree.isResourceNode(one) ? one.name : basename((one as ISCMResource).sourceUri);
		const otherName = ResourceTree.isResourceNode(other) ? other.name : basename((other as ISCMResource).sourceUri);
J
Joao Moreno 已提交
335 336 337 338 339

		return compareFileNames(oneName, otherName);
	}
}

340
export class SCMTreeKeyboardNavigationLabelProvider implements ICompressibleKeyboardNavigationLabelProvider<TreeElement> {
J
Joao Moreno 已提交
341 342

	getKeyboardNavigationLabel(element: TreeElement): { toString(): string; } | undefined {
343
		if (ResourceTree.isResourceNode(element)) {
344 345
			return element.name;
		} else if (isSCMResourceGroup(element)) {
J
Joao Moreno 已提交
346
			return element.label;
347
		} else {
J
Joao Moreno 已提交
348 349
			return basename(element.sourceUri);
		}
350
	}
J
Joao Moreno 已提交
351

352
	getCompressedNodeKeyboardNavigationLabel(elements: TreeElement[]): { toString(): string | undefined; } | undefined {
353
		const folders = elements as IResourceNode<ISCMResource, ISCMResourceGroup>[];
354
		return folders.map(e => e.name).join('/');
J
Joao Moreno 已提交
355 356 357
	}
}

J
Joao Moreno 已提交
358 359 360
class SCMResourceIdentityProvider implements IIdentityProvider<TreeElement> {

	getId(element: TreeElement): string {
361
		if (ResourceTree.isResourceNode(element)) {
J
Joao Moreno 已提交
362 363 364 365
			const group = element.context;
			return `${group.provider.contextValue}/${group.id}/$FOLDER/${element.uri.toString()}`;
		} else if (isSCMResource(element)) {
			const group = element.resourceGroup;
J
Joao Moreno 已提交
366
			const provider = group.provider;
J
Joao Moreno 已提交
367
			return `${provider.contextValue}/${group.id}/${element.sourceUri.toString()}`;
J
Joao Moreno 已提交
368
		} else {
J
Joao Moreno 已提交
369 370
			const provider = element.provider;
			return `${provider.contextValue}/${element.id}`;
J
Joao Moreno 已提交
371 372
		}
	}
J
Joao Moreno 已提交
373
}
J
Joao Moreno 已提交
374 375 376 377

interface IGroupItem {
	readonly group: ISCMResourceGroup;
	readonly resources: ISCMResource[];
J
Joao Moreno 已提交
378
	readonly tree: ResourceTree<ISCMResource, ISCMResourceGroup>;
J
Joao Moreno 已提交
379 380 381
	readonly disposable: IDisposable;
}

J
Joao Moreno 已提交
382 383
function groupItemAsTreeElement(item: IGroupItem, mode: ViewModelMode): ICompressedTreeElement<TreeElement> {
	const children = mode === ViewModelMode.List
384 385 386
		? Iterator.map(Iterator.fromArray(item.resources), element => ({ element, incompressible: true }))
		: Iterator.map(item.tree.root.children, node => asTreeElement(node, true));

J
Joao Moreno 已提交
387
	return { element: item.group, children, incompressible: true, collapsible: true };
388 389
}

390 391
function asTreeElement(node: IResourceNode<ISCMResource, ISCMResourceGroup>, forceIncompressible: boolean): ICompressedTreeElement<TreeElement> {
	return {
J
Joao Moreno 已提交
392
		element: (node.childrenCount === 0 && node.element) ? node.element : node,
393
		children: Iterator.map(node.children, node => asTreeElement(node, false)),
J
Joao Moreno 已提交
394
		incompressible: !!node.element || forceIncompressible
395
	};
J
Joao Moreno 已提交
396 397
}

J
Joao Moreno 已提交
398
const enum ViewModelMode {
J
Joao Moreno 已提交
399 400
	List = 'list',
	Tree = 'tree'
J
Joao Moreno 已提交
401 402
}

403
class ViewModel {
J
Joao Moreno 已提交
404

405
	private readonly _onDidChangeMode = new Emitter<ViewModelMode>();
J
Joao Moreno 已提交
406 407 408 409 410
	readonly onDidChangeMode = this._onDidChangeMode.event;

	get mode(): ViewModelMode { return this._mode; }
	set mode(mode: ViewModelMode) {
		this._mode = mode;
411 412 413 414 415 416 417 418 419 420 421

		for (const item of this.items) {
			item.tree.clear();

			if (mode === ViewModelMode.Tree) {
				for (const resource of item.resources) {
					item.tree.add(resource.sourceUri, resource);
				}
			}
		}

J
Joao Moreno 已提交
422 423 424 425
		this.refresh();
		this._onDidChangeMode.fire(mode);
	}

J
Joao Moreno 已提交
426
	private items: IGroupItem[] = [];
427
	private visibilityDisposables = new DisposableStore();
J
Joao Moreno 已提交
428
	private scrollTop: number | undefined;
J
Joao Moreno 已提交
429
	private firstVisible = true;
J
Joao Moreno 已提交
430 431 432
	private disposables = new DisposableStore();

	constructor(
433
		private groups: ISequence<ISCMResourceGroup>,
J
Joao Moreno 已提交
434
		private tree: WorkbenchCompressibleObjectTree<TreeElement, FuzzyScore>,
J
Joao Moreno 已提交
435 436 437
		private _mode: ViewModelMode,
		@IEditorService protected editorService: IEditorService,
		@IConfigurationService protected configurationService: IConfigurationService,
438
	) { }
J
Joao Moreno 已提交
439 440 441 442 443

	private onDidSpliceGroups({ start, deleteCount, toInsert }: ISplice<ISCMResourceGroup>): void {
		const itemsToInsert: IGroupItem[] = [];

		for (const group of toInsert) {
J
Joao Moreno 已提交
444
			const tree = new ResourceTree<ISCMResource, ISCMResourceGroup>(group, group.provider.rootUri || URI.file('/'));
J
Joao Moreno 已提交
445 446
			const resources: ISCMResource[] = [...group.elements];
			const disposable = combinedDisposable(
447
				group.onDidChange(() => this.tree.refilter()),
J
Joao Moreno 已提交
448 449
				group.onDidSplice(splice => this.onDidSpliceGroup(item, splice))
			);
450

451
			const item: IGroupItem = { group, resources, tree, disposable };
452

453 454 455 456
			if (this._mode === ViewModelMode.Tree) {
				for (const resource of resources) {
					item.tree.add(resource.sourceUri, resource);
				}
457
			}
J
Joao Moreno 已提交
458 459 460 461 462 463 464 465 466 467

			itemsToInsert.push(item);
		}

		const itemsToDispose = this.items.splice(start, deleteCount, ...itemsToInsert);

		for (const item of itemsToDispose) {
			item.disposable.dispose();
		}

468
		this.refresh();
J
Joao Moreno 已提交
469 470 471 472 473
	}

	private onDidSpliceGroup(item: IGroupItem, { start, deleteCount, toInsert }: ISplice<ISCMResource>): void {
		const deleted = item.resources.splice(start, deleteCount, ...toInsert);

474 475 476 477
		if (this._mode === ViewModelMode.Tree) {
			for (const resource of deleted) {
				item.tree.delete(resource.sourceUri);
			}
J
Joao Moreno 已提交
478 479 480 481

			for (const resource of toInsert) {
				item.tree.add(resource.sourceUri, resource);
			}
J
Joao Moreno 已提交
482 483
		}

484 485
		this.refresh(item);
	}
J
Joao Moreno 已提交
486

487 488 489
	setVisible(visible: boolean): void {
		if (visible) {
			this.visibilityDisposables = new DisposableStore();
490 491
			this.groups.onDidSplice(this.onDidSpliceGroups, this, this.visibilityDisposables);
			this.onDidSpliceGroups({ start: 0, deleteCount: this.items.length, toInsert: this.groups.elements });
J
Joao Moreno 已提交
492 493 494 495 496

			if (typeof this.scrollTop === 'number') {
				this.tree.scrollTop = this.scrollTop;
				this.scrollTop = undefined;
			}
J
Joao Moreno 已提交
497 498 499

			this.editorService.onDidActiveEditorChange(this.onDidActiveEditorChange, this, this.visibilityDisposables);
			this.onDidActiveEditorChange();
500 501 502
		} else {
			this.visibilityDisposables.dispose();
			this.onDidSpliceGroups({ start: 0, deleteCount: this.items.length, toInsert: [] });
J
Joao Moreno 已提交
503
			this.scrollTop = this.tree.scrollTop;
504 505
		}
	}
J
Joao Moreno 已提交
506

507 508
	private refresh(item?: IGroupItem): void {
		if (item) {
J
Joao Moreno 已提交
509
			this.tree.setChildren(item.group, groupItemAsTreeElement(item, this.mode).children);
510
		} else {
J
Joao Moreno 已提交
511
			this.tree.setChildren(null, this.items.map(item => groupItemAsTreeElement(item, this.mode)));
512
		}
J
Joao Moreno 已提交
513 514
	}

J
Joao Moreno 已提交
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
	private onDidActiveEditorChange(): void {
		if (!this.configurationService.getValue<boolean>('scm.autoReveal')) {
			return;
		}

		if (this.firstVisible) {
			this.firstVisible = false;
			this.visibilityDisposables.add(disposableTimeout(() => this.onDidActiveEditorChange(), 250));
			return;
		}

		const editor = this.editorService.activeEditor;

		if (!editor) {
			return;
		}

		const uri = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER });

		if (!uri) {
			return;
		}

		// go backwards from last group
539
		for (let i = this.items.length - 1; i >= 0; i--) {
J
Joao Moreno 已提交
540 541 542 543 544 545 546 547 548
			const item = this.items[i];
			const resource = this.mode === ViewModelMode.Tree
				? item.tree.getNode(uri)?.element
				: find(item.resources, r => isEqual(r.sourceUri, uri));

			if (resource) {
				this.tree.reveal(resource);
				this.tree.setSelection([resource]);
				this.tree.setFocus([resource]);
549
				return;
J
Joao Moreno 已提交
550 551 552 553
			}
		}
	}

J
Joao Moreno 已提交
554
	dispose(): void {
555 556
		this.visibilityDisposables.dispose();
		this.disposables.dispose();
J
Joao Moreno 已提交
557 558 559
	}
}

J
Joao Moreno 已提交
560 561 562
export class ToggleViewModeAction extends Action {

	static readonly ID = 'workbench.scm.action.toggleViewMode';
563
	static readonly LABEL = localize('toggleViewMode', "Toggle View Mode");
J
Joao Moreno 已提交
564 565 566 567 568 569 570 571 572 573 574 575 576

	constructor(private viewModel: ViewModel) {
		super(ToggleViewModeAction.ID, ToggleViewModeAction.LABEL);

		this._register(this.viewModel.onDidChangeMode(this.onDidChangeMode, this));
		this.onDidChangeMode(this.viewModel.mode);
	}

	async run(): Promise<void> {
		this.viewModel.mode = this.viewModel.mode === ViewModelMode.List ? ViewModelMode.Tree : ViewModelMode.List;
	}

	private onDidChangeMode(mode: ViewModelMode): void {
M
Miguel Solorio 已提交
577
		const iconClass = mode === ViewModelMode.List ? 'codicon-list-tree' : 'codicon-list-flat';
J
Joao Moreno 已提交
578
		this.class = `scm-action toggle-view-mode ${iconClass}`;
J
Joao Moreno 已提交
579 580 581
	}
}

J
Joao Moreno 已提交
582 583 584 585 586 587 588 589
function convertValidationType(type: InputValidationType): MessageType {
	switch (type) {
		case InputValidationType.Information: return MessageType.INFO;
		case InputValidationType.Warning: return MessageType.WARNING;
		case InputValidationType.Error: return MessageType.ERROR;
	}
}

S
SteVen Batten 已提交
590
export class RepositoryPane extends ViewPane {
J
Joao Moreno 已提交
591 592 593

	private cachedHeight: number | undefined = undefined;
	private cachedWidth: number | undefined = undefined;
J
Joao Moreno 已提交
594 595 596
	private inputBoxContainer!: HTMLElement;
	private inputBox!: InputBox;
	private listContainer!: HTMLElement;
J
Joao Moreno 已提交
597
	private tree!: WorkbenchCompressibleObjectTree<TreeElement, FuzzyScore>;
J
Joao Moreno 已提交
598 599
	private viewModel!: ViewModel;
	private listLabels!: ResourceLabels;
J
Joao Moreno 已提交
600
	private menus: SCMMenus;
J
Joao Moreno 已提交
601
	private toggleViewModelModeAction: ToggleViewModeAction | undefined;
J
Joao Moreno 已提交
602
	protected contextKeyService: IContextKeyService;
J
Joao Moreno 已提交
603
	private commitTemplate = '';
J
Joao Moreno 已提交
604 605 606

	constructor(
		readonly repository: ISCMRepository,
S
SteVen Batten 已提交
607
		options: IViewPaneOptions,
J
Joao Moreno 已提交
608
		@IKeybindingService protected keybindingService: IKeybindingService,
609
		@IWorkbenchThemeService protected themeService: IWorkbenchThemeService,
J
Joao Moreno 已提交
610 611 612 613 614 615 616 617
		@IContextMenuService protected contextMenuService: IContextMenuService,
		@IContextViewService protected contextViewService: IContextViewService,
		@ICommandService protected commandService: ICommandService,
		@INotificationService private readonly notificationService: INotificationService,
		@IEditorService protected editorService: IEditorService,
		@IInstantiationService protected instantiationService: IInstantiationService,
		@IConfigurationService protected configurationService: IConfigurationService,
		@IContextKeyService contextKeyService: IContextKeyService,
J
Joao Moreno 已提交
618 619
		@IMenuService protected menuService: IMenuService,
		@IStorageService private storageService: IStorageService
J
Joao Moreno 已提交
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
	) {
		super(options, keybindingService, contextMenuService, configurationService, contextKeyService);

		this.menus = instantiationService.createInstance(SCMMenus, this.repository.provider);
		this._register(this.menus);
		this._register(this.menus.onDidChangeTitle(this._onDidChangeTitleArea.fire, this._onDidChangeTitleArea));

		this.contextKeyService = contextKeyService.createScoped(this.element);
		this.contextKeyService.createKey('scmRepository', this.repository);
	}

	render(): void {
		super.render();
		this._register(this.menus.onDidChangeTitle(this.updateActions, this));
	}

	protected renderHeaderTitle(container: HTMLElement): void {
		let title: string;
		let type: string;

		if (this.repository.provider.rootUri) {
			title = basename(this.repository.provider.rootUri);
			type = this.repository.provider.label;
		} else {
			title = this.repository.provider.label;
			type = '';
		}

		super.renderHeaderTitle(container, title);
		addClass(container, 'scm-provider');
		append(container, $('span.type', undefined, type));
	}

	protected renderBody(container: HTMLElement): void {
		const focusTracker = trackFocus(container);
		this._register(focusTracker.onDidFocus(() => this.repository.focus()));
		this._register(focusTracker);

		// Input
		this.inputBoxContainer = append(container, $('.scm-editor'));

		const updatePlaceholder = () => {
			const binding = this.keybindingService.lookupKeybinding('scm.acceptInput');
			const label = binding ? binding.getLabel() : (platform.isMacintosh ? 'Cmd+Enter' : 'Ctrl+Enter');
			const placeholder = format(this.repository.input.placeholder, label);

			this.inputBox.setPlaceHolder(placeholder);
		};

		const validationDelayer = new ThrottledDelayer<any>(200);
		const validate = () => {
			return this.repository.input.validateInput(this.inputBox.value, this.inputBox.inputElement.selectionStart || 0).then(result => {
				if (!result) {
					this.inputBox.inputElement.removeAttribute('aria-invalid');
					this.inputBox.hideMessage();
				} else {
					this.inputBox.inputElement.setAttribute('aria-invalid', 'true');
					this.inputBox.showMessage({ content: result.message, type: convertValidationType(result.type) });
				}
			});
		};

		const triggerValidation = () => validationDelayer.trigger(validate);

		this.inputBox = new InputBox(this.inputBoxContainer, this.contextViewService, { flexibleHeight: true, flexibleMaxHeight: 134 });
		this.inputBox.setEnabled(this.isBodyVisible());
		this._register(attachInputBoxStyler(this.inputBox, this.themeService));
		this._register(this.inputBox);

		this._register(this.inputBox.onDidChange(triggerValidation, null));

		const onKeyUp = domEvent(this.inputBox.inputElement, 'keyup');
		const onMouseUp = domEvent(this.inputBox.inputElement, 'mouseup');
		this._register(Event.any<any>(onKeyUp, onMouseUp)(triggerValidation, null));

		this.inputBox.value = this.repository.input.value;
		this._register(this.inputBox.onDidChange(value => this.repository.input.value = value, null));
		this._register(this.repository.input.onDidChange(value => this.inputBox.value = value, null));

		updatePlaceholder();
		this._register(this.repository.input.onDidChangePlaceholder(updatePlaceholder, null));
		this._register(this.keybindingService.onDidUpdateKeybindings(updatePlaceholder, null));

		this._register(this.inputBox.onDidHeightChange(() => this.layoutBody()));

		if (this.repository.provider.onDidChangeCommitTemplate) {
J
Joao Moreno 已提交
706
			this._register(this.repository.provider.onDidChangeCommitTemplate(this.onDidChangeCommitTemplate, this));
J
Joao Moreno 已提交
707 708
		}

J
Joao Moreno 已提交
709
		this.onDidChangeCommitTemplate();
J
Joao Moreno 已提交
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730

		// Input box visibility
		this._register(this.repository.input.onDidChangeVisibility(this.updateInputBoxVisibility, this));
		this.updateInputBoxVisibility();

		// List
		this.listContainer = append(container, $('.scm-status.show-file-icons'));

		const updateActionsVisibility = () => toggleClass(this.listContainer, 'show-actions', this.configurationService.getValue<boolean>('scm.alwaysShowActions'));
		Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('scm.alwaysShowActions'))(updateActionsVisibility);
		updateActionsVisibility();

		const delegate = new ProviderListDelegate();

		const actionViewItemProvider = (action: IAction) => this.getActionViewItem(action);

		this.listLabels = this.instantiationService.createInstance(ResourceLabels, { onDidChangeVisibility: this.onDidChangeBodyVisibility });
		this._register(this.listLabels);

		const renderers = [
			new ResourceGroupRenderer(actionViewItemProvider, this.themeService, this.menus),
J
Joao Moreno 已提交
731
			new ResourceRenderer(() => this.viewModel, this.listLabels, actionViewItemProvider, () => this.getSelectedResources(), this.themeService, this.menus)
J
Joao Moreno 已提交
732 733 734
		];

		const filter = new SCMTreeFilter();
J
Joao Moreno 已提交
735
		const sorter = new SCMTreeSorter(() => this.viewModel);
J
Joao Moreno 已提交
736
		const keyboardNavigationLabelProvider = new SCMTreeKeyboardNavigationLabelProvider();
J
Joao Moreno 已提交
737
		const identityProvider = new SCMResourceIdentityProvider();
J
Joao Moreno 已提交
738

739
		this.tree = this.instantiationService.createInstance<typeof WorkbenchCompressibleObjectTree, WorkbenchCompressibleObjectTree<TreeElement, FuzzyScore>>(
J
Joao Moreno 已提交
740
			WorkbenchCompressibleObjectTree,
J
Joao Moreno 已提交
741
			'SCM Tree Repo',
J
Joao Moreno 已提交
742 743 744 745
			this.listContainer,
			delegate,
			renderers,
			{
J
Joao Moreno 已提交
746
				identityProvider,
J
Joao Moreno 已提交
747 748 749
				horizontalScrolling: false,
				filter,
				sorter,
J
Joao Moreno 已提交
750 751 752 753
				keyboardNavigationLabelProvider,
				overrideStyles: {
					listBackground: SIDE_BAR_BACKGROUND
				}
J
Joao Moreno 已提交
754 755 756 757
			});

		this._register(Event.chain(this.tree.onDidOpen)
			.map(e => e.elements[0])
758
			.filter(e => !!e && !isSCMResourceGroup(e) && !ResourceTree.isResourceNode(e))
J
Joao Moreno 已提交
759 760
			.on(this.open, this));

J
Joao Moreno 已提交
761 762
		this._register(Event.chain(this.tree.onDidPin)
			.map(e => e.elements[0])
763
			.filter(e => !!e && !isSCMResourceGroup(e) && !ResourceTree.isResourceNode(e))
J
Joao Moreno 已提交
764
			.on(this.pin, this));
J
Joao Moreno 已提交
765

766
		this._register(this.tree.onContextMenu(this.onListContextMenu, this));
J
Joao Moreno 已提交
767 768
		this._register(this.tree);

769
		let mode = this.configurationService.getValue<'tree' | 'list'>('scm.defaultViewMode') === 'list' ? ViewModelMode.List : ViewModelMode.Tree;
J
Joao Moreno 已提交
770

771
		const rootUri = this.repository.provider.rootUri;
J
Joao Moreno 已提交
772

773 774
		if (typeof rootUri !== 'undefined') {
			const storageMode = this.storageService.get(`scm.repository.viewMode:${rootUri.toString()}`, StorageScope.WORKSPACE) as ViewModelMode;
J
Joao Moreno 已提交
775

776 777
			if (typeof storageMode === 'string') {
				mode = storageMode;
J
Joao Moreno 已提交
778 779 780
			}
		}

781
		this.viewModel = this.instantiationService.createInstance(ViewModel, this.repository.provider.groups, this.tree, mode);
782
		this._register(this.viewModel);
J
Joao Moreno 已提交
783

784 785 786
		addClass(this.listContainer, 'file-icon-themable-tree');
		addClass(this.listContainer, 'show-file-icons');

J
Joao Moreno 已提交
787 788 789
		this.updateIndentStyles(this.themeService.getFileIconTheme());
		this._register(this.themeService.onDidFileIconThemeChange(this.updateIndentStyles, this));
		this._register(this.viewModel.onDidChangeMode(this.onDidChangeMode, this));
790

791 792
		this.toggleViewModelModeAction = new ToggleViewModeAction(this.viewModel);
		this._register(this.toggleViewModelModeAction);
J
Joao Moreno 已提交
793

794
		this._register(this.onDidChangeBodyVisibility(this._onDidChangeVisibility, this));
J
Joao Moreno 已提交
795 796

		this.updateActions();
J
Joao Moreno 已提交
797 798
	}

J
Joao Moreno 已提交
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
	private updateIndentStyles(theme: IFileIconTheme): void {
		toggleClass(this.listContainer, 'list-view-mode', this.viewModel.mode === ViewModelMode.List);
		toggleClass(this.listContainer, 'tree-view-mode', this.viewModel.mode === ViewModelMode.Tree);
		toggleClass(this.listContainer, 'align-icons-and-twisties', this.viewModel.mode === ViewModelMode.Tree && theme.hasFileIcons && !theme.hasFolderIcons);
		toggleClass(this.listContainer, 'hide-arrows', this.viewModel.mode === ViewModelMode.Tree && theme.hidesExplorerArrows === true);
	}

	private onDidChangeMode(): void {
		this.updateIndentStyles(this.themeService.getFileIconTheme());

		const rootUri = this.repository.provider.rootUri;

		if (typeof rootUri === 'undefined') {
			return;
		}

		this.storageService.store(`scm.repository.viewMode:${rootUri.toString()}`, this.viewModel.mode, StorageScope.WORKSPACE);
	}

J
Joao Moreno 已提交
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
	layoutBody(height: number | undefined = this.cachedHeight, width: number | undefined = this.cachedWidth): void {
		if (height === undefined) {
			return;
		}

		this.cachedHeight = height;

		if (this.repository.input.visible) {
			removeClass(this.inputBoxContainer, 'hidden');
			this.inputBox.layout();

			const editorHeight = this.inputBox.height;
			const listHeight = height - (editorHeight + 12 /* margin */);
			this.listContainer.style.height = `${listHeight}px`;
			this.tree.layout(listHeight, width);
		} else {
			addClass(this.inputBoxContainer, 'hidden');

			this.listContainer.style.height = `${height}px`;
			this.tree.layout(height, width);
		}
	}

	focus(): void {
		super.focus();

		if (this.isExpanded()) {
			if (this.repository.input.visible) {
				this.inputBox.focus();
			} else {
				this.tree.domFocus();
			}

			this.repository.focus();
		}
	}

855 856 857 858 859
	private _onDidChangeVisibility(visible: boolean): void {
		this.inputBox.setEnabled(visible);
		this.viewModel.setVisible(visible);
	}

J
Joao Moreno 已提交
860
	getActions(): IAction[] {
J
Joao Moreno 已提交
861 862 863 864 865 866 867 868 869
		if (this.toggleViewModelModeAction) {

			return [
				this.toggleViewModelModeAction,
				...this.menus.getTitleActions()
			];
		} else {
			return this.menus.getTitleActions();
		}
J
Joao Moreno 已提交
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
	}

	getSecondaryActions(): IAction[] {
		return this.menus.getTitleSecondaryActions();
	}

	getActionViewItem(action: IAction): IActionViewItem | undefined {
		if (!(action instanceof MenuItemAction)) {
			return undefined;
		}

		return new ContextAwareMenuEntryActionViewItem(action, this.keybindingService, this.notificationService, this.contextMenuService);
	}

	getActionsContext(): any {
		return this.repository.provider;
	}

	private open(e: ISCMResource): void {
		e.open();
	}

J
Joao Moreno 已提交
892 893 894 895 896 897 898
	private pin(): void {
		const activeControl = this.editorService.activeControl;

		if (activeControl) {
			activeControl.group.pinEditor(activeControl.input);
		}
	}
J
Joao Moreno 已提交
899

900 901 902 903
	private onListContextMenu(e: ITreeContextMenuEvent<TreeElement>): void {
		if (!e.element) {
			return;
		}
J
Joao Moreno 已提交
904

905
		const element = e.element;
J
Joao Moreno 已提交
906
		let actions: IAction[] = [];
J
Joao Moreno 已提交
907

908 909 910
		if (isSCMResourceGroup(element)) {
			actions = this.menus.getResourceGroupContextActions(element);
		} else if (ResourceTree.isResourceNode(element)) {
J
Joao Moreno 已提交
911 912 913 914 915
			if (element.element) {
				actions = this.menus.getResourceContextActions(element.element);
			} else {
				actions = this.menus.getResourceFolderContextActions(element.context);
			}
916
		} else {
917
			actions = this.menus.getResourceContextActions(element);
918
		}
J
Joao Moreno 已提交
919

920 921 922 923 924 925 926
		this.contextMenuService.showContextMenu({
			getAnchor: () => e.anchor,
			getActions: () => actions,
			getActionsContext: () => element,
			actionRunner: new MultipleSelectionActionRunner(() => this.getSelectedResources())
		});
	}
J
Joao Moreno 已提交
927

928
	private getSelectedResources(): (ISCMResource | IResourceNode<ISCMResource, ISCMResourceGroup>)[] {
J
Joao Moreno 已提交
929
		return this.tree.getSelection()
930
			.filter(r => !!r && !isSCMResourceGroup(r))! as any;
J
Joao Moreno 已提交
931 932
	}

J
Joao Moreno 已提交
933 934
	private onDidChangeCommitTemplate(): void {
		if (typeof this.repository.provider.commitTemplate === 'undefined' || !this.repository.input.visible) {
J
Joao Moreno 已提交
935 936 937
			return;
		}

J
Joao Moreno 已提交
938 939 940 941 942 943 944 945
		const oldCommitTemplate = this.commitTemplate;
		this.commitTemplate = this.repository.provider.commitTemplate;

		if (this.inputBox.value && this.inputBox.value !== oldCommitTemplate) {
			return;
		}

		this.inputBox.value = this.commitTemplate;
J
Joao Moreno 已提交
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
	}

	private updateInputBoxVisibility(): void {
		if (this.cachedHeight) {
			this.layoutBody(this.cachedHeight);
		}
	}
}

export class RepositoryViewDescriptor implements IViewDescriptor {

	private static counter = 0;

	readonly id: string;
	readonly name: string;
S
Sandeep Somavarapu 已提交
961
	readonly ctorDescriptor: SyncDescriptor<RepositoryPane>;
J
Joao Moreno 已提交
962 963 964 965 966 967
	readonly canToggleVisibility = true;
	readonly order = -500;
	readonly workspace = true;

	constructor(readonly repository: ISCMRepository, readonly hideByDefault: boolean) {
		const repoId = repository.provider.rootUri ? repository.provider.rootUri.toString() : `#${RepositoryViewDescriptor.counter++}`;
J
Joao Moreno 已提交
968 969 970 971
		const hasher = new Hasher();
		hasher.hash(repository.provider.label);
		hasher.hash(repoId);
		this.id = `scm:repository:${hasher.value}`;
J
Joao Moreno 已提交
972 973
		this.name = repository.provider.rootUri ? basename(repository.provider.rootUri) : repository.provider.label;

S
Sandeep Somavarapu 已提交
974
		this.ctorDescriptor = new SyncDescriptor(RepositoryPane, [repository]);
J
Joao Moreno 已提交
975 976
	}
}