Archive for July, 2014

Dialogs as Functions

Wednesday, July 16th, 2014

This is just an idea I’ve had. I wanted to write it down in some meaningful way so that I can rediscover it later. This is less a C++’ism, and more a JavaScript/Squirrel’ism.

* * *

In any situation where your user interface presents a popup dialog, that process of presenting the dialog should be a function call. Here is pseudocode:

The general idea here is that there should be 2 ways to use the function: 1. Without arguments, to bring up the entry dialog; 2. With arguments, to bypass the entry dialog (for macro/scripting use). The data in extracted from the function arguments, or the shown dialog, and the action is taken place.

Args should be the language equivalent of an object (JavaScript, Squirrel, etc). Alternatively, an array of objects could work too, but named elements would result in nicer code. Like above, it’s assumed a Yes/No/Cancel dialog would store a boolean named State to tell you which (Yes or No) was picked.

The above assumes a synchronous environment, where it’s safe to give a function “ShowDialog_YesNoCancel” full control.

In an asynchronous environment, you’ll want to use something like a Deferred or Future. If there are no arguments, the ShowDialog function will provide the object you bind your State handling function to. Otherwise, bind it to one that will succeed.

Alternatively, there are probably nice ways to handle this using coroutines or generators.