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

From Freeplane - free mind mapping and knowledge management software
Line 5: Line 5:
 
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 ==
+
==Preparations ==
  
 +
=== 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. If you experience any problems with it in the future first check if you actually have the most recent add-on version installed.
 
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''
 +
 +
=== Editors, Develoment Environments ===
 +
If you are considering to create scripts as part of your add-on you it's advisable to [[Scripting_environment_setup|set up an integrated scripting environment]]. If you have 250 MB spare disk space do it. - It will pay-off soon.
  
 
==Steps towards your own add-on==
 
==Steps towards your own add-on==

Revision as of 21:40, 30 March 2012

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.

Preparations

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

Editors, Develoment Environments

If you are considering to create scripts as part of your add-on you it's advisable to set up an integrated scripting environment. If you have 250 MB spare disk space do it. - It will pay-off soon.

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.)

More about the configuration of menus can be found on the wiki page Menus and commands.