• Login
Community
  • Login

Trying to avoid reload prompt

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
2 Posts 2 Posters 272 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Alan Kilborn
    last edited by Alan Kilborn Feb 10, 2021, 9:58 PM Feb 10, 2021, 9:56 PM

    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:

    b907e5ee-79ec-4d32-be89-b1c1d79af921-image.png

    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
            break
    
    if file_already_open:
    
        notepad.reloadFile(our_file, False)  # do not alert user
        notepad.activateFile(our_file)
    
    else:
    
        notepad.open(our_file)
    

    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.

    1 Reply Last reply Reply Quote 1
    • E
      Ekopalypse
      last edited by Feb 10, 2021, 10:48 PM

      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.

      1 Reply Last reply Reply Quote 2
      2 out of 2
      • First post
        2/2
        Last post
      The Community of users of the Notepad++ text editor.
      Powered by NodeBB | Contributors