Ok/Cancel dialog for run commands

Hi, guys!

I frequently make project templates with custom toolbars. I distribute these templates to coworkers. Makes it easy to get started with different yet common project types. Often, I want to include an action that is destructive or has irreversible consequences, but it it too easy to accidentally press the wrong toolbar button, so I end up not including these actions in the toolbar.

Is there any way that I can get an Ok/Cancel dialog with my run commands? With that, I could feel much much safer adding all of my desired functionality to my custom toolbars. Seems like a common enough pattern that there should actually be a select box in the command properties dialog to include a safety check dialog.

Thanks,
Wayne

If I understand what are you talking about, you need run a “confirm” function in your JavaScript file. It’s return true if user click on “Ok” and false if user click on “Cancel”

Sorry I wasn’t clearer here. No js involved, not running a macro. I am making toolbox commands. I can interpolate all sorts of prompt dialogs, but a simple ok/cancel is not one of them. A confirm checkbox in the command properties would be awesome, and seems like a very common need.

If you’ve got any guidance on creating a macro I can stick in the toolbar that does the equivalent of querying the user and then running the command (or not) I would appreciate it. Either running it as a ‘hidden’ command ‘part’ in a folder (and not in the toolbar) or as a complete macro solution I can put in the toolbar.

The problems I can see with a complete macro solution is that the %p and %P interpolations aren’t available (don’t know why) and my command definitely needs to specify the project dir as the start in dir and in the path of the python command. So something that I can put in the toolbar that can get the user’s confirmation and invoke the command ‘part’ sitting in a toolbox folder would be awesome.

Although a simple ‘get user confirmation’ checkbox in the command properties would be more awesome.

Thanks,
Wayne

Hey Wayne,

