Difference between revisions of "Scripting API (Preview)"

From Freeplane - free mind mapping and knowledge management software
(obsoleted - see scripting API instead)
 
Line 1: Line 1:
This page describes a development version which will only work with preview/alpha/beta/test versions of Freeplane. If you are seeking for the stable released version see [[Scripting API]].
+
#REDIRECT [[Scripting API]]
 
 
==Overview over the changes==
 
The development is currently driven by the implementation of the [[Formula]] feature that provides mindmappers with features you know from spreadsheet processors like Excel. This implies
 
 
 
* The syntax must allow more concise statements. For instance to convert a node text to a number you can now write <tt>to.num</tt> instead of <tt>Double.parse(node.text)</tt>. Attributes are available as <tt>node['name']</tt> in addition to the old <tt>node.attributes.get('name')</tt>.
 
* The API must provide additional functionality that is needed for formulas.
 
* The API must be re-organized to provide a read-only API for formulas.
 
 
 
===Extended Namespace for Scripts===
 
Methods and attributes of the current node are directly available to a script so instead of <tt>node.children.size()</tt> you may simply write <tt>children.size()</tt>.
 
 
 
Additionally the following methods are directly available:
 
 
 
<groovy>
 
 
 
  /** Shortcut for node.map.node(id) - necessary for ids to other maps. */
 
  Node N(String id);
 
 
 
  /** Shortcut for node.map.node(id).text. */
 
  String T(String id);
 
 
 
  /** Shortcut for node.map.node(id).value. */
 
  public Object V(String id);
 
 
 
  /** returns valueIfNull if value is null and value otherwise. */
 
  public Object ifNull(Object value, Object valueIfNull);
 
</groovy>
 
 
 
===Convertible===
 
A very important usability improvement, not only for formula writers, is the introduction of the class [[Scripting: Convertible|Convertible]] that is returned now by some new methods/properties:
 
 
 
* <tt>node.to</tt> (or <tt>node.getTo())</tt>
 
* <tt>node['attr_name']</tt> (or <tt>node.getAt('attr_name'))</tt>
 
* <tt>node.note</tt> (or <tt>node.getNote())</tt>
 
 
 
===Extended Setters===
 
Many "setters" on the other hand, like <tt>node.setText()</tt> have been extended to accept not only Strings but Objects. Much effort was spent to ensure that this conversion matches the conversions that <tt>Convertible</tt> performs for Strings. For example <tt>node.text = new Date()</tt> is converted to <tt>2010-10-05T22:11:03.243+0000</tt> which <tt>Convertible</tt> knows how to convert back to date (try <tt>node.to.date</tt>).
 
 
 
For formulas it's important that the formulas itself don't change the state of the map. Currently only the first step is made: All subinterfaces <tt>Xyz</tt> have a base interface <tt>XyzRO</tt> that includes only the methods that are suitable for formulas. The Proxy implementations implement the full interfaces currently and the constraint is not enforced.
 
 
 
===New Free Functions===
 
 
 
===New Controller methods===
 
Some controller methods were introduced mainly for testing:
 
 
 
* <tt>Controller.newMap()</tt>
 
* <tt>Controller.undo()</tt>
 
* <tt>Controller.redo()</tt>
 
 
 
==Example Maps==
 
* [[Media:Scripting-convertible-and-more.mm|Scripting API improvements]] (download only since the browser doesn't support formulas yet)
 
 
 
==Entry Points==
 
Each script is given two variables:
 
 
 
<groovy>
 
final Proxy.Node node;
 
final Proxy.Controller c;
 
</groovy>
 
 
 
''New:'' Methods and properties of the current node are directly available so you can write <tt>children.size()</tt> instead of <tt>node.children.size()</tt>.
 
 
 
[[Category:Script]]
 

Latest revision as of 08:21, 11 March 2013

Redirect to: