Trying to avoid reload prompt

  • So I have a Pythonscript that creates an output text file from some other data. When the script completes, if the output text file isn’t a tab in N++ it should be opened into one. If it IS a tab in N++, that tab should be switched to. The file isn’t ever edited by the N++ user (me!), just viewed, so changes to this file can never be “lost”.

    My goal is to not have the user (me!) get prompted to reload a changed file for this file. So far I’m semi-successful.

    I have my settings set thusly:


    And my script looks like this:

    # -*- coding: utf-8 -*-
    from Npp import notepad
    our_file = r'd:\test.txt'
    with open(our_file, 'w') as f: f.write('dedodododedadada' + '\n')
    file_already_open = False
    for (filename, bufferID, index, view) in notepad.getFiles():
        if filename == our_file:
            file_already_open = True
    if file_already_open:
        notepad.reloadFile(our_file, False)  # do not alert user

    All goes well, and I’m not prompted for a reload…until I switch tabs and switch back to the tab of the output file. THEN I get a reload prompt.

    I’m soliciting ideas on how to avoid this prompt, or perhaps someone pointing out a critical flaw in the design/flow of what I’m wanting to do.

    I suppose I could close the file if it is open, before acting on it. :-)
    But…I’ll let the question stand.

  • Npp uses ReadDirectoryChangesW to get notified when a file has been modified. I don’t think you can catch this message.
    Reopening might be the only solution I guess.

Log in to reply