Next Previous Up Top Contents Index

5.3.3 Updating the user interface

5.3.3.4 Refreshing the list of tasks

The refresh-task-frame method is called whenever the list of tasks needs to be refreshed for whatever reason. This happens most commonly after adding or removing a task from the list, or loading in a new task list from a file on disk. The method refresh-task-frame takes an instance of <task-frame> as an argument and returns no values. For the Task List 1 project the definition is:

define method refresh-task-frame
    (frame :: <task-frame>) => ()
  let list-box = frame.task-list;
  let task-list = frame.frame-task-list;
  let modified? = task-list.task-list-modified?;
  let tasks = task-list.task-list-tasks;
  if (gadget-items(list-box) == tasks)
    update-gadget(list-box)
  else
    gadget-items(list-box) := tasks
  end;
  gadget-enabled?(frame.save-button) := modified?;
  gadget-enabled?(frame.save-menu-button) := modified?;
  note-task-selection-change(frame);
end method refresh-task-frame;

However, the Task List 2 project requires a call to command-enabled?, so the definition is:

define method refresh-task-frame
    (frame :: <task-frame>) => ()
  let list-box = frame.task-list;
  let task-list = frame.frame-task-list;
  let modified? = task-list.task-list-modified?;
  let tasks = task-list.task-list-tasks;
  if (gadget-items(list-box) == tasks)
    update-gadget(list-box)
  else
    gadget-items(list-box) := tasks
  end;
  command-enabled?(save-file, frame) := modified?;
  note-task-selection-change(frame);
end method refresh-task-frame;

To begin, refresh-task-frame sets a number of local variables:

list-box

The list box used to display the list of tasks in task list manager.

task-list

The task list currently loaded in the task list manager.

modified?

The value of the task-list-modified? slot of task-list.

tasks

The sequence of tasks stored in task-list.

Next, the following code is executed:

if (gadget-items(list-box) == tasks)
  update-gadget(list-box)
else
  gadget-items(list-box) := tasks
end;

This code ensures that if the items in the list box are the same as the sequence of tasks in the task list, then the display in the list box is updated to ensure all the items are displayed correctly. If the items in the list box are not the same as the sequence of tasks, then the items in the list box are updated to reflect the current task list. The items in the list box could be different if a task had been added or removed from the list, or if a completely new set of tasks had been loaded into the task list manager.

Lastly, the following three lines

gadget-enabled?(frame.save-button) := modified?;
gadget-enabled?(frame.save-menu-button) := modified?;
note-task-selection-change(frame);

ensure that the Save button and File > Save menu command are enabled if the task list has been modified, and then any changes that need to be made to the GUI as a result of changing the selected item are performed, by calling note-task-selection-change.

Add the code for this method to frame.dylan.


Building Applications Using DUIM - 26 May 1999

Next Previous Up Top Contents Index