Two methods are used to determine which task is selected in the task list manager, and to set a specific task in the task list manager: frame-selected-task and frame-selected-task-setter.
The frame-selected-task method returns the task that is currently selected in the task list manager, or #f if no task is selected. This method is used by frame-remove-task to determine which task should be deleted from the task list. It is also used by note-task-selection-change to determine whether or not a task is selected.
define method frame-selected-task
(frame :: <task-frame>) => (task :: false-or(<task>))
let list-box = task-list(frame);
gadget-value(list-box)
end method frame-selected-task;
The frame-selected-task method works by determining the gadget-value of the list box that displays the tasks in the task list manager. The gadget-value of a collection such as a list box is the selected item. Notice how you can access the value of a pane in a frame instance in exactly the same way that you can access the value of a slot in a class instance; the definition of the pane creates an accessor that is just like a slot accessor. Recall that the name of the list box in the definition of the <task-frame> class is task-list.
A setter method is also defined for frame-selected-task, as shown below:
define method frame-selected-task-setter
(task :: false-or(<task>), frame :: <task-frame>)
=> (task :: false-or(<task>))
let list-box = task-list(frame);
gadget-value(list-box) := task;
note-task-selection-change(frame);
task
end method frame-selected-task-setter;
This method takes two arguments: the task to select in the task list manager, and the frame to which the task belongs. It returns the task. The method determines the list box used to display tasks in frame, and then sets the gadget-value of that list box to task. Finally, it calls note-task-selection-change, described below, to update other parts of the user interface appropriately, such as buttons on the tool bar.
As with most setter methods, frame-selected-task-setter is not called directly. Instead, it is called implicitly by setting a value using frame-selected-task. For example,
frame-selected-task(frame) := #f;
ensures that no tasks are selected in frame.
The frame-selected-task-setter method is called by two other methods: frame-add-task (to ensure that the task added is subsequently selected) and frame-remove-task (to ensure that no tasks are selected once a task has been removed from the list). These methods are described in Section 5.3.2.1 on page 60.
Add the code for these methods to frame.dylan.