These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Adding new menu item - how to avoid repeat additions?

Nifty
Registered: Jan 16 2011
Posts: 17
Answered

I have created a folder level javascript to show a custom search dialog box when it is called from buttons on certain pages within an indexed and interlinked collection of PDF files.
Within this script I have added a menu item to the Help menu, which when selected opens the search dialog. This all worked but of course the additional menu item appeared as soon as Acrobat/Reader was opened regardless of whether it was a file within this collection or not. To limit the menu item to appear only when the associated PDFs were being used I made the add menu item instruction a trusted function which is then called from a document level javascript in the main (openning) menu page of this PDF collection. This too works, apart from the fact that everytime the user returns to the main menu it causes the menu item to be added again, so I am getting repeat additions of the same menu item.
 
Is there a way of coding either the add menu trusted function or the call command from the document so that it registers whether the menu item is already there and if so it will not repeat the operation.
Any other ways around this problem?
 
Thanks in anticipation.
 
Nifty
Norfolk, England
 
Using Acrobat 8.2.5 Professional

My Product Information:
Acrobat Pro 8.1.7, Windows
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Just don't use a menu item if you will be initiating the search dialog from buttons within the file. Instead, define the function that presents the search dialog in the folder-level JavaScript and call it directly in the buttons.
Nifty
Registered: Jan 16 2011
Posts: 17
Sorry George, I may not have made my desire clear.

I do wish to have a menu item that links to the search dialog because we have over 6,800 interlinked PDF files in this collection and I wish the search facility to be available from wherever the user may be within the library. My mention of one or two buttons also activating the search dialog was a bit of a red herring since these will literally be only one or two on key main menu pages.
I certainly don't wish to be adding several 100s of search buttons to pages.

Initiating the menu addition from the opening menu page solves the issue of it appearing when in an unrelated PDF document but it then has created the problem I wish to now solve, which is that it continually adds to the menu everytime the user returns to the main menu page.
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
A simple way would be to use a variable to keep track of whether or not you've added the menu item.
Nifty
Registered: Jan 16 2011
Posts: 17
Sorted thank you.

I have defined a variable, SearchMenu, at the beginning of the folder level script and set it to FALSE.
Then I have changed by trusted function to contain an if / else statement which tests the state of SearchMenu and if it is FALSE it adds the new menu option and then sets the variable to TRUE, else if SearchMenu is not FALSE (i.e TRUE) it does nothing - or rather, it resets the variable to TRUE.

Code is as follows:

// At beginning of folder level script
SearchMenu = "False";

//Later in same folder level script I have the trusted function
FWaddMenu = app.trustedFunction( function()
{
if (SearchMenu == "False")
{
app.beginPriv();
app.addMenuItem({cName:"-", cParent:"Help", cExec:" "});
app.addMenuItem({cName:"<< FIELDWISE SEARCH >>",
cParent: "Help",
cExec: "DoFWSearch()"});
app.endPriv();
SearchMenu = "True";
}
else
{
SearchMenu = "True";
}
}
);

I have then simply called FWaddMenu from the opening page's document level script.