Skip to content

Commit a15e939

Browse files
committed
delete item in explorer, done #16
1 parent a0d98ab commit a15e939

File tree

9 files changed

+72
-22
lines changed

9 files changed

+72
-22
lines changed

api/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ export class AtelierAPI {
197197
}
198198
return this.request(1, 'GET', `${this.ns}/doc/${name}`, params);
199199
}
200+
// api v1+
201+
deleteDoc(name: string): Promise<any> {
202+
return this.request(1, 'DELETE', `${this.ns}/doc/${name}`);
203+
}
200204
// v1+
201205
putDoc(name: string, data: { enc: boolean; content: string[] }, ignoreConflict?: boolean): Promise<any> {
202206
let params = { ignoreConflict };

commands/delete.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as vscode from 'vscode';
2+
3+
import { RootNode } from '../explorer/models/rootNode';
4+
import { PackageNode } from '../explorer/models/packageNode';
5+
import { ClassNode } from '../explorer/models/classesNode';
6+
import { RoutineNode } from '../explorer/models/routineNode';
7+
import { outputChannel } from '../utils';
8+
import { AtelierAPI } from '../api';
9+
import { explorerProvider } from '../extension';
10+
11+
function deleteList(items: string[], workspaceFolder: string): Promise<any> {
12+
if (!items || !items.length) {
13+
vscode.window.showWarningMessage('Nothing to export');
14+
}
15+
16+
const api = new AtelierAPI();
17+
api.setConnection(workspaceFolder);
18+
return Promise.all(
19+
items.map(item => api.deleteDoc(item))
20+
).then(files => {
21+
outputChannel.appendLine(`Deleted items: ${files.filter(el => el.result).length}`);
22+
const failed = files.filter(el => !el.result).map(el => `${el.file} - ${el.error}`);
23+
if (files.find(el => !el.result)) {
24+
outputChannel.appendLine(`Items failed to delete: \n${failed.join('\n')}`);
25+
}
26+
});
27+
}
28+
29+
export async function deleteItem(node: RootNode | PackageNode | ClassNode | RoutineNode): Promise<any> {
30+
const workspaceFolder = node.workspaceFolder;
31+
const nodes = node instanceof RootNode ? node.getChildren(node) : Promise.resolve([node]);
32+
return nodes
33+
.then(nodes =>
34+
nodes.reduce(
35+
(list, subNode) => list.concat(subNode instanceof PackageNode ? subNode.getClasses() : [subNode.fullName]),
36+
[]
37+
)
38+
)
39+
.then(items => {
40+
deleteList(items, workspaceFolder);
41+
explorerProvider.refresh();
42+
});
43+
}

explorer/models/classesNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NodeBase } from './nodeBase';
33
import { DocumentContentProvider } from '../../providers/DocumentContentProvider';
44

