The quick hack would be to modify "_exec_custom_tool()" in "zim/gui/__init__.py"
Below my -- untested ! -- modified version of the routine. As you might guess the .desktop file for the custom tool (see .config/zim/customtools) should contain a key "X-Zim-ReplaceSelection" set to "True". If this works, also the custom tool dialog (defined in zim/gui/customtools.py) should be updated to add that key as a checkbox. I can also imagine a similar key to insert output text at the cursor. Please try it out and let me know if you get it to work. Cheers! Jaap def _exec_custom_tool(self, action): manager = CustomToolManager() tool = manager.get_tool(action.get_name()) logger.info('Execute custom tool %s', tool.name) args = (self.notebook, self.page, self.mainwindow.pageview) try: if tool.isreadonly: tool.spawn(args) elif tool['Desktop Entry'].get('X-Zim-ReplaceSelection', False): output = tool.pipe(args) pageview = self.mainwindow.pageview # XXX buffer = pageview.view.get_buffer() # XXX if buffer.get_has_selection(): start, end = buffer.get_selection_bounds() with buffer.user_action: buffer.delete(start, end) buffer.insert_at_cursor(output) else: pass # error here ?? else: tool.run(args) self.reload_page() self.notebook.index.update_async() # TODO instead of using run, use spawn and show dialog # with cancel button. Dialog blocks ui. except Exception, error: ErrorDialog(self, error).run() On Wed, Jun 18, 2014 at 8:36 AM, Sylvain Viart <launch...@ledragon.net> wrote: > Le 18/06/2014 05:07, Jaap Karssenberg a écrit : > > sort lines plugin can be an example how to do[…] > [start hacking to perform our own custom modification on selected text] > > > Another option is to patch the code calling custom tools and allow a > > custom tool to filter the selected text from stdin to stdout and have > > zim replace the selection when you call it. > > Sounds pretty cool. Could you point me some entry point in the code so I > can start hacking may be. > Is there a wish list tickets around or something? > > Regards, > Sylvain. > > _______________________________________________ > Mailing list: https://launchpad.net/~zim-wiki > Post to : zim-wiki@lists.launchpad.net > Unsubscribe : https://launchpad.net/~zim-wiki > More help : https://help.launchpad.net/ListHelp >
_______________________________________________ Mailing list: https://launchpad.net/~zim-wiki Post to : zim-wiki@lists.launchpad.net Unsubscribe : https://launchpad.net/~zim-wiki More help : https://help.launchpad.net/ListHelp