Page 2 of 3

Posted: 21.06.2020 08:51
by tmsg
:D Perfect. Now I can switch seamlessly between viewer and editor... I find this very useful (eg with encoding problems when moving files from Windows to Linux). Well done, great feature.

EDIT: Hm... load a file, switch to hex view, switch back to text edit, add some text and try to save. Error message saying file can't be saved. I toggled read-only... no change.

Probably some flag set by the viewer.

Posted: 21.06.2020 10:58
by Alexey
some Win-only issue... will check it soon.

Posted: 21.06.2020 11:48
by tmsg
Confirmed as Windows only... works in Linux.

Posted: 21.06.2020 13:58
by Alexey
fixed, thanks (update- later).

Posted: 21.06.2020 14:20
by tmsg
Great.

FWIW, this is the plugin code (disclaimer: I am no Pythonista):

Code: Select all

	def fancy_python_name(self):
		if ed.get_prop(PROP_V_MODE)!=VMODE_NONE:
			ed.set_prop(PROP_V_MODE,VMODE_NONE)
			ed.focus()
			ed.set_caret(*Command.hexCr[ed])
			ed.cmd(cmds.cCommand_ScrollToCaretTop)
		else:
			Command.hexCr[ed]=ed.get_carets()[0]
			ed.set_prop(PROP_V_MODE,VMODE_HEX)
			ed.set_prop(PROP_V_WIDTH_HEX,32)
There's a small problem in that the ed.cmd(cmds.cCommand_ScrollToCaretTop) call doesn't really do what it's supposed to do.

Posted: 21.06.2020 14:53
by Alexey
Code uses unset var... need do this:

Code: Select all

class Command:
  crt = None #global inited var

  def method(self):
    # code to restore crt
    if self.crt:
      ed.set_caret(*self.crt)

    #code to save crt
    self.crt = ed.get_carets()[0]  

Posted: 21.06.2020 14:55
by Alexey
> the ed.cmd(cmds.cCommand_ScrollToCaretTop) call doesn't really do what it's supposed to do.
It works here- if I place 10 carets, scroll to end of big file, cmd scrolls to top caret

Posted: 21.06.2020 15:15
by tmsg
Alexey wrote:Code uses unset var... need do this:
I've left that bit out as an exercise for the reader :lol: Of course, I have defined hexCr (as evidenced by it being referenced as Command.hexCr).
Alexey wrote:> the ed.cmd(cmds.cCommand_ScrollToCaretTop) call doesn't really do what it's supposed to do.
It works here- if I place 10 carets, scroll to end of big file, cmd scrolls to top caret
Sure, it works in the general case but it definitely does not work when switching back into text editor mode.

Posted: 21.06.2020 15:22
by Alexey
Could you give code of plugin which uses this cmd_ and fails? it must switch to hex, to editor, and call cmd, and fail.

Posted: 21.06.2020 15:36
by Alexey
could you try call
ed.action(EDACTION_UPDATE)
before calling cmd_ (or after it)?