I'm working on a script add-in which uses OnDoubleClick callback. It works fine, except that it gets called for every selected file (for example I select 20 files and press Enter and script will be called 20 times). How can I specify it should be run once per global double-click event no matter how many files were selected (like @runonce but for script add-in)?
This seems to work, by making the OnDoubleClick handler check if it's being called for the first file in the lister:
initData.name = "TestDC"
initData.desc = ""
initData.copyright = ""
initData.version = "1.0"
initData.default_enable = false
If (doubleClickData.item.realpath = doubleClickData.tab.selected(0).realpath) Then
' Your code here.
In the next update you'll be able to do this to have OnDoubleClick only called once per event (and you would then access the files using doubleClickData.tab.selected directly).
doubleClickData.cont = False
I'm curious, what is it you use this for? o) I have hard times imagining something that processes multiple files on return.
Sounds like a simple script button could do the same thing more straight forward? If not I'm even more interested in what you are doing there. o)
@leo: thanks, that seems to be a good solution!
@jon: great! I'll use this and perhaps I'll do a version check (if possible, have to take a look at docs when I return home) and use leo's suggestion (check) if Opus version is below next beta, otherwise I'll have script simply set doubleClickData.cont = False
@tbone: I'm working on add-in which asks user to confirm if more than X files (threshold is configurable by end user via Opus script config GUI) are about to be opened. For example you have 200 ultra-high-res images (or whatever) selected and you accidentally press Enter - with this add-in enabled - Opus will ask you to confirm that you indeed want to proceed to open these 200 selected files at once (happened to me recently, my computer was unusable for 10 minutes while IrfanView instances kept spawning and loading 200 ultra-hd images - I couldn't even move a mouse let alone get to task manager or console to kill it with fire taskkill /F /IM).
Reason why I didn't do it as a button or command that can be used with button/hotkey/mouse event is because I wanted to make it as Opus add-in which any user can single-click to install and instantly have this behavior (it's like Firefox/Chrome/Opera plugin) rather than having to tinker in multiple places.
The add-in is 99.9% done and works great except for above mentioned (non) issue. I will share it soon
Ah I see, so this is not to kickoff something, but to prevent it.
I think accidentally opening of a bunch of files happened to everyone once at least, so this totally makes sense.
To have it event-based is the only real approach to this as well of course, thx for explaining! o)
Is it correct to use (jscript) this to detect if I'm on old version of Opus (and then run leo's method as a fallback)?
if (doubleClickData.cont == undefined)
Yes, that should do it. You always can test for "==undefined" for properties, but not for "loose" objects/variables
if (doIExist == undefined") //would error.
if (iExist.doIExist == undefined") //would not error.
//would also not error
//error handling code
//and that would also not error and can be used everywhere, even in global scope, because "this" always exists.
//so to be exact, there are no loose objects/variables, it's just that you need to know its container is there and use
//that for testing (use the fully qualified path to the variable so to say).
if (this.doIExist == undefined)[/code]
Be cautious with objects and variables the DO environment provides, these work in a way I still cannot sort to something I encountered before, but they work excellent if used properly, that's what's more important of course. Once you got behind the scheme you adapt to this easily as well, you might have noticed already. o)
Thanks! Please take a look at the attached add-in script, do you have any suggestions to improve it? I think it's completed (but before introducing it in appropriate sub-forum I want to test it with upcoming Opus update).
ConfirmMultiopen.js.txt (2.74 KB)
Too bad I can't edit my previous post, here is the optimized version (less code and looks nicer).
ConfirmMultiopen.js.txt (2.7 KB)
Is there a reason you keep the property names so short? What about continue or once, if really short is what you prefer, but that's a word at least! o)
You don't mind uploading my edited version of yours? It kind of shrinked a bit, maybe you find things you like.
Event.DClick_ConfirmMultiopen.js.txt (1.96 KB)
Why is it actually, that returning true cancels events, while returning false tells DO to continue. I remember working with a visual basic framework, where this was similar, I had 2 hard years editing validation routines from my collegues, as I always got confused if they returned false if something was valid. How weird is that? o)) Using variables/constants with sensible names for hiding an irritating value is the key here I guess.
Interesting remix, I am studying it closely
On returning false for success, it's quite common pattern: for example Windows expects program to return 0 (analogous to false) if no error occurred (normal exit). I guess false/0 is (on the lowest level) least amount of information, meaning "no changes". But now we digress
Is there a reason you keep the property names so short? What about continue or once, if really short is what you prefer, but that's a word at least! o)[/quote]
continue is what I started with, but then I realised that's a JScript reserved keyword. You should know that
Is it possible to set default focus to "Cancel" button in dialog (tab.Dlg)? (I want to make this configurable) Now focus is on the first button "Proceed" and I can't find anything in docs how to change it.
Perhaps there is a way to specify index of button to be focused when Dlg opens?
Waaah, of course it is! Please just forget what I was talking about. o))
A little workaround would be to swap buttons texts, but then cancel is not the very right button anymore, which is something I hate seeing/using. o)
But maybe this is better, I'd prefer this:
while (1==(result=DOpus.Dlg.Request("Delete files?","Think twice|Ok|Cancel","MultiOpenConfirmation")));
cont does not describe to me what is expected to happen. Does cont mean keep processing the rest of the files, or do it once and continue on, I would need to look it up. I would rather see a longer prop that makes it clearer what will happen. I don't think there is much benefit in making it short.
My suggestion would be RunOncePerEvent, or RunOnceForAllFiles, or RunOnce, or RunOnceForEachSelectFile.
Naming things is hard to get right.
You'd need to look it up anyway to know it even exists.
The next update will have a Dlg.defid property to let you do that.