Skip to content

Commit

Permalink
Make session inaccessible files remembered (part 2/2)
Browse files Browse the repository at this point in the history
Following the commit: 4248c2a

If the user enables the option "Remember inaccessible files from past session" (disabled by default), and an opened session (the default session "session.xml" or a user session) contains one or several inaccessible files, a message dialog will appear, giving the user the choice to open or not open the placeholders. If the user chooses to open them, empty and read-only documents will be opened as placeholders for these inaccessible files.

Fix #12079, fix #12744, fix #13696, close #14252
  • Loading branch information
donho committed Oct 22, 2023
1 parent 4248c2a commit 0879451
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 51 deletions.
15 changes: 14 additions & 1 deletion PowerEditor/installer/nativeLang/english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Translation note:
2. All the comments are for explanation, they are not for translation.
-->
<NotepadPlus>
<Native-Langue name="English" filename="english.xml" version="8.5.5">
<Native-Langue name="English" filename="english.xml" version="8.5.9">
<Menu>
<Main>
<!-- Main Menu Entries -->
Expand Down Expand Up @@ -1167,6 +1167,7 @@ You can define several column markers by using white space to separate the diffe
<Item id="6821" name="seconds"/>
<Item id="6822" name="Backup path:"/>
<Item id="6309" name="Remember current session for next launch"/>
<Item id="6825" name="Remember inaccessible files from past session"/>
<Item id="6801" name="Backup on save"/>
<Item id="6315" name="None"/>
<Item id="6316" name="Simple backup"/>
Expand Down Expand Up @@ -1481,8 +1482,20 @@ Please test those commands and, if needed, re-edit them.
Alternatively, you can downgrade to Notepad++ v8.5.2 and restore your previous data.
Notepad++ will backup your old &quot;shortcuts.xml&quot; and save it as &quot;shortcuts.xml.v8.5.2.backup&quot;.
Renaming &quot;shortcuts.xml.v8.5.2.backup&quot; -&gt; &quot;shortcuts.xml&quot;, your commands should be restored and work properly."/><!-- HowToReproduce: Close Notepad++, remove shortcuts.xml.v8.5.2.backup & v852ShortcutsCompatibilityWarning.xml if present, relaunch Notepad++, delete or modify a shortcuts via Shortcut Mapper, close Notepad++, then the message will show up -->
<NbFileToOpenImportantWarning title="Amount of files to open is too large" message="$INT_REPLACE$ files are about to be opened.
Are you sure you want to open them?"/>
<NotEnoughRoom4Saving title="Save failed" message="Failed to save file.
It seems there's not enough space on disk to save file. Your file is not saved."/>
<FileInaccessibleUserSession title="File inaccessible" message="Some files from your manually-saved session &quot;$STR_REPLACE$&quot; are inaccessible. They can be opened as empty and read-only documents as placeholders.
Would you like to create those placeholders?
NOTE: Choosing not to create the placeholders or closing them later, your manually-saved session will NOT be modified on exit."/>
<FileInaccessibleDefaultSessionXml title="File inaccessible" message="Some files from your past session are inaccessible. They can be opened as empty and read-only documents as placeholders.
Would you like to create those placeholders?
NOTE: Choosing not to create the placeholders or closing them later, your session WILL BE MODIFIED ON EXIT! We suggest you backup your &quot;session.xml&quot; now."/>
</MessageBox>
<ClipboardHistory>
<PanelTitle name="Clipboard History"/>
Expand Down
14 changes: 13 additions & 1 deletion PowerEditor/installer/nativeLang/english_customizable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Translation note:
2. All the comments are for explanation, they are not for translation.
-->
<NotepadPlus>
<Native-Langue name="English" filename="english_customizable.xml" version="8.5.5">
<Native-Langue name="English" filename="english_customizable.xml" version="8.5.9">
<Menu>
<Main>
<!-- Main Menu Entries -->
Expand Down Expand Up @@ -1177,6 +1177,7 @@ You can define several column markers by using white space to separate the diffe
<Item id="6821" name="seconds"/>
<Item id="6822" name="Backup path:"/>
<Item id="6309" name="Remember current session for next launch"/>
<Item id="6825" name="Remember inaccessible files from past session"/>
<Item id="6801" name="Backup on save"/>
<Item id="6315" name="None"/>
<Item id="6316" name="Simple backup"/>
Expand Down Expand Up @@ -1493,7 +1494,18 @@ Notepad++ will backup your old &quot;shortcuts.xml&quot; and save it as &quot;sh
Renaming &quot;shortcuts.xml.v8.5.2.backup&quot; -&gt; &quot;shortcuts.xml&quot;, your commands should be restored and work properly."/><!-- HowToReproduce: Close Notepad++, remove shortcuts.xml.v8.5.2.backup & v852ShortcutsCompatibilityWarning.xml if present, relaunch Notepad++, delete or modify a shortcuts via Shortcut Mapper, close Notepad++, then the message will show up -->
<NotEnoughRoom4Saving title="Save failed" message="Failed to save file.
It seems there's not enough space on disk to save file. Your file is not saved."/>
<NbFileToOpenImportantWarning title="Amount of files to open is too large" message="$INT_REPLACE$ files are about to be opened.
Are you sure you want to open them?"/>
<FileInaccessibleUserSession title="File inaccessible" message="Some files from your manually-saved session &quot;$STR_REPLACE$&quot; are inaccessible. They can be opened as empty and read-only documents as placeholders.
Would you like to create those placeholders?
NOTE: Choosing not to create the placeholders or closing them later, your manually-saved session will NOT be modified on exit."/>
<FileInaccessibleDefaultSessionXml title="File inaccessible" message="Some files from your past session are inaccessible. They can be opened as empty and read-only documents as placeholders.
Would you like to create those placeholders?
NOTE: Choosing not to create the placeholders or closing them later, your session WILL BE MODIFIED ON EXIT! We suggest you backup your &quot;session.xml&quot; now."/>
</MessageBox>
<ClipboardHistory>
<PanelTitle name="Clipboard History"/>
Expand Down
13 changes: 12 additions & 1 deletion PowerEditor/installer/nativeLang/french.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Translation note:
2. All the comments are for explanation, they are not for translation.
-->
<NotepadPlus>
<Native-Langue name="français" filename="french.xml" version="8.5.5">
<Native-Langue name="français" filename="french.xml" version="8.5.9">
<Menu>
<Main>
<!-- Main Menu Entries -->
Expand Down Expand Up @@ -1167,6 +1167,7 @@ Vous pouvez définir plusieurs marqueurs de colonne en utilisant un espace pour
<Item id="6821" name="secondes"/>
<Item id="6822" name="dans le dossier"/>
<Item id="6309" name="Mémoriser la session actuelle"/>
<Item id="6825" name="Mémoriser les fichiers inaccessibles de la session précédente"/>
<Item id="6801" name="Sauvegarde"/>
<Item id="6315" name="Aucune"/>
<Item id="6316" name="Simple"/>
Expand Down Expand Up @@ -1481,6 +1482,16 @@ Veuillez tester ces commandes et, si besoin, ré-éditer celles-ci.
Autrement, vous pouvez revenir vers Notepad++ v8.5.2 et restaurer les données précédentes.
Notepad++ va sauvegarder votre ancien &quot;shortcuts.xml&quot; et l'enregistrer sous &quot;shortcuts.xml.v8.5.2.backup&quot;.
En renommant &quot;shortcuts.xml.v8.5.2.backup&quot; -&gt; &quot;shortcuts.xml&quot;, vos commandes devraient être proprement restaurées."/><!-- HowToReproduce: Close Notepad++, remove shortcuts.xml.v8.5.2.backup & v852ShortcutsCompatibilityWarning.xml if present, relaunch Notepad++, delete or modify a shortcuts via Shortcut Mapper, close Notepad++, then the message will show up -->
<FileInaccessibleUserSession title="Fichier inaccessible" message="Certains fichiers de votre session sauvegardée manuellement &quot;$STR_REPLACE$&quot; sont inaccessibles. Ils peuvent être ouverts comme des documents vides et en lecture seule en tant qu'espaces réservés.
Voulez-vous créer des espaces réservés pour eux ?
Notez que si vous choisissez de ne pas créer d'espaces réservés ou de les fermer plus tard, votre session sauvegardée manuellement ne sera PAS modifiée à la sortie."/>
<FileInaccessibleDefaultSessionXml title="Fichier inaccessible" message="Certains fichiers de votre session précédente sont inaccessibles. Ils peuvent être ouverts comme des documents vides et en lecture seule en tant qu'espaces réservés.
Voulez-vous créer des espaces réservés pour eux ?
Notez que si vous choisissez de ne pas créer d'espaces réservés ou de les fermer plus tard, votre fichier de session sera modifié à la sortie. Nous vous suggérons de faire une sauvegarde du fichier de session &quot;session.xml&quot; maintenant."/>
<NotEnoughRoom4Saving title="Échec de l'enregistrement" message="Échec de l'enregistrement du fichier.
Il semblerait qu'il n'y a pas assez d'espace disque pour enregistrer le fichier. Votre fichier n'est pas enregistré."/>
</MessageBox>
Expand Down
14 changes: 13 additions & 1 deletion PowerEditor/installer/nativeLang/taiwaneseMandarin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<NotepadPlus>
<Native-Langue name="台灣繁體" filename="taiwaneseMandarin.xml" version="8.5.5">
<Native-Langue name="台灣繁體" filename="taiwaneseMandarin.xml" version="8.5.9">
<Menu>
<Main>
<!-- Main Menu Entries -->
Expand Down Expand Up @@ -1131,6 +1131,7 @@
<Item id="6821" name="秒備份一次"/>
<Item id="6822" name="備份資料夾:"/>
<Item id="6309" name="開啟程式時繼續上次的工作階段"/>
<Item id="6825" name="保存上次的工作階段中無法讀取的文件"/>
<Item id="6801" name="備份"/>
<Item id="6315" name=""/>
<Item id="6316" name="簡易備份"/>
Expand Down Expand Up @@ -1378,6 +1379,17 @@
繼續嗎?"/>
<NeedToRestartToLoadPlugins title="重新啟動 Notepad++" message="你必須重新啟動 Notepad++ 才能載入已安裝的外掛模組。"/>
<ChangeHistoryEnabledWarning title="重新啟動 Notepad++" message="你必須重新啟動 Notepad++ 才能啟動文件修改紀錄。"/>
<FileInaccessibleUserSession title="檔案不存在" message="儲存的工作階段 &quot;$STR_REPLACE$&quot; 中有一些已不存在的檔案。它們可以以空白唯讀文件的形式作為佔位欄而創建。
你想為它們創建佔位欄嗎?
請注意,如果你選擇不創建佔位欄或稍後關閉它們,工作階段檔案將不會在 Notepad++ 關閉時被修改。
"/>
<FileInaccessibleDefaultSessionXml title="檔案不存在" message="過去的工作階段中有一些已不存在的檔案。它們可以以空白唯讀文件的形式作為佔位欄而創建。
你想為它們創建佔位欄嗎?
請注意,如果你選擇不創建佔位欄或稍後關閉它們,工作階段檔案將在 Notepad++ 關閉時被修改。我們建議你現在備份工作階段檔案 &quot;session.xml&quot;"/>
</MessageBox>
<ClipboardHistory>
<PanelTitle name="剪貼簿記錄"/>
Expand Down
37 changes: 23 additions & 14 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6410,6 +6410,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
{
break;
}

