Closed cornfeedhobo closed 3 years ago
Pull requests are welcome. If not, I will give it a try next week
Am Mo., 19. Nov. 2018, 22:43 hat cornfeedhobo notifications@github.com geschrieben:
It would be nice to support 'when' https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts clauses.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AnWeber/vscode-statusbar-command/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AMz_c6UsJd8yWE5bjPQ7bdnKfEfySsjaks5uwyYFgaJpZM4Yp8to .
@AnWeber Haha, sorry, I don't touch javascript. I'll do more harm than good.
This is a really great extension!
I would like to use the mentioned "When" clauses to show/hide Statusbar buttons, but I cannot manage how to do that with those filter expressions.
For example, I have a button for "Toggle Block Comment" and that command has "When" = "editorTextFocus && !editorReadonly". I tried unsuccessfully those newly added "scriptEvents" and "script" settings like this:
"scriptEvents": ["vscode.workspace.onDidChangeConfiguration", "vscode.window.onDidChangeActiveTextEditor"],
"script": "if (editorTextFocus && !editorReadonly) {statusBarItem.show();} else {statusBarItem.hide();}",
I am far from being JavaScript/TypeScript expert, but I did quick search within the VSCode source code, and after that I tried even these lines:
"script": "if (EditorContextKeys.editorTextFocus && !EditorContextKeys.editorReadonly) ? ...
"script": "if (workbench.EditorContextKeys.editorTextFocus && !workbench.EditorContextKeys.editorReadonly) ? ...
"script": "if (window.activeTextEditor.hasTextFocus() && !window.activeTextEditor.isSimpleWidget && !window.activeTextEditor.readOnly) ? ...
Is that even possible with the available VSCode extensions API?
@Z-E-D Unfortunately it is not possible to integrate the when clause
api. This is not provided for extensions, nor does StatuBarItem provide this api out of the box. As a compromise I have integrated the possibility to use the VSCode API via Javascript.
In your example, the entry point vscode
is missing in particular.
{
"scriptEvents": ["vscode.workspace.onDidChangeConfiguration", "vscode.window.onDidChangeActiveTextEditor"],
"script": "if (vscode.window.activeTextEditor && !????) {statusBarItem.show();} else {statusBarItem.hide();}",
}
But I'm not sure if that will get you anywhere, since I don't know how to recognize Read Only TextEditor. If you want to look further, I would recommend you just clone the extension locally and debug it directly. You can then set appropriate breakpoints and possibly find solutions.
Steps
git clone https://github.com/AnWeber/vscode-statusbar-command.git
npm install
npm run compile (or watch)
code .
and launch Run Extension
(F5)
Thank you very much for your response. I am afraid that your suggestion is too far from my expertise, but I really appreciate your answer.
@Z-E-D You can also send me a concrete example of what you want to achieve. (Which files are read only?). If I find some spare time, I can have a look. Maybe in a new issue
Thanks for your offer, but that is not limited only on the read-only status of files. For example, the "Go to Definition" command has "When" = "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor". Or, the "Go to Previous Symbol Highlight" command has "When" = "editorTextFocus && hasWordHighlights". Or, the "Focus Previous Search Result" command with "hasSearchResult || inSearchEditor".
Anyway, it is not really a big deal, just my nitpicking. Just forget about it.
It would be nice to support 'when' clauses.