Assign key to default button option when shown information message in vscode extension? - vscode-extensions

I am creating an extension in VSCode that will close all open text documents when you click the option "Yes" in the vscode.window.showInformationMessage("Want to close?", "Yes", "No).
Pressing the "Yes" button will work fine but I want the "Enter" key on the keyboard to do the same? How can I listen for keystrokes when I register a command? Is it possible?
Here is my code right now:
context.subscriptions.push(
vscode.commands.registerCommand(
"close-tabs",
async (inputValue?: string) => {
const { activeTextEditor } = vscode.window;
if (!activeTextEditor) {
vscode.window.showInformationMessage("No active text editor");
return;
}
const answer = await vscode.window.showInformationMessage("Want to close tabs?", "Yes", "No");
if (answer === "Yes") {
vscode.commands.executeCommand("openEditors.closeAll");
}
// ON_ENTER: I was thinking an if case here that checks if enter has been pressed and also executes the command above?
}
)
);
To reiterate. How can I choose the "Yes" option when pressing the "Enter" key?

Since your InformationMessage box is not modal, it doesn't get focus when it appears.
I'm afraid you would have to make it modal - which in your case might be acceptable - to get the behaviour you want:
const answer = await vscode.window.showInformationMessage("Want to close tabs?", { modal: true }, "Yes", "No");
Then the message box's first button is automatically given focus and Enter will trigger it.

Related

How to change the database if printed?

I have a button that prints
<input type = "button" onclick = "printDiv ('printableArea')" class = "button1" value = "Print" />
<script>
function printDiv (divName) {
var printContents = document.getElementById (divName) .innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print ();
document.body.innerHTML = originalContents;
}
</script>
And it sends to print operation.
The customer currently has the option to print or cancel.
Is there a way to access code behind in case the customer presses a print button?
(I want to change in my database that the client has already printed ...)
Regards
Is there a way to access code behind in case the customer presses a print button?
Please note that we can not directly detect if user clicked the 'Print' or 'Cancel' button in printing dialog via JS code from a html page.
Similar issue discussed in this SO thread: How to capture the click event on the default print menu called by Javascript window.print()?
As a workaround, you can try to show a prompt dialog to confirm if the printing is complete and then make request to backend to update database once the afterprint event is raised, like below.
window.onafterprint = function () {
var message = "Have you printed the page(s)?";
var result = window.prompt(message,"yes");
if (result=="yes") {
//...
//make ajax request to backend
//...
}
};
You can add a GET request to an MVC Action like (in jQuery):
...
document.body.innerHTML = printContents;
var clientId = $("#clientId").val();
$.get("#Url.Action("SavePrinted", "Client")", { clientId: clientId });
window.print();
...

Click Event in CKEditor5 Toolbar

I found some information on CKEditor4 on trapping a clicked tool on the CKEditor toolbar but the v5 rewrite means this no longer works:
editor.on('afterCommandExec', handleAfterCommandExec);
function handleAfterCommandExec(event)
{
var commandName = event.data.name;
// For 'bold' commmand
if (commandName == 'bold')
alert("Bold button pressed!");
}
Are there any examples of working CKEditor 5 code to detect when a tool has been clicked? I'm actually trying to trap when someone clicks Track Changes to show the changes sidebar but hide it otherwise.
Maybe this works
const command = editor.commands.get('bold')
command.on('execute', () => {
console.log('Bold has been executed')
})

react-native re - ender component by clicking a button from another component

I have a list of interventions on my "first page". When I click on one, I navigate to its details, "second page", and there, is a button that allows me to start the events. When I click on that button it fills an object from a route : api/current
{
"interventionSummary": {some object}
}
When there's no intervention started :
{
"interventionSummary": null
}
When an intervention is started, it should be ended too so if the users doesn't I want to show a reminder message in the interventions list ("page 1") using: if interventionSummary !== null -> display the message to remind to end the intervention.
The problem is that my object interventionSummary is not updated when I go back on my interventionsList, unless I reload. For another page I was able to use :
this.props.navigation.addListener('focus', doStuff);
But the button and the route used were in the same page. I have tried, forceUpdate, simulate a state change : this.setState({state : this.state}) from solution on google, but nothing is working, I don't know how to make the component interventionsList see the update, or just re render after the click on the "second page"...
I hope that's clear, if anyone knows a way to do that
in your first page create your function.
myMethod() {
//function i want to call in second page
}
in your first page when navigating to second page(in my case when user presses a button) pass a function as a parameter like below:
onPress={() => this.props.navigation.navigate('SecondPage', {
rerenderOutputTitles: () => this.myMethod(),
})}
then in second page call this method wherever you want like below:
this.props.navigation.state.params.rerenderOutputTitles();

How to disable right click during navigation from one web page to other?

I have disabled right click by adding the following code. However, when I navigate from one page to other, during that window of time, on right click, the right click menu is opening.
document.onmousedown = function (event)
{
event = (event || window.event);
if (event.button == 2 )
{
alert("right click");
}
}
You can use oncontextmenu for this:
document.oncontextmenu = function () {return false;}
This can happen for case if document.onmousedown = function (event) isn't yet executed for some reason. Among reasons can be errors in java script or browser yet didn't execute document.onmousedown = function (event) because it is in process of executing some other javascript code.
Another proposal for consideration can be another way of disabling:
<body oncontextmenu="return false">

jqGrid: different navigator buttons depending on login status

I want to use different navigator buttons in jqGrid depending on login status.
for example: if the user is logged in then add/delete/edit button appeared.
Any ideas?
Thanks in advance.
It is possible to add buttons programmatically using the navButtonAdd method (for the navigation bar) and the toolbarButtonAdd method for the toolbar. For example:
jQuery("#grid").toolbarButtonAdd('#t_meters',{caption:"MyButton",
id: "t_my_button",
title: "Do my button action",
buttonicon: 'ui-icon-edit',
onClickButton:function(){
// Button handle code goes here...
}
});
And:
jQuery("#grid")..navButtonAdd('#pager',{
id: "t_my_button",
title: "Do my button action",
buttonicon: 'ui-icon-edit',
onClickButton:function(){
// Button handle code goes here...
}
});
For more information see the Custom Buttons on the Wiki.
Anyway, once this code is in place, you can detect login status server-side. Then use this knowledge to generate client code that only adds the buttons to your grid if the user is supposed to have access to them.
You can also use for example userdata (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#user_data) to send information about buttons which you need to have in the navigator. userdata should be set by server. Then with respect of:
var navGridParams = jQuery("grid_id").getGridParam('userData');
// var navGridParams = { edit: false, add: false, search: true }
you can get the data set by the server.
Now the typical call like:
jQuery("grid_id").navGrid('#pager', { edit: false, add: false, search: true });
You should place not after creating of jqGrid, but inside of than inside of loadComplete. So the code could looks like following:
var isNavCreated = false;
jQuery('#list').jqGrid({
// ...
loadComplete: function () {
var grid = jQuery("grid_id");
if (isNavCreated === false) {
isNavCreated = true;
var navGridParams = grid.getGridParam('userData');
grid.navGrid('#pager', navGridParams);
}
},
// ...
});
Another option that I see, is to use cookie instead of userdata to send information about navGridParams back to the client.