markersPanel.ts 21.6 KB
Newer Older
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/markers';
S
Sandeep Somavarapu 已提交
7

8
import { URI } from 'vs/base/common/uri';
9
import { TPromise } from 'vs/base/common/winjs.base';
10
import * as dom from 'vs/base/browser/dom';
J
Joao Moreno 已提交
11
import { IAction, IActionItem, Action } from 'vs/base/common/actions';
12 13
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Panel } from 'vs/workbench/browser/panel';
14
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
15
import Constants from 'vs/workbench/parts/markers/electron-browser/constants';
J
Joao Moreno 已提交
16
import { Marker, ResourceMarkers, RelatedInformation, MarkersModel } from 'vs/workbench/parts/markers/electron-browser/markersModel';
17
import * as Viewer from 'vs/workbench/parts/markers/electron-browser/markersTreeViewer';
S
Sandeep Somavarapu 已提交
18
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
J
Joao Moreno 已提交
19
import { MarkersFilterActionItem, MarkersFilterAction, QuickFixAction, QuickFixActionItem, IMarkersFilterActionChangeEvent } from 'vs/workbench/parts/markers/electron-browser/markersPanelActions';
S
Sandeep Somavarapu 已提交
20
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
21
import Messages from 'vs/workbench/parts/markers/electron-browser/messages';
22
import { RangeHighlightDecorations } from 'vs/workbench/browser/parts/editor/rangeDecorations';
B
Benjamin Pasero 已提交
23
import { IThemeService } from 'vs/platform/theme/common/themeService';
24
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
25
import { IMarkersWorkbenchService } from 'vs/workbench/parts/markers/electron-browser/markers';
S
Sandeep Somavarapu 已提交
26 27
import { IStorageService } from 'vs/platform/storage/common/storage';
import { Scope } from 'vs/workbench/common/memento';
28
import { localize } from 'vs/nls';
S
Sandeep Somavarapu 已提交
29
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
J
Joao Moreno 已提交
30 31
import { Iterator } from 'vs/base/common/iterator';
import { ITreeElement } from 'vs/base/browser/ui/tree/tree';
J
Joao Moreno 已提交
32
import { debounceEvent } from 'vs/base/common/event';
33
import { WorkbenchObjectTree } from 'vs/platform/list/browser/listService';
J
Joao Moreno 已提交
34 35 36 37 38
import { FilterOptions } from 'vs/workbench/parts/markers/electron-browser/markersFilterOptions';
import { IExpression, getEmptyExpression } from 'vs/base/common/glob';
import { mixin, deepClone } from 'vs/base/common/objects';
import { IWorkspaceFolder, IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { isAbsolute, join } from 'vs/base/common/paths';
J
Joao Moreno 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

type TreeElement = ResourceMarkers | Marker | RelatedInformation;

function createModelIterator(model: MarkersModel): Iterator<ITreeElement<TreeElement>> {
	const resourcesIt = Iterator.fromArray(model.resourceMarkers);

	return Iterator.map(resourcesIt, m => {
		const markersIt = Iterator.fromArray(m.markers);

		const children = Iterator.map(markersIt, m => {
			const relatedInformationIt = Iterator.from(m.relatedInformation);
			const children = Iterator.map(relatedInformationIt, r => ({ element: r }));

			return { element: m, children };
		});

		return { element: m, children };
	});
}
58 59 60

export class MarkersPanel extends Panel {

S
Sandeep Somavarapu 已提交
61
	private lastSelectedRelativeTop: number = 0;
62
	private currentActiveResource: URI = null;
S
Sandeep Somavarapu 已提交
63

64
	private tree: WorkbenchObjectTree<TreeElement>;
S
Sandeep Somavarapu 已提交
65
	private rangeHighlightDecorations: RangeHighlightDecorations;
66

S
Sandeep Somavarapu 已提交
67 68
	private actions: IAction[];
	private collapseAllAction: IAction;
S
Sandeep Somavarapu 已提交
69
	private filterAction: MarkersFilterAction;
70
	private filterInputActionItem: MarkersFilterActionItem;
S
Sandeep Somavarapu 已提交
71

S
Sandeep Somavarapu 已提交
72
	private treeContainer: HTMLElement;
S
Sandeep Somavarapu 已提交
73
	private messageBoxContainer: HTMLElement;
S
Sandeep Somavarapu 已提交
74
	private ariaLabelElement: HTMLElement;
S
Sandeep Somavarapu 已提交
75
	private panelSettings: any;
S
Sandeep Somavarapu 已提交
76
	private panelFoucusContextKey: IContextKey<boolean>;
S
Sandeep Somavarapu 已提交
77

J
Joao Moreno 已提交
78 79
	private filter: Viewer.Filter;

80
	private currentResourceGotAddedToMarkersData: boolean = false;
81

82 83
	constructor(
		@IInstantiationService private instantiationService: IInstantiationService,
84
		@IEditorService private editorService: IEditorService,
S
Sandeep Somavarapu 已提交
85
		@IConfigurationService private configurationService: IConfigurationService,
86
		@ITelemetryService telemetryService: ITelemetryService,
S
Sandeep Somavarapu 已提交
87
		@IThemeService themeService: IThemeService,
S
Sandeep Somavarapu 已提交
88 89
		@IMarkersWorkbenchService private markersWorkbenchService: IMarkersWorkbenchService,
		@IStorageService storageService: IStorageService,
J
Joao Moreno 已提交
90 91
		@IContextKeyService contextKeyService: IContextKeyService,
		@IWorkspaceContextService private workspaceContextService: IWorkspaceContextService,
92
	) {
B
Benjamin Pasero 已提交
93
		super(Constants.MARKERS_PANEL_ID, telemetryService, themeService);
S
Sandeep Somavarapu 已提交
94
		this.panelFoucusContextKey = Constants.MarkerPanelFocusContextKey.bindTo(contextKeyService);
S
Sandeep Somavarapu 已提交
95
		this.panelSettings = this.getMemento(storageService, Scope.WORKSPACE);
S
Sandeep Somavarapu 已提交
96
		this.setCurrentActiveEditor();
97 98
	}

S
Sandeep Somavarapu 已提交
99
	public create(parent: HTMLElement): Promise<void> {
100
		super.create(parent);
101

B
Benjamin Pasero 已提交
102
		this.rangeHighlightDecorations = this._register(this.instantiationService.createInstance(RangeHighlightDecorations));
S
Sandeep Somavarapu 已提交
103

104
		dom.addClass(parent, 'markers-panel');
105

S
Sandeep Somavarapu 已提交
106
		const container = dom.append(parent, dom.$('.markers-panel-container'));
S
Sandeep Somavarapu 已提交
107

S
Sandeep Somavarapu 已提交
108
		this.createArialLabelElement(container);
109
		this.createMessageBox(container);
S
Sandeep Somavarapu 已提交
110
		this.createTree(container);
S
Sandeep Somavarapu 已提交
111
		this.createActions();
112
		this.createListeners();
113

J
Joao Moreno 已提交
114
		this.updateFilter();
S
Sandeep Somavarapu 已提交
115

S
Sandeep Somavarapu 已提交
116 117 118
		this.onDidFocus(() => this.panelFoucusContextKey.set(true));
		this.onDidBlur(() => this.panelFoucusContextKey.set(false));

J
Joao Moreno 已提交
119 120 121
		this.render();

		return Promise.resolve(null);
122 123
	}

S
Sandeep Somavarapu 已提交
124
	public getTitle(): string {
B
Benjamin Pasero 已提交
125
		return Messages.MARKERS_PANEL_TITLE_PROBLEMS;
S
Sandeep Somavarapu 已提交
126 127
	}

128
	public layout(dimension: dom.Dimension): void {
S
Sandeep Somavarapu 已提交
129
		this.treeContainer.style.height = `${dimension.height}px`;
J
Joao Moreno 已提交
130
		this.tree.layout(dimension.height);
S
Sandeep Somavarapu 已提交
131 132 133
		if (this.filterInputActionItem) {
			this.filterInputActionItem.toggleLayout(dimension.width < 1200);
		}
134 135
	}

S
Sandeep Somavarapu 已提交
136
	public focus(): void {
J
Joao Moreno 已提交
137
		if (this.tree.getHTMLElement() === document.activeElement) {
138 139 140
			return;
		}

J
Joao Moreno 已提交
141
		this.tree.getHTMLElement().focus();
142 143 144 145 146 147 148 149 150 151 152 153

		// TODO@joao
		// if (this.markersWorkbenchService.markersModel.hasFilteredResources()) {
		// 	this.tree.domFocus();
		// 	if (this.tree.getSelection().length === 0) {
		// 		this.tree.focusFirst();
		// 	}
		// 	this.highlightCurrentSelectedMarkerRange();
		// 	this.autoReveal(true);
		// } else {
		// 	this.messageBoxContainer.focus();
		// }
S
Sandeep Somavarapu 已提交
154 155
	}

S
Sandeep Somavarapu 已提交
156 157 158 159 160 161
	public focusFilter(): void {
		if (this.filterInputActionItem) {
			this.filterInputActionItem.focus();
		}
	}

S
Sandeep Somavarapu 已提交
162
	public setVisible(visible: boolean): Promise<void> {
S
Sandeep Somavarapu 已提交
163 164 165 166 167 168 169 170 171 172 173
		const wasVisible = this.isVisible();
		return super.setVisible(visible)
			.then(() => {
				if (this.isVisible()) {
					if (!wasVisible) {
						this.refreshPanel();
					}
				} else {
					this.rangeHighlightDecorations.removeHighlightRange();
				}
			});
S
Sandeep Somavarapu 已提交
174 175
	}

S
Sandeep Somavarapu 已提交
176
	public getActions(): IAction[] {
S
Sandeep Somavarapu 已提交
177
		if (!this.actions) {
S
Sandeep Somavarapu 已提交
178
			this.createActions();
S
Sandeep Somavarapu 已提交
179
		}
S
Sandeep Somavarapu 已提交
180 181 182
		return this.actions;
	}

S
Sandeep Somavarapu 已提交
183
	public openFileAtElement(element: any, preserveFocus: boolean, sideByside: boolean, pinned: boolean): boolean {
184
		const { resource, selection } = element instanceof Marker ? { resource: element.resource, selection: element.range } :
185
			element instanceof RelatedInformation ? { resource: element.raw.resource, selection: element.raw } : { resource: null, selection: null };
186
		if (resource && selection) {
S
Sandeep Somavarapu 已提交
187
			this.editorService.openEditor({
188
				resource,
S
Sandeep Somavarapu 已提交
189
				options: {
190
					selection,
S
Sandeep Somavarapu 已提交
191 192
					preserveFocus,
					pinned,
193
					revealIfVisible: true
S
Sandeep Somavarapu 已提交
194
				},
195
			}, sideByside ? SIDE_GROUP : ACTIVE_GROUP).then(editor => {
S
Sandeep Somavarapu 已提交
196
				if (editor && preserveFocus) {
197
					this.rangeHighlightDecorations.highlightRange({ resource, range: selection }, <ICodeEditor>editor.getControl());
S
Sandeep Somavarapu 已提交
198 199 200
				} else {
					this.rangeHighlightDecorations.removeHighlightRange();
				}
201
			});
S
Sandeep Somavarapu 已提交
202 203 204 205 206 207 208
			return true;
		} else {
			this.rangeHighlightDecorations.removeHighlightRange();
		}
		return false;
	}

209
	// TODO@joao
B
Benjamin Pasero 已提交
210
	private refreshPanel(): TPromise<any> {
S
Sandeep Somavarapu 已提交
211
		if (this.isVisible()) {
212 213
			this.collapseAllAction.enabled = true /* this.markersWorkbenchService.markersModel.hasFilteredResources() */;
			dom.toggleClass(this.treeContainer, 'hidden', false/* !this.markersWorkbenchService.markersModel.hasFilteredResources() */);
S
Sandeep Somavarapu 已提交
214
			this.renderMessage();
215
			// if (this.markersWorkbenchService.markersModel.hasFilteredResources()) {
J
Joao Moreno 已提交
216
			this.tree.setChildren(null, createModelIterator(this.markersWorkbenchService.markersModel));
217
			// }
S
Sandeep Somavarapu 已提交
218 219
		}
		return TPromise.as(null);
220 221
	}

J
Joao Moreno 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
	private updateFilter() {
		const excludeExpression = this.getExcludeExpression(this.filterAction.useFilesExclude);
		this.filter.options = new FilterOptions(this.filterAction.filterText, excludeExpression);
		this.tree.refilter();
	}

	private getExcludeExpression(useFilesExclude: boolean): IExpression {
		if (!useFilesExclude) {
			return {};
		}

		const workspaceFolders = this.workspaceContextService.getWorkspace().folders;
		if (workspaceFolders.length) {
			const result = getEmptyExpression();
			for (const workspaceFolder of workspaceFolders) {
				mixin(result, this.getExcludesForFolder(workspaceFolder));
			}
			return result;
		} else {
			return this.getFilesExclude();
		}
	}

	private getExcludesForFolder(workspaceFolder: IWorkspaceFolder): IExpression {
		const expression = this.getFilesExclude(workspaceFolder.uri);
		return this.getAbsoluteExpression(expression, workspaceFolder.uri.fsPath);
	}

	private getFilesExclude(resource?: URI): IExpression {
		return deepClone(this.configurationService.getValue('files.exclude', { resource })) || {};
	}

	private getAbsoluteExpression(expr: IExpression, root: string): IExpression {
		return Object.keys(expr)
			.reduce((absExpr: IExpression, key: string) => {
				if (expr[key] && !isAbsolute(key)) {
					const absPattern = join(root, key);
					absExpr[absPattern] = expr[key];
				}

				return absExpr;
			}, Object.create(null));
	}
S
Sandeep Somavarapu 已提交
265

S
Sandeep Somavarapu 已提交
266
	private createMessageBox(parent: HTMLElement): void {
J
Joao Moreno 已提交
267
		this.messageBoxContainer = dom.append(parent, dom.$('.message-box-container'));
S
Sandeep Somavarapu 已提交
268 269 270 271 272 273 274
		this.messageBoxContainer.setAttribute('aria-labelledby', 'markers-panel-arialabel');
	}

	private createArialLabelElement(parent: HTMLElement): void {
		this.ariaLabelElement = dom.append(parent, dom.$(''));
		this.ariaLabelElement.setAttribute('id', 'markers-panel-arialabel');
		this.ariaLabelElement.setAttribute('aria-live', 'polite');
S
Sandeep Somavarapu 已提交
275 276
	}

J
Joao Moreno 已提交
277
	// TODO@joao
S
Sandeep Somavarapu 已提交
278
	private createTree(parent: HTMLElement): void {
S
Sandeep Somavarapu 已提交
279
		this.treeContainer = dom.append(parent, dom.$('.tree-container.show-file-icons'));
J
Joao Moreno 已提交
280 281 282 283 284 285 286 287 288 289
		// const dnd = this.instantiationService.createInstance(SimpleFileResourceDragAndDrop, obj => obj instanceof ResourceMarkers ? obj.resource : void 0);
		// const controller = this.instantiationService.createInstance(Controller, () => this.focusFilter());

		const virtualDelegate = new Viewer.VirtualDelegate();
		const renderers = [
			this.instantiationService.createInstance(Viewer.FileResourceMarkersRenderer),
			this.instantiationService.createInstance(Viewer.ResourceMarkersRenderer),
			this.instantiationService.createInstance(Viewer.MarkerRenderer, a => this.getActionItem(a)),
			this.instantiationService.createInstance(Viewer.RelatedInformationRenderer)
		];
J
Joao Moreno 已提交
290
		this.filter = new Viewer.Filter();
J
Joao Moreno 已提交
291

292
		this.tree = this.instantiationService.createInstance(WorkbenchObjectTree,
J
Joao Moreno 已提交
293 294
			this.treeContainer,
			virtualDelegate,
295
			renderers,
J
Joao Moreno 已提交
296 297 298
			{
				filter: this.filter
			}
299
		) as any as WorkbenchObjectTree<TreeElement>;
J
Joao Moreno 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327

		// this.tree = this.instantiationService.createInstance(WorkbenchTree, this.treeContainer, {
		// 	dataSource: new Viewer.DataSource(),
		// 	renderer,
		// 	controller,
		// 	accessibilityProvider: this.instantiationService.createInstance(Viewer.MarkersTreeAccessibilityProvider),
		// 	dnd
		// }, {
		// 		twistiePixels: 20,
		// 		ariaLabel: Messages.MARKERS_PANEL_ARIA_LABEL_PROBLEMS_TREE
		// 	});

		// const markerFocusContextKey = Constants.MarkerFocusContextKey.bindTo(this.tree.contextKeyService);
		// const relatedInformationFocusContextKey = Constants.RelatedInformationFocusContextKey.bindTo(this.tree.contextKeyService);
		// this._register(this.tree.onDidChangeFocus(elements => {
		// 	markerFocusContextKey.set(elements.some(e => e instanceof Marker));
		// 	relatedInformationFocusContextKey.set(elements.some(e => e instanceof RelatedInformation));
		// }));
		// const focusTracker = this._register(dom.trackFocus(this.tree.getHTMLElement()));
		// this._register(focusTracker.onDidBlur(() => {
		// 	markerFocusContextKey.set(false);
		// 	relatedInformationFocusContextKey.set(false);
		// }));

		// const markersNavigator = this._register(new TreeResourceNavigator(this.tree, { openOnFocus: true }));
		// this._register(debounceEvent(markersNavigator.openResource, (last, event) => event, 75, true)(options => {
		// 	this.openFileAtElement(options.element, options.editorOptions.preserveFocus, options.sideBySide, options.editorOptions.pinned);
		// }));
S
Sandeep Somavarapu 已提交
328 329
	}

J
Joao Moreno 已提交
330
	// TODO@joao
S
Sandeep Somavarapu 已提交
331
	private createActions(): void {
J
Joao Moreno 已提交
332 333 334 335 336 337 338 339
		this.collapseAllAction = new Action('vs.tree.collapse', localize('collapse', "Collapse"), 'monaco-tree-action collapse-all', true, async () => {
			// this.tree.collapseAll();
			this.tree.setSelection([]);
			this.tree.setFocus([]);
			this.tree.getHTMLElement().focus();
			this.tree.focusFirst();
		});

S
Sandeep Somavarapu 已提交
340 341
		this.filterAction = this.instantiationService.createInstance(MarkersFilterAction, { filterText: this.panelSettings['filter'] || '', filterHistory: this.panelSettings['filterHistory'] || [], useFilesExclude: !!this.panelSettings['useFilesExclude'] });
		this.actions = [this.filterAction, this.collapseAllAction];
S
Sandeep Somavarapu 已提交
342 343
	}

344
	private createListeners(): void {
J
Joao Moreno 已提交
345 346 347
		const onModelChange = debounceEvent<URI, URI[]>(this.markersWorkbenchService.markersModel.onDidChange, (uris, uri) => { if (!uris) { uris = []; } uris.push(uri); return uris; }, 0);

		this._register(onModelChange(this.onDidChangeModel, this));
B
Benjamin Pasero 已提交
348 349
		this._register(this.editorService.onDidActiveEditorChange(this.onActiveEditorChanged, this));
		this._register(this.tree.onDidChangeSelection(() => this.onSelected()));
J
Joao Moreno 已提交
350 351 352 353 354
		this._register(this.filterAction.onDidChange((event: IMarkersFilterActionChangeEvent) => {
			if (event.filterText || event.useFilesExclude) {
				this.updateFilter();
			}
		}));
B
Benjamin Pasero 已提交
355
		this.actions.forEach(a => this._register(a));
356 357
	}

J
Joao Moreno 已提交
358
	private onDidChangeModel(resources: URI[]) {
S
Sandeep Somavarapu 已提交
359
		this.currentResourceGotAddedToMarkersData = this.currentResourceGotAddedToMarkersData || this.isCurrentResourceGotAddedToMarkersData(resources);
J
Joao Moreno 已提交
360 361 362 363 364 365
		this.refreshPanel();
		this.updateRangeHighlights();
		if (this.currentResourceGotAddedToMarkersData) {
			this.autoReveal();
			this.currentResourceGotAddedToMarkersData = false;
		}
S
Sandeep Somavarapu 已提交
366 367
	}

368 369
	private isCurrentResourceGotAddedToMarkersData(changedResources: URI[]) {
		if (!this.currentActiveResource) {
S
Sandeep Somavarapu 已提交
370 371
			return false;
		}
372 373
		const resourceForCurrentActiveResource = this.getResourceForCurrentActiveResource();
		if (resourceForCurrentActiveResource) {
S
Sandeep Somavarapu 已提交
374 375
			return false;
		}
376
		return changedResources.some(r => r.toString() === this.currentActiveResource.toString());
S
Sandeep Somavarapu 已提交
377 378
	}

B
Benjamin Pasero 已提交
379
	private onActiveEditorChanged(): void {
S
Sandeep Somavarapu 已提交
380 381 382 383 384
		this.setCurrentActiveEditor();
		this.autoReveal();
	}

	private setCurrentActiveEditor(): void {
B
Benjamin Pasero 已提交
385 386
		const activeEditor = this.editorService.activeEditor;
		this.currentActiveResource = activeEditor ? activeEditor.getResource() : void 0;
S
Sandeep Somavarapu 已提交
387 388
	}

389
	private onSelected(): void {
S
Sandeep Somavarapu 已提交
390
		let selection = this.tree.getSelection();
391
		if (selection && selection.length > 0) {
S
Sandeep Somavarapu 已提交
392
			this.lastSelectedRelativeTop = this.tree.getRelativeTop(selection[0]);
393 394 395
		}
	}

396
	// TODO@joao
J
Joao Moreno 已提交
397
	private render(): void {
398
		dom.toggleClass(this.treeContainer, 'hidden', false/* !this.markersWorkbenchService.markersModel.hasFilteredResources() */);
J
Joao Moreno 已提交
399
		this.tree.setChildren(null, createModelIterator(this.markersWorkbenchService.markersModel));
S
Sandeep Somavarapu 已提交
400
		this.renderMessage();
S
Sandeep Somavarapu 已提交
401 402
	}

403
	// TODO@joao
S
Sandeep Somavarapu 已提交
404
	private renderMessage(): void {
405
		dom.clearNode(this.messageBoxContainer);
S
Sandeep Somavarapu 已提交
406
		const markersModel = this.markersWorkbenchService.markersModel;
407 408 409 410 411
		// if (markersModel.hasFilteredResources()) {
		this.messageBoxContainer.style.display = 'none';
		const { total, filtered } = markersModel.stats();
		if (filtered === total) {
			this.ariaLabelElement.setAttribute('aria-label', localize('No problems filtered', "Showing {0} problems", total));
S
Sandeep Somavarapu 已提交
412
		} else {
413
			this.ariaLabelElement.setAttribute('aria-label', localize('problems filtered', "Showing {0} of {1} problems", filtered, total));
S
Sandeep Somavarapu 已提交
414
		}
415 416 417 418 419 420 421 422 423 424 425 426 427 428
		this.messageBoxContainer.removeAttribute('tabIndex');
		// } else {
		// 	this.messageBoxContainer.style.display = 'block';
		// 	this.messageBoxContainer.setAttribute('tabIndex', '0');
		// 	if (markersModel.hasResources()) {
		// 		if (markersModel.filterOptions.filter) {
		// 			this.renderFilteredByFilterMessage(this.messageBoxContainer);
		// 		} else {
		// 			this.renderFilteredByFilesExcludeMessage(this.messageBoxContainer);
		// 		}
		// 	} else {
		// 		this.renderNoProblemsMessage(this.messageBoxContainer);
		// 	}
		// }
429 430
	}

431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
	// private renderFilteredByFilesExcludeMessage(container: HTMLElement) {
	// 	const span1 = dom.append(container, dom.$('span'));
	// 	span1.textContent = Messages.MARKERS_PANEL_NO_PROBLEMS_FILE_EXCLUSIONS_FILTER;
	// 	const link = dom.append(container, dom.$('a.messageAction'));
	// 	link.textContent = localize('disableFilesExclude', "Disable Files Exclude Filter.");
	// 	link.setAttribute('tabIndex', '0');
	// 	dom.addStandardDisposableListener(link, dom.EventType.CLICK, () => this.filterAction.useFilesExclude = false);
	// 	dom.addStandardDisposableListener(link, dom.EventType.KEY_DOWN, (e: IKeyboardEvent) => {
	// 		if (e.equals(KeyCode.Enter) || e.equals(KeyCode.Space)) {
	// 			this.filterAction.useFilesExclude = false;
	// 			e.stopPropagation();
	// 		}
	// 	});
	// 	this.ariaLabelElement.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_FILE_EXCLUSIONS_FILTER);
	// }

	// private renderFilteredByFilterMessage(container: HTMLElement) {
	// 	const span1 = dom.append(container, dom.$('span'));
	// 	span1.textContent = Messages.MARKERS_PANEL_NO_PROBLEMS_FILTERS;
	// 	const link = dom.append(container, dom.$('a.messageAction'));
	// 	link.textContent = localize('clearFilter', "Clear Filter.");
	// 	link.setAttribute('tabIndex', '0');
	// 	dom.addStandardDisposableListener(link, dom.EventType.CLICK, () => this.filterAction.filterText = '');
	// 	dom.addStandardDisposableListener(link, dom.EventType.KEY_DOWN, (e: IKeyboardEvent) => {
	// 		if (e.equals(KeyCode.Enter) || e.equals(KeyCode.Space)) {
	// 			this.filterAction.filterText = '';
	// 			e.stopPropagation();
	// 		}
	// 	});
	// 	this.ariaLabelElement.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_FILTERS);
	// }

	// private renderNoProblemsMessage(container: HTMLElement) {
	// 	const span = dom.append(container, dom.$('span'));
	// 	span.textContent = Messages.MARKERS_PANEL_NO_PROBLEMS_BUILT;
	// 	this.ariaLabelElement.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_BUILT);
	// }
S
Sandeep Somavarapu 已提交
468

S
Sandeep Somavarapu 已提交
469
	private autoReveal(focus: boolean = false): void {
470 471
		let autoReveal = this.configurationService.getValue<boolean>('problems.autoReveal');
		if (typeof autoReveal === 'boolean' && autoReveal) {
472
			this.revealMarkersForCurrentActiveEditor(focus);
473 474 475
		}
	}

S
Sandeep Somavarapu 已提交
476
	private revealMarkersForCurrentActiveEditor(focus: boolean = false): void {
477
		let currentActiveResource = this.getResourceForCurrentActiveResource();
478 479 480 481
		if (currentActiveResource) {
			if (this.tree.isExpanded(currentActiveResource) && this.hasSelectedMarkerFor(currentActiveResource)) {
				this.tree.reveal(this.tree.getSelection()[0], this.lastSelectedRelativeTop);
				if (focus) {
J
Joao Moreno 已提交
482
					this.tree.setFocus(this.tree.getSelection());
483 484
				}
			} else {
J
Joao Moreno 已提交
485 486 487 488 489 490 491
				this.tree.expand(currentActiveResource);
				this.tree.reveal(currentActiveResource, 0);

				if (focus) {
					this.tree.setFocus([currentActiveResource]);
					this.tree.setSelection([currentActiveResource]);
				}
492
			}
S
Sandeep Somavarapu 已提交
493 494 495
		} else if (focus) {
			this.tree.setSelection([]);
			this.tree.focusFirst();
496 497 498
		}
	}

499
	private getResourceForCurrentActiveResource(): ResourceMarkers | null {
J
Joao Moreno 已提交
500
		return this.currentActiveResource ? this.markersWorkbenchService.markersModel.getResourceMarkers(this.currentActiveResource) : null;
S
Sandeep Somavarapu 已提交
501 502
	}

503
	private hasSelectedMarkerFor(resource: ResourceMarkers): boolean {
S
Sandeep Somavarapu 已提交
504 505 506
		let selectedElement = this.tree.getSelection();
		if (selectedElement && selectedElement.length > 0) {
			if (selectedElement[0] instanceof Marker) {
J
Joao Moreno 已提交
507
				if (resource.resource.toString() === (<Marker>selectedElement[0]).marker.resource.toString()) {
S
Sandeep Somavarapu 已提交
508 509 510 511 512 513 514
					return true;
				}
			}
		}
		return false;
	}

S
Sandeep Somavarapu 已提交
515
	private updateRangeHighlights() {
516
		this.rangeHighlightDecorations.removeHighlightRange();
J
Joao Moreno 已提交
517
		if (this.tree.getHTMLElement() === document.activeElement) {
S
Sandeep Somavarapu 已提交
518 519 520 521 522
			this.highlightCurrentSelectedMarkerRange();
		}
	}

	private highlightCurrentSelectedMarkerRange() {
J
Joao Moreno 已提交
523 524 525 526
		const selections = this.tree.getSelection();

		if (selections.length !== 1) {
			return;
S
Sandeep Somavarapu 已提交
527
		}
J
Joao Moreno 已提交
528 529 530 531 532 533 534 535

		const selection = selections[0];

		if (!(selection instanceof Marker)) {
			return;
		}

		this.rangeHighlightDecorations.highlightRange(selection);
S
Sandeep Somavarapu 已提交
536 537
	}

J
Joao Moreno 已提交
538 539
	public getFocusElement(): ResourceMarkers | Marker | RelatedInformation {
		return this.tree.getFocus()[0];
S
Sandeep Somavarapu 已提交
540 541 542
	}

	public getActionItem(action: IAction): IActionItem {
543
		if (action.id === MarkersFilterAction.ID) {
S
Sandeep Somavarapu 已提交
544
			this.filterInputActionItem = this.instantiationService.createInstance(MarkersFilterActionItem, this.filterAction);
S
Sandeep Somavarapu 已提交
545
			return this.filterInputActionItem;
546
		}
S
Sandeep Somavarapu 已提交
547 548 549
		if (action.id === QuickFixAction.ID) {
			return this.instantiationService.createInstance(QuickFixActionItem, action);
		}
550
		return super.getActionItem(action);
S
Sandeep Somavarapu 已提交
551 552
	}

S
Sandeep Somavarapu 已提交
553 554
	public shutdown(): void {
		// store memento
S
Sandeep Somavarapu 已提交
555 556 557
		this.panelSettings['filter'] = this.filterAction.filterText;
		this.panelSettings['filterHistory'] = this.filterAction.filterHistory;
		this.panelSettings['useFilesExclude'] = this.filterAction.useFilesExclude;
S
Sandeep Somavarapu 已提交
558 559

		super.shutdown();
560 561
	}

562
	public dispose(): void {
B
Benjamin Pasero 已提交
563
		super.dispose();
564
		this.tree.dispose();
565
	}
566
}