How to add a custom context menu to a text field in Vexi?

I want to add a custom entry to the context menu of a Vexi application.

I tried adding a function contextActions, but it throws an error:

<textarea>
    thisbox.contextmenu.contextActions = function() {
        return [{
            text: "Foo",
            action: function(v) { cascade = v; vexi.log.info("foo"); },
            enabled: enabled
        }]);
    }
</textarea>

How to do it?

+4
source share
1 answer

To extend the existing textarea context menu implementation in a reusable way, create a template that pre-uses vexi.widget.textareaand place a read trap in the property contextActions. We can use cascadeto invoke reading from this property, i.e. Call an existing implementation that returns an array. We just add to this array:

<vexi xmlns="vexi.widget">
    <textarea>
        // overlays the trap specified in the inherited
        // org.vexi.lib.text.contextmenu by textarea
        thisbox.contextActions ++= function() {
            var actions = cascade;
            actions.push(
            new .menuitem({
                text: "Foo",
                action: function(v) { cascade = v; vexi.log.info("foo"); },
                enabled: enabled
            }));
            return actions;
        }
    </textarea>
</vexi>

Traps, <textarea> ( ..). , src/vexi/widget/textarea.t, . , org.vexi.lib.widget.textarea preapplies org.vexi.lib.text.contextmenu // ..

+3

All Articles