Fix bugs for remembering inaccessible file of past session (placeholder)

Fix #14271, fix #14272, fix #14273
This commit is contained in:
Don Ho 2023-10-27 03:12:29 +02:00
parent e5ee4c3638
commit dd6140f8c0
4 changed files with 28 additions and 6 deletions

View File

@ -2606,10 +2606,10 @@ void Notepad_plus::checkDocState()
::CheckMenuItem(_mainMenuHandle, IDM_EDIT_SETREADONLY, MF_BYCOMMAND | (isUserReadOnly ? MF_CHECKED : MF_UNCHECKED));
enableCommand(IDM_FILE_DELETE, isFileExisting, MENU);
//enableCommand(IDM_FILE_RENAME, isFileExisting, MENU);
enableCommand(IDM_FILE_OPEN_CMD, isFileExisting, MENU);
enableCommand(IDM_FILE_OPEN_FOLDER, isFileExisting, MENU);
enableCommand(IDM_FILE_RELOAD, isFileExisting, MENU);
enableCommand(IDM_FILE_CONTAININGFOLDERASWORKSPACE, isFileExisting, MENU);
enableCommand(IDM_FILE_OPEN_DEFAULT_VIEWER, isAssoCommandExisting(curBuf->getFullPathName()), MENU);
@ -2628,6 +2628,15 @@ void Notepad_plus::checkDocState()
enableCommand(IDM_VIEW_MONITORING, !curBuf->isUntitled(), MENU | TOOLBAR);
checkMenuItem(IDM_VIEW_MONITORING, curBuf->isMonitoringOn());
_toolBar.setCheck(IDM_VIEW_MONITORING, curBuf->isMonitoringOn());
enableCommand(IDM_FILE_SAVEAS, !curBuf->isInaccessible(), MENU);
enableCommand(IDM_FILE_RENAME, !curBuf->isInaccessible(), MENU);
if (curBuf->isInaccessible())
enableCommand(IDM_EDIT_CLEARREADONLY, false, MENU);
enableCommand(IDM_VIEW_GOTO_ANOTHER_VIEW, !curBuf->isInaccessible(), MENU);
enableCommand(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, !curBuf->isInaccessible(), MENU);
enableCommand(IDM_VIEW_GOTO_NEW_INSTANCE, !curBuf->isInaccessible() && !curBuf->isDirty() && !curBuf->isUntitled(), MENU);
enableCommand(IDM_VIEW_LOAD_IN_NEW_INSTANCE, !curBuf->isInaccessible() && !curBuf->isDirty() && !curBuf->isUntitled(), MENU);
}
void Notepad_plus::checkUndoState()
@ -6423,7 +6432,11 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask)
prepareBufferChangedDialog(buffer);
// Then we ask user to update
if (doReloadOrNot(buffer->getFullPathName(), buffer->isDirty()) != IDYES)
if (doReloadOrNot(buffer->getFullPathName(), buffer->isDirty()) == IDYES)
{
buffer->setInaccessibility(false); // it's accessible in any way
}
else
{
// Since the file content has changed but the user doesn't want to reload it, set state to dirty
buffer->setDirty(true);

View File

@ -2410,12 +2410,11 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch
// 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))
if (nppGUI._keepSessionAbsentFileEntries && nppParam.theWarningHasBeenGiven() && nppParam.isPlaceHolderEnabled() && (nppGUI._fileAutoDetection & cdEnabledOld))
{
checkModifiedDocument(false); // so here we launch file-detection for all placeholders manually
}

View File

@ -585,21 +585,30 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_tabPopupMenu.checkItem(IDM_EDIT_SETREADONLY, isUserReadOnly);
bool isSysReadOnly = buf->getFileReadOnly();
bool isInaccessible = buf->isInaccessible();
_tabPopupMenu.enableItem(IDM_EDIT_SETREADONLY, !isSysReadOnly && !buf->isMonitoringOn());
_tabPopupMenu.enableItem(IDM_EDIT_CLEARREADONLY, isSysReadOnly);
if (isInaccessible)
_tabPopupMenu.enableItem(IDM_EDIT_CLEARREADONLY, false);
bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE;
_tabPopupMenu.enableItem(IDM_FILE_DELETE, isFileExisting);
_tabPopupMenu.enableItem(IDM_FILE_RELOAD, isFileExisting);
_tabPopupMenu.enableItem(IDM_FILE_OPEN_FOLDER, isFileExisting);
_tabPopupMenu.enableItem(IDM_FILE_OPEN_CMD, isFileExisting);
_tabPopupMenu.enableItem(IDM_FILE_CONTAININGFOLDERASWORKSPACE, isFileExisting);
_tabPopupMenu.enableItem(IDM_FILE_OPEN_DEFAULT_VIEWER, isAssoCommandExisting(buf->getFullPathName()));
bool isDirty = buf->isDirty();
bool isUntitled = buf->isUntitled();
_tabPopupMenu.enableItem(IDM_VIEW_GOTO_NEW_INSTANCE, !(isDirty||isUntitled));
_tabPopupMenu.enableItem(IDM_VIEW_LOAD_IN_NEW_INSTANCE, !(isDirty||isUntitled));
_tabPopupMenu.enableItem(IDM_VIEW_GOTO_ANOTHER_VIEW, !isInaccessible);
_tabPopupMenu.enableItem(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, !isInaccessible);
_tabPopupMenu.enableItem(IDM_VIEW_GOTO_NEW_INSTANCE, !isInaccessible && !isDirty && !isUntitled);
_tabPopupMenu.enableItem(IDM_VIEW_LOAD_IN_NEW_INSTANCE, !isInaccessible && !isDirty && !isUntitled);
_tabPopupMenu.enableItem(IDM_FILE_SAVEAS, !isInaccessible);
_tabPopupMenu.enableItem(IDM_FILE_RENAME, !isInaccessible);
_tabPopupMenu.display(p);
return TRUE;

View File

@ -187,6 +187,7 @@ public:
bool isUntitled() const { return ((_currentStatus & DOC_UNNAMED) == DOC_UNNAMED); }
bool isInaccessible() const { return _isInaccessible; }
void setInaccessibility(bool val) { _isInaccessible = val; }
bool getFileReadOnly() const { return _isFileReadOnly; }