| Did you know ... | Search Documentation: |
| Using Conditions |
Tests inside a dialog window
This example demonstrates the use of conditional messages to relate dialog-items to each other.
Using this technique is to be preferred over tests in the application code to relate and query values of dialog windows.
The example shows a text entry field (text_item) and a create
button. Pressing the create button should create a keyword in the
application.
First the code is shown doing almost everything in Prolog, next an alternative using some PCE primitives is given.
% bad_make_keywords_dialog(D)
%
% Creates a dialog to generate keywords, using Prolog
% to link the dialog together.
bad_make_keywords_dialog :-
new(D, dialog('Create keyword')),
send(D, append, new(label)),
send(D, append,
text_item(keyword, '',
message(@prolog, create, D))),
send(D, append,
button(create, message(@prolog, create, D))),
send(D, append,
button(cancel, message(@prolog, cancel, D))),
send(D, open).
create(D) :-
get(?(D, member, keyword), selection, Kwd),
( Kwd == ''
-> send(D, report, warning,
'Please first enter a keyword')
; create_keyword(Kwd)
).
cancel(D) :-
send(D, destroy).
% good_make_keywords_dialog(?Dialog)
%
% Creates the same dialog, but using PCE to glue the
% things together. This way the distinction between
% UI and application become more clear.
good_make_keywords_dialog :-
new(D, dialog('Create keyword')),
send(D, append, new(label)),
send(D, append, new(T, text_item(keyword, ''))),
send(D, append,
button(create,
if(T?selection == '',
message(D, report, warning,
'Please enter a keyword'),
message(@prolog, create_keyword,
T?selection)))),
send(D, append,
button(cancel, message(D, destroy))),
send(D, default_button, create),
send(D, open).
create_keyword(Name) :-
format('Create keyword ~w~n', Name).
% Only start the good one
:- good_make_keywords_dialog.
<-get_catch_all ->has_value