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