New Dialog: Options()

Help with writing and running scripts

New Dialog: Options()

Postby PJFromOverHere » Mon Mar 28, 2011 3:50 pm

It would be nice if the Ecmascript/Javascript folk could implement this, but until then I would hope IDM would throw it into their JS implementation.

A new dialog a la alert(), confirm(), prompt() called options() called like so:

//syntax: options(TITLE,DEFAULTCHOICE,CHOICESARRAY)
//CHOICESARRAY can be numeric-indexed or an associative array
//return undefined if CANCEL pushed
var TheChoices = {a:'ChoiceA', b:'ChoiceB', X: 'Exit'};
var mychoice = options('Make your choice','X',TheChoices);

When I write some of my UE JS scripts I'd like to present a menu of choices to myself so that I don't have to write a bunch of individual scripts to handle only slightly different situations.

This has been emailed to IDM support for consideration.

How many agree that this would be useful?
User avatar
PJFromOverHere
Newbie
 
Posts: 8
Joined: Wed Sep 26, 2007 11:00 pm

Re: New Dialog: Options()

Postby Mofi » Tue Mar 29, 2011 1:06 am

Although I understand your intention, I don't really understand what your option dialog should look like. What type has the array TheChoices? What should the options dialog look like?

I don't need such an option dialog for myself, but I think it would be a very useful enhancement for many script writers to have an options dialog.

The dialog should have:

  1. a title text displayed in the dialog window title,
  2. a request text with up to 3 lines at top of the dialog with using \n in the text to force a line break inside this multiline string,
  3. a list of string items for a listbox.
The first list item is automatically preselected on opening the dialog which makes a Cancel button unnecessary and additionally has the advantage that no error condition must be handled. The syntax for this option dialog command could be:

listbox("window title","text above listbox,\nfor example:\nPlease choose line termination type:","DOS","UNIX","MAC");

The return value of the function is either an integer with value 0 for first option, value 1 for second option, ... or the string selected by the script user. An integer as return value can more easily evaluated, but a string would be easier to read when used in following conditions. Normally an integer is returned by a listbox control.

I have not sent this to IDM support by email. I have just contributed my idea on such an options dialog here.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4069
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: New Dialog: Options()

Postby PJFromOverHere » Thu Apr 07, 2011 3:20 pm

theChoices, as stated, would be either a Javascript associative array, or a simple numeric-indexed array. Programmer's choice depending on the situation. Associative arrays are quite valid in JS so why restrict to simple arrays?

As to the request text parameter, good idea, so that the rationale for the dialog can be explained a little further.

