Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

163 feature offer active file ctrl+shift p commands #184

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/semi": "warn",
"@typescript-eslint/camelcase": "off",
"curly": "warn",
"curly": "off",
JoernBerkefeld marked this conversation as resolved.
Show resolved Hide resolved
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
25 changes: 17 additions & 8 deletions src/devtools/containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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();
if (fileURI) filesURI.push(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.");
}
})
);
Expand Down
1 change: 0 additions & 1 deletion src/devtools/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
12 changes: 11 additions & 1 deletion src/editor/containers.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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
};

Expand Down
6 changes: 5 additions & 1 deletion src/editor/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

Expand Down
Loading