← Back to team overview

zim-wiki team mailing list archive

Re: Modifying custom tool to handle selected text

 

Thanks for the test.  I made a patch myself, including also extra checkbox
in the dialog and a fix for the comment issue and a fix for the extra
newline.

Should show up as revision 682 in the dev tree.

Regards,

Jaap



On Wed, Jun 18, 2014 at 11:06 PM, Sylvain Viart <launchpad@xxxxxxxxxxxx>
wrote:

> Dev post with a lot of code and a patch at the end.
>
>
> > Bug during  "Tools > Custom Tools"
> > If the tool entry as no comment, it fails…
>
> I did not debug the issue above.
>
> I joined a patch that make the base works.
> Note the change: buffer.insert_at_cursor(''.join(output))
>
> The fact is, that data is not piped to stdin it is…  in the argument %t
>
> So the custom tool become:
>
> #!/bin/bash
> echo "$1" | tee -a ~/tmp/zim-custom.log | cat -n
>
> Which works.
>
> The bbcode quote custom tool:
>
> #!/bin/bash
> echo -n "[quote]$1[/quote]"
>
> An extra newline is inserted:
>
> Some text to quote become:
>      ^^^^
>
> Some [quote]text[/quote]
> to quote become:
>
>
>
> echo -n doesn't add extra new line.
>
> >>> import subprocess
> >>> subprocess.check_output(['zim-stdin', "test it"])
> '[quote]test it[/quote]'
>
> It's somewhere else.
>
> I stop here.
> Sylvain.
>
> === modified file 'zim/gui/__init__.py'
> --- zim/gui/__init__.py    2014-02-04 19:51:26 +0000
> +++ zim/gui/__init__.py    2014-06-18 20:29:36 +0000
> @@ -2178,10 +2178,23 @@
>          manager = CustomToolManager()
>          tool = manager.get_tool(action.get_name())
>          logger.info('Execute custom tool %s', tool.name)
> +        logger.info('myCT %s', tool['Desktop
> Entry'].get('X-Zim-ExecTool'))
>          args = (self.notebook, self.page, self.mainwindow.pageview)
>          try:
> +            logger.info('custom tool %s', tool['Desktop
> Entry'].get('X-Zim-ReplaceSelection'))
>              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(''.join(output))
> +                else:
> +                    pass # error here ??
>              else:
>                  tool.run(args)
>                  self.reload_page()
> @@ -2191,6 +2204,7 @@
>          except Exception, error:
>              ErrorDialog(self, error).run()
>
> +
>      def show_help(self, page=None):
>          '''Menu action to show the user manual. Will start a new zim
>          instance showing the notebook with the manual.
>
> === modified file 'zim/gui/applications.py'
> --- zim/gui/applications.py    2014-04-08 18:41:06 +0000
> +++ zim/gui/applications.py    2014-06-18 20:24:46 +0000
> @@ -978,6 +978,7 @@
>              ('X-Zim-ReadOnly',            Boolean(True)),
>              ('X-Zim-ShowInToolBar',        Boolean(False)),
>              ('X-Zim-ShowInContextMenu',    Choice(None, ('Text',
> 'Page'))),
> +            ('X-Zim-ReplaceSelection',    Boolean(False)),
>      )
>
>      def isvalid(self):
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~zim-wiki
> Post to     : zim-wiki@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~zim-wiki
> More help   : https://help.launchpad.net/ListHelp
>

References