-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathui.ts
218 lines (184 loc) · 8.03 KB
/
ui.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as vscode from 'vscode';
import { Client } from './client';
let ui: UI;
interface IndexableQuickPickItem extends vscode.QuickPickItem {
index: number;
}
interface KeyedQuickPickItem extends vscode.QuickPickItem {
key: string;
}
export class UI {
private navigationStatusBarItem: vscode.StatusBarItem;
private configStatusBarItem: vscode.StatusBarItem;
private browseEngineStatusBarItem: vscode.StatusBarItem;
private intelliSenseStatusBarItem: vscode.StatusBarItem;
constructor() {
// 1000 = priority, it needs to be high enough to be on the left of the Ln/Col.
this.navigationStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 1000);
this.navigationStatusBarItem.tooltip = "C/C++ Navigation";
this.navigationStatusBarItem.command = "C_Cpp.Navigate";
this.ShowNavigation = true;
this.configStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 2);
this.configStatusBarItem.command = "C_Cpp.ConfigurationSelect";
this.configStatusBarItem.tooltip = "C/C++ Configuration";
this.ShowConfiguration = true;
this.intelliSenseStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 1);
this.intelliSenseStatusBarItem.text = "";
this.intelliSenseStatusBarItem.tooltip = "Updating IntelliSense...";
this.intelliSenseStatusBarItem.color = "Red";
this.ShowFlameIcon = true;
this.browseEngineStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 0);
this.browseEngineStatusBarItem.text = "";
this.browseEngineStatusBarItem.tooltip = "Discovering files...";
this.browseEngineStatusBarItem.color = "White";
this.browseEngineStatusBarItem.command = "C_Cpp.ShowParsingCommands";
this.ShowDBIcon = true;
}
private set NavigationLocation(location: string) {
this.navigationStatusBarItem.text = location;
}
private set ActiveConfig(label: string) {
this.configStatusBarItem.text = label;
}
private set TagParseStatus(label: string) {
this.browseEngineStatusBarItem.tooltip = label;
}
private get IsTagParsing(): boolean {
return this.browseEngineStatusBarItem.text !== "";
}
private set IsTagParsing(val: boolean) {
this.browseEngineStatusBarItem.text = val ? "$(database)" : "";
this.ShowDBIcon = val;
}
private get IsUpdatingIntelliSense(): boolean {
return this.intelliSenseStatusBarItem.text !== "";
}
private set IsUpdatingIntelliSense(val: boolean) {
this.intelliSenseStatusBarItem.text = val ? "$(flame)" : "";
this.ShowFlameIcon = val;
}
private set ShowNavigation(show: boolean) {
if (show) {
this.navigationStatusBarItem.show();
} else {
this.navigationStatusBarItem.hide();
}
}
private set ShowDBIcon(show: boolean) {
if (show && this.IsTagParsing) {
this.browseEngineStatusBarItem.show();
} else {
this.browseEngineStatusBarItem.hide();
}
}
private set ShowFlameIcon(show: boolean) {
if (show && this.IsUpdatingIntelliSense) {
this.intelliSenseStatusBarItem.show();
} else {
this.intelliSenseStatusBarItem.hide();
}
}
private set ShowConfiguration(show: boolean) {
if (show) {
this.configStatusBarItem.show();
} else {
this.configStatusBarItem.hide();
}
}
public activeDocumentChanged(): void {
let activeEditor: vscode.TextEditor = vscode.window.activeTextEditor;
let show: boolean = (activeEditor && (activeEditor.document.languageId === "cpp" || activeEditor.document.languageId === "c"));
this.ShowConfiguration = show;
this.ShowDBIcon = show;
this.ShowFlameIcon = show;
this.ShowNavigation = show;
}
public bind(client: Client): void {
client.TagParsingChanged(value => { this.IsTagParsing = value; });
client.IntelliSenseParsingChanged(value => { this.IsUpdatingIntelliSense = value; });
client.NavigationLocationChanged(value => { this.NavigationLocation = value; });
client.TagParserStatusChanged(value => { this.TagParseStatus = value; });
client.ActiveConfigChanged(value => { this.ActiveConfig = value; });
}
public showNavigationOptions(navigationList: string): void {
let options: vscode.QuickPickOptions = {};
options.placeHolder = "Select where to navigate to";
let items: IndexableQuickPickItem[] = [];
let navlist: string[] = navigationList.split(";");
for (let i: number = 0; i < navlist.length - 1; i += 2) {
items.push({ label: navlist[i], description: "", index: Number(navlist[i + 1]) });
}
vscode.window.showQuickPick(items, options)
.then(selection => {
if (!selection) {
return;
}
vscode.window.activeTextEditor.revealRange(new vscode.Range(selection.index, 0, selection.index, 0), vscode.TextEditorRevealType.InCenter);
vscode.window.activeTextEditor.selection = new vscode.Selection(new vscode.Position(selection.index, 0), new vscode.Position(selection.index, 0));
});
}
public showConfigurations(configurationNames: string[]): Thenable<number> {
let options: vscode.QuickPickOptions = {};
options.placeHolder = "Select a Configuration...";
let items: IndexableQuickPickItem[] = [];
for (let i: number = 0; i < configurationNames.length; i++) {
items.push({ label: configurationNames[i], description: "", index: i });
}
items.push({ label: "Edit Configurations...", description: "", index: configurationNames.length });
return vscode.window.showQuickPick(items, options)
.then(selection => {
if (!selection) {
return -1;
}
return selection.index;
});
}
public showWorkspaces(workspaceNames: { name: string; key: string }[]): Thenable<string> {
let options: vscode.QuickPickOptions = {};
options.placeHolder = "Select a Workspace...";
let items: KeyedQuickPickItem[] = [];
workspaceNames.forEach(name => items.push({ label: name.name, description: "", key: name.key }));
return vscode.window.showQuickPick(items, options)
.then(selection => {
if (!selection) {
return "";
}
return selection.key;
});
}
public showParsingCommands(): Thenable<number> {
let options: vscode.QuickPickOptions = {};
options.placeHolder = "Select a parsing command...";
let items: IndexableQuickPickItem[];
items = [];
if (this.browseEngineStatusBarItem.tooltip === "Parsing paused") {
items.push({ label: "Resume Parsing", description: "", index: 1 });
} else {
items.push({ label: "Pause Parsing", description: "", index: 0 });
}
return vscode.window.showQuickPick(items, options)
.then(selection => {
if (!selection) {
return -1;
}
return selection.index;
});
}
public dispose(): void {
this.configStatusBarItem.dispose();
this.browseEngineStatusBarItem.dispose();
this.intelliSenseStatusBarItem.dispose();
this.navigationStatusBarItem.dispose();
}
}
export function getUI(): UI {
if (ui === undefined) {
ui = new UI();
}
return ui;
}