## 4.5 Editing attributes

In the previous section, we discussed dialogs for entering values. Another typical use of dialog windows is to modify setting of the application, or more in general, edit attributes of existing entities in the application. These entities may both be represented as XPCE objects or as constructs in the host language (dynamic predicates or the recorded database in Prolog).

Such dialog windows first show the current settings. It allows for modifying the controls showing the various aspects of the current state and three buttons providing the following functions:

- Apply
  Apply the current controls, which implies invoking some behaviour on the application to realise the setting of the---modified--- controls.
- Restore
  Reset the controls to the current status of the application.
- Cancel
  Destroy the dialog and do not modify the current settings of the application.

The following methods are defined on all primitive controls as well as on the dialog window faciliate the implementations of dialog windows as described above.

dialog_item ->default: any|function
dialog_item ->restore:
  For most dialog items, the `<->`default value is the second initialisation argument. Instead of a plain value, this can be a function object. The initial `<-`selection is set by evaluating this function. In addition, `->`restore will evaluate the function again and reset the selection.
dialog_item ->apply: always:bool
  Execute the `->`message of each dialog item for which `dialog_item `<-`modified' yields @on. If the argument is @on, the modified flag is not checked.
dialog ->apply:
dialog ->restore:
  Broadcasts `->`apply or `->`restore to each item in the dialog.

### 4.5.1 Example: editing attributes of a graphical

We will illustrate these methods described above in this example, which implements a dialog for editing the colour of the interior and thickness of the line around a graphical. Double-clicking on a graphical pops up a dialog window for changing these values. The result is show in figure 11.

    colour(white).
    colour(red).
    colour(green).
    colour(blue).
    colour(black).

    append_colour(M, C) :-
            new(Img, pixmap(@nil, white, black, 32, 16)),
            send(Img, fill, colour(C)),
            send(M, append, menu_item(colour(C), label := Img)).

    edit_graphical(Gr) :-
            new(D, dialog(string('Edit graphical %s', Gr?name))),
            send(D, append,
                 new(M, menu(colour, choice,
                             message(Gr, fill_pattern, @arg1)))),
            send(M, layout, horizontal),
            forall(colour(C), append_colour(M, C)),
            send(M, default, Gr?fill_pattern),
            send(D, append, slider(pen, 0, 10, Gr?pen,
                                   message(Gr, pen, @arg1))),
            send(D, append, button(apply)),
            send(D, append, button(restore)),
            send(D, append, button(quit, message(D, destroy))),
            send(D, default_button, apply),
            send(D, open).

    attributedemo :-
            send(new(P, picture('Attribute Demo')), open),
            send(P, display,
                 new(B, box(100, 100)), point(20, 20)),
            send(P, display,
                 new(E, ellipse(100, 50)), point(150, 20)),
            send_list([B, E], fill_pattern, colour(white)),
            new(C, click_gesture(left, '', double,
                                 message(@prolog, edit_graphical,
                                         @receiver))),
            send(B, recogniser, C),
            send(E, recogniser, C).

Figure 11 : Attribute editor for graphical objects