You are here: PSPad forum > English discussion forum > Load file without losing Undo's

Load file without losing Undo's

Goto Page: 1 2 Next

#1 Load file without losing Undo's

Posted by: Professor Bernd | Date: 2020-10-19 20:18 | IP: IP Logged

"Undo's" means: steps to undo the last changes (Ctrl+Z).

A file is loaded in an editor/tab. I did some work in the editor and there are "Undo's". With a VBScript an external program is started which changes the file externally (tidy).

How can I load the modified file into the same editor/tab without losing the "Undo's"?

I have worked on it for many hours and tried many possibilities, unfortunately without success. sad smiley

Options: Reply | Quote | Up ^


#2 Re: Load file without losing Undo's

Posted by: pspad | Date: 2020-10-20 03:20 | IP: IP Logged

Undo is stored in memiry. There is no possibility now to save/load it with file.
If you reload file, you will loose it.
Loading undo buffers means you need some mechanism to check if file wasnt modified externally, cause undos must much to exact copy of file.
Ifvanything will modify your file from outside, stored undo is useless.

Better is possibility to make a backups and return in time

Options: Reply | Quote | Up ^


#3 Re: Load file without losing Undo's

Posted by: Professor Bernd | Date: 2020-10-20 06:45 | IP: IP Logged

pspad:
Ifvanything will modify your file from outside, stored undo is useless.

The user starts the above-mentioned VBScript by shortcut and thus knows that the file is modified externally. If the user does not like the result, he can use the Undo's to return to the previous state. Then he presses Ctrl+S and his file is back to the desired state.

Ok, here is my workaround: When the user starts the external program, the current file is changed externally. Then I use VBScript to read the file as "sNewText" and replace the old text in the active editor/tab with "obj.text(sNewText)". This way all Undo's are preserved.

Problem: The encoding (charset) of the file.

In order to display all characters as they should be, the encoding from the read-in must match the encoding of the editor/tab. But this seems to be impossible in VBScript.

So since it's not possible to reload the file without losing all Undo's, can you please add a function for VBScript for my workaround to get the encoding for the current editor/tab?

For example:

obj.encoding(): string
returns editor encoding (only for saved file)

Options: Reply | Quote | Up ^


#4 Re: Load file without losing Undo's

Posted by: vbr | Date: 2020-10-20 18:32 | IP: IP Logged

Professor Bernd:
pspad:
Ifvanything will modify your file from outside, stored undo is useless.

The user starts the above-mentioned VBScript by shortcut and thus knows that the file is modified externally. If the user does not like the result, he can use the Undo's to return to the previous state. Then he presses Ctrl+S and his file is back to the desired state.

Ok, here is my workaround: When the user starts the external program, the current file is changed externally. Then I use VBScript to read the file as "sNewText" and replace the old text in the active editor/tab with "obj.text(sNewText)". This way all Undo's are preserved.

Problem: The encoding (charset) of the file.

In order to display all characters as they should be, the encoding from the read-in must match the encoding of the editor/tab. But this seems to be impossible in VBScript.

So since it's not possible to reload the file without losing all Undo's, can you please add a function for VBScript for my workaround to get the encoding for the current editor/tab?

For example:

obj.encoding(): string
returns editor encoding (only for saved file)

