Difference between revisions of "Add-ons (Develop)"
(→menuLocations) |
|||
Line 64: | Line 64: | ||
("addons." could have been omitted but leave it there to avoid naming collisions.) | ("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|Menus and commands]]. | ||
[[Category:Extension]] | [[Category:Extension]] |
Revision as of 08:12, 2 December 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.
Contents
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:
- an existing script myCoolScript.groovy in <freeplaneuserdir>/script/myCoolScript.groovy; and
- an icon mycoolicon.png in <freeplaneuserdir>/icons/mycoolicon.png.
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 v0.1 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, myCoolAddOn.
- Save the new map to myCoolAddOn/myCoolAddOn.mm.
- Copy or move myCoolScript.groovy to myCoolAddOn/scripts/myCoolScript.groovy.
- In the map create a new subnode of the scripts node with name myCoolScript.groovy.
- Copy mycoolicon.png to zips/icons/mycoolicon.png.
- 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 menuLocation below.
- Save the map.
- 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.
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.