Fix Load project file by dragging doesn't work

Make workspace (project) & session xml setting files consistent while their file extensions are defined in Preferences dialog:
1. If I specify a session file in the command line (, or if I double-click a session file in the Explorer), not the session file itself is opened, but the session stored in it.
2. If I specify a workspace file in the command line (, or if I double-click a workspace file in the Explorer), not the workspace file itself is opened, but the Project Panel 1 switches to the specified workspace file.
3. If I specify a session file in the `File` menu `Open Ctrl-O`, not the session file itself is opened, but the session stored in it.
4. If I specify a workspace file in the `File` menu `Open Ctrl-O`, not the workspace file itself is opened, but the Project Panel 1 switches to the specified workspace file.
5. If I drag a session file to Npp, not the session file itself is opened, but the session stored in it.
6. If I drag a workspace file to Npp, not the workspace file itself is opened, but the Project Panel 1 switches to the specified workspace file.

That means that once an user extension is defined for these 2 types of file, Notepad++ stores only the session or the workspace but not opens the file itself. The session and workspace setting files are not supposed to be edited manually.

If a defined conflict happens (for example, a non session or workspace setting file with the defined extension), user can always remove the defined extension from Preferences dialog temporarily to open it.

cherry picked from commit 70e746b7a8fe44c9a1e724581ceb3b457138a474

Close #8374, fix #8324
This commit is contained in:
Udo Hoffmann 2020-06-04 19:28:51 +02:00 committed by Don HO
parent 58ded005bd
commit 87dc9cc5d2
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
6 changed files with 49 additions and 30 deletions

View File

@ -6001,10 +6001,9 @@ void Notepad_plus::launchFileBrowser(const vector<generic_string> & folders, boo
void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID) void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID)
{ {
NppParameters& nppParam = NppParameters::getInstance();
if (!(*pProjPanel)) if (!(*pProjPanel))
{ {
NppParameters& nppParam = NppParameters::getInstance();
(*pProjPanel) = new ProjectPanel; (*pProjPanel) = new ProjectPanel;
(*pProjPanel)->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf()); (*pProjPanel)->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf());
(*pProjPanel)->setWorkSpaceFilePath(nppParam.getWorkSpaceFilePath(panelID)); (*pProjPanel)->setWorkSpaceFilePath(nppParam.getWorkSpaceFilePath(panelID));
@ -6042,6 +6041,11 @@ void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int
(*pProjPanel)->setBackgroundColor(bgColor); (*pProjPanel)->setBackgroundColor(bgColor);
(*pProjPanel)->setForegroundColor(fgColor); (*pProjPanel)->setForegroundColor(fgColor);
} }
else
{
if ((*pProjPanel)->saveWorkspaceRequest())
(*pProjPanel)->openWorkSpace(nppParam.getWorkSpaceFilePath(panelID));
}
(*pProjPanel)->display(); (*pProjPanel)->display();
} }

View File

@ -388,8 +388,9 @@ private:
// then WM_ENDSESSION is send with wParam == FALSE // then WM_ENDSESSION is send with wParam == FALSE
// in this case this boolean is set true, so Notepad++ will quit and its current session will be saved // in this case this boolean is set true, so Notepad++ will quit and its current session will be saved
bool _isWorkspaceFileLoadedFromCommandLine = false; bool _isWorkspaceFileLoadedFromCommandLine = false; // Set during Notepad_plus::doOpen if workspace file is opened.
// But it is only evaluated during startup, when doOpen
// has been called while command line interpretation.
ScintillaCtrls _scintillaCtrls4Plugins; ScintillaCtrls _scintillaCtrls4Plugins;
std::vector<std::pair<int, int> > _hideLinesMarks; std::vector<std::pair<int, int> > _hideLinesMarks;

View File

