Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 114aa26

Browse files
committed
simplify direction toggle
1 parent b265a66 commit 114aa26

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
{
6565
"id": "calls-view.tree",
66-
"name": "Calls",
66+
"name": "Call Hierarchy",
6767
"when": "calls-view.isActive"
6868
}
6969
]
@@ -202,17 +202,17 @@
202202
},
203203
{
204204
"command": "calls-view.show.outgoing",
205-
"group": "navigation",
205+
"group": "navigation@1",
206206
"when": "view == calls-view.tree && calls-view.mode == showIncoming"
207207
},
208208
{
209209
"command": "calls-view.show.incoming",
210-
"group": "navigation",
210+
"group": "navigation@1",
211211
"when": "view == calls-view.tree && calls-view.mode == showOutgoing"
212212
},
213213
{
214214
"command": "calls-view.clear",
215-
"group": "navigation",
215+
"group": "navigation@2",
216216
"when": "view == calls-view.tree && calls-view.hasResults"
217217
}
218218
],

src/calls/index.ts

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,35 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import { CallsDirection, CallsModel } from './model';
78
import { DataProvider } from './provider';
8-
import { CallsModel, CallsDirection } from './model';
99

1010
export function register(disposables: vscode.Disposable[]) {
1111

1212
const viewId = 'calls-view.tree';
1313
const provider = new DataProvider();
1414

15-
const view = vscode.window.createTreeView(viewId, {
16-
treeDataProvider: provider,
17-
showCollapseAll: true
18-
});
19-
15+
const view = vscode.window.createTreeView(viewId, { treeDataProvider: provider });
2016

2117
let callsDirection = CallsDirection.Outgoing;
2218
vscode.commands.executeCommand('setContext', 'calls-view.mode', 'showOutgoing');
2319

24-
const setDirectionToOutgoing = () => {
25-
if (callsDirection !== CallsDirection.Outgoing) {
26-
callsDirection = CallsDirection.Outgoing;
27-
vscode.commands.executeCommand('setContext', 'calls-view.mode', 'showOutgoing');
28-
refresh();
29-
}
30-
}
31-
32-
const setDirectionToIncoming = () => {
33-
if (callsDirection !== CallsDirection.Incoming) {
34-
callsDirection = CallsDirection.Incoming;
35-
vscode.commands.executeCommand('setContext', 'calls-view.mode', 'showIncoming');
36-
refresh();
37-
}
38-
}
39-
40-
const refresh = () => {
41-
const { model } = provider;
42-
if (model) {
43-
updateModel(model.changeDirection());
44-
} else {
45-
showCallHierarchy();
20+
const setModeCommand = (direction: CallsDirection) => {
21+
if (callsDirection !== direction) {
22+
callsDirection = direction;
23+
vscode.commands.executeCommand('setContext', 'calls-view.mode', direction === CallsDirection.Incoming ? 'showIncoming' : 'showOutgoing');
24+
if (provider.model) {
25+
updateModel(provider.model.changeDirection());
26+
} else {
27+
showCommand();
28+
}
4629
}
4730
}
4831

4932
const updateModel = async (model: CallsModel | undefined) => {
5033

5134
vscode.commands.executeCommand('setContext', 'calls-view.hasResults', Boolean(model));
52-
35+
view.message = '';
5336
provider.model = model;
5437
updateTitle();
5538
if (model) {
@@ -61,17 +44,17 @@ export function register(disposables: vscode.Disposable[]) {
6144
const updateTitle = () => {
6245
if (provider.model) {
6346
if (provider.model.direction === CallsDirection.Outgoing) {
64-
view.title = `Calls From`;
47+
view.title = `Call Hierarchy - Calls`;
6548
} else {
66-
view.title = `Callers Of`;
49+
view.title = `Call Hierarchy - Callers`;
6750
}
6851

6952
} else {
70-
view.title = 'Calls'
53+
view.title = 'Call Hierarchy'
7154
}
7255
}
7356

74-
const showCallHierarchy = async (uri?: vscode.Uri, position?: vscode.Position) => {
57+
const showCommand = async (uri?: vscode.Uri, position?: vscode.Position) => {
7558
let model: CallsModel | undefined;
7659
if (uri instanceof vscode.Uri && position instanceof vscode.Position) {
7760
model = new CallsModel(uri, position, callsDirection);
@@ -83,11 +66,16 @@ export function register(disposables: vscode.Disposable[]) {
8366
updateModel(model);
8467
}
8568

69+
const clearCommand = () => {
70+
updateModel(undefined);
71+
view.message = `To populate this view, open an editor and run the 'Show Call Hierarchy'-command.`;
72+
};
73+
8674
disposables.push(
8775
view,
88-
vscode.commands.registerCommand('calls-view.show', showCallHierarchy),
89-
vscode.commands.registerCommand('calls-view.show.outgoing', setDirectionToOutgoing),
90-
vscode.commands.registerCommand('calls-view.show.incoming', setDirectionToIncoming),
91-
vscode.commands.registerCommand('calls-view.clear', () => updateModel(undefined))
76+
vscode.commands.registerCommand('calls-view.show', showCommand),
77+
vscode.commands.registerCommand('calls-view.show.outgoing', () => setModeCommand(CallsDirection.Outgoing)),
78+
vscode.commands.registerCommand('calls-view.show.incoming', () => setModeCommand(CallsDirection.Incoming)),
79+
vscode.commands.registerCommand('calls-view.clear', clearCommand)
9280
);
9381
}

0 commit comments

Comments
 (0)