From 585cc27b1f46dcdb5f4adf4d5be387f1b22cf06e Mon Sep 17 00:00:00 2001 From: Don HO Date: Thu, 26 Mar 2020 14:54:04 +0100 Subject: [PATCH] Make TreeView sorting unrecursivable And update coding style. --- .../WinControls/FileBrowser/fileBrowser.cpp | 29 ++++++++++--------- .../FunctionList/functionListPanel.cpp | 6 ++-- .../src/WinControls/ProjectPanel/TreeView.cpp | 12 ++++---- .../src/WinControls/ProjectPanel/TreeView.h | 2 +- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index e309c266..2e72cb72 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -262,10 +262,11 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP generic_string addedFilePath = file2Change[0].substr(0, sepPos + 1); addedFilePath += pathSuffix; bool isAdded = addInTree(rootPath, addedFilePath, nullptr, linarPathArray); - if (not isAdded) + if (!isAdded) { //MessageBox(NULL, addedFilePath.c_str(), TEXT("file/folder is not added"), MB_OK); } + break; } @@ -287,7 +288,7 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP // search recursively and modify the tree structure bool isRemoved = deleteFromTree(rootPath, nullptr, linarPathArray); - if (not isRemoved) + if (!isRemoved) { //MessageBox(NULL, file2Change[0].c_str(), TEXT("file/folder is not removed"), MB_OK); } @@ -318,7 +319,7 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP vector linarPathArray2 = split(pathSuffix2, '\\'); bool isRenamed = renameInTree(rootPath, nullptr, linarPathArray, linarPathArray2[linarPathArray2.size() - 1]); - if (not isRenamed) + if (!isRenamed) { //MessageBox(NULL, file2Change[0].c_str(), TEXT("file/folder is not removed"), MB_OK); } @@ -464,7 +465,7 @@ void FileBrowser::destroyMenus() generic_string FileBrowser::getNodePath(HTREEITEM node) const { - if (not node) return TEXT(""); + if (!node) return TEXT(""); vector fullPathArray; generic_string fullPath; @@ -760,7 +761,7 @@ void FileBrowser::popupMenuCmd(int cmdID) // case IDM_FILEBROWSER_REMOVEROOTFOLDER: { - if (not selectedNode) return; + if (!selectedNode) return; generic_string *rootPath = (generic_string *)_treeView.getItemParam(selectedNode); if (_treeView.getParent(selectedNode) != nullptr || rootPath == nullptr) @@ -782,7 +783,7 @@ void FileBrowser::popupMenuCmd(int cmdID) case IDM_FILEBROWSER_EXPLORERHERE: { - if (not selectedNode) return; + if (!selectedNode) return; generic_string path = getNodePath(selectedNode); if (::PathFileExists(path.c_str())) @@ -800,7 +801,7 @@ void FileBrowser::popupMenuCmd(int cmdID) case IDM_FILEBROWSER_CMDHERE: { - if (not selectedNode) return; + if (!selectedNode) return; if (getNodeType(selectedNode) == browserNodeType_file) selectedNode = _treeView.getParent(selectedNode); @@ -816,7 +817,7 @@ void FileBrowser::popupMenuCmd(int cmdID) case IDM_FILEBROWSER_COPYPATH: { - if (not selectedNode) return; + if (!selectedNode) return; generic_string path = getNodePath(selectedNode); str2Clipboard(path, _hParent); } @@ -824,7 +825,7 @@ void FileBrowser::popupMenuCmd(int cmdID) case IDM_FILEBROWSER_COPYFILENAME: { - if (not selectedNode) return; + if (!selectedNode) return; generic_string fileName = getNodeName(selectedNode); str2Clipboard(fileName, _hParent); } @@ -832,7 +833,7 @@ void FileBrowser::popupMenuCmd(int cmdID) case IDM_FILEBROWSER_FINDINFILES: { - if (not selectedNode) return; + if (!selectedNode) return; generic_string path = getNodePath(selectedNode); ::SendMessage(_hParent, NPPM_LAUNCHFINDINFILESDLG, reinterpret_cast(path.c_str()), 0); } @@ -1149,7 +1150,7 @@ bool FileBrowser::addInTree(const generic_string& rootPath, const generic_string if (linarPathArray.size() == 1) { // Of course item to add should be exist on the disk - if (not::PathFileExists(addItemFullPath.c_str())) + if (!::PathFileExists(addItemFullPath.c_str())) return false; // Search : if no found, add @@ -1166,6 +1167,7 @@ bool FileBrowser::addInTree(const generic_string& rootPath, const generic_string { _treeView.addItem(linarPathArray[0].c_str(), node, INDEX_LEAF); } + return true; } else @@ -1251,7 +1253,8 @@ bool FileBrowser::renameInTree(const generic_string& rootPath, HTREEITEM node, c // found it, rename it _treeView.renameItem(foundItem, renameTo.c_str()); - return true; + + return true; } bool FolderInfo::addToStructure(generic_string & fullpath, std::vector linarPathArray) @@ -1476,7 +1479,7 @@ DWORD WINAPI FolderUpdater::watching(void *params) break; case FILE_ACTION_RENAMED_NEW_NAME: - if (not oldName.empty()) + if (!oldName.empty()) { file2Change.push_back(oldName); file2Change.push_back(wstrFilename); diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index 40a42cf8..32ea4781 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -198,7 +198,7 @@ void FunctionListPanel::sortOrUnsort() { bool doSort = shouldSort(); if (doSort) - _pTreeView->sort(_pTreeView->getRoot()); + _pTreeView->sort(_pTreeView->getRoot(), true); else { TCHAR text2search[MAX_PATH] ; @@ -369,7 +369,7 @@ void FunctionListPanel::reload() bool isSort = (previousParams->_searchParameters)._doSort; setSort(isSort); if (isSort) - _pTreeView->sort(_pTreeView->getRoot()); + _pTreeView->sort(_pTreeView->getRoot(), true); } } @@ -627,7 +627,7 @@ void FunctionListPanel::searchFuncAndSwitchView() } if (doSort) - _pTreeView->sort(_pTreeView->getRoot()); + _pTreeView->sort(_pTreeView->getRoot(), true); } static WNDPROC oldFunclstToolbarProc = NULL; diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp index a89b19f5..dfb343af 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp @@ -103,7 +103,7 @@ bool TreeView::setItemParam(HTREEITEM Item2Set, const TCHAR *paramStr) LPARAM TreeView::getItemParam(HTREEITEM Item2Get) const { - if (not Item2Get) + if (!Item2Get) return false; //TCHAR textBuffer[MAX_PATH]; TVITEM tvItem; @@ -117,7 +117,7 @@ LPARAM TreeView::getItemParam(HTREEITEM Item2Get) const generic_string TreeView::getItemDisplayName(HTREEITEM Item2Set) const { - if (not Item2Set) + if (!Item2Set) return TEXT(""); TCHAR textBuffer[MAX_PATH]; TVITEM tvItem; @@ -131,7 +131,7 @@ generic_string TreeView::getItemDisplayName(HTREEITEM Item2Set) const bool TreeView::renameItem(HTREEITEM Item2Set, const TCHAR *newName) { - if (not Item2Set || not newName) + if (!Item2Set || !newName) return false; TVITEM tvItem; @@ -712,10 +712,12 @@ bool TreeView::restoreFoldingStateFrom(const TreeStateNode & treeState2Compare, return isOk; } -void TreeView::sort(HTREEITEM hTreeItem) +void TreeView::sort(HTREEITEM hTreeItem, bool isRecusive) { ::SendMessage(_hSelf, TVM_SORTCHILDREN, TRUE, reinterpret_cast(hTreeItem)); + if (!isRecusive) + return; for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem)) - sort(hItem); + sort(hItem, isRecusive); } diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h index e4be4a4e..e352a448 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h @@ -125,7 +125,7 @@ public: bool restoreFoldingStateFrom(const TreeStateNode & treeState2Compare, HTREEITEM treeviewNode); bool retrieveFoldingStateTo(TreeStateNode & treeState2Construct, HTREEITEM treeviewNode); bool searchLeafAndBuildTree(TreeView & tree2Build, const generic_string & text2Search, int index2Search); - void sort(HTREEITEM hTreeItem); + void sort(HTREEITEM hTreeItem, bool isRecusive); protected: WNDPROC _defaultProc;