From 51ac6d7b10337d70f759784ecea61e890d63d5e0 Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Thu, 9 Apr 2020 15:36:54 +0530 Subject: [PATCH 1/3] Single click on icon open yaml editor --- images/dark/edit.svg | 1 + images/light/edit.svg | 1 + package.json | 78 +++++++++++++++++++++++++++++++++++++++++++ src/extension.ts | 1 + src/tkn.ts | 51 ++++++++++++++++++---------- 5 files changed, 114 insertions(+), 18 deletions(-) create mode 100755 images/dark/edit.svg create mode 100755 images/light/edit.svg diff --git a/images/dark/edit.svg b/images/dark/edit.svg new file mode 100755 index 00000000..da956cb2 --- /dev/null +++ b/images/dark/edit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/light/edit.svg b/images/light/edit.svg new file mode 100755 index 00000000..ecde9240 --- /dev/null +++ b/images/light/edit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/package.json b/package.json index fce75530..cc66b5b1 100644 --- a/package.json +++ b/package.json @@ -136,6 +136,14 @@ } ], "commands": [ + { + "command": "tekton.edit", + "title": "Open In Editor", + "icon": { + "light": "images/light/edit.svg", + "dark": "images/dark/edit.svg" + } + }, { "command": "tekton.pipeline.preview", "title": "Open Pipeline preview to the Side", @@ -707,6 +715,56 @@ "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == taskrun", "group": "c2" }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipeline", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipelinerun", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == clustertask", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipelineresource", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == taskrun", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggertemplates", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggerbinding", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == eventlistener", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == conditions", + "group": "inline" + }, + { + "command": "tekton.edit", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == task", + "group": "inline" + }, { "command": "tekton.openInEditor", "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipeline", @@ -736,6 +794,26 @@ "command": "tekton.openInEditor", "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == task", "group": "c0@1" + }, + { + "command": "tekton.openInEditor", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggertemplates", + "group": "c0@1" + }, + { + "command": "tekton.openInEditor", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggerbinding", + "group": "c0@1" + }, + { + "command": "tekton.openInEditor", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == eventlistener", + "group": "c0@1" + }, + { + "command": "tekton.openInEditor", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == conditions", + "group": "c0@1" } ], "editor/title": [ diff --git a/src/extension.ts b/src/extension.ts index 1b418f61..d7408d92 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -42,6 +42,7 @@ export async function activate(context: vscode.ExtensionContext): Promise vscode.commands.registerCommand('tekton.explorer.refresh', (context) => execute(Pipeline.refresh, context)), vscode.commands.registerCommand('tekton.pipeline.start', (context) => execute(Pipeline.start, context)), vscode.commands.registerCommand('tekton.openInEditor', (context) => execute(TektonItem.openInEditor, context)), + vscode.commands.registerCommand('tekton.edit', (context) => execute(TektonItem.openInEditor, context)), vscode.commands.registerCommand('tekton.pipeline.restart', (context) => execute(Pipeline.restart, context)), //vscode.commands.registerCommand('tekton.pipeline.createFromLocal', (context) => execute(Pipeline.createFromLocal, context)), vscode.commands.registerCommand('tekton.pipeline.list', (context) => execute(Pipeline.list, context)), diff --git a/src/tkn.ts b/src/tkn.ts index 6f14d29f..c26220a2 100644 --- a/src/tkn.ts +++ b/src/tkn.ts @@ -4,7 +4,7 @@ *-----------------------------------------------------------------------------------------------*/ import { CliCommand, CliExitData, Cli, CliImpl, createCliCommand, cliCommandToString } from './cli'; -import { ProviderResult, TreeItemCollapsibleState, Terminal, Uri, workspace, TreeItem, Command as vsCommand } from 'vscode'; +import { ProviderResult, TreeItemCollapsibleState, Terminal, Uri, workspace, TreeItem } from 'vscode'; import { WindowUtil } from './util/windowUtils'; import * as path from 'path'; import { ToolsConfig } from './tools'; @@ -62,9 +62,13 @@ export enum ContextType { TASKNODE = 'tasknode', CLUSTERTASKNODE = 'clustertasknode', TKN_DOWN = 'tknDown', + TRIGGERTEMPLATESNODE = 'triggertemplatesnode', TRIGGERTEMPLATES = 'triggertemplates', + TRIGGERBINDINGNODE= 'triggerbindingnode', TRIGGERBINDING= 'triggerbinding', + EVENTLISTENERNODE= 'eventlistenernode', EVENTLISTENER= 'eventlistener', + CONDITIONSNODE = 'conditionsnode', CONDITIONS = 'conditions', PIPELINERUNNODE = 'pipelinerunnode', } @@ -344,26 +348,46 @@ export class TektonNodeImpl implements TektonNode { tooltip: 'Cannot connect to the tekton', getChildren: () => [] }, - triggertemplates: { + triggertemplatesnode: { icon: 'TT.svg', tooltip: 'TriggerTemplates: {label}', getChildren: () => this.tkn.getTriggerTemplates(this) }, - triggerbinding: { + triggertemplates: { + icon: 'TT.svg', + tooltip: 'TriggerTemplates: {label}', + getChildren: () => [] + }, + triggerbindingnode: { icon: 'TB.svg', tooltip: 'TriggerBinding: {label}', getChildren: () => this.tkn.getTriggerBinding(this) }, - eventlistener: { + triggerbinding: { + icon: 'TB.svg', + tooltip: 'TriggerBinding: {label}', + getChildren: () => [] + }, + eventlistenernode: { icon: 'EL.svg', tooltip: 'EventListener: {label}', getChildren: () => this.tkn.getEventListener(this) }, - conditions: { + eventlistener: { + icon: 'EL.svg', + tooltip: 'EventListener: {label}', + getChildren: () => [] + }, + conditionsnode: { icon: 'C.svg', tooltip: 'Conditions: {label}', getChildren: () => this.tkn.getConditions(this) }, + conditions: { + icon: 'C.svg', + tooltip: 'Conditions: {label}', + getChildren: () => [] + }, taskrunnode: { icon: 'TR.svg', tooltip: 'TaskRuns: {label}', @@ -408,15 +432,6 @@ export class TektonNodeImpl implements TektonNode { return format(this.CONTEXT_DATA[this.contextValue].tooltip, this); } - get command(): vsCommand | undefined { - const arrName = ['Pipelines', 'Tasks', 'ClusterTasks', 'PipelineResources', 'TriggerTemplates', 'TriggerBinding', 'EventListener', 'Conditions', 'PipelineRuns', 'TaskRuns']; - if (arrName.includes(this.name)) { - return undefined; - } else { - return { command: 'tekton.openInEditor', title: 'Open In Editor', arguments: [this] }; - } - } - get label(): string { return this.name; } @@ -667,10 +682,10 @@ export class TknImpl implements Tkn { const clustertaskNode = new TektonNodeImpl(TknImpl.ROOT, 'ClusterTasks', ContextType.CLUSTERTASKNODE, this, TreeItemCollapsibleState.Collapsed); const taskRunNode = new TektonNodeImpl(TknImpl.ROOT, 'TaskRuns', ContextType.TASKRUNNODE, this, TreeItemCollapsibleState.Collapsed); const pipelineResourceNode = new TektonNodeImpl(TknImpl.ROOT, 'PipelineResources', ContextType.PIPELINERESOURCENODE, this, TreeItemCollapsibleState.Collapsed); - const triggerTemplatesNode = new TektonNodeImpl(TknImpl.ROOT, 'TriggerTemplates', ContextType.TRIGGERTEMPLATES, this, TreeItemCollapsibleState.Collapsed); - const triggerBindingNode = new TektonNodeImpl(TknImpl.ROOT, 'TriggerBinding', ContextType.TRIGGERBINDING, this, TreeItemCollapsibleState.Collapsed); - const eventListenerNode = new TektonNodeImpl(TknImpl.ROOT, 'EventListener', ContextType.EVENTLISTENER, this, TreeItemCollapsibleState.Collapsed); - const conditionsNode = new TektonNodeImpl(TknImpl.ROOT, 'Conditions', ContextType.CONDITIONS, this, TreeItemCollapsibleState.Collapsed); + const triggerTemplatesNode = new TektonNodeImpl(TknImpl.ROOT, 'TriggerTemplates', ContextType.TRIGGERTEMPLATESNODE, this, TreeItemCollapsibleState.Collapsed); + const triggerBindingNode = new TektonNodeImpl(TknImpl.ROOT, 'TriggerBinding', ContextType.TRIGGERBINDINGNODE, this, TreeItemCollapsibleState.Collapsed); + const eventListenerNode = new TektonNodeImpl(TknImpl.ROOT, 'EventListener', ContextType.EVENTLISTENERNODE, this, TreeItemCollapsibleState.Collapsed); + const conditionsNode = new TektonNodeImpl(TknImpl.ROOT, 'Conditions', ContextType.CONDITIONSNODE, this, TreeItemCollapsibleState.Collapsed); pipelineTree.push(pipelineNode, pipelineRunNode, taskNode, clustertaskNode, taskRunNode,pipelineResourceNode, triggerTemplatesNode, triggerBindingNode, eventListenerNode, conditionsNode); this.cache.set(pipelineNode, await this.getPipelines(pipelineNode)); this.cache.set(pipelineRunNode, await this.getPipelineRunsList(pipelineRunNode)); From 08eff40fedb4d6e6284865937530a55df61530f8 Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Fri, 10 Apr 2020 10:21:19 +0530 Subject: [PATCH 2/3] Added new image --- images/dark/edit.svg | 1 - images/dark/go-to-file.svg | 3 +++ images/light/edit.svg | 1 - images/light/go-to-file.svg | 3 +++ package.json | 4 ++-- 5 files changed, 8 insertions(+), 4 deletions(-) delete mode 100755 images/dark/edit.svg create mode 100644 images/dark/go-to-file.svg delete mode 100755 images/light/edit.svg create mode 100644 images/light/go-to-file.svg diff --git a/images/dark/edit.svg b/images/dark/edit.svg deleted file mode 100755 index da956cb2..00000000 --- a/images/dark/edit.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/images/dark/go-to-file.svg b/images/dark/go-to-file.svg new file mode 100644 index 00000000..ed302ae1 --- /dev/null +++ b/images/dark/go-to-file.svg @@ -0,0 +1,3 @@ + + + diff --git a/images/light/edit.svg b/images/light/edit.svg deleted file mode 100755 index ecde9240..00000000 --- a/images/light/edit.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/images/light/go-to-file.svg b/images/light/go-to-file.svg new file mode 100644 index 00000000..392a840c --- /dev/null +++ b/images/light/go-to-file.svg @@ -0,0 +1,3 @@ + + + diff --git a/package.json b/package.json index cc66b5b1..55079a39 100644 --- a/package.json +++ b/package.json @@ -140,8 +140,8 @@ "command": "tekton.edit", "title": "Open In Editor", "icon": { - "light": "images/light/edit.svg", - "dark": "images/dark/edit.svg" + "light": "images/light/go-to-file.svg", + "dark": "images/dark/go-to-file.svg" } }, { From a8113038f2e9615036574900cd9d2fce21c5027d Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Fri, 10 Apr 2020 17:52:40 +0530 Subject: [PATCH 3/3] use regex to open in editor --- package.json | 94 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 92 deletions(-) diff --git a/package.json b/package.json index 55079a39..01a39c9e 100644 --- a/package.json +++ b/package.json @@ -717,102 +717,12 @@ }, { "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipeline", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipelinerun", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == clustertask", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipelineresource", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == taskrun", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggertemplates", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggerbinding", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == eventlistener", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == conditions", - "group": "inline" - }, - { - "command": "tekton.edit", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == task", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem =~ /^(pipeline|pipelinerun|clustertask|pipelineresource|taskrun|triggertemplates|triggerbinding|eventlistener|conditions|task)$/", "group": "inline" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipeline", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipelinerun", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == clustertask", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == pipelineresource", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == taskrun", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == task", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggertemplates", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == triggerbinding", - "group": "c0@1" - }, - { - "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == eventlistener", - "group": "c0@1" }, { "command": "tekton.openInEditor", - "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem == conditions", + "when": "view =~ /^tekton(CustomTree|PipelineExplorer)View/ && viewItem =~ /^(pipeline|pipelinerun|clustertask|pipelineresource|taskrun|task|triggertemplates|triggerbinding|eventlistener|conditions)$/", "group": "c0@1" } ],