internal static Selection SelectAll(EditingContext context, bool local) { if (context == null) { throw new ArgumentNullException("context"); } ModelService requiredService = context.Services.GetRequiredService <ModelService>(); Selection s = context.Items.GetValue <Selection>(); Selection selection = new Selection(); ModelItem primarySelection = s.PrimarySelection; if (local && primarySelection != null) { if (!SelectionImplementation.IsMultiSelection(s) && primarySelection.Content != (ModelProperty)null) { selection = SelectionImplementation.SelectContent(primarySelection); if (selection.PrimarySelection == null && primarySelection.Parent != null) { selection = SelectionImplementation.SelectContent(primarySelection.Parent); } } else if (SelectionImplementation.AreSiblings(s)) { selection = SelectionImplementation.SelectContent(primarySelection.Parent); } } if (selection.PrimarySelection == null) { selection = new Selection(SelectionImplementation.EnumerateContents(requiredService.Root)); } context.Items.SetValue((ContextItem)selection); return(selection); }
private static IEnumerable <ModelItem> EnumerateContents(ModelItem start) { if (SelectionImplementation.IsSelectable(start)) { yield return(start); ModelProperty content = start.Content; if (content != (ModelProperty)null && content.IsSet) { if (content.IsCollection) { foreach (ModelItem start1 in content.Collection) { foreach (ModelItem modelItem in SelectionImplementation.EnumerateContents(start1)) { yield return(modelItem); } } } else { ModelItem value = content.Value; if (value != null) { foreach (ModelItem modelItem in SelectionImplementation.EnumerateContents(value)) { yield return(modelItem); } } } } } }