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

Command Pallette Button #37

Open
momiccioli opened this issue Feb 7, 2020 · 11 comments
Open

Command Pallette Button #37

momiccioli opened this issue Feb 7, 2020 · 11 comments

Comments

@momiccioli
Copy link

Whats the syntax to configure a button to run a command palette action? For example save current file.

@Joey79100
Copy link

That's a duplicate of #7. However I'm interested as well, because the answer in that other issue seems incomplete:
Just putting the VSCode command in "command" is not enough. It tries to run the command in the terminal instead.

Here's a basic example that would open settings on click.

"actionButtons": {
	"defaultColor": "#172c3d", // Can also use string color names.
	"reloadButton": null, // Custom reload button text or icon (default ↻). null value enables automatic reload on configuration change
	"commands": [
		{
			"name": "Settings",
			"color": "#ffffff",
			"command": "workbench.action.openSettings",
		}
	]
}

What am I missing?

@seunlanlege
Copy link
Owner

In order to achieve this, we would have to use the vscode.commands.executeCommands api

as stated here: https://code.visualstudio.com/api/extension-guides/command,

happy to provide mentoring if anyone is interested in picking this up.

@Joey79100
Copy link

So that means it's not possible yet without modifying the extension itself? Just to make it clear, because the answer on the previous issue made it sound like it was already possible.

@seunlanlege
Copy link
Owner

seunlanlege commented Mar 3, 2020

In order to achieve this, we would have to use the vscode.commands.executeCommands API

At the time, this API didn't exist.

@Joey79100
Copy link

I get that, but that means before the API the extension natively executed commands? The other posted asked if it was possible to call a palette command and you said it was possible as long as we knew the actual command. Is it not possible anymore?

@tjohnsonhvac
Copy link

@seunlanlege I think I might me willing to tackle this. I am good with js, have not done much with ts. I did go through the vscode extension tutorial for a js extension. Pretty straight forward. I read the command api page.
I see the example:

let uri = Uri.file('/some/path/to/folder');
let success = await commands.executeCommand('vscode.openFolder', uri);

Thinking out loud here, the process would be:

  • add the 'vsCommand' property to package.json

  • in init.ts line 49, pass the 'vsCommand' read from settings.json directly into const vsCommand variable (with some checks so a shell and a vsCommand cannot both be passed in)

  • pass vsCommand into commands.executeCommand() instead of the terminal.

Can you think of anything I'm missing?

@seunlanlege
Copy link
Owner

Can you think of anything I'm missing?

Nope, looks good to me 👌🏾

@mbenkmann
Copy link

Maybe merge this extension

https://marketplace.visualstudio.com/items?itemName=geddski.macros

into Action Buttons. It seems to complement Action Buttons nicely because it has exactly the features missing:

  • macros of built in actions
  • key bindings

@Nabav
Copy link

Nabav commented Jun 21, 2023

I have the save action button with:

  "actionButtons": {
    "defaultColor": "none",
    "commands": [
      {
        "name": "$(save)",
        "useVsCodeApi": true,
        "command": "workbench.action.files.save"
      },
    ]
  },

@momiccioli, does it solve your problem?

@momiccioli
Copy link
Author

momiccioli commented Jun 21, 2023 via email

@momiccioli
Copy link
Author

momiccioli commented Jul 4, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants