plugin to (re)open file as hex/binary

Plugins for SynWrite and CudaText...
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post 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.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

some Win-only issue... will check it soon.
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

Confirmed as Windows only... works in Linux.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

fixed, thanks (update- later).
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post 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.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post 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]  
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post 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
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post 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.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post 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.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

could you try call
ed.action(EDACTION_UPDATE)
before calling cmd_ (or after it)?
Post Reply