Difference between revisions of "Add-ons (Develop)"

From Freeplane - free mind mapping and knowledge management software
(Steps towards your own add-on)
Line 1: Line 1:
This page will provide detailed information about developing [[Add-ons|Freeplane add-ons]].
+
This page gives instructions for developing [[Add-ons|Freeplane add-ons]].
  
Add-ons are installed in the Freeplane user directory (see Tools->Open user directory). They may contain any number of scripts and Zip archives which are unpacked on installation. Combinations of scripts and Zips especially interesting since this enables you to package scripts with required libraries/JARs/class files. For instance it's possible to bundle some Groovy scripts for creating diagrams with the JFreechart library - so there's no need to download and install the JFreechart libraries anymore.
+
Add-ons are installed in the Freeplane user directory (see ''Tools > Open user directory''). They may contain any number of scripts and Zip archives which are unpacked on installation. Combinations of scripts and Zips are especially interesting since they enable you to package scripts with required libraries/JARs/class files. For instance it's possible to bundle some Groovy scripts for creating diagrams with the JFreechart library - so there's no need to download and install the JFreechart libraries anymore. Another applications are custom Java libraries that provide additional functionality for use in formulas.
  
 
Since plugins (such as the Scripting, LaTeX or Formula plugin you know) may also be installed into the Freeplane user directory, add-ons may even provide plugins.
 
Since plugins (such as the Scripting, LaTeX or Formula plugin you know) may also be installed into the Freeplane user directory, add-ons may even provide plugins.
 
  
 
==Preparation: Install developer tools ==
 
==Preparation: Install developer tools ==
  
