dialogos-project / dialogos

The DialogOS dialog system.
https://www.dialogos.app
GNU General Public License v3.0
20 stars 7 forks source link

Updating Node Properties in the Code #213

Closed stbusch closed 3 years ago

stbusch commented 3 years ago

Hello, the comment to the createEditorComponent method in the Node class says:

The values of such properties are automatically updated when you close the properties window by clicking "Ok". You can also update the values of properties by changing the entries in the "properties" argument. (Do not change the values of this.properties directly; this is necessary for proper functioning of the "Cancel" button and proper propagation to propertyChangeListeners.

What exactly is the option the sentence

You can also update the values of properties by changing the entries in the "properties" argument

is referring to? Does it mean calling setProperties again? The last sentence could be understood as discouraging just that. Thanks for some clarification.

timobaumann commented 3 years ago

The idea is as follows: implementing classes implement createEditorComponent which adds GUI to change properties of the implemented node. The Node base class handles for you some generic properties (such as node color, name, etc.) and also the ability to accept GUI changes or to cancel them, depending on which button the user finally presses (Okay vs. Cancel).

For this, it's necessary that you do not change the node's properties directly from the GUI elements that you add in createEditorComponent (neither by calling this.properties.set(some_key, some_value), nor by calling this.setProperty(some_key, some_value)). Instead, createEditorComponent receives a copy of the node's components as argument (unfortunately, this one is also called properties, just like the corresponding object field). Your GUI elements should then manipulate this properties copy and once the user closes the dialog, Node either accepts the changes to the main copy, or ignores them (depending on Okay/Cancel being pressed).