AnsweredAssumed Answered

Disable Custom EPDM Menus C#?

Question asked by Dmitry Zamoshnikov on May 10, 2019

Is there a way to grey out a menu based on the object type the user right clicks?  I wouldn't want the menu to execute if there's a folder selected.  I'm thinking I can go through the selection list and just return if one of the object's mlObjectID1==0, but I'm curious if I can disable to menu from the start rather than have to run through the loop.



using FileList = System.Collections.Generic.Dictionary<EdmLib.IEdmFile5, EdmLib.IEdmFolder5>; // poor-mans typedef


Code Snippet:

/// <summary>
/// The user has activated a menu item or toolbar button that
/// your add-in has added. This command returns a combination of
/// refresh flags in the mlEdmRefreshFlags member of the EdmCmd structure.
/// </summary>
/// <remarks>The following members are for the ppoCmdData array</remarks>
/// <param name="mlObjectID1" type="integer">ID of file; 0 if a folder is selected</param>
/// <param name="mlObjectID2" type="integer">ID of folder; 0 if a file is selected</param>
/// <param name="mlObjectID3" type="integer">ID of parent folder of the selected file or folder</param>
/// <param name="mlObjectID4" type="integer">NOT USED</param>
/// <param name="mbsStrData1" type="string">Name of file or folder; not full path</param>
/// <param name="mbsStrData2" type="string">NOT USED</param>
/// <param name="mbsStrData3" type="string">NOT USED</param>
/// <param name="mlLongData1" type="integer">NOT USED</param>
/// <param name="mlLongData2" type="integer">NOT USED</param>
/// <param name="mlLongData3" type="integer">NOT USED</param>
/// <param name="mpoExtra" type="object*">NOT USED</param>
public virtual void OnEdmCmd_Menu(ref EdmCmd poCmd, ref Array ppoCmdData)
IEdmVault5 vault = (IEdmVault5)poCmd.mpoVault;
if (vault == null) // is there a vault?
mLog.Write("No Vault");
FileList fileList = new FileList();
IEdmFile5 file; // pointer to the file
IEdmFolder5 parentFolder; // pointer to the parent folder
// populate the file list
foreach (EdmCmdData affectedFile in ppoCmdData)
parentFolder = (IEdmFolder5)vault.GetObject(EdmObjectType.EdmObject_Folder, affectedFile.mlObjectID3); // get the folder
if (affectedFile.mlObjectID1 == 0)
mLog.Write("A folder was selected: " + parentFolder.Name);
file = (IEdmFile5)vault.GetObject(EdmObjectType.EdmObject_File, affectedFile.mlObjectID1); // get the file
parentFolder = (IEdmFolder5)vault.GetObject(EdmObjectType.EdmObject_Folder, affectedFile.mlObjectID3); // get the folder
fileList.Add(file, parentFolder); // populate the list
if (poCmd.mlCmdID== 1005) // did my menu command ID get triggered?
mLog.Write("Triggered my menu command");