Index: plugin/index.html =================================================================== --- plugin/index.html (revision 32983) +++ plugin/index.html (revision 32984) @@ -13,6 +13,7 @@
  • variables in tmpasm files
  • standard plugin cookies
  • how to create actions +
  • how to create per plugin menu items

    advanced topics

    Index: plugin/menu.html =================================================================== --- plugin/menu.html (nonexistent) +++ plugin/menu.html (revision 32984) @@ -0,0 +1,64 @@ + + +

    pcb-rnd - plugin development - per plugin menus

    +

    +Some plugins may need to create menu items. This should not be done in +the central menu file, because the plugin may be disabled leaving +defunct menu items in the menu system. Instead, each such plugin shall +inject a menu patch file on load and remove the menu patch on plugin unload. + +

    the menu file

    +

    +The menu file is normally not a menu patch file but +a plain menu file since it only needs to extend the existing menu system and +this is the easiest way to do so. It's recommended to insert menus under +anchors because this method provides better stability over menu file changes. +

    +The menu file is typically called: pluginname-menu.lht + +

    tmpasm

    +

    +The menu file must be registered in the tmpasm file. Add these lines in +Plug.tmpasm to set the file name: +

    +put /local/pcb/mod/MENUFILE {pluginname-menu.lht}
    +put /local/pcb/mod/MENUVAR {pluginname_menu}
    +
    + +

    Create the menu variable

    +

    +Menu patch requires the following lines around the top of the plugin code: +

    +#include <librnd/core/hid_menu.h>
    +#include "menu_internal.c"
    +
    +

    +The menu file is translated to a variable named in MENUVAR above, typically +pluginname_menu - this is the "internal" version embedded in the +executable, fallback in case the menu file is not found. + +

    plugin init

    +

    +Copy these lines in the plugin init callback: +

    +	rnd_hid_menu_load(rnd_gui, NULL, pluginname_cookie, 175, NULL, 0, pluginname_menu, "plugin: pluginname");
    +
    +

    +Replace 175 with the patch priority - in the most common setup this controls +the order of newly created menu items under the same anchor. + +

    plugin uninit

    +

    +On uninit the menu patch needs to be unloaded: +

    +	rnd_hid_menu_unload(rnd_gui, pluginname_cookie);
    +
    + +

    make dep

    +

    +After committing all these, you will need to run make dep in src/. Before committing +that, double check svn diff: it must not have any unrelated change, only files +related to your plugin. + + + Index: plugin/menu.lht =================================================================== --- plugin/menu.lht (nonexistent) +++ plugin/menu.lht (revision 32984) @@ -0,0 +1,9 @@ +ha:rnd-menu-v1 { + li:anchored { + ha:@import_sch { + li:submenu { + ha:Load TinyCAD .net file = { action=LoadTinyCADFrom() } + } + } + } +} \ No newline at end of file