How to Get Selected Documents in Custom Callback State Function?

I want to make my custom document menu's availability (greyed out or active) be based on the document type, so I need to use callback state function. My question is how to get the selected document in custom callback function?

I found some sample code for selected project, like this:

-------Begin--------------

BOOL CheckProjInfo()
{
    BOOL bRtn = FALSE;
    // NOTE: This method of retrieving selected Project number has not been verified. Other methods
    // of getting it from the interface may be necessary.
    LONG lProjId = aaApi_TreeGetItemData(aaApi_GetMainDscTree());
    if ((lProjId < 1L) || (aaApi_SelectProject(lProjId) < 1L))
        return bRtn;
    CString sProjName = aaApi_GetProjectStringProperty(PROJ_PROP_NAME,0L);
    CString sProjDesc = aaApi_GetProjectStringProperty(PROJ_PROP_DESC,0L);

// Add your logic here
    if(sProjName == something)
       bRtn = TRUE;
    else if(sProjDesc == something)
       bRtn = TRUE;

return bRtn;
}

Can somebody give me an example about documents? Thanks a lot.

------- End----------

  • I don't think it is possible (but I could be wrong).  A document menu item is available when you have a folder selected, but also with the results of searches.  I think you might be able to get a handle to that "window" and possibly figure out a way to determine what is displayed (and highlighted?), but I don't know of an "easy" way to do this.

    Also, it might take an unreasonable (to the user!) amount of time to process before the menu actually pops up.

    Why not just examine what is passed in your called function, and if it pass your tests, continue, otherwise throw up an error dialog or otherwise ask the user what they want to do because of the exceptions to your rules?

  • Thanks Dan, your suggestion will work obviously, but seems not very "elegant". If we can make sure my way is not possible, I'll follow your suggestion definitely.

    But I found out this post "Specifying a custom mask for menu item" posted years ago, he mentioned "I've used similar approach on some custom state functions for documents", so I'm thinking maybe it's possible.

  • Yes,  is a pretty clever fellow, so he might have figured out a way to do what you want, perhaps others have as well. Please share whatever you make work as I'm sure others, myself included, would be interested.

    FWIW, I didn't try (or study) the code that Jeff and other posted, but it appears to assume that a folder has been selected, so you might want to defensively code so that if the results are from a search, custom folder, etc., that the behavior is acceptable.

    Thanks!

  • I have a working custom mask for a couple of custom doc menu commands that rely on data that isn't exposed in the normal mask data for selected documents. It does exactly what Dan suggests - goes to the interface window and retrieves the data, passes that to my custom mask function and then returns the result based on what I needed.

    Dan is also correct that this method is not particularly fast processing. To the point that I had to put a limit on how many selected documents to even attempt running the custom mask on. In my case, I capped it at 50, anything more and things just degraded the user experience too severely. So if a user has selected more than 50 documents, it won't even try to process the mask and will just return the result that disables the command. PM me if you want more info or code - it is more involved than just posting a chunk of code here.

    Answer Verified By: Wence 

  • Thanks Jeff!

    Just had an idea.  I have used the ProjectWise menu based APIs to add commands to the saved search menu area.  Perhaps an option would be to create saved searches to return only the documents that meet your criteria and then you won't need a custom mask (menu state function) because the menu command would be for a saved search. 

    Now you might want to verify that the documents returned by the saved search meet your requirements, but at least then menu performance wouldn't be a issue, but it still may take some time to validate the data, so a "processing" dialog might be in order...