How to use confirm dialog handler? - dialog

I tried to use the confirm dialog handler to click ok, but it still doesn't make the click. Am I using it right? Here is the code:
var handler = new ReturnDialogHandler();
using (new UseDialogOnce(WebBrowser.Current.DialogWatcher, handler))
{
WebBrowser.Current.AddDialogHandler(handler);
WebBrowser.Current.Link("delete").ClickNoWait();
handler.WaitUntilExists(5);
handler.OKButton.Click();
WebBrowser.Current.WaitForComplete();
}

In the unit tests for WatiN that handler is created like this:
var handler = ReturnDialogHandler.CreateInstance();

Related

How to remove a listener in chrome.webRequest API in dart?

Related to `chrome.webRequest.onBeforeRequest.removeListener`? -- How to stop a chrome web listener, I am trying to deregister a listener using dart:js
After invoking onBeforeRequest.callMethod('removeListener', [callback]); I notice that the listener is still being called. Furthermore, directly after adding a listener the hasListenerreturns false (even thought the listener is being registered).
var callback = (map) { /* some code */ };
var filter = new JsObject.jsify({"key": "value"});
var opt_extraInfoSpec = new JsObject.jsify(["extra opt"]);
// chrome.webRequest.onBeforeRequest.addListener
JsObject onBeforeRequest = context['chrome']['webRequest']['onBeforeRequest'];
onBeforeRequest.callMethod('addListener', [callback, filter, opt_extraInfoSpec]);
Logger.root.fine('main(): does callback exist: ${onBeforeRequest.callMethod('hasListener', [callback])}');
It seems to be necessary to follow 100% the dart:js recommendations how to use a dart Function in the javascript environment. I guess my problem was that the original dart dynamic function is wrapped automatically in a proxy. Hence the callMethod for addListener used a different proxy object then the callMethod for hasListener, even thought both of them were based on the same original dart object (i.e. callback).
The solution is to use the JsFunction and define the callback as following:
var callback = new JsFunction.withThis((that, map) { /* some code */ });

Haxe check which button is pressed (DOM Event)

I recently started programming in Haxe, because I don't like JavaScript too much. I made an EventHandler and wanted to check which button is pressed at this time. In the documentation I found Event.button, but that doesn't work (I think because of browser compatibility, it compiles to e.button in JavaScript which doesn't work).
How else can I check which button is pressed in my event?
To listen to an event you can do:
static function main(){
Browser.document.getElementById('myButton').onClick = clickHandler;
}
function clickHandler(e : Dynamic){
var target : Element = e.target;
}
This is will get the pressed element.

Add-in express and BackGroundWorker threading

Here's the problem:
I have an Outlook add-in made with add-in express.
It hosts a panel with the only winforms ElementHost, where WPF content is performing.
In this WPF control I have a textbox and button.
Button click triggers Backgroundworker to load info from database, in 'RunWorkerCompleted' process this data is being put into control.
When button is pressed - everything goes normally. But if I catch 'Enter' key press in textbox and then trigger BackgroundWorker - 'RunWorkerCompleted' is being launched not in the main thread, but in a thread pool, and cannot access WPF elements.
In both cases BackGroundWorker.RunWorkerAsync() is being called from Main thread, DoWork runs in thread pool, and only in case of enter-key-catch, RunWorkerCompleted also runs in a thread pool.
You've run into a bug in Add-in Express. In some cases Add-in Express event handlers are called with System.Threading.SynchronizationContext.Current set to null. BackgroundWorker use it in RunWorkerAsync method to save the ui context, so that is the problem.
To fix SynchronizationContext you could use the following workaround. Here MyAction is the method where you call RunWorkerAsync from.
var ctx = SynchronizationContext.Current;
if (ctx != null)
{
MyAction();
}
else
{
var timer = new DispatcherTimer();
timer.Tick += (s, a) =>
{
MyAction();
timer.Stop();
timer = null;
};
timer.Interval = TimeSpan.FromMilliseconds(10);
timer.Start();
}
Another solution would be saving the valid SynchronizationContext.Current value somewhere in a static member and then calling SynchronizationContext.Post in the event handler for the same purpose. I haven't tried this one though.

Is there a way to trigger plotselected event without triggering plotclick event?

I need click events in the chart.
But I also need to allow user to select a range to zoom in.
Click events are registered properly. However on doing a selection, it triggers both plotselected and plotclick events.
How do I prevent the plotclick event from being triggered while plotselected is triggered?
Selection plugin: https://github.com/flot/flot/blob/master/jquery.flot.selection.js
Currently no, there's no way to avoid getting both events.
One solution might be to remove the 'clickable' option and instead listen to the 'plotunselected' event, which is triggered by a click without drag.
The problem is plotselected triggering plotclick event.
The following conditional check solved my problem.
$("#graph").bind("plotclick", function (event, pos, item) {
if (item == undefined) return false;
// the rest of the click event here
});
resting's answer didn't quite work for me as my use case needed to handle the plotclick event even if there was no item clicked.
I was able to determine if an event was a plotselection vs plotclick event in the plotclick event handler by setting a variable in the plotselection event handler and then checking it in the plotclick handler:
var plotSelectionEvent = false;
$("#placeholder").bind("plotselected", function (event, ranges) {
plotSelectionEvent = true;
// rest of the plot selection event code
});
$("#placeholder").bind("plotclick", function (event, pos, item) {
// check if this event was originally a plot selection event
// reset the variable and return if it was
if (plotSelectionEvent) {
plotSelectionEvent = false;
return;
}
// rest of the plot selection event code
});

Chrome extension delay condition

I have created a chrome extension which does something after its button is clicked.
However I dont want it be abused so I need the its code to be executed after some time.
How can I surround this code with a timeout in order to achieve this?
Thank you for reading me!
chrome.tabs.getSelected(null,function(tab) {
var Mp=tab.url.substring(0,23);
if(Mp=='https://www.example.com')
{
onWindowLoad();
chrome.extension.onMessage.addListener(function(request, sender) {
if (request.action == "getSource")
{
...Working here
}
});
}
else
{
message.innerHTML='<span style="color: #f00">This is not a valid page</span>';
}
});
function onWindowLoad()
{
var message = document.querySelector('#message');
chrome.tabs.executeScript(null, {file: "getPagesSource.js"});
}
I had to make a compromise so just after the getSelected I added the following line:
chrome.browserAction.disable(tab.Id);
It disables the action button thus it cant be clicked while the script sends the data to the server, as with this extension I grab the tab url in order to store it in my database.
After the ajax response and adding the following
if(xhr.readyState==4)
{
message.innerHTML=xhr.responseText;
chrome.browserAction.enable(tab.Id); /////<---THAT LINE
}
the button gets ready again to be clicked.
I couldnt find the way to add a specific delay in seconds, this way seems stupid but its working, as the response's delay from my server is enough for switching the 2 states of the action button.
With this, however another problem came up, which Ill write in different question.

Resources