case DOC_MODIFIED: //ask for reloading
{
// Since it is being monitored DOC_NEEDRELOAD is going to handle the change.
Expand Down Expand Up @@ -6446,6 +6447,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
}
break;
}

case DOC_NEEDRELOAD: // by log monitoring
{
doReload(buffer->getID(), false);
Expand All @@ -6465,6 +6467,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)

break;
}

case DOC_DELETED: //ask for keep
{
prepareBufferChangedDialog(buffer);
Expand All @@ -6475,21 +6478,27 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
scnN.nmhdr.idFrom = (uptr_t)buffer->getID();
_pluginsManager.notify(&scnN);

int doCloseDoc = doCloseOrNot(buffer->getFullPathName()) == IDNO;
if (doCloseDoc)
if (buffer->isInaccessible() && nppParam.isPlaceHolderEnabled())
{
//close in both views, doing current view last since that has to remain opened
bool isSnapshotMode = nppGUI.isSnapshotMode();
doClose(buffer->getID(), otherView(), isSnapshotMode);
doClose(buffer->getID(), currentView(), isSnapshotMode);
return;
buffer->setUnsync(true);
}
else
{
// buffer in Notepad++ is not syncronized anymore with the file on disk
buffer->setUnsync(true);
int doCloseDoc = doCloseOrNot(buffer->getFullPathName()) == IDNO;
if (doCloseDoc)
{
//close in both views, doing current view last since that has to remain opened
bool isSnapshotMode = nppGUI.isSnapshotMode();
doClose(buffer->getID(), otherView(), isSnapshotMode);
doClose(buffer->getID(), currentView(), isSnapshotMode);
return;
}
else
{
// buffer in Notepad++ is not syncronized anymore with the file on disk
buffer->setUnsync(true);
}
}

break;
}
}
Expand Down Expand Up @@ -6649,14 +6658,14 @@ std::vector<generic_string> Notepad_plus::loadCommandlineParams(const TCHAR * co
if (pCmdParams->_isSessionFile && fnss.size() == 1)
{
Session session2Load;
if (nppParams.loadSession(session2Load, fnss.getFileName(0)))
const wchar_t* sessionFileName = fnss.getFileName(0);
if (nppParams.loadSession(session2Load, sessionFileName))
{
const bool isSnapshotMode = false;
const bool shouldLoadFileBrowser = true;

if (nppGUI._multiInstSetting == multiInstOnSession)
nppParams.setLoadedSessionFilePath(fnss.getFileName(0));
loadSession(session2Load, isSnapshotMode, shouldLoadFileBrowser);
nppParams.setLoadedSessionFilePath(sessionFileName);
loadSession(session2Load, isSnapshotMode, sessionFileName);
}
return std::vector<generic_string>();
}
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/Notepad_plus.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ friend class FileManager;
void macroPlayback(Macro);

void loadLastSession();
bool loadSession(Session & session, bool isSnapshotMode = false, bool shouldLoadFileBrowser = false);
bool loadSession(Session & session, bool isSnapshotMode = false, const wchar_t* userCreatedSessionName = nullptr);

void prepareBufferChangedDialog(Buffer * buffer);
void notifyBufferChanged(Buffer * buffer, int mask);
Expand Down
35 changes: 26 additions & 9 deletions PowerEditor/src/NppIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2104,9 +2104,13 @@ void Notepad_plus::loadLastSession()
_isFolding = false;
}

bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shouldLoadFileBrowser)
bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wchar_t* userCreatedSessionName)
{
NppParameters& nppParam = NppParameters::getInstance();
const NppGUI& nppGUI = nppParam.getNppGUI();

nppParam.setTheWarningHasBeenGiven(false);

bool allSessionFilesLoaded = true;
BufferID lastOpened = BUFFER_INVALID;
//size_t i = 0;
Expand Down Expand Up @@ -2145,7 +2149,9 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
}
else
{
lastOpened = MainFileManager.newPlaceholderDocument(pFn, MAIN_VIEW);
BufferID foundBufID = MainFileManager.getBufferFromName(pFn);
if (foundBufID == BUFFER_INVALID)
lastOpened = nppGUI._keepSessionAbsentFileEntries ? MainFileManager.newPlaceholderDocument(pFn, MAIN_VIEW, userCreatedSessionName) : BUFFER_INVALID;
}
if (isWow64Off)
{
Expand All @@ -2168,8 +2174,6 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou

if (!id) // it could be due to the hidden language from the sub-menu "Languages"
{
const NppGUI& nppGUI = nppParam.getNppGUI();

for (size_t k = 0; k < nppGUI._excludedLangList.size(); ++k) // try to find it in exclude lang list
{
if (nppGUI._excludedLangList[k]._langName == pLn)
Expand Down Expand Up @@ -2283,7 +2287,9 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
}
else
{
lastOpened = MainFileManager.newPlaceholderDocument(pFn, SUB_VIEW);
BufferID foundBufID = MainFileManager.getBufferFromName(pFn);
if (foundBufID == BUFFER_INVALID)
lastOpened = nppGUI._keepSessionAbsentFileEntries ? MainFileManager.newPlaceholderDocument(pFn, SUB_VIEW, userCreatedSessionName) : BUFFER_INVALID;
}
if (isWow64Off)
{
Expand Down Expand Up @@ -2396,12 +2402,24 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, bool shou
if (_pDocumentListPanel)
_pDocumentListPanel->reload();

if (shouldLoadFileBrowser && !session._fileBrowserRoots.empty())
if (userCreatedSessionName && !session._fileBrowserRoots.empty())
{
// Force launch file browser and add roots
// If the session is user's created session but not session.xml, we force to launch Folder as Workspace and add roots
launchFileBrowser(session._fileBrowserRoots, session._fileBrowserSelectedItem, true);
}

// Especially File status auto-detection set on "Enable for all opened files": nppGUI._fileAutoDetection & cdEnabledOld
// when "Remember inaccessible files from past session" is enabled: nppGUI._keepSessionAbsentFileEntries
// and while loading a user session: userCreatedSessionName != nullptr
// there are some (or 1) absent files: nppParam.theWarningHasBeenGiven()
// and user want to create the placeholders for these files: nppParam.isPlaceHolderEnabled()
//
// When above conditions are true, the created placeholders are not read-only, due to the lack of file-detection on them.
if (nppGUI._keepSessionAbsentFileEntries && nppParam.theWarningHasBeenGiven() && nppParam.isPlaceHolderEnabled() && userCreatedSessionName && (nppGUI._fileAutoDetection & cdEnabledOld))
{
checkModifiedDocument(false); // so here we launch file-detection for all placeholders manually
}

return allSessionFilesLoaded;
}

Expand Down Expand Up @@ -2464,8 +2482,7 @@ bool Notepad_plus::fileLoadSession(const TCHAR *fn)
if (nppParam.loadSession(session2Load, sessionFileName.c_str()))
{
const bool isSnapshotMode = false;
const bool shouldLoadFileBrowser = true;
isAllSuccessful = loadSession(session2Load, isSnapshotMode, shouldLoadFileBrowser);
isAllSuccessful = loadSession(session2Load, isSnapshotMode, sessionFileName.c_str());
result = true;
if (isEmptyNpp && nppGUI._multiInstSetting == multiInstOnSession)
nppParam.setLoadedSessionFilePath(sessionFileName);
Expand Down
20 changes: 20 additions & 0 deletions PowerEditor/src/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4871,6 +4871,21 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
}
}
}
else if (!lstrcmp(nm, TEXT("KeepSessionAbsentFileEntries")))
{
TiXmlNode *n = childNode->FirstChild();
if (n)
{
const TCHAR* val = n->Value();
if (val)
{
if (lstrcmp(val, TEXT("yes")) == 0)
_nppGUI._keepSessionAbsentFileEntries = true;
else
_nppGUI._keepSessionAbsentFileEntries = false;
}
}
}
else if (!lstrcmp(nm, TEXT("DetectEncoding")))
{
TiXmlNode *n = childNode->FirstChild();
Expand Down Expand Up @@ -7038,6 +7053,11 @@ void NppParameters::createXmlTreeFromGUIParams()
insertGUIConfigBoolNode(newGUIRoot, TEXT("RememberLastSession"), _nppGUI._rememberLastSession);
}

// <GUIConfig name = "RememberLastSession">yes< / GUIConfig>
{
insertGUIConfigBoolNode(newGUIRoot, TEXT("KeepSessionAbsentFileEntries"), _nppGUI._keepSessionAbsentFileEntries);
}

// <GUIConfig name = "DetectEncoding">yes< / GUIConfig>
{
insertGUIConfigBoolNode(newGUIRoot, TEXT("DetectEncoding"), _nppGUI._detectEncoding);
Expand Down

0 comments on commit 0879451

Please sign in to comment.