From 38faeea238cc40b3db97cfae2077cfe999c4dcbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fred=20Lef=C3=A9v=C3=A8re-Laoide?= Date: Tue, 27 Dec 2022 13:11:23 +0100 Subject: [PATCH] #113 delete configuration node --- core/l10n/bundle.l10n.json | 1 + core/package.json | 13 ++++++-- core/package.nls.json | 2 ++ core/src/context.ts | 2 +- core/src/editors/ConfigEditor.ts | 54 +++++++++++++++++++++++++------- core/webviews/package.json | 2 +- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/core/l10n/bundle.l10n.json b/core/l10n/bundle.l10n.json index eb96611..b504544 100644 --- a/core/l10n/bundle.l10n.json +++ b/core/l10n/bundle.l10n.json @@ -1,4 +1,5 @@ { + "Do you really want to definitely delete {0}:{1} from the configuration ?": "Do you really want to definitely delete {0}:{1} from the configuration ?", "Cannot show a {0} entity in a {1} Perpective.": "Cannot show a {0} entity in a {1} Perpective.", "Entity {0} Name should not contain space, '.' or be empty or be default '{1}'": "Entity {0} Name should not contain space, '.' or be empty or be default '{1}'", "Another {0} entity has the name {1}": "Another {0} entity has the name {1}", diff --git a/core/package.json b/core/package.json index f31b994..3e7f0f6 100644 --- a/core/package.json +++ b/core/package.json @@ -3,7 +3,7 @@ "displayName": "Taipy Studio Configuration Builder", "description": "Visual Studio Code extension for Taipy: Configuration Builder", "publisher": "Avaiga", - "version": "0.0.6", + "version": "0.1.0", "homepage": "https://github.com/Avaiga/taipy-studio.git", "repository": { "type": "git", @@ -50,7 +50,7 @@ }, { "command": "taipy.perspective.showFromDiagram", - "title": "%taipy.config.commands.taipy.perspective.show%", + "title": "%taipy.config.commands.taipy.perspective.showFromDiagram%", "icon": "$(type-hierarchy)" }, { @@ -58,6 +58,11 @@ "title": "%taipy.config.commands.taipy.diagram.addNode%", "icon": "$(add)" }, + { + "command": "taipy.config.deleteNode", + "title": "%taipy.config.commands.taipy.config.deleteNode%", + "icon": "$(delete)" + }, { "command": "taipy.config.datanode.create", "title": "%taipy.config.commands.taipy.config.datanode.create%", @@ -203,6 +208,10 @@ "command": "taipy.diagram.addNode", "when": "viewItem != default && view == taipy-config-datanodes || viewItem != default && view == taipy-config-tasks || viewItem != default && view == taipy-config-pipelines" }, + { + "command": "taipy.config.deleteNode", + "when": "view == taipy-config-datanodes || view == taipy-config-tasks || view == taipy-config-pipelines || view == taipy-config-scenarios" + }, { "command": "taipy.config.revealInExplorer", "when": "view == taipy-configs" diff --git a/core/package.nls.json b/core/package.nls.json index 88bb711..fdaab77 100644 --- a/core/package.nls.json +++ b/core/package.nls.json @@ -7,7 +7,9 @@ "taipy.config.commands.taipy.config.pipeline.create": "Taipy: Create New Pipeline", "taipy.config.commands.taipy.config.scenario.create": "Taipy: Create New Scenario", "taipy.config.commands.taipy.perspective.show": "Taipy: Show View", + "taipy.config.commands.taipy.perspective.showFromDiagram": "Taipy: Show View", "taipy.config.commands.taipy.diagram.addNode": "Taipy: Add/Show node in active View", + "taipy.config.commands.taipy.config.deleteNode": "Taipy: Delete node from configuration", "taipy.config.customEditors.taipy-config-editor": "Taipy Config Editor", "taipy.config.icon.theme.label": "Taipy product icon set", "taipy.config.viewsContainers.activitybar.taipy-config-panel": "Taipy Configs", diff --git a/core/src/context.ts b/core/src/context.ts index 2986c35..d801287 100644 --- a/core/src/context.ts +++ b/core/src/context.ts @@ -285,7 +285,7 @@ export class Context { return (uri && this.symbolsByUri[uri]) || []; } - private async refreshSymbols(document: TextDocument) { + async refreshSymbols(document: TextDocument) { const uri = document.uri.toString(); if (this.symbolsByUri[uri]) { await this.readSymbols(document); diff --git a/core/src/editors/ConfigEditor.ts b/core/src/editors/ConfigEditor.ts index 4eafba9..20e261f 100644 --- a/core/src/editors/ConfigEditor.ts +++ b/core/src/editors/ConfigEditor.ts @@ -3,6 +3,7 @@ import { CancellationToken, commands, CustomTextEditorProvider, + DocumentSymbol, ExtensionContext, l10n, languages, @@ -95,6 +96,7 @@ export class ConfigEditorProvider implements CustomTextEditorProvider { commands.registerCommand("taipy.config.clearCache", this.clearCache, this); commands.registerCommand("taipy.diagram.addNode", this.addNodeToCurrentDiagram, this); + commands.registerCommand("taipy.config.deleteNode", this.deleteConfigurationNode, this); } async createNewElement(uri: Uri, nodeType: string) { @@ -132,13 +134,36 @@ export class ConfigEditorProvider implements CustomTextEditorProvider { return this.cache[perspectiveUri]; } + private async deleteConfigurationNode(item: TreeItem) { + const nodeType = item.contextValue; + const nodeName = item.label as string; + const answer = await window.showWarningMessage(l10n.t("Do you really want to definitely delete {0}:{1} from the configuration ?", nodeType, nodeName), "Yes", "No"); + if (answer === "Yes") { + const uri = getOriginalUri(item.resourceUri); + const realDocument = await this.taipyContext.getDocFromUri(uri); + const symbols = this.taipyContext.getSymbols(uri.toString()); + const nameSymbol = getSymbol(symbols, nodeType, nodeName); + if (!nameSymbol) { + return false; + } + const edits: TextEdit[] = [TextEdit.delete(nameSymbol.range)]; + await this.removeNodeLinks(realDocument, nodeType, nodeName, symbols, edits); + const res = await this.applyEdits(realDocument.uri, edits); + if (res) { + await this.taipyContext.refreshSymbols(realDocument); + this.updateWebview(realDocument, realDocument.isDirty); + } + return res; + } + } + private addNodeToCurrentDiagram(item: TreeItem) { this.addNodeToActiveDiagram(item.contextValue, item.label as string); } private addNodeToActiveDiagram(nodeType: string, nodeName: string, check = false) { - for (let pps of Object.values(this.panelsByUri)) { - for (let [pId, ps] of Object.entries(pps)) { + for (const pps of Object.values(this.panelsByUri)) { + for (const [pId, ps] of Object.entries(pps)) { const panel = ps.find((p) => p.active); if (panel) { if (check) { @@ -410,21 +435,13 @@ export class ConfigEditorProvider implements CustomTextEditorProvider { return this.applyEdits(uri, edits); } - private async removeNodeFromPerspective(realDocument: TextDocument, nodeType: string, nodeName: string) { - const uri = realDocument.uri; - const symbols = this.taipyContext.getSymbols(uri.toString()); - const nameSymbol = getSymbol(symbols, nodeType, nodeName); - if (!nameSymbol) { - return false; - } - const edits = [] as TextEdit[]; - getDescendantProperties(nodeType).forEach((p) => p && this.createOrDeleteLink(realDocument, nodeType, nodeName, p, "", false, true, edits)); + private async removeNodeLinks(realDocument: TextDocument, nodeType: string, nodeName: string, symbols: DocumentSymbol[], edits: TextEdit[] = []) { const parentType = getParentType(nodeType); const pp = getDescendantProperties(parentType); const pTypeSymbol = getSymbol(symbols, parentType); pTypeSymbol && pTypeSymbol.children.forEach(parentSymbol => { pp.forEach((property, idx) => { - if (property && getSymbolArrayValue(realDocument, parentSymbol, property).some((n: string) => n === nodeName)) { + if (property && getSymbolArrayValue(realDocument, parentSymbol, property).some((n: string) => getUnsuffixedName(n) === nodeName)) { if (idx === 0) { // input property: reverse order this.createOrDeleteLink(realDocument, nodeType, nodeName, parentType, parentSymbol.name, false, false, edits); @@ -435,6 +452,19 @@ export class ConfigEditorProvider implements CustomTextEditorProvider { } }); }); + return edits; + } + + private async removeNodeFromPerspective(realDocument: TextDocument, nodeType: string, nodeName: string) { + const uri = realDocument.uri; + const symbols = this.taipyContext.getSymbols(uri.toString()); + const nameSymbol = getSymbol(symbols, nodeType, nodeName); + if (!nameSymbol) { + return false; + } + const edits: TextEdit[] = []; + getDescendantProperties(nodeType).forEach((p) => p && this.createOrDeleteLink(realDocument, nodeType, nodeName, p, "", false, true, edits)); + await this.removeNodeLinks(realDocument, nodeType, nodeName, symbols, edits); return this.applyEdits(realDocument.uri, edits); } diff --git a/core/webviews/package.json b/core/webviews/package.json index 705a5ab..00b668a 100644 --- a/core/webviews/package.json +++ b/core/webviews/package.json @@ -3,7 +3,7 @@ "displayName": "taipy-studio-webviews", "description": "Components for Visual Studio Code extension for Taipy", "publisher": "Avaiga", - "version": "0.0.6", + "version": "0.1.0", "categories": [ "Other" ],