@ -247,6 +247,10 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
} }
else if (_notepad_plus_plus_core._isWorkspaceFileLoadedFromCommandLine) else if (_notepad_plus_plus_core._isWorkspaceFileLoadedFromCommandLine)
{ {
// Switch back to Project Panel 1, when a workspace file has been specified in the command line.
// This code is executed only once in lifetime of the process, at the first initialization. It is necessary, because
// the Project Panels are not loaded by Notepad_plus::doOpen only, but also by the Plugin Manager restoring the state
// of the last session from config.xml.
::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_PROJECT_PANEL_1, 0); ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_PROJECT_PANEL_1, 0);
} }

View File

@ -212,7 +212,9 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive,
{ {
nppParam.setWorkSpaceFilePath(0, longFileName); nppParam.setWorkSpaceFilePath(0, longFileName);
_isWorkspaceFileLoadedFromCommandLine = true; _isWorkspaceFileLoadedFromCommandLine = true;
// command(IDM_VIEW_PROJECT_PANEL_1); // This line switches to Project Panel 1 while starting up Npp
// and after dragging a workspace file to Npp:
command(IDM_VIEW_PROJECT_PANEL_1);
return BUFFER_INVALID; return BUFFER_INVALID;
} }

View File

@ -863,6 +863,35 @@ HTREEITEM ProjectPanel::addFolder(HTREEITEM hTreeItem, const TCHAR *folderName)
return addedItem; return addedItem;
} }
bool ProjectPanel::saveWorkspaceRequest()
{ // returns true for continue and false for break
if (_isDirty)
{
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
int res = pNativeSpeaker->messageBox("ProjectPanelOpenDoSaveDirtyWsOrNot",
_hSelf,
TEXT("The current workspace was modified. Do you want to save the current project?"),
TEXT("Open Workspace"),
MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
if (res == IDYES)
{
if (!saveWorkSpace())
return false;
}
else if (res == IDNO)
{
// Don't save so do nothing here
}
else if (res == IDCANCEL)
{
// User cancels action "New Workspace" so we interrupt here
return false;
}
}
return true;
}
void ProjectPanel::popupMenuCmd(int cmdID) void ProjectPanel::popupMenuCmd(int cmdID)
{ {
// get selected item handle // get selected item handle
@ -989,31 +1018,8 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_OPENWS: case IDM_PROJECT_OPENWS:
{ {
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); if (!saveWorkspaceRequest())
if (_isDirty) break;
{
int res = pNativeSpeaker->messageBox("ProjectPanelOpenDoSaveDirtyWsOrNot",
_hSelf,
TEXT("The current workspace was modified. Do you want to save the current project?"),
TEXT("Open Workspace"),
MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL);
if (res == IDYES)
{
if (!saveWorkSpace())
return;
}
else if (res == IDNO)
{
// Don't save so do nothing here
}
else if (res == IDCANCEL)
{
// User cancels action "New Workspace" so we interrupt here
return;
}
}
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL)); FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
setFileExtFilter(fDlg); setFileExtFilter(fDlg);
@ -1021,6 +1027,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
{ {
if (!openWorkSpace(fn)) if (!openWorkSpace(fn))
{ {
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
pNativeSpeaker->messageBox("ProjectPanelOpenFailed", pNativeSpeaker->messageBox("ProjectPanelOpenFailed",
_hSelf, _hSelf,
TEXT("The workspace could not be opened.\rIt seems the file to open is not a valid project file."), TEXT("The workspace could not be opened.\rIt seems the file to open is not a valid project file."),

View File

@ -83,6 +83,7 @@ public:
}; };
void newWorkSpace(); void newWorkSpace();
bool saveWorkspaceRequest();
bool openWorkSpace(const TCHAR *projectFileName); bool openWorkSpace(const TCHAR *projectFileName);
bool saveWorkSpace(); bool saveWorkSpace();
bool saveWorkSpaceAs(bool saveCopyAs); bool saveWorkSpaceAs(bool saveCopyAs);