Bug 67366 - XContextMenuInterceptor does not work anymore
Summary: XContextMenuInterceptor does not work anymore
Status: RESOLVED DUPLICATE of bug 66031
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
4.1.0.4 release
Hardware: Other All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2013-07-26 19:09 UTC by Olivier R.
Modified: 2013-08-05 05:23 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
extension for test (3.87 KB, application/vnd.openofficeorg.extension)
2013-08-04 22:16 UTC, Olivier R.
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier R. 2013-07-26 19:09:44 UTC
I wrote an extension which shows information in the context menu of Writer.

It doesn’t work anymore with LO 4.1. This is a regression.

I implemented my own XContextMenuInterceptor with notifyContextMenuExecute which create new entries to the context menu, then I return the proper value: com.sun.star.ui.ContextMenuInterceptorAction.EXECUTE_MODIFIED

But nothing happens. The extension works properly until it returns the value.

Here is the simplified code (in Python) :


import uno
import unohelper
import re

from com.sun.star.task import XJob
from com.sun.star.task import XJobExecutor
from com.sun.star.ui import XContextMenuInterceptor
from com.sun.star.beans import PropertyValue
    
class MyContextMenuInterceptor (XContextMenuInterceptor, unohelper.Base):
    def __init__ (self, ctx):
        self.ctx = ctx

    def notifyContextMenuExecute (self, xEvent):
        try:
            xContextMenu = xEvent.ActionTriggerContainer
            if (xContextMenu):
                i = xContextMenu.Count

                xMenuItem = xContextMenu.createInstance("com.sun.star.ui.ActionTrigger")
                xMenuItem.setPropertyValue("Text", u"MY INFORMATION")
                xContextMenu.insertByIndex(i, xMenuItem)

                print("it goes and works until there")
                # The controller should execute the modified context menu and stop notifying other interceptors.
                return uno.getConstantByName("com.sun.star.ui.ContextMenuInterceptorAction.EXECUTE_MODIFIED")
        except:
            traceback.print_exc()
        return uno.getConstantByName("com.sun.star.ui.ContextMenuInterceptorAction.IGNORED")

        
class JobExecutor (XJob, unohelper.Base):
    def __init__ (self, ctx):
        self.ctx = ctx
        
    def execute (self, args):
        if not args:
            return
        
        # what event?
        bCorrectEvent = False
        for arg in args:
            if arg.Name == "Environment":
                for v in arg.Value:
                    if v.Name == "EnvType" and v.Value == "DOCUMENTEVENT":
                        bCorrectEvent = True
                    elif v.Name == "EventName":
                        pass
                        # check is correct event
                        #print "Event: %s" % v.Value
                    elif v.Name == "Model":
                        model = v.Value
        if bCorrectEvent:
            if model.supportsService("com.sun.star.text.TextDocument"):
                xController = model.getCurrentController()
                if xController:
                    xController.registerContextMenuInterceptor(MyContextMenuInterceptor(self.ctx))


g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(JobExecutor, "grammalecte.ContextMenuHandler", ("grammalecte.ContextMenuHandler",),)
Comment 1 Arnaud Versini 2013-08-04 22:04:50 UTC
Confirmed on master
Comment 2 Arnaud Versini 2013-08-04 22:07:49 UTC
Error in debug build console :

Until there, it's OK
Python exception: <class 'NameError'>: global name 'traceback' is not defined, traceback follows
  /home/arnaud/.config/libreoffice/4/user/uno_packages/cache/uno_packages/luysh6iv.tmp_/ContextMenu-1.oxt/ContextMenu.py:53 in function notifyContextMenuExecute() [traceback.print_exc()]
Comment 3 Olivier R. 2013-08-04 22:16:35 UTC
Created attachment 83630 [details]
extension for test
Comment 4 Olivier R. 2013-08-04 22:18:51 UTC
It says that com.sun.star.ui.ContextMenuInterceptorAction.EXECUTE_MODIFIED is not a CONSTANT, which it used to be.
Comment 5 Olivier R. 2013-08-04 22:20:32 UTC
Same issue than here, I assume:
https://bugs.freedesktop.org/show_bug.cgi?id=66031
Comment 6 Olivier R. 2013-08-05 05:23:11 UTC

*** This bug has been marked as a duplicate of bug 66031 ***