Restore Folder as Workspace's latest selected item of last session on start up
Fix #8353
This commit is contained in:
parent
f3fce2de4a
commit
a2264e5b36
|
@ -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<generic_string> & folders, bool fromScratch)
|
||||
void Notepad_plus::launchFileBrowser(const vector<generic_string> & folders, const generic_string& selectedItemPath, bool fromScratch)
|
||||
{
|
||||
if (!_pFileBrowser)
|
||||
{
|
||||
|
@ -6042,6 +6043,7 @@ void Notepad_plus::launchFileBrowser(const vector<generic_string> & folders, boo
|
|||
}
|
||||
|
||||
_pFileBrowser->display();
|
||||
_pFileBrowser->selectItemFromPath(selectedItemPath);
|
||||
|
||||
checkMenuItem(IDM_VIEW_FILEBROWSER, true);
|
||||
_toolBar.setCheck(IDM_VIEW_FILEBROWSER, true);
|
||||
|
|
|
@ -607,7 +607,7 @@ private:
|
|||
void launchProjectPanel(int cmdID, ProjectPanel ** pProjPanel, int panelID);
|
||||
void launchDocMap();
|
||||
void launchFunctionList();
|
||||
void launchFileBrowser(const std::vector<generic_string> & folders, bool fromScratch = false);
|
||||
void launchFileBrowser(const std::vector<generic_string> & folders, const generic_string& selectedItemPath, bool fromScratch = false);
|
||||
void showAllQuotes() const;
|
||||
static DWORD WINAPI threadTextPlayer(void *text2display);
|
||||
static DWORD WINAPI threadTextTroller(void *params);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -131,7 +131,8 @@ void Notepad_plus::command(int id)
|
|||
if (_pFileBrowser == nullptr) // first launch, check in params to open folders
|
||||
{
|
||||
vector<generic_string> 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<generic_string> dummy;
|
||||
launchFileBrowser(dummy);
|
||||
generic_string emptyStr;
|
||||
launchFileBrowser(dummy, emptyStr);
|
||||
checkMenuItem(IDM_VIEW_FILEBROWSER, true);
|
||||
_toolBar.setCheck(IDM_VIEW_FILEBROWSER, true);
|
||||
_pFileBrowser->setClosed(false);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1546,6 +1546,8 @@ public:
|
|||
};
|
||||
|
||||
const std::vector<generic_string> 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<generic_string> _fileBrowserRoot;
|
||||
generic_string _fileBrowserSelectedItemPath;
|
||||
|
||||
Accelerator *_pAccelerator;
|
||||
ScintillaAccelerator * _pScintAccelerator;
|
||||
|
|
|
@ -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<LPARAM>(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<generic_string> linarPathArray = split(pathSuffix, '\\');
|
||||
size_t rootPathLen = rootPath.size();
|
||||
if (rootPathLen > itemPathLen) // It should never happen
|
||||
return false;
|
||||
|
||||
vector<generic_string> 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<LPARAM>(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]);
|
||||
|
|
|
@ -164,6 +164,8 @@ public:
|
|||
std::vector<generic_string> 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);
|
||||
|
|
Loading…
Reference in New Issue