Skip to content

Commit be32bfa

Browse files
committed
show/hide generated items in Explorer view
1 parent e4b3310 commit be32bfa

File tree

10 files changed

+81
-40
lines changed

10 files changed

+81
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- When virtual filesystem `isfs://` used, now possible to execute some actions from Studio Source class menu
77
- Explorer view, new way of generation, should be faster now
88
- Explorer view, INC files now separate in own Includes folder
9+
- Explorer view, option to show/hide generated items
910

1011
## [0.7.12]
1112

package.json

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,21 @@
149149
},
150150
{
151151
"command": "vscode-objectscript.explorer.otherNamespace",
152-
"when": "view == ObjectScriptExplorer && viewItem == serverNode",
152+
"when": "view == ObjectScriptExplorer && viewItem =~ /^serverNode((?!:extra:).)*$/",
153153
"group": "inline"
154154
},
155155
{
156156
"command": "vscode-objectscript.explorer.otherNamespaceClose",
157-
"when": "view == ObjectScriptExplorer && viewItem =~ /^serverNodeExtra:/",
157+
"when": "view == ObjectScriptExplorer && viewItem =~ /^serverNode:extra:/",
158158
"group": "inline"
159+
},
160+
{
161+
"command": "vscode-objectscript.explorer.showGenerated",
162+
"when": "view == ObjectScriptExplorer && viewItem =~ /^serverNode((?!:generated:).)*$/"
163+
},
164+
{
165+
"command": "vscode-objectscript.explorer.hideGenerated",
166+
"when": "view == ObjectScriptExplorer && viewItem =~ /^serverNode.*:generated:/"
159167
}
160168
],
161169
"editor/context": [
@@ -315,22 +323,32 @@
315323
{
316324
"command": "vscode-objectscript.explorer.export",
317325
"title": "Export",
318-
"category": "ObjecScript"
326+
"category": "ObjectScript"
319327
},
320328
{
321329
"command": "vscode-objectscript.explorer.otherNamespace",
322330
"title": "View another namespace",
323-
"category": "ObjecScript"
331+
"category": "ObjectScript"
332+
},
333+
{
334+
"command": "vscode-objectscript.explorer.showGenerated",
335+
"title": "Show generated",
336+
"category": "ObjectScript"
337+
},
338+
{
339+
"command": "vscode-objectscript.explorer.hideGenerated",
340+
"title": "Hide generated",
341+
"category": "ObjectScript"
324342
},
325343
{
326344
"command": "vscode-objectscript.explorer.otherNamespaceClose",
327345
"title": "Close namespace",
328-
"category": "ObjecScript"
346+
"category": "ObjectScript"
329347
},
330348
{
331349
"command": "vscode-objectscript.explorer.delete",
332350
"title": "Delete",
333-
"category": "ObjecScript"
351+
"category": "ObjectScript"
334352
},
335353
{
336354
"command": "vscode-objectscript.explorer.refresh",

src/explorer/explorer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<Nod
6565
workspaceFolders.forEach(workspaceFolder => {
6666
const conn: any = config("conn", workspaceFolder.name);
6767
if (conn.active && conn.ns) {
68-
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData);
68+
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, {});
6969
rootNodes.push(node);
7070

7171
this._showExtra4Workspace.forEach(ns => {
72-
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, ns);
72+
node = new WorkspaceNode(workspaceFolder.name, this._onDidChangeTreeData, {
73+
namespace: ns,
74+
extraNode: true,
75+
});
7376
rootNodes.push(node);
7477
});
7578
}

src/explorer/models/classesNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as vscode from "vscode";
22
import { DocumentContentProvider } from "../../providers/DocumentContentProvider";
3-
import { NodeBase } from "./nodeBase";
3+
import { NodeBase, NodeOptions } from "./nodeBase";
44

55
export class ClassNode extends NodeBase {
66
public static readonly contextValue: string = "dataNode:classNode";
7-
public constructor(label: string, fullName: string, workspaceFolder: string, namespace: string) {
8-
super(label, fullName, workspaceFolder, namespace);
7+
public constructor(label: string, fullName: string, options: NodeOptions) {
8+
super(label, fullName, options);
99
}
1010

1111
public getTreeItem(): vscode.TreeItem {

src/explorer/models/nodeBase.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
import * as vscode from "vscode";
22
import { config } from "../../extension";
33

4+
export interface NodeOptions {
5+
extraNode?: boolean;
6+
generated?: boolean;
7+
namespace?: string;
8+
workspaceFolder?: string;
9+
}
10+
411
export class NodeBase {
12+
public readonly options: NodeOptions;
513
public readonly label: string;
614
public readonly fullName: string;
715
public readonly workspaceFolder: string;
816
public readonly conn: any;
917
public readonly extraNode: boolean;
1018
public readonly namespace: string;
1119

12-
protected constructor(label: string, fullName: string, workspaceFolder, namespace: string) {
20+
protected constructor(label: string, fullName: string, options: NodeOptions) {
21+
this.options = {
22+
generated: false,
23+
extraNode: false,
24+
...options,
25+
};
1326
this.label = label;
1427
this.fullName = fullName;
28+
const { workspaceFolder, namespace, extraNode } = options;
1529
this.workspaceFolder = workspaceFolder;
1630
this.conn = config("conn", workspaceFolder);
1731
this.namespace = namespace || this.conn.ns;
18-
this.extraNode = this.conn.ns !== this.namespace;
32+
this.extraNode = extraNode;
1933
}
2034

2135
public getTreeItem(): vscode.TreeItem {

src/explorer/models/packageNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as vscode from "vscode";
22
import { RootNode } from "./rootNode";
33

44
export class PackageNode extends RootNode {
5-
public constructor(label: string, fullName: string, category: string, workspaceFolder: string, namespace: string) {
6-
super(label, fullName, "dataNode:packageNode", category, workspaceFolder, namespace);
5+
public constructor(label: string, fullName: string, category: string, options) {
6+
super(label, fullName, "dataNode:packageNode", category, options);
77
}
88

99
public getTreeItem(): vscode.TreeItem {

src/explorer/models/rootNode.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22

3-
import { NodeBase } from "./nodeBase";
3+
import { NodeBase, NodeOptions } from "./nodeBase";
44
import { PackageNode } from "./packageNode";
55
import { RoutineNode } from "./routineNode";
66
import { AtelierAPI } from "../../api";
@@ -10,15 +10,8 @@ export class RootNode extends NodeBase {
1010
public readonly contextValue: string;
1111
private readonly _category: string;
1212

13-
public constructor(
14-
label: string,
15-
fullName: string,
16-
contextValue: string,
17-
category: string,
18-
workspaceFolder: string,
19-
namespace: string
20-
) {
21-
super(label, fullName, workspaceFolder, namespace);
13+
public constructor(label: string, fullName: string, contextValue: string, category: string, options: NodeOptions) {
14+
super(label, fullName, options);
2215
this.contextValue = contextValue;
2316
this._category = category;
2417
}
@@ -56,7 +49,7 @@ export class RootNode extends NodeBase {
5649
const orderBy = "1"; // by Name
5750
const flat = "0";
5851
const notStudio = "0";
59-
const generated = "0";
52+
const generated = this.options.generated ? "1" : "0";
6053

6154
spec = path + spec;
6255

@@ -76,13 +69,13 @@ export class RootNode extends NodeBase {
7669
const fullName = (this instanceof PackageNode ? this.fullName + "." : "") + el.Name;
7770
switch (el.Type) {
7871
case "9":
79-
return new PackageNode(el.Name, fullName, category, this.workspaceFolder, this.namespace);
72+
return new PackageNode(el.Name, fullName, category, this.options);
8073
case "4":
81-
return new ClassNode(el.Name, fullName, this.workspaceFolder, this.namespace);
74+
return new ClassNode(el.Name, fullName, this.options);
8275
case "0":
8376
case "1":
8477
case "2":
85-
return new RoutineNode(el.Name, fullName, this.workspaceFolder, this.namespace);
78+
return new RoutineNode(el.Name, fullName, this.options);
8679
default:
8780
return null;
8881
}

src/explorer/models/routineNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as vscode from "vscode";
22
import { DocumentContentProvider } from "../../providers/DocumentContentProvider";
3-
import { NodeBase } from "./nodeBase";
3+
import { NodeBase, NodeOptions } from "./nodeBase";
44

55
export class RoutineNode extends NodeBase {
66
public static readonly contextValue: string = "dataNode:routineNode";
7-
public constructor(label: string, fullName: string, workspaceFolder: string, namespace: string) {
8-
super(label, fullName, workspaceFolder, namespace);
7+
public constructor(label: string, fullName: string, options: NodeOptions) {
8+
super(label, fullName, options);
99
}
1010

1111
public getTreeItem(): vscode.TreeItem {

src/explorer/models/workspaceNode.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
import * as vscode from "vscode";
22

3-
import { NodeBase } from "./nodeBase";
3+
import { NodeBase, NodeOptions } from "./nodeBase";
44
import { RootNode } from "./rootNode";
5+
import { workspaceState } from "../../extension";
56

67
export class WorkspaceNode extends NodeBase {
78
public eventEmitter: vscode.EventEmitter<NodeBase>;
8-
public constructor(label: string, eventEmitter: vscode.EventEmitter<NodeBase>, namespace?: string) {
9-
super(label, label, label, namespace);
9+
public uniqueId: string;
10+
public constructor(label: string, eventEmitter: vscode.EventEmitter<NodeBase>, options: NodeOptions) {
11+
super(label, label, options);
12+
this.uniqueId = `serverNode${this.extraNode ? ":extra:" + this.namespace : ""}`;
13+
this.options.generated = workspaceState.get(`ExplorerGenerated:${this.uniqueId}`);
1014
this.eventEmitter = eventEmitter;
1115
}
1216

1317
public getTreeItem(): vscode.TreeItem {
1418
return {
1519
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
16-
contextValue: `serverNode${this.extraNode ? "Extra:" + this.namespace : ""}`,
17-
label: `${this.label}${this.extraNode ? `[${this.namespace}]` : ""}`,
20+
contextValue: `${this.uniqueId}${this.options.generated ? ":generated:" : ""}`,
21+
label: `${this.label}[${this.namespace}]`,
1822
};
1923
}
2024

2125
public async getChildren(element): Promise<NodeBase[]> {
2226
const children = [];
2327
let node: RootNode;
2428

25-
node = new RootNode("Classes", "", "dataRootNode:classesRootNode", "CLS", this.workspaceFolder, this.namespace);
29+
node = new RootNode("Classes", "", "dataRootNode:classesRootNode", "CLS", this.options);
2630
children.push(node);
2731

28-
node = new RootNode("Routines", "", "dataRootNode:routinesRootNode", "RTN", this.workspaceFolder, this.namespace);
32+
node = new RootNode("Routines", "", "dataRootNode:routinesRootNode", "RTN", this.options);
2933
children.push(node);
3034

31-
node = new RootNode("Includes", "", "dataRootNode:routinesRootNode", "INC", this.workspaceFolder, this.namespace);
35+
node = new RootNode("Includes", "", "dataRootNode:routinesRootNode", "INC", this.options);
3236
children.push(node);
3337

3438
return children;

src/extension.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
247247
vscode.commands.registerCommand("vscode-objectscript.explorer.openRoutine", vscode.window.showTextDocument),
248248
vscode.commands.registerCommand("vscode-objectscript.explorer.export", exportExplorerItem),
249249
vscode.commands.registerCommand("vscode-objectscript.explorer.delete", deleteItem),
250+
vscode.commands.registerCommand("vscode-objectscript.explorer.showGenerated", (workspaceNode: WorkspaceNode) => {
251+
workspaceState.update(`ExplorerGenerated:${workspaceNode.uniqueId}`, true);
252+
return explorerProvider.refresh();
253+
}),
254+
vscode.commands.registerCommand("vscode-objectscript.explorer.hideGenerated", (workspaceNode: WorkspaceNode) => {
255+
workspaceState.update(`ExplorerGenerated:${workspaceNode.uniqueId}`, false);
256+
return explorerProvider.refresh();
257+
}),
250258
vscode.commands.registerCommand("vscode-objectscript.explorer.otherNamespace", (workspaceNode: WorkspaceNode) => {
251259
return explorerProvider.selectNamespace(workspaceNode.label);
252260
}),

0 commit comments

Comments
 (0)