Triggering an action with the mouse

The only remaining issues are how to trigger a function through the mouse and how to recover a variable name from a selected subtree.

The mouse event list specifies a callback package for a given mouse button. Le-Lisp calls the functions whose names are created by concatenating the callback prefix to mouse-down, mouse-drag, and mouse-up when these events occur. In section , we bound the callback package {Exp}:select-variable to the middle mouse button. Therefore, we must define the following functions:


(de {Exp}:select-variable:mouse-down (ctedit event))
(de {Exp}:select-variable:mouse-drag (ctedit event))
(de {Exp}:select-variable:mouse-up (ctedit event))

When we click with the mouse, the ctedit, using the position information provided by the Le-Lisp event structure, calculates a path from the root of the graphic structure to the selected token or tokens. The call:

(send 'image-path )

returns the path in the graphic structure for a given Le-Lisp event, called the image path. We may then convert this path into one that identifies the corresponding position in the abstract syntax tree. The call:

({ctedit}:get-subject-path )

returns the structural path for the given image path. This path points to a subtree, so we need only retrieve the subtree, and if its associated operator is variable, emit the signal hi-var-request in the tool network. This is done in the mouse-down function:


(de {Exp}:select-variable:mouse-down (ctedit event)
    (lets ((image-path (send 'image-path ctedit event))
           (subject-path ({ctedit}:get-subject-path ctedit image-path))
           (subtree ({path}:first-value subject-path))
           )
       (stobject-emit 
         ({ctedit}:subject ctedit)
         '#:Exp-highlight-stnode:hi-var-request
         (when subtree
            (let ((operator-name ({tree}:operator-name subtree)))
               (when (eq 'variable operator-name)
                 ({tree}:atom_value subtree)))))
       ))

Note that we emit the signal from the ctedit, and not directly from the stnode that encapsulates it with the function stobject-emit. This function's first argument is the encapsulated object. The second argument is full signal name composed of the the class of the stnode used to encapsulate the object and the desired signal name. We emit the hi-var-request signal even when the mouse doesn't select a subtree or the selected subtree does not have the associated operator variable. This allows us to clear the highlight selection with the mouse.

We have not specified mouse-drag or mouse-up behavior here. However, you might want to change the mouse behavior so that the variable is selected only when the mouse button is released, not depressed. Or you might want to change the selection as long as the mouse is dragged, etc.


                  



Tutorial