Can "File Status Auto Detection" be changed programmatically?
-
Is it possible to enable and disable the option “File Status Auto Detection” programmatically, on demand?
Basically, I want to get rid of the message “This file has been modified by another program” in some specific scenario when I’m expecting a certain file to be modified externally at some point, whereas I do want this message in all the other cases. -
@Vitalii-Dovgan
From https://npp-user-manual.org/docs/preferencesFile Status Auto-Detection [pulldown] Enable: for the active file only, will check periodically to see if the file has been updated on disk, and will prompt to ask if you want to reload the file from the disk, or keep the version that’s currently in Notepad++ Enable for all open files: for all active files, check periodically to see if the file has been updated on disk Disable: will not check to see if the file has been updated on disk ☐ Update silently: instead of prompting, will automatically reload the file from disk ☐ Scroll to the last line after update: will scroll to the end of the file after reloading from disk (otherwise, the caret and scrolled-location stays where it was before the update)
Of course, Peter Jones wrote that documentation, so he presumably would be the person most knowledgeable about that.
-
@Mark-Olson,
Indeed, there is a manual option, thank you for pointing to the exact section of the documentation.
My question was rather related to ability to change this option programmatically (not manually), by means of Notepad++'s plugin. Maybe something similar to (I’m just wondering or guessing, so it is a pseudo-code):pNppOptions = (NppOptions*) SendMessage(hNppWnd, NPPM_GETOPTIONS, 0, 0); pNppOptions->nFileStatusAutoDetection = fsadSilent;
The
NPPM_GETOPTIONS
does not currently exist. So I’m wondering: is there another way to do such a thing? Or, maybe, I should create a feature request proposing to add such functionality? And, to be precise, it is not limited only to the File Status Auto Detection options - ideally, all and every Notepad++‘s option should be available programmatically for plugins’ purposes. -
My question was rather related to ability to change this option programmatically (not manually), by means of Notepad++'s plugin.
The source code makes one obscure reference to some kind of
NPPM_ENABLECHECKDOCOPT
API, which looks to be internal:> git grep -n -C 5 NPPM_ENABLECHECKDOCOPT PowerEditor/src/resource.h-662- // check all opened documents status. PowerEditor/src/resource.h-663- // If files are modified, then reloaod (with or without prompt, it depends on settings). PowerEditor/src/resource.h-664- // if files are deleted, then prompt user to close the documents PowerEditor/src/resource.h-665- PowerEditor/src/resource.h-666- #define NPPM_INTERNAL_ENABLECHECKDOCOPT (NPPMSG + 54) PowerEditor/src/resource.h:667: // VOID NPPM_ENABLECHECKDOCOPT(OPT, 0) PowerEditor/src/resource.h-668- // where OPT is : PowerEditor/src/resource.h-669- #define CHECKDOCOPT_NONE 0 PowerEditor/src/resource.h-670- #define CHECKDOCOPT_UPDATESILENTLY 1 PowerEditor/src/resource.h-671- #define CHECKDOCOPT_UPDATEGO2END 2 PowerEditor/src/resource.h-672-
The
NPPM_INTERNAL_ENABLECHECKDOCOPT
message is handled here.ideally, all and every Notepad++‘s option should be available programmatically for plugins’ purposes.
I’m afraid that would give a dangerous amount of control to “third-party” processes that (let’s face it) are quite trivial to exploit, e.g., by dropping a compromised DLL in place of the authentic one (the checksum is only validated when downloading the plugin, not before loading it).
A handful of popular plugins don’t even have published source code. Should we trust them with APIs that could silently overwrite files?
-
@rdipardo said in Can “File Status Auto Detection” be changed programmatically?:
NPPM_INTERNAL_ENABLECHECKDOCOPT
Wow, this is exactly what I wanted! Except one thing: I did not find a way to get a current value of this option :( My initial idea was the following:
- get the current value of the “File Status Auto-Detection”
- set it to “Update silently” (CHECKDOCOPT_UPDATESILENTLY)
- run the external tool that modifies a file
- finally, restore the previous value of the “File Status Auto-Detection”
As for the file “resource.h”, I sincerely believe that all of its NPPM_INTERNAL_ messages must be officially exposed to Notepad++'s plugins. The plugins are part of Notepad++'s infrastructure, and the more powerful API is exposed to them, the more powerful plugins can be.
I agree with the question of safety, especially in case of closed-source plugins, but we have the entire Notepad++ community to report any possible issues, plus there are such powerful instruments such as Process Monitor and even System Monitor by SysInternals, that can help to track any undesired activity.
This whole question of safety reminds me the disputes of whether it’s worth to use nuclear energy or not. I’m on that side who believes that the nuclear energy is absolutely worth to be used and it is not wise to reject it. The catastrophes of the past were caused by imperfection of technologies plus mistakes in the design that were allowed under push of the bureaucracy. But it does not mean the entire idea of the nuclear energy is wrong and should be avoided. The Humanity have been learning and improving both the technology and the human-related processes. -
Actually, I raised this question exactly because of plugin’s needs. You see, I’m experimenting with another mind-blowing technique that can be used in NppExec:
https://htmlpreview.github.io/?https://github.com/d0vgan/nppexec/blob/develop/NppExec/doc/NppExec/NppExec_Manual/4.6.15.html
(I should confess the underlying idea does not belong to me, but all the text and script commands are mine).
If you want to try it, just notice thatset local f ~ fileexists $(FULL_CURRENT_PATH)
is currently available only in thedevelop
branch.
The last lines of this instruction mention the message “This file has been modified by another program” and my regret for inability to disable/enable it programmatically.
This may be the answer to the question of whether we need it available for plugins or not ;) -
@Vitalii-Dovgan If you preserve a file’s modified time stamp then Notepad++ does not notice it has changed. Thus it’s possible to sneak in and make changes without triggering the pop-up.
Of course, that also means Notepad++'s in-memory copy of an open file would be out of sync with with what’s on disk. If you do
File / Reload from Disk
then Notepad++ will pick up the new file contents.Reload from Disk
is also available in the right click menu for the file’s tab.