Update to the most recent Freeplane version and install the [http://freeplane.sourceforge.net/wiki/index.php/Add-ons#Add-on_Insert_Inline_Image Developer Tools] from the [[Add-ons]] page (follow the installation instructions there). The add-on provides scripts that relieves you from most of the tedious work.
+
Update to the most recent Freeplane version and install the [http://freeplane.sourceforge.net/wiki/index.php/Add-ons#Add-on_Insert_Inline_Image Developer Tools] from the [[Add-ons]] page (follow the installation instructions there). The add-on provides scripts that relieves you from most of the tedious work. If you experience any problems with it in the future first check if you actually have the most recent add-on version installed.
  
 
The add-on functions are available in: ''Tools > Developer tools''
 
The add-on functions are available in: ''Tools > Developer tools''
  
 +
==Steps towards your own add-on==
 +
 +
The goal of the example add-on is to put:
 +
#an existing script <tt>myCoolScript.groovy</tt> in <tt><freeplaneuserdir>/script/myCoolScript.groovy</tt>; and
 +
#an icon <tt>mycoolicon.png</tt> in <tt><freeplaneuserdir>/icons/mycoolicon.png</tt>.
 +
 +
The steps to follow are:
 +
# In Freeplane create a new empty map by ''Ctrl+n''.
 +
# Invoke ''Tools > Developer Tools > Build add-on''. You will be asked for the name of your add-on. Answer ''My Cool Add-on''
 +
# Look through the messages in the info box that is shown if everything looks alright. The ''name'' attribute of the root node will be ''myCoolAddOn''. This is the identifying technical name of the add-on that is usually used as a file name, for menu locations and translation keys and so on. The node text ''My Cool Add-on'' is the English name/translation of the add-on.
 +
# Set the version attribute of the root node to <tt>v0.1</tt> and fill the other attributes of the root node (only ''freeplaneVersionTo'' is optional).
 +
# Write an initial description of the add-on as a child node of the ''description'' node.
 +
# Create a new directory somewhere with the technical name of the add-on, <tt>myCoolAddOn</tt>.
 +
# Save the new map to <tt>myCoolAddOn/myCoolAddOn.mm</tt>.
 +
# Copy or move <tt>myCoolScript.groovy</tt> to <tt>myCoolAddOn/scripts/myCoolScript.groovy</tt>.
 +
# In the map create a new subnode of the ''scripts'' node with name ''myCoolScript.groovy''.
 +
# Copy <tt>mycoolicon.png</tt> to <tt>zips/icons/mycoolicon.png</tt>.
 +
# In the map create a new subnode of the ''zips'' node with name ''icons''.
 +
# Invoke ''Tools > Developer Tools > Build add-on'' again. This will add the required attributes of the script node and proposes proper ''deinstall'' rules (just accept them when you are asked for it).
 +
# Fill the attributes of the ''myCoolScript.groovy'' node. The notes on the ''scripts'' node will help you to find the right attribute values. See also the section about <tt>menuLocation</tt> below.
 +
# Save the map.
 +
# Invoke ''Package add-on for publication''. This will create the file <tt>myCoolAddOn-v0.1.mm</tt> which can be installed via ''Tools > Scripts > Install Add-on'' (or via ''Tools > Add-ons'').
 +
 +
Before publishing your add-on read all notes in the add-on map. (They are meant for add-on developers, not for users since users are not expected to read an add-on package.) The notes should guide you to add all missing information. Carefully revise the defaults that the ''Build add-on'' script has entered.
  
==Steps towards your own add-on==
+
==Script configuration==
 +
This is a bit tricky since the script configuration consists of quite a lot attributes, some of them with a strong relation to translations and to menu configuration. For most questions the notes on the ''scripts'' node will be sufficient as a documentation.
 +
 
 +
===<tt>menuLocation</tt>s===
 +
A menu location is the menu or submenu into which the new menu item for the script will be put into.
 +
 
 +
The Freeplane menus (main menu, context menu, menu for applets and file browser) are configured via XML files. It helps a lot if you get an understanding how the structure in this file relates to the actual menu. The most relevant menus for scripts are configured through [http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/trunk/annotate/head%3A/freeplane/resources/xml/mindmapmodemenu.xml mindmapmodemenu.xml]. To inspect it select ''Download file'' and load the file in your web browser. To get an overview over its structure fold/unfold the nodes. You see that the "file" submenu is a sub node of the "menu_bar" menu_category which defines the main menu. (There're also definitions for context menus: "map_popup", "node_popup" and the "main_toolbar"). A menu location is a path that starts with a root menu_category, e.g.
  
The goal of the example is to create an add-on called ''myAddOn'' which puts:
+
  /menu_bar/file/import
#a hypothetical script <tt>myCoolScript.groovy</tt> in <tt><freeplaneuserdir>/script/myCoolScript.groovy</tt>; and
 
#a hypothetical icon <tt>mycoolicon.png</tt> in <tt><freeplaneuserdir>/icons/mycoolicon.png</tt>.
 
  
 +
For some paths there are aliases/shortcuts. These are defined as "menu_key" attribute of a menu_submenu node, e.g.
  
'''First''' prepare a directory called ''myAddOn'' with  the following structure:
+
  main_menu_scripting
* myAddOn/scripts
 
* myAddOn/zips/icons
 
  
 +
which is an alias for
  
'''Second''' put the above files in this structure:
+
  /menu_bar/extras/first/scripting
# Copy <tt>myCoolScript.groovy</tt> to <tt>myAddOn/scripts/myCoolScript.groovy</tt>.
 
# Copy <tt>mycoolicon.png</tt> to <tt>zips/icons/mycoolicon.png</tt>.
 
  
 +
Note that you can define <tt>menuLocation</tt>s that do not exist in the menu already. If you do that you have to make sure that for every submenu level there's a translation for its name. Here's an example from the ''Edit Goodies'' add-on:
  
'''Third''' create and save the map ''myAddOn''
+
  /menu_bar/edit/editGoodies
# Create a new mind map and set the root name (core) to ''myAddOn''
 
# Select ''Tools->Developer Tools->Build add-on'' to generate the template.  First a dialog with a default name of the add-on displays. Accept the default name ''myAddOn'', or you get an error message. Then a dialog displays a log of the actions which generate the template nodes. 
 
# The root node myAddOn now has got a number of attributes. The first attribute is ''name'' with value ''myAddOn''. This is the so-called technical name of the add-on which should not be changed. The root name (core) could be changed.
 
# From the other attributes of the root node, at least the version should be filled in. E.g. fill in for version <tt>v0.1</tt> etc.
 
# The map ''myAddOn'' has a template node ''scripts''. Create a child node with name ''myCoolScript.groovy''.
 
# The map ''myAddOn'' has a template node ''zips''. Create a child node with name ''icons''. And create a child of ''icons'' with the name ''mycoolicon.png''.
 
# Select (again) ''Tools->Developer Tools->Build add-on''. This will add the required attributes of the script node and proposes proper ''deinstall'' rules (just accept them when you are asked for it).
 
# Select ''Tools > Developer Tools > Package add-on for publication''. This will create the file <tt>myAddOn-v0.1.mm</tt>
 
  
 +
This creates a new submenu below the ''Edit'' menu. From Freeplane v1.2.10_5 on this only requires the definition of a translation for
  
'''Fourth''', install and test:
+
  addons.editGoodies
* Select ''Tools->Scripts->Install Add-on'' (or via ''Tools->Add-ons'').
 
  
 +
("addons." could have been omitted but leave it there to avoid naming collisions.)
  
Before publishing your add-on read all notes in the add-on map. (They are meant for developers, not for users since users are not expected to read an add-on package.) The notes should guide you to add all missing information. Carefully revise the defaults that the ''Build add-on'' script has entered.
 
  
 
[[Category:Extension]]
 
[[Category:Extension]]

Revision as of 03:32, 20 November 2011

This page gives instructions for developing Freeplane add-ons.

Add-ons are installed in the Freeplane user directory (see Tools > Open user directory). They may contain any number of scripts and Zip archives which are unpacked on installation. Combinations of scripts and Zips are especially interesting since they enable you to package scripts with required libraries/JARs/class files. For instance it's possible to bundle some Groovy scripts for creating diagrams with the JFreechart library - so there's no need to download and install the JFreechart libraries anymore. Another applications are custom Java libraries that provide additional functionality for use in formulas.

Since plugins (such as the Scripting, LaTeX or Formula plugin you know) may also be installed into the Freeplane user directory, add-ons may even provide plugins.

Preparation: Install developer tools

Update to the most recent Freeplane version and install the Developer Tools from the Add-ons page (follow the installation instructions there). The add-on provides scripts that relieves you from most of the tedious work. If you experience any problems with it in the future first check if you actually have the most recent add-on version installed.

The add-on functions are available in: Tools > Developer tools

Steps towards your own add-on

The goal of the example add-on is to put:

  1. an existing script myCoolScript.groovy in <freeplaneuserdir>/script/myCoolScript.groovy; and
  2. an icon mycoolicon.png in <freeplaneuserdir>/icons/mycoolicon.png.

The steps to follow are:

  1. In Freeplane create a new empty map by Ctrl+n.
  2. Invoke Tools > Developer Tools > Build add-on. You will be asked for the name of your add-on. Answer My Cool Add-on
  3. Look through the messages in the info box that is shown if everything looks alright. The name attribute of the root node will be myCoolAddOn. This is the identifying technical name of the add-on that is usually used as a file name, for menu locations and translation keys and so on. The node text My Cool Add-on is the English name/translation of the add-on.
  4. Set the version attribute of the root node to v0.1 and fill the other attributes of the root node (only freeplaneVersionTo is optional).
  5. Write an initial description of the add-on as a child node of the description node.
  6. Create a new directory somewhere with the technical name of the add-on, myCoolAddOn.
  7. Save the new map to myCoolAddOn/myCoolAddOn.mm.
  8. Copy or move myCoolScript.groovy to myCoolAddOn/scripts/myCoolScript.groovy.
  9. In the map create a new subnode of the scripts node with name myCoolScript.groovy.
  10. Copy mycoolicon.png to zips/icons/mycoolicon.png.
  11. In the map create a new subnode of the zips node with name icons.
  12. Invoke Tools > Developer Tools > Build add-on again. This will add the required attributes of the script node and proposes proper deinstall rules (just accept them when you are asked for it).
  13. Fill the attributes of the myCoolScript.groovy node. The notes on the scripts node will help you to find the right attribute values. See also the section about menuLocation below.
  14. Save the map.
  15. Invoke Package add-on for publication. This will create the file myCoolAddOn-v0.1.mm which can be installed via Tools > Scripts > Install Add-on (or via Tools > Add-ons).

Before publishing your add-on read all notes in the add-on map. (They are meant for add-on developers, not for users since users are not expected to read an add-on package.) The notes should guide you to add all missing information. Carefully revise the defaults that the Build add-on script has entered.

Script configuration

This is a bit tricky since the script configuration consists of quite a lot attributes, some of them with a strong relation to translations and to menu configuration. For most questions the notes on the scripts node will be sufficient as a documentation.

menuLocations

A menu location is the menu or submenu into which the new menu item for the script will be put into.

The Freeplane menus (main menu, context menu, menu for applets and file browser) are configured via XML files. It helps a lot if you get an understanding how the structure in this file relates to the actual menu. The most relevant menus for scripts are configured through mindmapmodemenu.xml. To inspect it select Download file and load the file in your web browser. To get an overview over its structure fold/unfold the nodes. You see that the "file" submenu is a sub node of the "menu_bar" menu_category which defines the main menu. (There're also definitions for context menus: "map_popup", "node_popup" and the "main_toolbar"). A menu location is a path that starts with a root menu_category, e.g.

 /menu_bar/file/import

For some paths there are aliases/shortcuts. These are defined as "menu_key" attribute of a menu_submenu node, e.g.

 main_menu_scripting

which is an alias for

 /menu_bar/extras/first/scripting

Note that you can define menuLocations that do not exist in the menu already. If you do that you have to make sure that for every submenu level there's a translation for its name. Here's an example from the Edit Goodies add-on:

 /menu_bar/edit/editGoodies

This creates a new submenu below the Edit menu. From Freeplane v1.2.10_5 on this only requires the definition of a translation for

 addons.editGoodies

("addons." could have been omitted but leave it there to avoid naming collisions.)