You may be wondering what has happened to task-text, the text field in which you typed the text of each new task. In the new design, this is moved to a new dialog box that is popped up whenever you choose a command to add a new task to the list. This section shows you how to define this dialog.
The method prompt-for-task below creates and displays a dialog that asks the user to type the text for a new task. The definition of task-text is very similar to the definition you provided in the initial design, with the exception that the activate callback exits the dialog, rather than calling the not-yet-implemented function.
The method takes two keyword arguments: a title, which is assigned a value by default, and an owner, which is used as the owner for the dialog that is displayed by prompt-for-task. Note that the title is never explicitly set by any calls to prompt-for-task in the task list manager; it is provided here as an illustration of how you can provide a default value for a keyword argument, rather than requiring that it either always be passed in the call to the method, or that it be hard-wired into the code.
The method returns two values: the name of the new task, that is, the text that the user types into the text field, and the priority of the new task.
Add this method to frame.dylan.
Note: The definition of the prompt-for-task method uses the <priority> type. Note that this type is defined in Section 5.1, "Defining the underlying data structures for tasks". Until the relevant code in Section 5.1 is added to your project, any attempt to build it will generate a serious warning.
define method prompt-for-task
(#key title = "Type text of new task", owner)
=> (name :: false-or(<string>),
priority :: false-or(<priority>))
let task-text
= make(<text-field>,
label: "Task text:",
activate-callback: exit-dialog);
let priority-field
= make(<radio-box>,
items: $priority-items,
label-key: first,
value-key: second,
value: #"medium");
let frame-add-task-dialog
= make(<dialog-frame>,
title: title,
owner: owner,
layout: vertically ()
task-text;
priority-field
end,
input-focus: task-text);
if (start-dialog(frame-add-task-dialog))
values(gadget-value(task-text), gadget-value(priority-field))
end
end method prompt-for-task;
Notice that the dialog used in the prompt-for-task method is created inline within the method definition. In this particular case, the dialog is only ever needed within the context of prompt-for-task and so it is not necessary to use define frame to create a distinct class of frame specifically for this dialog.
Note also that OK and Cancel buttons are generated automatically for a dialog box; you do not need to define them explicitly.
Later on, the activate callback you define for the add-button pane calls this method, then inserts the return value into the list task-list.