New-Tools

Integrating new tools is simple.  Your tool's interface will be a contextual popup menu.  Right-Clicking in a Hemlock window will produce this popup menu when your tool is the Default Tool.

(1)  Preliminaries:

(defpackage "YOUR-TOOLNAME" (:use :cl :ccl))
(in-package "YOUR-TOOLNAME")
(require :context-menu)

By conventions toolnames have an appended "-CM", indicating that they are a part of a suite of tools.

(2)  Derive a class from ns:ns-menu:
It it will probably have several slots, but it must have a tool-menu slot and probably a doc-path slot.  See the class, list-definitions-menu, in list-definitions-1.lisp.

(3)  Provide a menu creation function:
This will be specific to your tool, but it must include this statement:

(setf (tool-menu menu) (cmenu:add-default-tool-menu menu :doc-file (doc-path menu)))

This sets the tool-menu slot mentioned above.  Menu is the menu being created and (doc-path menu) is the path to an optional documentation file.  This call will insert a Default Tool submenu as your first menu-item.  See list-definition-context-menu in list-definitions-1.lisp.  You can also do this in an initialize-instance :after method.  See hemlock-commands-1.lisp for an example.

You should probably make your popup menu look like the other popup menus.  This means using the fonts, font-sizes and colors that are used by List-Definitions, Hemlock-Commands and CL-Documentation. 

(4)  Provide an #/update method for your new menu class that looks like this:

(objc:defmethod (#/update :void) ((self list-definitions-menu))
  (cmenu:update-tool-menu self (tool-menu self) :sub-title (sub-title self))
  (call-next-method))

(sub-title self) is optional.  If your tool has multiple menus selected with modifier keys, you can insert a descriptive sub-title as shown.  See list-definitions.lisp

The update method will update the Default Tool submenu so that it includes all other required tools.  This is necessary, because the number and type of tools will probably not be known when your tool is loaded.  This depends on which tools the user requires and the order in which he requires them.

(5)  Provide a get-<your-toolname>-menu function:
See get-list-definitions-menu in list-definitions-1.lisp for an example.

(6)  Register the new tool:

(cmenu:register-tool "List-Definitions-CM" #'get-list-definitions-menu)

The first argument is the name of your tool.
The second argument is the function described in item (5) above.

(7)  (provide :your-toolname)