markersPanelActions.ts 6.1 KB
Newer Older
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import { Delayer } from 'vs/base/common/async';
7 8
import * as DOM from 'vs/base/browser/dom';
import * as lifecycle from 'vs/base/common/lifecycle';
S
Sandeep Somavarapu 已提交
9
import { TPromise } from 'vs/base/common/winjs.base';
10 11 12
import { IAction, Action } from 'vs/base/common/actions';
import { BaseActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox';
A
Alexandru Dima 已提交
13
import { KeyCode } from 'vs/base/common/keyCodes';
J
Johannes Rieken 已提交
14 15
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
16
import { TogglePanelAction } from 'vs/workbench/browser/panel';
17 18 19
import Messages from 'vs/workbench/parts/markers/electron-browser/messages';
import Constants from 'vs/workbench/parts/markers/electron-browser/constants';
import { MarkersPanel } from 'vs/workbench/parts/markers/electron-browser/markersPanel';
20
import { IPartService } from 'vs/workbench/services/part/common/partService';
21
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
22
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
S
Sandeep Somavarapu 已提交
23
import { CollapseAllAction as TreeCollapseAction } from 'vs/base/parts/tree/browser/treeDefaults';
24
import Tree = require('vs/base/parts/tree/browser/tree');
B
Benjamin Pasero 已提交
25 26
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
27
import { IMarkersWorkbenchService } from 'vs/workbench/parts/markers/electron-browser/markers';
28

29
export class ToggleMarkersPanelAction extends TogglePanelAction {
30

M
Matt Bierner 已提交
31 32
	public static readonly ID = 'workbench.actions.view.problems';
	public static readonly LABEL = Messages.MARKERS_PANEL_TOGGLE_LABEL;
33

34
	constructor(id: string, label: string,
35
		@IPartService partService: IPartService,
36
		@IPanelService panelService: IPanelService,
37
	) {
38
		super(id, label, Constants.MARKERS_PANEL_ID, panelService, partService);
39 40 41
	}
}

S
Sandeep Somavarapu 已提交
42 43
export class ShowProblemsPanelAction extends Action {

M
Matt Bierner 已提交
44 45
	public static readonly ID = 'workbench.action.problems.focus';
	public static readonly LABEL = Messages.MARKERS_PANEL_SHOW_LABEL;
S
Sandeep Somavarapu 已提交
46 47

	constructor(id: string, label: string,
K
kieferrm 已提交
48
		@IPanelService private panelService: IPanelService
S
Sandeep Somavarapu 已提交
49 50 51 52 53 54 55 56 57
	) {
		super(id, label);
	}

	public run(): TPromise<any> {
		return this.panelService.openPanel(Constants.MARKERS_PANEL_ID, true);
	}
}

S
Sandeep Somavarapu 已提交
58 59
export class CollapseAllAction extends TreeCollapseAction {

K
kieferrm 已提交
60
	constructor(viewer: Tree.ITree, enabled: boolean) {
S
Sandeep Somavarapu 已提交
61 62
		super(viewer, enabled);
	}
63
}
64 65 66

export class FilterAction extends Action {

M
Matt Bierner 已提交
67
	public static readonly ID: string = 'workbench.actions.problems.filter';
S
Sandeep Somavarapu 已提交
68

S
Sandeep Somavarapu 已提交
69
	constructor() {
S
Sandeep Somavarapu 已提交
70
		super(FilterAction.ID, Messages.MARKERS_PANEL_ACTION_TOOLTIP_FILTER, 'markers-panel-action-filter', true);
71 72 73 74 75 76 77 78
	}

}

export class FilterInputBoxActionItem extends BaseActionItem {

	protected toDispose: lifecycle.IDisposable[];

79
	private delayedFilterUpdate: Delayer<void>;
80

81
	constructor(private markersPanel: MarkersPanel, action: IAction,
J
Johannes Rieken 已提交
82
		@IContextViewService private contextViewService: IContextViewService,
B
Benjamin Pasero 已提交
83
		@IThemeService private themeService: IThemeService,
S
Sandeep Somavarapu 已提交
84
		@IMarkersWorkbenchService private markersWorkbenchService: IMarkersWorkbenchService,
J
Johannes Rieken 已提交
85
		@ITelemetryService private telemetryService: ITelemetryService) {
86 87
		super(markersPanel, action);
		this.toDispose = [];
J
Johannes Rieken 已提交
88
		this.delayedFilterUpdate = new Delayer<void>(500);
89 90 91 92
	}

	public render(container: HTMLElement): void {
		DOM.addClass(container, 'markers-panel-action-filter');
93
		let filterInputBox = new InputBox(container, this.contextViewService, {
94
			placeholder: Messages.MARKERS_PANEL_FILTER_PLACEHOLDER,
95
			ariaLabel: Messages.MARKERS_PANEL_FILTER_PLACEHOLDER
96
		});
B
Benjamin Pasero 已提交
97
		this.toDispose.push(attachInputBoxStyler(filterInputBox, this.themeService));
S
Sandeep Somavarapu 已提交
98
		filterInputBox.value = this.markersWorkbenchService.markersModel.filterOptions.completeFilter;
99
		this.toDispose.push(filterInputBox.onDidChange(filter => this.delayedFilterUpdate.trigger(() => this.updateFilter(filter))));
S
Sandeep Somavarapu 已提交
100
		this.toDispose.push(DOM.addStandardDisposableListener(filterInputBox.inputElement, 'keyup', (keyboardEvent) => this.onInputKeyUp(keyboardEvent, filterInputBox)));
101 102
		this.toDispose.push(DOM.addStandardDisposableListener(container, 'keydown', this.handleKeyboardEvent));
		this.toDispose.push(DOM.addStandardDisposableListener(container, 'keyup', this.handleKeyboardEvent));
103 104
	}

S
Sandeep Somavarapu 已提交
105
	private updateFilter(filter: string) {
S
Sandeep Somavarapu 已提交
106
		this.markersPanel.updateFilter(filter);
107
		this.reportFilteringUsed();
S
Sandeep Somavarapu 已提交
108 109
	}

110
	private reportFilteringUsed(): void {
J
Johannes Rieken 已提交
111
		let data = {};
S
Sandeep Somavarapu 已提交
112 113 114
		data['errors'] = this.markersWorkbenchService.markersModel.filterOptions.filterErrors;
		data['warnings'] = this.markersWorkbenchService.markersModel.filterOptions.filterWarnings;
		data['infos'] = this.markersWorkbenchService.markersModel.filterOptions.filterInfos;
K
kieferrm 已提交
115
		/* __GDPR__
K
kieferrm 已提交
116
			"problems.filter" : {
K
kieferrm 已提交
117 118 119
				"errors" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
				"warnings": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
				"infos": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
K
kieferrm 已提交
120 121
			}
		*/
S
Sandeep Somavarapu 已提交
122
		this.telemetryService.publicLog('problems.filter', data);
123 124
	}

125 126 127 128 129 130 131 132
	public dispose(): void {
		this.toDispose = lifecycle.dispose(this.toDispose);
		super.dispose();
	}

	// Action toolbar is swallowing some keys for action items which should not be for an input box
	private handleKeyboardEvent(e: IKeyboardEvent) {
		switch (e.keyCode) {
A
Alexandru Dima 已提交
133 134 135 136
			case KeyCode.Space:
			case KeyCode.LeftArrow:
			case KeyCode.RightArrow:
			case KeyCode.Escape:
137 138 139 140
				e.stopPropagation();
				break;
		}
	}
S
Sandeep Somavarapu 已提交
141

J
Johannes Rieken 已提交
142
	private onInputKeyUp(keyboardEvent: IKeyboardEvent, filterInputBox: InputBox) {
S
Sandeep Somavarapu 已提交
143 144
		switch (keyboardEvent.keyCode) {
			case KeyCode.Escape:
J
Johannes Rieken 已提交
145
				filterInputBox.value = '';
S
Sandeep Somavarapu 已提交
146 147 148 149 150
				return;
			default:
				return;
		}
	}
151
}