Hi,
I was just about to propose a workaround You found - i.e. replacing the text content via scripting instead of reloading the file. This way the undo history is preserved.
However, I'm not quite sure about the encoding problem - I'd think, the external tool must somehow cope with the encoding correctly as well, otherwise it could corrupt the content.?
Could it be, that it can handle the on-disk file (even without extra encoding information), however, it doesn't work if the text content is passed via scripting?
Just a suggestion, I haven't actually tried it sofar - could a tempoorary copy of the current-tab's file be created as input for the external file? The result could (hopefully?) be read as a new content of the tab.
In my experience, the encoding handling got much better with PSPad 5 (compared to previous versions), at least using Javascript (that I am more familiar with), the scripting can now pass general unicode characters from the tab (at least the "basic multilingual plane in unicode - BMP up to U+FFFF). I believe, the text is handled internally, mostly idependently of individual encodings, but one can assign some universal encoding, such as utf-8 to the above mentioned temporary file, and after external reformatting etc. the content would be used using the same encoding.

However, it might well be I am not aware of some extra complications, since I guess, You likely already tried such an approach...

regards,
vbr

Options: Reply | Quote | Up ^


#5 Re: Load file without losing Undo's

Posted by: Professor Bernd | Date: 2020-10-21 04:41 | IP: IP Logged

Hello vbr, nice to hear from you! smiling smiley

You are right about many things winking smiley For example that I have already tried these approaches. Unfortunately there is always something in the way.

The external program "Tidy for AutoIt3" does its job without problems. First it copies the current file (= backup), edits this file and saves it at the place of the source file. No problems with file encoding. I can open the file e.g. with PSPad and everything is fine. Up to here. - Unfortunately I can't get it in PSPad without causing a problem.

If you load the new file in VBScript ...

- ... with WSH functions (fso.OpenTextFile, ...) it is read as ASCII and characters are displayed wrong (ö ä ü ß ...).

- ... with ADO functions ("ADODB.Stream" - LoadFromFile, ...) you have to specify the file encoding precisely (incl. charset, BOM...), otherwise you will lose the complete text that looks like this: 椣据畬敤㰠獍䉧硯潃獮慴瑮⹳畡㸳਍਍畆据张䉟

- ... with PSPad functions (obj.reloadFile(), obj.openFile, ...) you lose all Undo's.

- ... using a temporary second editor/tab, an additional tab will become visible, the whole surface of PSPad will flicker and the additional tab will close again.

I've been working on it for 4 days now, without success. It's a pity that PSPad has no better interfaces than VBScript and JavaScript.

Thank you very much for your tips and the effort you made!

Options: Reply | Quote | Up ^


#6 Re: Load file without losing Undo's

Posted by: pspad | Date: 2020-10-21 06:34 | IP: IP Logged

PSPad scripting interface is developed as needed.
New functionality is created and was made for your requests in the past. The future is the same.

Options: Reply | Quote | Up ^


#7 Re: Load file without losing Undo's

Posted by: Professor Bernd | Date: 2020-10-21 06:57 | IP: IP Logged

Please excuse me, that shouldn't make your work bad. Your work is great and you have already implemented many feature requests. Thanks a lot!

Options: Reply | Quote | Up ^


#8 Re: Load file without losing Undo's

Posted by: Professor Bernd | Date: 2020-10-21 17:10 | IP: IP Logged

I have made another attempt. The current file was externally converted to UTF-8 BOM and then read in via ADODB.Stream, etc. - Unfortunately also unsuccessfully, there are other problems with it.

Can you implement an additional function in VBScript to reload the current file and keep the undo's?

Options: Reply | Quote | Up ^


#9 Re: Load file without losing Undo's

Posted by: Professor Bernd | Date: 2020-10-21 17:27 | IP: IP Logged

Or can I use a new editor invisibly? So with "Set objTmp = NewEditor()" and "objTmp.Text(sNewText)", but without a new tab being visible?

Options: Reply | Quote | Up ^


#10 Re: Load file without losing Undo's

Posted by: vbr | Date: 2020-10-22 18:12 | IP: IP Logged

Professor Bernd:
...
If you load the new file in VBScript ...

- ... with WSH functions (fso.OpenTextFile, ...) it is read as ASCII and characters are displayed wrong (ö ä ü ß ...).
...

Hi, I somehow thought, the things would be much complicated...
just in case (but I do think, it won't be new for You either...),

could it be, that OpenTextFile can be made to return unicode?
I am not sure, whether it is relevant for this case (VBScript via WSH), but according to:
docs.microsoft.com

the "format" argument might do this (if ommited, ASCII is apparently used).
"""
object.OpenTextFile (filename, [ iomode, [ create, [ format ]]])
...
The format argument can have any of the following settings:
SETTINGS
Constant Value Description
TristateUseDefault -2 Opens the file by using the system default.
TristateTrue -1 Opens the file as Unicode.
TristateFalse 0 Opens the file as ASCII.
"""

It seems strange, that the VB functions wouldn't allow for explicitely saving and reading a file using a given encoding, but I don't have much experience in this area.

Anyway, if all this doesn't work, probably some extra support for the scripting interface in PSPad would be needed.

regards,
vbr

Options: Reply | Quote | Up ^


Goto Page: 1 2 Next





Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR