Fix Function list current empty lost issue while Sort/Unsort/Save/Reload

Retains tree state of function tree during Sort/Unsort and Save/Reload actions.

Fix #8819, fix #10280, fix #10294, close #10322
This commit is contained in:
Ashfaaq18 2021-08-03 23:47:50 +05:30 committed by Don Ho
parent 13623669a4
commit 5c2c317352
5 changed files with 26 additions and 25 deletions

View File

@ -1300,7 +1300,7 @@ bool FileBrowser::addToTree(FilesToChange & group, HTREEITEM node)
_treeView.addItem(file.c_str(), node, INDEX_LEAF, reinterpret_cast<LPARAM>(customData)); _treeView.addItem(file.c_str(), node, INDEX_LEAF, reinterpret_cast<LPARAM>(customData));
} }
} }
_treeView.customSorting(node, categorySortFunc, 0); _treeView.customSorting(node, categorySortFunc, 0, false);
return true; return true;
} }
else else
@ -1491,7 +1491,7 @@ bool FileBrowser::renameInTree(const generic_string& rootPath, HTREEITEM node, c
_treeView.renameItem(foundItem, renameTo.c_str()); _treeView.renameItem(foundItem, renameTo.c_str());
SortingData4lParam* compareData = reinterpret_cast<SortingData4lParam*>(_treeView.getItemParam(foundItem)); SortingData4lParam* compareData = reinterpret_cast<SortingData4lParam*>(_treeView.getItemParam(foundItem));
compareData->_label = renameTo; compareData->_label = renameTo;
_treeView.customSorting(_treeView.getParent(foundItem), categorySortFunc, 0); _treeView.customSorting(_treeView.getParent(foundItem), categorySortFunc, 0, false);
return true; return true;
} }

View File

@ -53,7 +53,7 @@ void FunctionListPanel::addEntry(const TCHAR *nodeName, const TCHAR *displayText
itemParent = _treeView.searchSubItemByName(nodeName, root); itemParent = _treeView.searchSubItemByName(nodeName, root);
if (!itemParent) if (!itemParent)
{ {
generic_string* invalidValueStr = new generic_string(TEXT("-1")); generic_string* invalidValueStr = new generic_string(posStr);
posStrs.push_back(invalidValueStr); posStrs.push_back(invalidValueStr);
LPARAM lParamInvalidPosStr = reinterpret_cast<LPARAM>(invalidValueStr); LPARAM lParamInvalidPosStr = reinterpret_cast<LPARAM>(invalidValueStr);
@ -213,7 +213,7 @@ void FunctionListPanel::sortOrUnsort()
if (text2search[0] == '\0') // main view if (text2search[0] == '\0') // main view
{ {
reload(); _pTreeView->customSorting(_pTreeView->getRoot(), categorySortFunc, 0, true);
} }
else // aux view else // aux view
{ {
@ -239,6 +239,18 @@ void FunctionListPanel::sortOrUnsort()
} }
} }
int CALLBACK FunctionListPanel::categorySortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM /*lParamSort*/)
{
generic_string* posString1 = reinterpret_cast<generic_string*>(lParam1);
generic_string* posString2 = reinterpret_cast<generic_string*>(lParam2);
size_t pos1 = generic_atoi(posString1->c_str());
size_t pos2 = generic_atoi(posString2->c_str());
if (pos1 > pos2)
return 1;
else
return -1;
}
bool FunctionListPanel::serialize(const generic_string & outputFilename) bool FunctionListPanel::serialize(const generic_string & outputFilename)
{ {
@ -392,12 +404,12 @@ void FunctionListPanel::reload()
{ {
::SendMessage(_hSearchEdit, WM_SETTEXT, 0, reinterpret_cast<LPARAM>((previousParams->_searchParameters)._text2Find.c_str())); ::SendMessage(_hSearchEdit, WM_SETTEXT, 0, reinterpret_cast<LPARAM>((previousParams->_searchParameters)._text2Find.c_str()));
_treeView.restoreFoldingStateFrom(previousParams->_treeState, root);
bool isSort = (previousParams->_searchParameters)._doSort; bool isSort = (previousParams->_searchParameters)._doSort;
setSort(isSort); setSort(isSort);
if (isSort) if (isSort)
_pTreeView->sort(_pTreeView->getRoot(), true); _pTreeView->sort(_pTreeView->getRoot(), true);
_treeView.restoreFoldingStateFrom(previousParams->_treeState, root);
} }
} }

View File

@ -90,6 +90,7 @@ public:
}; };
// functionalities // functionalities
static int CALLBACK categorySortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM /*lParamSort*/);
void sortOrUnsort(); void sortOrUnsort();
void reload(); void reload();
void markEntry(); void markEntry();

View File

@ -670,23 +670,6 @@ bool TreeView::restoreFoldingStateFrom(const TreeStateNode & treeState2Compare,
if (!treeviewNode) if (!treeviewNode)
return false; return false;
TCHAR textBuffer[MAX_PATH];
TVITEM tvItem;
tvItem.hItem = treeviewNode;
tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH;
tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_STATE;
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
if (treeState2Compare._label != textBuffer)
return false;
if (tvItem.lParam)
{
if (treeState2Compare._extraData != *(reinterpret_cast<generic_string *>(tvItem.lParam)))
return false;
}
if (treeState2Compare._isExpanded) //= (tvItem.state & TVIS_EXPANDED) != 0; if (treeState2Compare._isExpanded) //= (tvItem.state & TVIS_EXPANDED) != 0;
expand(treeviewNode); expand(treeviewNode);
else else
@ -720,7 +703,7 @@ void TreeView::sort(HTREEITEM hTreeItem, bool isRecusive)
} }
void TreeView::customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam) void TreeView::customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam, bool isRecusive)
{ {
TVSORTCB treeViewSortCB; TVSORTCB treeViewSortCB;
treeViewSortCB.hParent = hTreeItem; treeViewSortCB.hParent = hTreeItem;
@ -728,4 +711,9 @@ void TreeView::customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFu
treeViewSortCB.lParam = lParam; treeViewSortCB.lParam = lParam;
::SendMessage(_hSelf, TVM_SORTCHILDRENCB, 0, reinterpret_cast<LPARAM>(&treeViewSortCB)); ::SendMessage(_hSelf, TVM_SORTCHILDRENCB, 0, reinterpret_cast<LPARAM>(&treeViewSortCB));
if (!isRecusive)
return;
for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem))
customSorting(hItem, sortingCallbackFunc, lParam, isRecusive);
} }

View File

@ -115,7 +115,7 @@ public:
bool retrieveFoldingStateTo(TreeStateNode & treeState2Construct, HTREEITEM treeviewNode); bool retrieveFoldingStateTo(TreeStateNode & treeState2Construct, HTREEITEM treeviewNode);
bool searchLeafAndBuildTree(TreeView & tree2Build, const generic_string & text2Search, int index2Search); bool searchLeafAndBuildTree(TreeView & tree2Build, const generic_string & text2Search, int index2Search);
void sort(HTREEITEM hTreeItem, bool isRecusive); void sort(HTREEITEM hTreeItem, bool isRecusive);
void customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam); void customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam, bool isRecursive);
protected: protected:
WNDPROC _defaultProc; WNDPROC _defaultProc;