From dd6140f8c04bab1856a698d6cc8b7feac6d8c398 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 27 Oct 2023 03:12:29 +0200 Subject: [PATCH] Fix bugs for remembering inaccessible file of past session (placeholder) Fix #14271, fix #14272, fix #14273 --- PowerEditor/src/Notepad_plus.cpp | 17 +++++++++++++++-- PowerEditor/src/NppIO.cpp | 3 +-- PowerEditor/src/NppNotification.cpp | 13 +++++++++++-- PowerEditor/src/ScintillaComponent/Buffer.h | 1 + 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index d2808e547..3e61e5374 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -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); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 1c45c7299..440fd377f 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -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 } diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 105677568..41bccc5ff 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -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; diff --git a/PowerEditor/src/ScintillaComponent/Buffer.h b/PowerEditor/src/ScintillaComponent/Buffer.h index bee4fe9e9..4143094e2 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.h +++ b/PowerEditor/src/ScintillaComponent/Buffer.h @@ -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; }