If you want to stick with Commands you could try implementing the [%(ask) interpolation](
(http://docs.activestate.com/komodo/8.5/shortcuts.html#shortcuts_askcode). eg. Are you TOTALLY sure you want to run this Run Command? Wayne might fire you if you screw this up. Type 'yes' or 'y' to continue.

Having said that though, any interpolation you can do in a run command can be done in a macro using Macro Interpolation API.

If you do switch to a macro, you’ll have the option of using Komodos existing dialog templates. That will take a little more work though as you’ll need to customize you’re own Chrome (nothing to do with the well known browser) package I believe.

Cheers,

  • Carey

Thanks Carey.

Okay I can’t find again right now, but I did see something in the help file about %p and %P not being interpolated in macros. Maybe I misunderstood.

Anyhow, since I don’t want to add text to my command (adding y or yes to a command would surely break it), just an %(ask:Are you sure you want to reset the world?) seems to do the trick. Cancel cancels the command, ok runs it.

Still, it’s a bit problematic as there is still that pesky text widget and I don’t want any text accidentally added. It would be sweet if I could specify to ask that I want no text input, and then It would behave perfectly as a confirm.

Is it possible for me to make my own interpolation shortcut that I could then share?

For example %(confirm:prompt):

Thanks,
Wayne

EDIT:
Just to be clear, I never thought about using ask as a confirm, given it’s text box, but I’m using it now, and not sitting around looking for another solution. It gets me 90% of what I wanted. Just my OCD that makes me want a more ‘perfect’ solution. So thanks a lot Carey, for knocking the scales off my blind spot!

I just can’t seem to get away from it… so consider this a feature request.

All toolbox part properties dialogs, except the containers of course, should have a check box and a text box for a prompt to add confirmation.

Not only does this make it easy for distributing toolbars and such, but it also makes it simple for the end user to enable or disable confirmation as they see fit, without them needing to modify anything else about the object in question.

That seems like a very good thing to me. And very nice for anyone who supports or manages a team where the sharing of tools can be an integral part of insuring code quality, adherence to standards and having all members benefit from the tools made by one.

Thoughts?
Wayne

It feels like it’s better done with a macro:

  1. Use the macro recorder thinger to record yourself using the run action.
  2. Save the macro.
  3. Edit the macro to do the prompt, and skip the actual action if it’s cancelled.

The run dialog is sort of already complicated enough and we should probably avoid adding extra UI bits; imagine you’re a new Komodo user and try to run something simple… it’s already quite intimidating. The macro recorder is meant to help you make things like this.

Does that help?

Sorry Mook, but I’ve got to disagree.

The command dialog is really not that complex or intimidating. Look at preferences. If that’s acceptable to Komodo’s target audience, I really can’t see how a confirm check box in command properties would throw them for a loop. A confirm check box is pretty much as simple an addition as could be made and would greatly enhance the utility for those who support a team of programmers or a classroom of students. Or even those who just would like to make their personal irreversible commands safer, especially in toolbars, where a single misplaced click can invoke the command. This seems like a very good addition to me, well worth the extremely small addition to complexity.

As for beginners, fine, they need extra hand holding always. But they can do what beginners always do. Ignore any setting they don’t understand or care about, and let the default (unchecked) be. As for professional programmers, professors and college students, which I assume is the bulk of your audience, I hardly see this as an issue.

As for using the macros to do this simple but very important task, ouch! Talk about adding complexity! So, to get a confirm box:

  1. Make the command in some toolbox folder that is not the toolbar.
  2. Record a macro accessing that command, save it in the toolbar.
  3. Edit the macro to present a confirm dialog. (Exactly how do I access
    Komodo’s confirm dialog? Please don’t say I should ‘manipulate the
    dom’.)
  4. Return on cancel, or run the command on ok.

So, every time I want to make a command that should be confirmed, I need to maintain a separate folder for the command, give the command a non-clashing name, record and modify a macro for the toolbar, have a fragile link to maintain. I’d much rather just check a confirm check box in the properties.

The purpose of an IDE is to make my life easier, not more complex. All this complexity is added by trying to add the functionality of confirmation in the wrong place… the macro. It see seems fairly obvious to me that it is a property of the command and therefore belongs in the properties dialog. Talk about DRY, that’s the place it can be implemented once for reuse.

Macros are for doing things above and beyond the reasonable support the IDE offers like particular group needs, particular programmer needs, particular project needs. I’m very happy to go through the hoops to do something that isn’t something is so basic, so clearly a property that is needed, has such wide application for a wide group of users and improves the usability and safety of the IDE so much.

Thoughts?
Wayne

EDIT:
Sorry, Mook, I misunderstood your directions. I just tried recording the command from the tool menu run command. Before, I was recording the macro by clicking the existing command from the toolbox itself. The tools run command macro doesn’t find the part, so no need to maintain a separate part and a macro to invoke it. It actually demonstrates how to make a command call directly.

So, the amount of complexity in creating the commands is much less than I asserted above. I’d still like my pony, but if someone can show me how to invoke and act on a Komodo confirm dialog, I would be quiet about this feature from now on. :smile:

Thanks again,
Wayne

BTW, this is where I got the idea that %p was unavailable in macros. It appears that it’s just python macros, can’t imagine why.In the help for python macros:

Interpolate a string

There is currently no equivalent in XPCOM for evaluating interpolation codes.
This can be done using the old komodo namespace as follows:

  import komodo
  komodo.interpolate()

Some interpolation shortcuts cannot be used within Python macros. These include %P and %ask, and the :orask modifier on other shortcuts. A ValueError is raised if they are used.

Okay, after a whole lot of digging, I was able to come up with the following:

// Macro recorded on: Sat Jun 21 2014 15:41:28 GMT-0400 (Eastern Standard Time)
komodo.assertMacroVersion(3);

/*** Start Command Confirmation ***/

// Holds passed parmeters and responses.
var dialogIO = {
    title: 'Mindblowing Command',
    prompt:'This action is irreversable.  Are you sure you want to continue?',
    response: 'Cancel'
};
// Open the dialog and wait for user input.
ko.windowManager.openDialog(
    "chrome://komodo/content/dialogs/okCancel.xul",
    "_blank",
    "chrome,modal,titlebar,centerscreen",
    dialogIO);
// If user cancels, just get out of here.
if (dialogIO.response == 'Cancel') return;

/*** End Command Confirmation. ***/

if (komodo.view) { komodo.view.setFocus(); }
ko.run.runEncodedCommand(window, '%(python3) manage.py validate {\'cwd\': u\'%p\'}');

The first two and last two lines are generated by recording a macro using menu Tools>Run Command or ctrl-R.

  1. Include everything between Start Command Confirmation and End
    Command Confirmation comments

  2. You can feel free to remove the response: ‘Cancel’ line or change
    ‘Cancel’ to ‘OK’. These are setting the default button and response returned by the dialog. Default is ‘OK’. Your choice.

  3. Modify the title: ‘title’ string to a title of your choice. I would
    choose the macro name.

  4. Modify the prompt: ‘prompt’ string to your prompt of choice. The
    given value works for me.

This is better than nothing. Shortcomings of this method re a built in confirm check box (with or without a settable prompt string that becomes active when the box is checked):

  1. The title isn’t just automatically set to the macro’s name. Room for error.

  2. The user needs to edit the distributed macro and comment out or
    remove the confirmation code to disable it.

  3. It is now much more difficult for the user to modify simple things
    about the supplied command. For instance, if they wish to change
    the command to do something supported simply in the properties, like run in
    a command window or set an environment variable to support their environment, they will need to
    do some less than obvious changes to the command call.

  4. If the user must modify macros, instead of just dealing with
    properties to customize commands, I will face much more resistance
    in user compliance with using distributed toolboxes.

So, I still want my pony!

Is there anything here I could have done differently/better?
Wayne

As you wish.

You’re welcome to file a Komodo Enhancement Request for adding the a confirmation option for commands.

We’re always open to suggestions from the community so please do file the request. If it’s left in the forum it will not get acted upon. Be aware though that Komodo 9 roadmap has been set and will not likely be added to. This will have to wait until a later release or until someone from the community pushes the suggestion to the Komodo repo.

  • Carey

Thanks, Carey.

I entered a request. I think I’m going to go back to using %ask, and stick it right in front of the command, so that if the user enters any text, the command will most likely break. Then it shouldn’t be too hard for me to explain how to disable the confirmation and the easy property settings are still available via the properties dialog.

Of course, if there are %ask or it’s ilk anywhere in the command, the user will have ample opportunity to cancel without the need of a confirmation dialog.

Thanks,
Wayne