Ellié Computing Home Page
My Shopping Cart

Your shopping cart is empty

Display Cart

Call us at +1 586 62 ELLIE / +1 586 62 35543 Office Opened
sales@elliecomputing.com - Contact us


Adding menu items to the contextual menus

 

 

Since Ellié Computing Merge 2.2, you can add items to the contextual menus with scripts.

When displaying a contextual menu in the views, ECMerge calls the function "query_contextual_menu" on itself. By default, this function is undefined and therefore nothing happens. However if this function returns a menu item Array (as defined in the Application.popup_menu function), a "Macros" menu item is inserted at the top of the contextual menu, its sub-menu is the menu returned by the function.

An example

This example adds a dummy menu item to the folders view contextual menu, which displays "hi hoo" when clicked.

FolderDocument.View.prototype.query_contextual_menu = function () {
    return [ { label: "menu item", event:function() { alert("hi hoo") } } ];
}

More insight

ECMAScript defines prototyping semanitcs, this is some kind run-time value oriented in-heritance. What it means is that specific View objects are derived from less specific View: FolderDocument.View (as well as ImageDocument.View or TextDocument.View) derives from Document.View.

If you place your function on Document.View it will thus be seen in all the views, this is interesting for menu items with general interest. On the other hand, menu items of interest for a single type of view should go in the appropriate ???Document.View object. You can change the contextual menu for a single view also though it is harder to see interest in this.

How to use both shared menu items and per-view type menu items

Here is an example of how it can be done:

FolderDocument.View.prototype.query_contextual_menu = function () {

    // put your items here... in own_items
    var own_items = [ { label: "menu item", event:function() { alert("hi hoo") } } ];

    if (this.__proto__.__proto__.query_contextual_menu !== undefined)
    {
        try {
            var proto_items = this.__proto__.__proto__.query_contextual_menu.call (this);
        }
        catch (e) {
            log ("there was a problem in Document.View.prototype.query_contextual_menu\n"+ String(e) );
        }

        if (proto_items !== undefined)
        {
            proto_items.splice (0, 0, 0, 0);
            proto_items.push ( [ { label: '' } ] );
            own_items.splice.apply (own_items, proto_items);
        }
    }

    return own_items;
}


See Also