55
export class ClassNode extends NodeBase {
6-
public static readonly contextValue: string = 'classNode';
6+
public static readonly contextValue: string = 'dataNode:classNode';
77
constructor(
88
public readonly label: string,
99
public readonly fullName: string,
@@ -23,7 +23,7 @@ export class ClassNode extends NodeBase {
2323
return {
2424
label: `${displayName}`,
2525
collapsibleState: vscode.TreeItemCollapsibleState.None,
26-
contextValue: 'classNode',
26+
contextValue: 'dataNode:classNode',
2727
command: {
2828
command: 'vscode-objectscript.explorer.openClass',
2929
arguments: [DocumentContentProvider.getUri(this.fullName, this._workspaceFolder, this._namespace)],

explorer/models/packageNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NodeBase } from './nodeBase';
33
import { ClassNode } from './classesNode';
44

55
export class PackageNode extends NodeBase {
6-
public static readonly contextValue: string = 'packageNode';
6+
public static readonly contextValue: string = 'dataNode:packageNode';
77
constructor(
88
public readonly label: string,
99
private readonly _items,
@@ -23,7 +23,7 @@ export class PackageNode extends NodeBase {
2323
return {
2424
label: `${displayName}`,
2525
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
26-
contextValue: 'packageNode'
26+
contextValue: 'dataNode:packageNode'
2727
// iconPath: {
2828
// light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'package.svg'),
2929
// dark: path.join(__filename, '..', '..', '..', '..', 'images', 'dark', 'package.svg')

explorer/models/rootNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export class RootNode extends NodeBase {
2929
}
3030

3131
async getChildren(element): Promise<NodeBase[]> {
32-
if (element.contextValue === 'classesRootNode') {
32+
if (element.contextValue === 'dataRootNode:classesRootNode') {
3333
return this.getClasses();
3434
}
3535

36-
if (element.contextValue === 'routinesRootNode') {
36+
if (element.contextValue === 'dataRootNode:routinesRootNode') {
3737
return this.getRoutines();
3838
}
3939
}

explorer/models/routineNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NodeBase } from './nodeBase';
33
import { DocumentContentProvider } from '../../providers/DocumentContentProvider';
44

55
export class RoutineNode extends NodeBase {
6-
public static readonly contextValue: string = 'routineNode';
6+
public static readonly contextValue: string = 'dataNode:routineNode';
77
constructor(
88
public readonly label: string,
99
public readonly fullName: string,
@@ -23,7 +23,7 @@ export class RoutineNode extends NodeBase {
2323
return {
2424
label: `${displayName}`,
2525
collapsibleState: vscode.TreeItemCollapsibleState.None,
26-
contextValue: 'routineNode',
26+
contextValue: 'dataNode:routineNode',
2727
command: {
2828
command: 'vscode-objectscript.explorer.openRoutine',
2929
arguments: [DocumentContentProvider.getUri(this.fullName, this._workspaceFolder, this._namespace)],

explorer/models/workspaceNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export class WorkspaceNode extends NodeBase {
3939
let workspaceFolder = element.label;
4040

4141
data = await this.getDocNames('CLS');
42-
node = new RootNode('Classes', 'classesRootNode', this.eventEmitter, data, workspaceFolder, this._namespace);
42+
node = new RootNode('Classes', 'dataRootNode:classesRootNode', this.eventEmitter, data, workspaceFolder, this._namespace);
4343
children.push(node);
4444

4545
data = await this.getDocNames('RTN');
46-
node = new RootNode('Routines', 'routinesRootNode', this.eventEmitter, data, workspaceFolder, this._namespace);
46+
node = new RootNode('Routines', 'dataRootNode:routinesRootNode', this.eventEmitter, data, workspaceFolder, this._namespace);
4747
children.push(node);
4848

4949
return children;

extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { xml2doc } from './commands/xml2doc';
1010
import { subclass } from './commands/subclass';
1111
import { superclass } from './commands/superclass';
1212
import { serverActions } from './commands/serverActions';
13+
import { deleteItem } from './commands/delete';
1314

1415
import { ObjectScriptClassSymbolProvider } from './providers/ObjectScriptClassSymbolProvider';
1516
import { ObjectScriptRoutineSymbolProvider } from './providers/ObjectScriptRoutineSymbolProvider';
@@ -151,6 +152,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
151152
vscode.commands.registerCommand('vscode-objectscript.explorer.openClass', vscode.window.showTextDocument),
152153
vscode.commands.registerCommand('vscode-objectscript.explorer.openRoutine', vscode.window.showTextDocument),
153154
vscode.commands.registerCommand('vscode-objectscript.explorer.export', exportExplorerItem),
155+
vscode.commands.registerCommand('vscode-objectscript.explorer.delete', deleteItem),
154156
vscode.commands.registerCommand('vscode-objectscript.explorer.showSystem', (workspaceNode?: WorkspaceNode) => {
155157
if (workspaceNode) {
156158
explorerProvider.showSystem4Workspace(workspaceNode.label, true);

package.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@
103103
"command": "vscode-objectscript.explorer.export",
104104
"when": "true"
105105
},
106+
{
107+
"command": "vscode-objectscript.explorer.delete",
108+
"when": "false"
109+
},
106110
{
107111
"command": "vscode-objectscript.explorer.refresh",
108112
"when": "true"
@@ -126,23 +130,15 @@
126130
"view/item/context": [
127131
{
128132
"command": "vscode-objectscript.explorer.export",
129-
"when": "view == ObjectScriptExplorer && viewItem == classesRootNode"
133+
"when": "view == ObjectScriptExplorer && viewItem =~ /^dataNode:/"
130134
},
131135
{
132136
"command": "vscode-objectscript.explorer.export",
133-
"when": "view == ObjectScriptExplorer && viewItem == routinesRootNode"
137+
"when": "view == ObjectScriptExplorer && viewItem =~ /^dataRootNode:/"
134138
},
135139
{
136-
"command": "vscode-objectscript.explorer.export",
137-
"when": "view == ObjectScriptExplorer && viewItem == packageNode"
138-
},
139-
{
140-
"command": "vscode-objectscript.explorer.export",
141-
"when": "view == ObjectScriptExplorer && viewItem == classNode"
142-
},
143-
{
144-
"command": "vscode-objectscript.explorer.export",
145-
"when": "view == ObjectScriptExplorer && viewItem == routineNode"
140+
"command": "vscode-objectscript.explorer.delete",
141+
"when": "view == ObjectScriptExplorer && viewItem =~ /^dataNode:/"
146142
},
147143
{
148144
"command": "vscode-objectscript.explorer.showSystem",
@@ -317,6 +313,11 @@
317313
"title": "Export",
318314
"category": "ObjecScript"
319315
},
316+
{
317+
"command": "vscode-objectscript.explorer.delete",
318+
"title": "Delete",
319+
"category": "ObjecScript"
320+
},
320321
{
321322
"command": "vscode-objectscript.explorer.refresh",
322323
"title": "Refresh Explorer",

0 commit comments

Comments
 (0)