diff --git a/NEWS.md b/NEWS.md index 063ba764..84d3ed06 100644 --- a/NEWS.md +++ b/NEWS.md @@ -27,6 +27,7 @@ Red Panda C++ Version 2.23 - enhancement: Show code completion suggestion after "typedef" and "const". - fix: GLFW project template. - fix: Inherited class/struct members are not correctly shown in the completion suggestions. + - enhancement: Sort symbols by their declaration pos in the Class Browser, if not sort by alpha order. Red Panda C++ Version 2.22 diff --git a/RedPandaIDE/widgets/classbrowser.cpp b/RedPandaIDE/widgets/classbrowser.cpp index 90df22c3..e069021d 100644 --- a/RedPandaIDE/widgets/classbrowser.cpp +++ b/RedPandaIDE/widgets/classbrowser.cpp @@ -295,6 +295,25 @@ void ClassBrowserModel::addMembers() void ClassBrowserModel::sortNode(ClassBrowserNode *node) { + if (!pSettings->ui().classBrowserSortAlpha()) { + if (mClassBrowserType==ProjectClassBrowserType::CurrentFile) { + std::sort(node->children.begin(),node->children.end(), + [](ClassBrowserNode* node1,ClassBrowserNode* node2) { + return (node1->statement->line < node2->statement->line); + }); + } else { + std::sort(node->children.begin(),node->children.end(), + [](ClassBrowserNode* node1,ClassBrowserNode* node2) { + int comp=QString::compare(node1->statement->fileName, node2->statement->fileName); + if (comp<0) + return true; + else if (comp==0) + return (node1->statement->line < node2->statement->line); + return false; + }); + }; + } + if (pSettings->ui().classBrowserSortAlpha() && pSettings->ui().classBrowserSortType()) { std::sort(node->children.begin(),node->children.end(),