plugin to (re)open file as hex/binary

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

plugin to (re)open file as hex/binary

Post by tmsg »

I'm trying to write a py function to open a file as binary.

Code: Select all

def openBinary(self):
		fn=_get_filename(ed)
		file_open(fn,-1,'/view-hex')
doesn't work, probably because the file is open already. Hm...

Code: Select all

def openBinary(self):
		fn=_get_filename(ed)
		ed.cmd(cmds.cmd_FileClose)
		file_open(fn,-1,'/view-hex')
would not be optimal because the file is closed and reopened but it doesn't work in the first place. Any idea?

Additionally, is there a way if a file is view-hex-opened to have more than 32 bytes per row?
Last edited by tmsg on 21.06.2020 09:29, edited 1 time in total.
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

>Additionally, is there a way if a file is view-hex-opened to have more than 32 bytes per row?
I have added it now- ed.get_prop/set_prop with PROP_V_WIDTH_HEX, PROP_V_WIDTH_UHEX.
must think how to reopen file...
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Also changed the API so setting ed.set_prop(PROP_V_MODE,...) switches editor to viewer.

BTW, "def openBinary" is Java style, pls don't use it, write like "def open_binary"
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Beta with new api- http://uvviewsoft.com/c/
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

@Alexey Thanks for those changes, appreciated.
Alexey wrote:BTW, "def openBinary" is Java style, pls don't use it, write like "def open_binary"
I've not written a single line of Java in my whole life :D and I've written my first Pascal programs some 12 years before Java was even invented... so I'd rather think it's MY style.

As to style matters and Python in general... probably best not to get me started :evil:
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

Toggling to Hex now works almost perfect, the only small problem is that

Code: Select all

ed.set_prop(PROP_V_WIDTH_HEX,32)
doesn't work first time round.

However, toggling back to edit mode seems not possible...? Perhaps there's an API for that but if so I don't know which.

Also, while playing with this... wouldn't it not great if I could do something like this:

Code: Select all

fn='x:\\somepath\\somefile.txt'
file_open((fn,fn), group=-1, options="/edit /view-hex")
Not saying this is the best way to do that but this would make it possible to open a file in a tab with two different views: left as a full editor and right as hex. Sounds super cool. 8-)
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

>ed.set_prop(PROP_V_WIDTH_HEX,32)
It works here (after I open file in VMODE_HEX). maybe you didnt update cudatext.py?
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Current app structure don't allow to show viewer (hex) with editor, both.
So cannot do it.
Also it's terrible to sync memory buffers - editor has one list of data, viewer- another one
tmsg
Posts: 120
Joined: 20.05.2020 12:08

Post by tmsg »

Alexey wrote:>ed.set_prop(PROP_V_WIDTH_HEX,32)
It works here (after I open file in VMODE_HEX). maybe you didnt update cudatext.py?
I was setting the width BEFORE switching. Now it works.

EDIT: I assume switching back to Editor mode doesn't work either?
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Now it works!
see new beta (same URL)
wiki
https://wiki.freepascal.org/index.php?t ... did=137204
Post Reply