diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index ca8310013..6aa375cde 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3335,7 +3335,8 @@ void Notepad_plus::dropFiles(HDROP hdrop) else if (not isOldMode && (folderPaths.size() != 0 && filePaths.size() == 0)) // new mode && only folders { // process new mode - launchFileBrowser(folderPaths); + generic_string emptyStr; + launchFileBrowser(folderPaths, emptyStr); } ::DragFinish(hdrop); @@ -5990,7 +5991,7 @@ void Notepad_plus::launchAnsiCharPanel() _pAnsiCharPanel->display(); } -void Notepad_plus::launchFileBrowser(const vector & folders, bool fromScratch) +void Notepad_plus::launchFileBrowser(const vector & folders, const generic_string& selectedItemPath, bool fromScratch) { if (!_pFileBrowser) { @@ -6042,6 +6043,7 @@ void Notepad_plus::launchFileBrowser(const vector & folders, boo } _pFileBrowser->display(); + _pFileBrowser->selectItemFromPath(selectedItemPath); checkMenuItem(IDM_VIEW_FILEBROWSER, true); _toolBar.setCheck(IDM_VIEW_FILEBROWSER, true); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index f306b95be..da146da07 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -607,7 +607,7 @@ private: void launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID); void launchDocMap(); void launchFunctionList(); - void launchFileBrowser(const std::vector & folders, bool fromScratch = false); + void launchFileBrowser(const std::vector & folders, const generic_string& selectedItemPath, bool fromScratch = false); void showAllQuotes() const; static DWORD WINAPI threadTextPlayer(void *text2display); static DWORD WINAPI threadTextTroller(void *params); diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 8d663ecb0..51b693004 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -246,7 +246,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin // To avoid dockable panel toggle problem. if (cmdLineParams->_openFoldersAsWorkspace) { - _notepad_plus_plus_core.launchFileBrowser(fns, true); + generic_string emptyStr; + _notepad_plus_plus_core.launchFileBrowser(fns, emptyStr, true); } ::SendMessage(_hSelf, WM_ACTIVATE, WA_ACTIVE, 0); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index feec82d84..ebd424ab8 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -131,7 +131,8 @@ void Notepad_plus::command(int id) if (_pFileBrowser == nullptr) // first launch, check in params to open folders { vector dummy; - launchFileBrowser(dummy); + generic_string emptyStr; + launchFileBrowser(dummy, emptyStr); if (_pFileBrowser != nullptr) { checkMenuItem(IDM_VIEW_FILEBROWSER, true); @@ -736,7 +737,7 @@ void Notepad_plus::command(int id) if (_pFileBrowser == nullptr) // first launch, check in params to open folders { NppParameters& nppParam = NppParameters::getInstance(); - launchFileBrowser(nppParam.getFileBrowserRoots()); + launchFileBrowser(nppParam.getFileBrowserRoots(), nppParam.getFileBrowserSelectedItemPath()); if (_pFileBrowser != nullptr) { checkMenuItem(IDM_VIEW_FILEBROWSER, true); @@ -756,7 +757,8 @@ void Notepad_plus::command(int id) else { vector dummy; - launchFileBrowser(dummy); + generic_string emptyStr; + launchFileBrowser(dummy, emptyStr); checkMenuItem(IDM_VIEW_FILEBROWSER, true); _toolBar.setCheck(IDM_VIEW_FILEBROWSER, true); _pFileBrowser->setClosed(false); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 8bccd2dc0..5c266f2e1 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2208,11 +2208,17 @@ void NppParameters::feedFileListParameters(TiXmlNode *node) } } -void NppParameters::feedProjectPanelsParameters(TiXmlNode *node) +void NppParameters::feedFileBrowserParameters(TiXmlNode *node) { TiXmlNode *fileBrowserRoot = node->FirstChildElement(TEXT("FileBrowser")); if (!fileBrowserRoot) return; + const TCHAR *selectedItemPath = (fileBrowserRoot->ToElement())->Attribute(TEXT("latestSelectedItem")); + if (selectedItemPath) + { + _fileBrowserSelectedItemPath = selectedItemPath; + } + for (TiXmlNode *childNode = fileBrowserRoot->FirstChildElement(TEXT("root")); childNode; childNode = childNode->NextSibling(TEXT("root")) ) @@ -2225,7 +2231,7 @@ void NppParameters::feedProjectPanelsParameters(TiXmlNode *node) } } -void NppParameters::feedFileBrowserParameters(TiXmlNode *node) +void NppParameters::feedProjectPanelsParameters(TiXmlNode *node) { TiXmlNode *projPanelRoot = node->FirstChildElement(TEXT("ProjectPanels")); if (!projPanelRoot) return; diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 3dd281038..8624c08ab 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1546,6 +1546,8 @@ public: }; const std::vector getFileBrowserRoots() const { return _fileBrowserRoot; }; + generic_string getFileBrowserSelectedItemPath() const { return _fileBrowserSelectedItemPath; }; + void setWorkSpaceFilePath(int i, const TCHAR *wsFile); void setWorkingDir(const TCHAR * newPath); @@ -1794,6 +1796,7 @@ private: generic_string _workSpaceFilePathes[3]; std::vector _fileBrowserRoot; + generic_string _fileBrowserSelectedItemPath; Accelerator *_pAccelerator; ScintillaAccelerator * _pScintAccelerator; diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index 97d3b8f55..9912e6bcd 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -383,21 +383,34 @@ void FileBrowser::initPopupMenus() ::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_FILEBROWSER_CMDHERE, cmdHere.c_str()); } -bool FileBrowser::selectCurrentEditingFile() const +bool FileBrowser::selectItemFromPath(const generic_string& itemPath) const { - TCHAR currentDocPath[MAX_PATH] = { '0' }; - ::SendMessage(_hParent, NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast(currentDocPath)); - generic_string rootFolderPath = currentDocPath; + if (itemPath.empty()) + return false; + + size_t itemPathLen = itemPath.size(); for (const auto f : _folderUpdaters) { - if (isRelatedRootFolder(f->_rootFolder._rootPath, rootFolderPath)) + if (isRelatedRootFolder(f->_rootFolder._rootPath, itemPath)) { generic_string rootPath = f->_rootFolder._rootPath; - generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size()); - vector linarPathArray = split(pathSuffix, '\\'); + size_t rootPathLen = rootPath.size(); + if (rootPathLen > itemPathLen) // It should never happen + return false; + vector linarPathArray; + if (rootPathLen == itemPathLen) + { + // Do nothing and use empty linarPathArray + } + else + { + generic_string pathSuffix = itemPath.substr(rootPathLen + 1, itemPathLen - rootPathLen); + linarPathArray = split(pathSuffix, '\\'); + } HTREEITEM foundItem = findInTree(rootPath, nullptr, linarPathArray); + if (foundItem) { _treeView.selectItem(foundItem); @@ -409,6 +422,15 @@ bool FileBrowser::selectCurrentEditingFile() const return false; } +bool FileBrowser::selectCurrentEditingFile() const +{ + TCHAR currentDocPath[MAX_PATH] = { '0' }; + ::SendMessage(_hParent, NPPM_GETFULLCURRENTPATH, MAX_PATH, reinterpret_cast(currentDocPath)); + generic_string currentDocPathStr = currentDocPath; + + return selectItemFromPath(currentDocPathStr); +} + BOOL FileBrowser::setImageList(int root_clean_id, int root_dirty_id, int open_node_id, int closed_node_id, int leaf_id) { HBITMAP hbmp; @@ -1227,7 +1249,11 @@ HTREEITEM FileBrowser::findInTree(const generic_string& rootPath, HTREEITEM node return nullptr; } - if (linarPathArray.size() == 1) + if (linarPathArray.empty()) // nothing to search, return node + { + return node; + } + else if (linarPathArray.size() == 1) { // Search return findChildNodeFromName(node, linarPathArray[0]); diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h index ebc21c6f8..f6f88353e 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.h @@ -164,6 +164,8 @@ public: std::vector getRoots() const; generic_string getSelectedItemPath() const; + bool selectItemFromPath(const generic_string& itemPath) const; + protected: HWND _hToolbarMenu = nullptr; @@ -186,6 +188,7 @@ protected: BrowserNodeType getNodeType(HTREEITEM hItem); void popupMenuCmd(int cmdID); + bool selectCurrentEditingFile() const; virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);