From 4248c2ae22e07a030c9dd0684de1fd38125e9dfd Mon Sep 17 00:00:00 2001 From: molsonkiko <46202915+molsonkiko@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:18:11 -0700 Subject: [PATCH] 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 --- PowerEditor/src/NppIO.cpp | 4 ++-- PowerEditor/src/ScintillaComponent/Buffer.cpp | 9 +++++++++ PowerEditor/src/ScintillaComponent/Buffer.h | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index af8361828..b46f3c99e 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -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) { diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 703c82067..4ca5ca0c3 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -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(); diff --git a/PowerEditor/src/ScintillaComponent/Buffer.h b/PowerEditor/src/ScintillaComponent/Buffer.h index 697094a1c..29ab6b384 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.h +++ b/PowerEditor/src/ScintillaComponent/Buffer.h @@ -88,6 +88,8 @@ public: BufferID loadFile(const TCHAR * filename, Document doc = static_cast(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);