When I add menu items to context menus they work as expected, except
when the items are added to a spell-check context menu.  
 
Items that are added to a spell-check context menu appear normally in
the menu, but selecting them causes unexpected behaviour.  If the item
is added to the top of the context menu, selecting it launches the
"Spelling" dialog.  If the item is added to the bottom of the context
menu, selecting it does nothing.  
 
I am not doing any special handling for spell-check context menus.  The
Java code that I'm using to implement the context menu interceptor is
listed below.
 
Does anyone know a work-around for this problem, or at least why there's
a difference?  My menu item has to be added to all context menus,
including the spell-check context menu.
 
 
public class MyMenuInterceptor implements XContextMenuInterceptor {
 
    public ContextMenuInterceptorAction
notifyContextMenuExecute(ContextMenuExecuteEvent contextMenuEvent) {
        try {
            // Get the context menu 
            XIndexContainer contextMenuContainer =
contextMenuEvent.ActionTriggerContainer;
 
            // create the new menu item
            XMultiServiceFactory serviceFactory =
(XMultiServiceFactory)UnoRuntime.queryInterface(
                    XMultiServiceFactory.class, contextMenuContainer);
            XPropertySet menuItem = createActionTrigger(
                    "Open document", ".uno:Open", serviceFactory);
 
            // add it to the context menu
            contextMenuContainer.insertByIndex(0, menuItem);
 
            // Notify the caller that the context menu has been modified
            return ContextMenuInterceptorAction.EXECUTE_MODIFIED;
        } catch(Exception e) {
            LOG.log(Level.WARNING, "Error creating context menu.", e);
        }
 
        return ContextMenuInterceptorAction.CANCELLED;
    }
 
    private XPropertySet createActionTrigger(String text, String
commandURL, 
            XMultiServiceFactory serviceFactory) {
        XPropertySet actionTriggerProperties = null;
 
        try {
            actionTriggerProperties =
(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, 
 
serviceFactory.createInstance("com.sun.star.ui.ActionTrigger"));
            actionTriggerProperties.setPropertyValue("Text", text);
            actionTriggerProperties.setPropertyValue("CommandURL",
commandURL); 
        } catch(Exception e) {
            LOG.log(Level.WARNING, "Error creating action trigger", e);
        }
 
        return actionTriggerProperties;
    }
}

 

Reply via email to