From 87dc9cc5d2278b0d443f5f626e7a732c43eea265 Mon Sep 17 00:00:00 2001 From: Udo Hoffmann Date: Thu, 4 Jun 2020 19:28:51 +0200 Subject: [PATCH] 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 --- PowerEditor/src/Notepad_plus.cpp | 8 ++- PowerEditor/src/Notepad_plus.h | 5 +- PowerEditor/src/Notepad_plus_Window.cpp | 4 ++ PowerEditor/src/NppIO.cpp | 4 +- .../WinControls/ProjectPanel/ProjectPanel.cpp | 57 +++++++++++-------- .../WinControls/ProjectPanel/ProjectPanel.h | 1 + 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 73c79d12..cb6731f7 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -6001,10 +6001,9 @@ void Notepad_plus::launchFileBrowser(const vector & folders, boo void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID) { + NppParameters& nppParam = NppParameters::getInstance(); if (!(*pProjPanel)) { - NppParameters& nppParam = NppParameters::getInstance(); - (*pProjPanel) = new ProjectPanel; (*pProjPanel)->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf()); (*pProjPanel)->setWorkSpaceFilePath(nppParam.getWorkSpaceFilePath(panelID)); @@ -6042,6 +6041,11 @@ void Notepad_plus::launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int (*pProjPanel)->setBackgroundColor(bgColor); (*pProjPanel)->setForegroundColor(fgColor); } + else + { + if ((*pProjPanel)->saveWorkspaceRequest()) + (*pProjPanel)->openWorkSpace(nppParam.getWorkSpaceFilePath(panelID)); + } (*pProjPanel)->display(); } diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 14437397..e81d7de2 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -388,8 +388,9 @@ private: // 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 - 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; std::vector > _hideLinesMarks; diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 0e72bafb..499d9c5e 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -247,6 +247,10 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin } 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); } diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index a8e372f9..0a1c22ac 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -212,7 +212,9 @@ BufferID Notepad_plus::doOpen(const generic_string& fileName, bool isRecursive, { nppParam.setWorkSpaceFilePath(0, longFileName); _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; } diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index ea7906b1..0a9b11f7 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -863,6 +863,35 @@ HTREEITEM ProjectPanel::addFolder(HTREEITEM hTreeItem, const TCHAR *folderName) 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) { // get selected item handle @@ -989,31 +1018,8 @@ void ProjectPanel::popupMenuCmd(int cmdID) case IDM_PROJECT_OPENWS: { - NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); - if (_isDirty) - { - - 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; - } - } + if (!saveWorkspaceRequest()) + break; FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL)); setFileExtFilter(fDlg); @@ -1021,6 +1027,7 @@ void ProjectPanel::popupMenuCmd(int cmdID) { if (!openWorkSpace(fn)) { + NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker(); pNativeSpeaker->messageBox("ProjectPanelOpenFailed", _hSelf, TEXT("The workspace could not be opened.\rIt seems the file to open is not a valid project file."), diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h index ab6dd396..f29eb7f4 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h @@ -83,6 +83,7 @@ public: }; void newWorkSpace(); + bool saveWorkspaceRequest(); bool openWorkSpace(const TCHAR *projectFileName); bool saveWorkSpace(); bool saveWorkSpaceAs(bool saveCopyAs);