Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem detecting saved/unsaved file state at startup #266

Open
alankilborn opened this issue Dec 29, 2022 · 5 comments
Open

Problem detecting saved/unsaved file state at startup #266

alankilborn opened this issue Dec 29, 2022 · 5 comments

Comments

@alankilborn
Copy link

I’m having trouble detecting the saved/unsaved state of the filetabs at Notepad++ startup using a script. Specifically, I’m being told that I have no unsaved tabs, when I do have some:

image

For the filetabs in yellow, the print() output (also in yellow) should say "unsaved" not "saved".

Here’s the code as text, from startup.py:

if 1:
    import os
    for (pathname, buffer_id, index, view) in notepad.getFiles():
        notepad.activateFile(pathname)
        state = 'unsaved' if editor.getModify() else 'saved'
        print('on startup, activating a {st} "{fn}"'.format(st=state, fn=pathname.rsplit(os.sep, 1)[-1]))

Using PS 2.0 or 3.10.4.

This was originally discussed on the Community HERE.

@Ekopalypse
Copy link
Contributor

In my opinion it is the task of Notepad++ and Scintilla to ensure,
that PS can determine this accordingly.
However, here are some hurdles that are probably difficult to overcome by Npp,
such as the fact that if Npp is restarted but configured with backup and session,
does not have an undo/redo list, which Scintilla would need to reset a modified buffer to a
savepoint or to change it again from there.
This would only work if Npp would not only save the last state itself, but all changes as needed by Scintilla, would be saved.

@alankilborn
Copy link
Author

In my opinion it is the task of Notepad++ and Scintilla to ensure

I think so, too, but I wanted to make sure PS isn't doing anything wrong first.
Just like @chcg to confirm...

@alankilborn
Copy link
Author

Bump; I just encountered this same issue in a different new script I am working on. :-(

@rdipardo
Copy link

@Ekopalypse

Scintilla would need to reset a modified buffer to a savepoint or to change it again from there. This would only work if Npp would not only save the last state itself, but all changes as needed by Scintilla, would be saved.

FYI, Scintilla now has APIs for persisting undo state:

An application may save both the document and its save stack between sessions to enable the user to return to the same state the next time they edit.
https://www.scintilla.org/ScintillaDoc.html#UndoSaveRestore

Usage examples are on the mailing list.

@Ekopalypse
Copy link
Contributor

@rdipardo - you are right, haven't had a chance to play with these new APIs yet but it's definitely interesting. Thx for pointing out the example too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants