Make session inaccessible files remembered (part 1/2)

Add the ability of "placrholders" (the empty document) for the inaccessible files of past session.

The inaccessible files from the current (default) session (i.e., session.xml) will not be lost in the next startup of Notepad++.
Furthermore, if file status detection is enabled in Notepad++ (default setting: ON), and the previously inaccessible files become accessible again (e.g., USB drive is inserted or network drive is remounted), the resurrected files can be reloaded on-the-fly without restarting Notepad++. The user will be prompted to reload if the placeholder is switched in.

Fix #12079, fix #12744, fix #13696, close #14168
This commit is contained in:
molsonkiko 2023-09-21 08:18:11 -07:00 committed by Don Ho
parent bbbf3e8dfc
commit 4248c2ae22
3 changed files with 13 additions and 2 deletions

View File

@ -2145,7 +2145,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
}
else
{
lastOpened = BUFFER_INVALID;
lastOpened = MainFileManager.newPlaceholderDocument(pFn, MAIN_VIEW);
}
if (isWow64Off)
{
@ -2283,7 +2283,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
}
else
{
lastOpened = BUFFER_INVALID;
lastOpened = MainFileManager.newPlaceholderDocument(pFn, SUB_VIEW);
}
if (isWow64Off)
{

View File

@ -1347,6 +1347,15 @@ BufferID FileManager::newEmptyDocument()
return id;
}
BufferID FileManager::newPlaceholderDocument(const TCHAR* missingFilename, int whichOne)
{
BufferID buf = MainFileManager.newEmptyDocument();
_pNotepadPlus->loadBufferIntoView(buf, whichOne);
buf->setFileName(missingFilename);
buf->_currentStatus = DOC_REGULAR;
return buf;
}
BufferID FileManager::bufferFromDocument(Document doc, bool isMainEditZone)
{
NppParameters& nppParamInst = NppParameters::getInstance();

View File

@ -88,6 +88,8 @@ public:
BufferID loadFile(const TCHAR * filename, Document doc = static_cast<Document>(NULL), int encoding = -1, const TCHAR *backupFileName = nullptr, FILETIME fileNameTimestamp = {}); //ID == BUFFER_INVALID on failure. If Doc == NULL, a new file is created, otherwise data is loaded in given document
BufferID newEmptyDocument();
// create an empty placeholder for a missing file when loading session
BufferID newPlaceholderDocument(const TCHAR * missingFilename, int whichOne);
//create Buffer from existing Scintilla, used from new Scintillas.
BufferID bufferFromDocument(Document doc, bool isMainEditZone);