Next: 10 Translating the application Up: GNUstep Renaissance Previous: 8 Another small example

9 Using ids

The file owner syntax explained in the previous sections is just a special case of a more general way of referring to objects by id. An id is just a name internally used to refer to objects; it's never displayed to the user, but it can be used internally in a gsmarkup file to refer to an object: when a gsmarkup file is loaded, objects in the file (or outside the file) can have an id set, and can be referred to by using the special syntax #id. The file owner is a special case of this; it is an object (external to the file) which has its id automatically set to NSOwner, so that you can refer to it using #NSOwner.

To set the id of an object inside that file, you just add an id attribute. For example, <window id="Foo" /> creates a window with an id of Foo.

To refer to the window, you can use the syntax #Foo; #Foo means ``the object whose id is Foo''. For example, <button target="#Foo" /> creates a button, and sets its target to be the object whose id is Foo, that is, the window.

As a more complete example, the following gsmarkup file creates a window, and inside the window a button; clicking on the button will call the performClose: method of the window (which closes the window):

<gsmarkup>

  <objects>

    <window id="A">
      <button title="Close window" action="performClose:" target="#A" />
    </window>

  </objects>

</gsmarkup>
Here the window has an id of A, and the button target is set to be the object with id A, which is the window. You can try out this example by replacing the Window.gsmarkup file in our example with this one.


Next: 10 Translating the application Up: GNUstep Renaissance Previous: 8 Another small example
2008-01-16