Step 7 - DialogsAs well as creating menus and icons, we can also create Dialogs with Gsharp. These can be used for presenting information and for getting input from the user. Gsharp supports eleven dialog types, which are: working, error, information, message, question, working, warning, prompt, template, bulletinBoard, selection and fileSelection. The first decision we need to make is - do we create our dialog each time we need it, or do we create it at startup so that it always exists. It is tidier and more efficient to create dialogs as we need them, but it is often simpler to create them at start-up. We want to make a dialog to show the source of our selected file. To simplify things we will create it at start-up.
Most dialogs that we create are "template" dialogs which allow you to create as many buttons, labels and fields on it as you wish, but in this case we can get away with using one of the simpler dialog types "message". The message dialog, contains a label, space for one GUI object and an OK button. We'll use the label for the filename, put a Text object in the work area and popdown the dialog whenever the OK buttons is pressed. Now we need to add a button to our View menu to popup our dialog. We also need to implement our PopdownDialogCB
When the user selects "View Source" from the View menu the function PopupDialogCB is called with callbackData set to "FileSource." PopupDialogCB calls: GuiPopupDialog("gsharp_1."+d); We could have hardcoded "gsharp_1.FileSource", but passing the dialog name in the callback data we've kept the callback generic and you can use it for other dialogs that you create. When the OK button of our dialog is pressed PopdownDialogCB is called. We've made this a generic function as well. The first argument of a callback is the name of the object generating the callback. In this case it was the dialog itself, but normally it is a button on the dialog, e.g. gsharp_1.templateDialog.OK. We use DialogFromObj to get the dialog name from the button/dialog name. The Dialog is then popped down. N.B. If this was a dialog that was made each time it was used - we would destroy the dialog rather than just pop it down. Finally we need to extend FileOpenCB to update our dialog whenever a file is loaded:
Our
application and tutorial are finished.
To see what the full code list see mysecondapp.gsa |