How to bypass 'The file has been modified by another program. Do you want to reload it?' message on focus change after I've already manually reloaded the document?

  • I use Notepad++ primarily to write AutoHotkey stuff and lately I’ve been using AutoHotkey more and more to interact with Notepad++ and Scintilla through the NPPM_* and SCI_* messages. I can’t however figure out how to do what I need here. I’m no expert because I know nothing of C++ and trying to convert strings to a format readable in AutoHotkey involves a lot of math and memory buffer pointers and I don’t even where to begin with the “[out] TCHAR **” stuff… But that’s beside the point, I’m just saying I can generally handle the messages that don’t interact with strings so I’m not sure why I’m lost with this issue.

    Let me explain my use case:

    I have a function that saves my clipboard text to a file and opens that file in N++. The first time I run the function, it works fine - the tab opens and activates in N++ like I want.

    However each time I use the function, the file is overwritten with the new clipboard and opened again. So if I still have the tab open in N++ and run the function, N++ simply switches to the tab without updating the text to the new file’s. Once the tab is active, I can send a ‘Reload from disk’ message (have tried both NPPM_RELOADFILE and NPPM_MENUCOMMAND + IDM_FILE_RELOAD) and the document will update with the new text. So far everything is how I want it. The issue is that once I activate any other window and navigate back to N++, I get the “This file has been modified by another program. Do you want to reload it?” alert from N++ even if I’ve already manually reloaded the file.

    To summarise:

    1. I open the file via command line while it’s already open in N++, and the tab activates, nothing more
    2. I manually send a ‘Reload’ command, and the document updates with current contents of file.

    At this point that’s the end of my desired interaction with N++ - that’s all I want to happen. But as soon as I change focus and return, I get the message box asking me to reload. It’s worth noting that at no point in this process, not after step 1 OR step 2, is there a ‘*’ in the window title or red floppy icon on the tab to signify the document being unsaved.

    So any advice? Right now I’ve hacked together a crappy workaround where as soon as I switch to the tab, I send a reload message, then I immediately de-activate N++ and reactivate it which triggers the message box, which I then dismiss by pressing the ‘Yes’ button. That’s all automated but I’d still really like to bypass the message box entirely. BUT I need that message box to otherwise appear in normal usage. I just feel like manually reloading the document should tell N++ to not ask at some point in the future whenever I switch to another program. So is this a bug or am I missing something?

    Thanks for reading.

  • @Vismund-Cygnus

    How about closing any open clipboard file first before running your “function that saves clipboard text to a file”? Seems like a lot of your problem would then not exist?

Log in to reply