From 1b9b05c4e6342c53ee12befa9337a5453f6529cd Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Wed, 5 Jun 2024 16:40:25 +0200 Subject: [PATCH 1/5] added command palette logic --- package.json | 6 +++--- src/devtools/containers.ts | 25 +++++++++++++++++-------- src/devtools/main.ts | 1 - src/editor/containers.ts | 12 +++++++++++- src/editor/output.ts | 6 +++++- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index e03df30..159bcc0 100644 --- a/package.json +++ b/package.json @@ -79,15 +79,15 @@ "commandPalette": [ { "command": "sfmc-devtools-vscext.devtoolsCMRetrieve", - "when": "false" + "when": "sfmc-devtools-vscode.isDevToolsProject" }, { "command": "sfmc-devtools-vscext.devtoolsCMDeploy", - "when": "false" + "when": "sfmc-devtools-vscode.isDevToolsProject" }, { "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", - "when": "false" + "when": "sfmc-devtools-vscode.isDevToolsProject" } ], "editor/title/context": [ diff --git a/src/devtools/containers.ts b/src/devtools/containers.ts index 6ec5bcb..7eff925 100644 --- a/src/devtools/containers.ts +++ b/src/devtools/containers.ts @@ -175,17 +175,26 @@ function activateContextMenuCommands() { editorCommands.registerCommand({ command, callbackAction: (file: Uri, multipleFiles: Uri[]) => { - const files: Uri[] = !Array.isArray(multipleFiles) ? [file] : multipleFiles; - if (files.length) { - const filesPath: string[] = editorWorkspace.getFilesURIPath(files); + let filesUri = []; + + // If file is undefined it could be that the command is being called from the commands palette + // else it should be the menu command + if (!file) { + // Gets the file uri that is currently open in the editor + const fileURI: Uri | undefined = editorContainers.getActiveTabFileURI(); + filesUri = fileURI ? [fileURI] : []; + } else { + filesUri = !Array.isArray(multipleFiles) ? [file] : multipleFiles; + } + + if (filesUri.length) { + // Gets the file path from the URI + const filesPath: string[] = editorWorkspace.getFilesURIPath(filesUri); const [__, key]: string[] = command.split(".devtools"); + // Executes the command return devtoolsMain.handleContextMenuActions(key, filesPath); - } else { - log( - "error", - "[container_activateContextMenuCommands] Error: Context Menu Callback didn't return any selected files." - ); } + log("warning", "Warn: No file was selected or is currently open in the editor."); } }) ); diff --git a/src/devtools/main.ts b/src/devtools/main.ts index 9279cf2..7097bab 100644 --- a/src/devtools/main.ts +++ b/src/devtools/main.ts @@ -119,7 +119,6 @@ function handleStatusBarActions(action: string): void { function handleContextMenuActions(action: string, selectedFiles: string[]): void { devtoolsContainers.modifyStatusBar("mcdev", "success"); - log("debug", "Setting Context Menu Actions..."); log("debug", `Action: ${action} Number of Selected Files: ${selectedFiles.length}`); switch (action.toLowerCase()) { diff --git a/src/editor/containers.ts b/src/editor/containers.ts index 958c5be..af6f213 100644 --- a/src/editor/containers.ts +++ b/src/editor/containers.ts @@ -1,4 +1,4 @@ -import { window, StatusBarItem, StatusBarAlignment, ThemeColor } from "vscode"; +import { window, StatusBarItem, StatusBarAlignment, ThemeColor, Uri, Tab, TabInputText } from "vscode"; function createStatusBarItem(command: string, title: string, name: string): StatusBarItem { let statusBar: StatusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 110); @@ -17,9 +17,19 @@ function getBackgroundColor(status: string) { return new ThemeColor(`statusBarItem.${status}Background`); } +function getActiveTabFileURI(): Uri | undefined { + const activeTab: Tab | undefined = window.tabGroups.activeTabGroup.activeTab; + if (activeTab && activeTab.input) { + const activeTabInput: TabInputText = activeTab.input as TabInputText; + return activeTabInput.uri; + } + return; +} + const editorContainers = { createStatusBarItem, displayStatusBarItem, + getActiveTabFileURI, getBackgroundColor }; diff --git a/src/editor/output.ts b/src/editor/output.ts index 4518d33..59bca0d 100644 --- a/src/editor/output.ts +++ b/src/editor/output.ts @@ -39,7 +39,11 @@ function log(level: keyof typeof LogLevel, output: string | number | object, log outputChannel.hide(); } - if (LogLevel[level] === LogLevel.info || LogLevel[level] === LogLevel.error) { + if ( + LogLevel[level] === LogLevel.info || + LogLevel[level] === LogLevel.error || + LogLevel[level] === LogLevel.warning + ) { outputChannel.appendLine(`${outputStr}`); } From d905487f509d65245808995c92390e02e65caf5b Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Wed, 5 Jun 2024 16:55:41 +0200 Subject: [PATCH 2/5] code improvement defining activeTab file URI --- .eslintrc.json | 2 +- src/devtools/containers.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 27f0647..45bb6b2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,7 +12,7 @@ "@typescript-eslint/naming-convention": "off", "@typescript-eslint/semi": "warn", "@typescript-eslint/camelcase": "off", - "curly": "warn", + "curly": "off", "eqeqeq": "warn", "no-throw-literal": "warn", "semi": "off" diff --git a/src/devtools/containers.ts b/src/devtools/containers.ts index 7eff925..714d5b4 100644 --- a/src/devtools/containers.ts +++ b/src/devtools/containers.ts @@ -175,21 +175,21 @@ function activateContextMenuCommands() { editorCommands.registerCommand({ command, callbackAction: (file: Uri, multipleFiles: Uri[]) => { - let filesUri = []; + let filesURI: Uri[] = []; // If file is undefined it could be that the command is being called from the commands palette // else it should be the menu command if (!file) { // Gets the file uri that is currently open in the editor const fileURI: Uri | undefined = editorContainers.getActiveTabFileURI(); - filesUri = fileURI ? [fileURI] : []; + if (fileURI) filesURI.push(fileURI); } else { - filesUri = !Array.isArray(multipleFiles) ? [file] : multipleFiles; + filesURI = !Array.isArray(multipleFiles) ? [file] : multipleFiles; } - if (filesUri.length) { + if (filesURI.length) { // Gets the file path from the URI - const filesPath: string[] = editorWorkspace.getFilesURIPath(filesUri); + const filesPath: string[] = editorWorkspace.getFilesURIPath(filesURI); const [__, key]: string[] = command.split(".devtools"); // Executes the command return devtoolsMain.handleContextMenuActions(key, filesPath); From 5889ebff4cfee98a29a2f5f3137d472ced5e7021 Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Thu, 6 Jun 2024 12:38:53 +0200 Subject: [PATCH 3/5] added editorIsOpen variable to detect when a file is open in terminal --- .eslintrc.json | 2 +- package.json | 6 +++--- src/devtools/containers.ts | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 45bb6b2..27f0647 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,7 +12,7 @@ "@typescript-eslint/naming-convention": "off", "@typescript-eslint/semi": "warn", "@typescript-eslint/camelcase": "off", - "curly": "off", + "curly": "warn", "eqeqeq": "warn", "no-throw-literal": "warn", "semi": "off" diff --git a/package.json b/package.json index 159bcc0..064a74e 100644 --- a/package.json +++ b/package.json @@ -79,15 +79,15 @@ "commandPalette": [ { "command": "sfmc-devtools-vscext.devtoolsCMRetrieve", - "when": "sfmc-devtools-vscode.isDevToolsProject" + "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /retrieve/" }, { "command": "sfmc-devtools-vscext.devtoolsCMDeploy", - "when": "sfmc-devtools-vscode.isDevToolsProject" + "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && (resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceExtname == '.json' || resourceExtname == '.html' || resourceExtname == '.sql' || resourceExtname == '.ssjs' || resourceLangId == 'markdown' || resourceLangId == 'AMPscript' || resourceLangId == 'ampscript')))" }, { "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", - "when": "sfmc-devtools-vscode.isDevToolsProject" + "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /retrieve/" } ], "editor/title/context": [ diff --git a/src/devtools/containers.ts b/src/devtools/containers.ts index 714d5b4..0dbd0dc 100644 --- a/src/devtools/containers.ts +++ b/src/devtools/containers.ts @@ -177,12 +177,13 @@ function activateContextMenuCommands() { callbackAction: (file: Uri, multipleFiles: Uri[]) => { let filesURI: Uri[] = []; + // Gets the file uri that is currently open in the editor + const fileURI: Uri | undefined = editorContainers.getActiveTabFileURI(); + // If file is undefined it could be that the command is being called from the commands palette // else it should be the menu command - if (!file) { - // Gets the file uri that is currently open in the editor - const fileURI: Uri | undefined = editorContainers.getActiveTabFileURI(); - if (fileURI) filesURI.push(fileURI); + if (!file && fileURI) { + filesURI.push(fileURI); } else { filesURI = !Array.isArray(multipleFiles) ? [file] : multipleFiles; } @@ -194,7 +195,6 @@ function activateContextMenuCommands() { // Executes the command return devtoolsMain.handleContextMenuActions(key, filesPath); } - log("warning", "Warn: No file was selected or is currently open in the editor."); } }) ); From 229c975a38cf983751647b4eefd03775e5963560 Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Thu, 6 Jun 2024 12:50:40 +0200 Subject: [PATCH 4/5] change command palette order in package.json --- package.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 064a74e..702fe67 100644 --- a/package.json +++ b/package.json @@ -59,35 +59,35 @@ } ], "menus": { - "explorer/context": [ + "commandPalette": [ { - "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/", "command": "sfmc-devtools-vscext.devtoolsCMRetrieve", - "group": "devtools" + "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /retrieve/" }, { - "when": "sfmc-devtools-vscode.isDevToolsProject && (resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceExtname == '.json' || resourceExtname == '.html' || resourceExtname == '.sql' || resourceExtname == '.ssjs' || resourceLangId == 'markdown' || resourceLangId == 'AMPscript' || resourceLangId == 'ampscript' || resourceDirname =~ /asset\\\\[a-zA-Z]*/)))", "command": "sfmc-devtools-vscext.devtoolsCMDeploy", - "group": "devtools" + "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && (resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceExtname == '.json' || resourceExtname == '.html' || resourceExtname == '.sql' || resourceExtname == '.ssjs' || resourceLangId == 'markdown' || resourceLangId == 'AMPscript' || resourceLangId == 'ampscript')))" }, { - "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy'", "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", - "group": "devtools" + "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /retrieve/" } ], - "commandPalette": [ + "explorer/context": [ { + "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/", "command": "sfmc-devtools-vscext.devtoolsCMRetrieve", - "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /retrieve/" + "group": "devtools" }, { + "when": "sfmc-devtools-vscode.isDevToolsProject && (resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceExtname == '.json' || resourceExtname == '.html' || resourceExtname == '.sql' || resourceExtname == '.ssjs' || resourceLangId == 'markdown' || resourceLangId == 'AMPscript' || resourceLangId == 'ampscript' || resourceDirname =~ /asset\\\\[a-zA-Z]*/)))", "command": "sfmc-devtools-vscext.devtoolsCMDeploy", - "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && (resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceExtname == '.json' || resourceExtname == '.html' || resourceExtname == '.sql' || resourceExtname == '.ssjs' || resourceLangId == 'markdown' || resourceLangId == 'AMPscript' || resourceLangId == 'ampscript')))" + "group": "devtools" }, { + "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy'", "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", - "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /retrieve/" + "group": "devtools" } ], "editor/title/context": [ From a8d6612f67e6154ab209a4d845da4914eef8202c Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Thu, 6 Jun 2024 13:32:17 +0200 Subject: [PATCH 5/5] fixed double commandPalette configuration --- package.json | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/package.json b/package.json index 712fa01..30389b0 100644 --- a/package.json +++ b/package.json @@ -123,20 +123,6 @@ "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", "group": "devtools" } - ], - "commandPalette": [ - { - "command": "sfmc-devtools-vscext.devtoolsCMRetrieve", - "when": "false" - }, - { - "command": "sfmc-devtools-vscext.devtoolsCMDeploy", - "when": "false" - }, - { - "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", - "when": "false" - } ] }, "configuration": {