@@ -112,6 +112,10 @@ class RpcHandler : public RpcMethods {
112112 ContextItem m_globalContext;
113113 bool m_packsLoaded = false ;
114114 bool m_solutionLoaded = false ;
115+ bool m_bUseAllPacks = false ;
116+
117+ void StoreSelectedComponents (RteTarget* rteTarget, map<RteComponent*, int >& selectedComponents);
118+ void UpdateFilter (const string& context, RteTarget* rteTarget, bool bAll); // returns true if changed
115119 const ContextItem& GetContext (const string& context) const ;
116120 RteTarget* GetActiveTarget (const string& context) const ;
117121 RteComponentAggregate* GetComponentAggregate (const string& context, const string& id) const ;
@@ -276,11 +280,8 @@ RpcArgs::PacksInfo RpcHandler::GetPacksInfo(const string& context) {
276280 return packsInfo;
277281}
278282
279- RpcArgs::CtRoot RpcHandler::GetComponentsTree (const string& context, const bool & all) {
280- RpcArgs::CtRoot ctRoot;
281- RteTarget* rteTarget = GetActiveTarget (context);
282- // store selected components, not aggregates: they will be destroyed
283- map<RteComponent*, int > selectedComponents;
283+ void RpcHandler::StoreSelectedComponents (RteTarget* rteTarget, map<RteComponent*, int >& selectedComponents)
284+ {
284285 auto & selectedAggregates = rteTarget->CollectSelectedComponentAggregates ();
285286 for (auto [aggregate, count] : selectedAggregates) {
286287 RteComponent* c = aggregate->GetComponent ();
@@ -289,6 +290,17 @@ RpcArgs::CtRoot RpcHandler::GetComponentsTree(const string& context, const bool&
289290 selectedComponents[c] = count;
290291 }
291292 }
293+ }
294+
295+ void RpcHandler::UpdateFilter (const string& context, RteTarget* rteTarget, bool all) {
296+ if (m_bUseAllPacks == all) {
297+ return ;
298+ }
299+ m_bUseAllPacks = all;
300+ // store selected components, not aggregates: they will be destroyed
301+ map<RteComponent*, int > selectedComponents;
302+ StoreSelectedComponents (rteTarget, selectedComponents);
303+
292304 RtePackageFilter packFilter;
293305 if (!all) {
294306 // construct and apply filter
@@ -300,7 +312,13 @@ RpcArgs::CtRoot RpcHandler::GetComponentsTree(const string& context, const bool&
300312 packIds.insert (id);
301313 }
302314 }
315+ // add new packs from current selection otherwise we will loose the selection
316+ for (auto [c, _count] : selectedComponents) {
317+ auto id = c->GetPackageID ();
318+ packIds.insert (id);
319+ }
303320 packFilter.SetSelectedPackages (packIds);
321+ packFilter.SetUseAllPacks (false );
304322 }
305323 // only update filter if differs from current state
306324 if (!packFilter.IsEqual (rteTarget->GetPackageFilter ())) {
@@ -313,8 +331,14 @@ RpcArgs::CtRoot RpcHandler::GetComponentsTree(const string& context, const bool&
313331 }
314332 rteTarget->EvaluateComponentDependencies ();
315333 }
334+ }
335+
336+ RpcArgs::CtRoot RpcHandler::GetComponentsTree (const string& context, const bool & all) {
337+ RteTarget* rteTarget = GetActiveTarget (context);
338+ UpdateFilter (context, rteTarget, all);
316339
317340 RpcDataCollector dc (rteTarget);
341+ RpcArgs::CtRoot ctRoot;
318342 dc.CollectCtClasses (ctRoot);
319343 return ctRoot;
320344}
0 commit comments