From 094cf981ab62531987195d3e2d88e31229b1d29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=BCkki=20D=C3=A1niel?= Date: Sat, 30 Sep 2023 11:04:48 +0200 Subject: [PATCH] Workspace and root files are now ordered by name. --- service/project/src/projectservice.cpp | 2 ++ .../include/workspaceservice/workspaceservice.h | 5 +++++ service/workspace/src/workspaceservice.cpp | 13 +++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/service/project/src/projectservice.cpp b/service/project/src/projectservice.cpp index 1a57a841a..787fcb48a 100644 --- a/service/project/src/projectservice.cpp +++ b/service/project/src/projectservice.cpp @@ -124,6 +124,8 @@ void ProjectServiceHandler::getRootFiles(std::vector& return_) return_.push_back(makeFileInfo(f)); } }); + + std::sort(return_.begin(), return_.end(), fileInfoOrder); } void ProjectServiceHandler::getChildFiles( diff --git a/service/workspace/include/workspaceservice/workspaceservice.h b/service/workspace/include/workspaceservice/workspaceservice.h index dea0a851a..8926eac2f 100644 --- a/service/workspace/include/workspaceservice/workspaceservice.h +++ b/service/workspace/include/workspaceservice/workspaceservice.h @@ -18,6 +18,11 @@ class WorkspaceServiceHandler : virtual public WorkspaceServiceIf void getWorkspaces(std::vector& _return) override; private: + /** + * This function defines an ordering between WorkspaceInfo objects by name. + */ + static bool workspaceInfoOrder(const WorkspaceInfo& left, const WorkspaceInfo& right); + std::string _workspace; }; diff --git a/service/workspace/src/workspaceservice.cpp b/service/workspace/src/workspaceservice.cpp index bb1153b44..1a88caa64 100644 --- a/service/workspace/src/workspaceservice.cpp +++ b/service/workspace/src/workspaceservice.cpp @@ -13,7 +13,7 @@ WorkspaceServiceHandler::WorkspaceServiceHandler(const std::string& workspace_) { } -void WorkspaceServiceHandler::getWorkspaces(std::vector& _return) +void WorkspaceServiceHandler::getWorkspaces(std::vector& return_) { namespace fs = boost::filesystem; @@ -35,8 +35,17 @@ void WorkspaceServiceHandler::getWorkspaces(std::vector& _return) info.id = filename; info.description = filename; - _return.push_back(std::move(info)); + return_.push_back(std::move(info)); } + + std::sort(return_.begin(), return_.end(), workspaceInfoOrder); +} + +bool WorkspaceServiceHandler::workspaceInfoOrder( + const WorkspaceInfo& left_, + const WorkspaceInfo& right_) +{ + return left_.id < right_.id; } } // workspace