returning undefined on cancel, I think, is still valid (i.e. to quote RUSH from "Freewill": "If you choose not to decide you still have made a choice") and therefore always pre-selecting the first item would reduce functionality. Having a programmer-defined default choice allows the user to simply hit OK (or press Enter) to make the default choice which is good. Also, it may not always be desirable to consider the first item the default (i.e. I work for the Canadian government. If, working on a public or internal app, I were to display a dialog asking "What's your preferred language?" and I defaulted it to "English" I'd get skewered.)

I was thinking the dialog would have option buttons but a listbox would be fine. An extra parameter could be AllowMultiple boolean which would display a multi-select listbox or checkboxes instead of radio buttons and the return would be an array [of numeric indexes or string key values depending on the Choices array supplied] instead of a single value.

And, if the programmer decides there is to be no cancel then allow that as a parameter, too. But always have an "OK" or "Continue" button so that the closing of the dialog isn't immediate upon making a choice (which is necessary if allowing multiple).

The reason I figured for allowing an associative array is that the letters {restrict the array keys to single-letter} can be used as the selectors, like with a console menu.
( ) A: ChoiceA
( ) B: ChoiceB
( ) X: Exit
or, if Multi-select
[ ] M: Male
[ ] T: Tall
[ ] X: Executive
{substituting actual radio or checkbox controls for the ( ) and [ ] and including the infoText above that}

so, extending:
Syntax could now be:
var selection = optionsdlg(windowTitle, infoText, defaultChoice, theChoices, allowMultiple, allowCancel);
ex1:
var windowTitle = 'Make your choice';
var infoText= "text above listbox,\nfor example:\nPlease choose line termination type:";
var theChoices = {a:'ChoiceA', b:'ChoiceB', X: 'Exit'};
var defaultChoice = 'X'; // undefined = no default choice
var mychoice = optionsdlg(windowTitle , infoText, defaultChoice ,theChoices , false, true); //mychoice is a string
var mychoice = optionsdlg(windowTitle , infoText, defaultChoice ,theChoices , true, true); //mychoice is an array of strings
ex2:
var theChoices = {"DOS","UNIX","MAC"};
var defaultChoice = -1; // -1 or undefined = no default choice
var mychoice = optionsdlg(windowTitle , infoText, defaultChoice ,theChoices , false, true); //mychoice is an integer
var mychoice = optionsdlg(windowTitle , infoText, defaultChoice ,theChoices , true, true); //mychoice is an array of integers


I think this would give script writers an extra level of interaction with their users. It's somewhat like being given the power of creating a userform from within Javascript (albeit with limited functionality). I think this complements alert(), confirm(), and prompt() nicely.
User avatar
PJFromOverHere
Newbie
 
Posts: 8
Joined: Wed Sep 26, 2007 11:00 pm

Re: New Dialog: Options()

Postby PJFromOverHere » Wed May 11, 2011 12:03 pm

Yes, actually a listbox on a form would be sufficient. The call to the function must include a "multiselect" boolean parameter. The UE custom window could look like this:

Code: Select all
---------------------------------------------------
|Title                                           X|
---------------------------------------------------
|   -------------------------------------------   |
|   | listbox with the options in it          |   |
|   |                                         |   |
|   |                                         |   |
|   |                                         |   |
|   |                                         |   |
|   |                                         |   |
|   -------------------------------------------   |
|                                                 |
|   info text                                     |
|                                                 |
|                                                 |
|        CANCELBUTTON          OKAYBUTTON         |
---------------------------------------------------


or an approximate facsimile thereof.
User avatar
PJFromOverHere
Newbie
 
Posts: 8
Joined: Wed Sep 26, 2007 11:00 pm

Re: New Dialog: Options()

Postby palou » Wed Jun 19, 2013 9:57 am

I know this topic was open long time ago, but it's exactly what I'm looking for.
Is there any news on that option dialog implementation?

Regards,
palou.
User avatar
palou
Basic User
Basic User
 
Posts: 48
Joined: Fri Dec 17, 2004 12:00 am
Location: Geneva / Switzerland

Re: New Dialog: Options()

Postby Mofi » Thu Jun 20, 2013 1:12 am

IDM has not implemented yet a command which opens a dialog to choose one or more options from a list.

And it looks like nobody has written a small tool which could be executed via a user tool to interact with an UltraEdit script.

The option parameters to such a tool would be best copied to Windows clipboard by the script, then the tool is started via a user tool. The tool shows the list based on the parameters in Windows clipboard, and returns the users choice via the Windows clipboard as text to the script.

Such a tool should be written as console application which opens the selection dialog window so that UltraEdit halts with script execution until the user clicks on OK button resulting in terminating the console application resulting in terminating user tool execution and finally in continuing the script execution.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4069
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: New Dialog: Options()

Postby palou » Thu Jun 20, 2013 1:49 am

Thanks Mofi for the explanation and the idea.

I'm not sure if I'm able to implement the tool you talk about, but I will surely re activate the feature request originally posted by PJFromOverHere.

Best regards,
Palou
User avatar
palou
Basic User
Basic User
 
Posts: 48
Joined: Fri Dec 17, 2004 12:00 am
Location: Geneva / Switzerland


Return to Scripts