Community
    • Login

    Trying to avoid reload prompt

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 242 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.
    • Alan KilbornA
      Alan Kilborn
      last edited by Alan Kilborn

      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
      • EkopalypseE
        Ekopalypse
        last edited by

        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
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors