| Summary: | XContextMenuInterceptor does not work anymore | ||
|---|---|---|---|
| Product: | LibreOffice | Reporter: | Olivier R. <olivier.dev> |
| Component: | Writer | Assignee: | Not Assigned <libreoffice-bugs> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | normal | CC: | arnaud.versini, olivier.dev |
| Priority: | medium | Keywords: | regression |
| Version: | 4.1.0.4 release | ||
| Hardware: | Other | ||
| OS: | All | ||
| Whiteboard: | |||
| Crash report or crash signature: | Regression By: | ||
| Attachments: | extension for test | ||
Confirmed on master 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()] Created attachment 83630 [details]
extension for test
It says that com.sun.star.ui.ContextMenuInterceptorAction.EXECUTE_MODIFIED is not a CONSTANT, which it used to be. Same issue than here, I assume: https://bugs.freedesktop.org/show_bug.cgi?id=66031 |
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",),)