Refactor group mode switching logic to ensure proper list management
Updated the Group and UpdateGroupCommandHandler classes to clarify the behavior of group mode switching. The transition to dynamic mode now clears the existing item list to prevent old items from interfering with the new rule-based composition. Enhanced documentation and comments to explain the implications of mode changes. Updated tests to reflect the new behavior, ensuring that the group correctly handles item lists during mode transitions. Localization strings were also updated to inform users about the changes in item management during mode switching.
This commit is contained in:
@@ -81,22 +81,24 @@ public class Group
|
||||
/// Вычисленный правилом состав при переходе в статический режим сюда не переносится: домен
|
||||
/// правило не интерпретирует. Материализует его вызывающая сторона до смены режима.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Меняет режим набора. Список позиций при этом **сбрасывается**: в двух режимах он означает
|
||||
/// разное, и переносить его как есть — значит соврать про то, чем группа стала.
|
||||
///
|
||||
/// Прежний состав, оставленный закреплённым, отменял бы саму суть перехода: правило считало бы
|
||||
/// состав заново, но старые позиции оставались бы в нём навсегда, и «по правилу» на деле
|
||||
/// означало бы «по правилу плюс всё, что было». Сузить набор правилом стало бы невозможно.
|
||||
///
|
||||
/// Обратный переход наполняет список вычисленным составом — это делает прикладной слой: правило
|
||||
/// живёт там, домен его не интерпретирует.
|
||||
/// </summary>
|
||||
public void SetMode(GroupMode mode)
|
||||
{
|
||||
if (Mode == mode)
|
||||
return;
|
||||
|
||||
Mode = mode;
|
||||
if (mode == GroupMode.Dynamic)
|
||||
{
|
||||
foreach (var item in _items)
|
||||
item.SetRole(GroupItemRole.Pinned);
|
||||
return;
|
||||
}
|
||||
|
||||
_items.RemoveAll(i => i.Role == GroupItemRole.Excluded);
|
||||
foreach (var item in _items)
|
||||
item.SetRole(GroupItemRole.Member);
|
||||
_items.Clear();
|
||||
}
|
||||
|
||||
/// <summary>Записать пересчитанную статистику.</summary>
|
||||
|
||||
Reference in New Issue
Block a user