Skip to main content
Known Participant
September 22, 2005
Question

How to create a Context Menu submenu?

  • September 22, 2005
  • 7 replies
  • 1628 views
I am trying to create a submenu which lists scripts in the content window - Does anyone know how to do this?

This works:

if (MenuElement.find ('Thumbnail/tscript') == null) var ah_ScriptsContext = new MenuElement( "command", "Scripts", "at the end of Thumbnail", "tscript");

But the submenu does not work:

var ah_runScriptImRnContext = new MenuElement("menu","AH Image Rename","at the end of Thumbnail/tscript");

I've tried various combinations of 'menu' / 'command' and everything else I can think of, so far no go.

Andrew
This topic has been closed for replies.

7 replies

Known Participant
September 22, 2005
That's one of those opinion things.

IMHO if all files do not satisfy the requirements then you must do one of 2 things:

Disable - so the action can't happen
Warn - (perhaps with a do not show again checkbox) that some of the files can not be processed.

getBridgeFiles does the warning thing (with the checkbox).

Bob
Adobe WAS Scripting
Known Participant
September 22, 2005
Hi Bob, thanks for that. I like the idea of presenting menu items on the basis of what is selected but how does it deal with multiple selections some of which belong and others which do not - I guess if any do not belong to the accepted extensions then the item should not appear in the menu.

Andrew
Known Participant
September 22, 2005
Here ya go, Andrew:

Bob
Adobe WAS Scripting

#target bridge

ContextDemo = {};

ContextDemo.handler = function( menu ) {
alert( menu.text );
}
try {
MenuElement.create( "menu", "Menu", "at the end of Thumbnail", "cMenu" );
ContextDemo.m1 = MenuElement.create( "command", "Command 1", "at the end of cMenu", "cMenu/sub1" );
ContextDemo.m1.onSelect = ContextDemo.handler;
ContextDemo.m2 = MenuElement.create( "command", "Command 2", "at the end of cMenu", "cMenu/sub2" );
ContextDemo.m2.onSelect = ContextDemo.handler;
} catch ( e ) {
}

// now let's get tricky
// disabling a script generated context menu makes it disappear from the context menu

SelectExample = {}
SelectExample.menuSelected = function() {
alert( "You selected " + app.document.selections[ 0 ].name );
}
SelectExample.menu = undefined;
SelectExample.onSelectHandler = function( event ) {
if ( event.object.constructor.name == "Thumbnail" ) {
if ( event.type == "select" ) {
// event.object is the Thumbnail object that was selected
if ( event.object.isFileType( "jpg,jpeg,psd,tif,tiff" ) ) { // enable the menu for these files with these extensions only
try {
if ( !isValidReference( SelectExample.menu ) ) {
SelectExample.menu = MenuElement.create( "command", "MyCommand", "at the end of Thumbnail", "myMenuID" );
SelectExample.menu.onSelect = SelectExample.menuSelected;
} else {
SelectExample.menu.enabled = true;
}
} catch ( e ) {
}
} else {
try {
SelectExample.menu.enabled = false;
} catch ( e ) {
}
}
return { handled:true }; // tells Bridge event was handled
}
}
return { handled:false }; // tells Bridge event wasn't handled and
//to continue through the handler array
}
app.eventHandlers.push( { handler: SelectExample.onSelectHandler } );
Pedro Cortez Marques
Legend
May 27, 2013

Hi Robert

I was testing this, but now on Bridge CS6 (windows7), it works ok only with 1 error:

there is no more .isFileType( )

event.object.isFileType( "jpg,jpeg,psd,tif,tiff" )

on Bridge CS6 (and CS5)

How could i detect if it is a CR2 or JPG, or even a Folder? on a event select Thumbnail?

If it is possible, I could add conditional subMenus. That should be great!

If you want, I'll put this question on a new post.

Paul Riggott
Inspiring
May 27, 2013

This is an 8 year old thread!

Some of these functions are from Bob's  WasScriptLibrary.jsx where you will find isFileType();

You will need to find a copy of this library.

Known Participant
September 22, 2005
I tried both, neither worked.

Andrew
Known Participant
September 22, 2005
I haven't tried this myself, but it looks like you are using the wrong menu type (first parameter when creating the MenuElement). Your first MenuElement is type "command" when I think it should be type "menu". That is probably why your sub-menu won't show up.
Known Participant
September 22, 2005
Hi John, thanks for the reply

That's basically what I want but with a context menu instead.

Right click a thumbnail in the content pane, and you see the 'Labels' option, which if clicked gives you various individual label options. I want to create an equivalent Scripts option in the same context menu (I can do that) which has individual script options within it (haven't managed to do that for a context menu so far, can do it for a main menu).

Andrew
Known Participant
September 22, 2005
I'm not sure I quite understand exactly what you are trying to do, but here's a code snippet from a test app of mine that creates a new top level menu and adds one menu item to that menu.

var menu = MenuElement.find("testMenuID");
if (menu == null)
{
// add a menu item
var testMenu = new MenuElement("menu", "Test", "before Help", "testMenuID");
var cmd1 = new MenuElement("command", "Test #1 - Array Mods", "at the end of testMenuID", "test1ID");
cmd1.onSelect = TestFunc_ArrayMods;
}

--John