diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs index 338590bce..4acb41dc8 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -312,7 +312,7 @@ namespace Terminal.Gui { selectedObject = value; if(!ReferenceEquals(oldValue,value)) - SelectionChanged?.Invoke(this,new SelectionChangedEventArgs(this,oldValue,value)); + OnSelectionChanged(new SelectionChangedEventArgs(this,oldValue,value)); } } @@ -645,6 +645,9 @@ namespace Terminal.Gui { case Key.PageDown | Key.ShiftMask: AdjustSelection(Bounds.Height,keyEvent.Key.HasFlag(Key.ShiftMask)); break; + case Key.A | Key.CtrlMask: + SelectAll(); + break; case Key.Home: GoToFirst(); break; @@ -1042,6 +1045,37 @@ namespace Terminal.Gui { } } } + + /// + /// Selects all objects in the tree when is enabled otherwise does nothing + /// + public void SelectAll() + { + if(!MultiSelect) + return; + + _multiSelectedRegions.Clear(); + + var map = BuildLineMap(); + + if(map.Length == 0) + return; + + _multiSelectedRegions.Push(new TreeSelection(map[0],map.Length,map)); + SetNeedsDisplay(); + + OnSelectionChanged(new SelectionChangedEventArgs(this,SelectedObject,SelectedObject)); + } + + + /// + /// Raises the SelectionChanged event + /// + /// + protected virtual void OnSelectionChanged (SelectionChangedEventArgs e) + { + SelectionChanged?.Invoke(this,e); + } } class TreeSelection where T : class { diff --git a/UICatalog/Scenarios/ClassExplorer.cs b/UICatalog/Scenarios/ClassExplorer.cs index 44dc156ca..a00e559a2 100644 --- a/UICatalog/Scenarios/ClassExplorer.cs +++ b/UICatalog/Scenarios/ClassExplorer.cs @@ -117,62 +117,70 @@ namespace UICatalog.Scenarios { private void TreeView_SelectionChanged (object sender, SelectionChangedEventArgs e) { var val = e.NewValue; + var all = treeView.GetAllSelectedObjects().ToArray(); if(val == null || val is ShowForType) return; try { - StringBuilder sb = new StringBuilder(); + if(all.Length > 1){ - // tell the user about the currently selected tree node - sb.AppendLine(e.NewValue.GetType().Name); + textView.Text = all.Length + " Objects"; + } + else + { + StringBuilder sb = new StringBuilder(); + + // tell the user about the currently selected tree node + sb.AppendLine(e.NewValue.GetType().Name); + + if(val is Assembly ass) { + sb.AppendLine($"Location:{ass.Location}"); + sb.AppendLine($"FullName:{ass.FullName}"); + } + + if(val is PropertyInfo p) { + sb.AppendLine($"Name:{p.Name}"); + sb.AppendLine($"Type:{p.PropertyType}"); + sb.AppendLine($"CanWrite:{p.CanWrite}"); + sb.AppendLine($"CanRead:{p.CanRead}"); + } - if(val is Assembly ass) { - sb.AppendLine($"Location:{ass.Location}"); - sb.AppendLine($"FullName:{ass.FullName}"); - } - - if(val is PropertyInfo p) { - sb.AppendLine($"Name:{p.Name}"); - sb.AppendLine($"Type:{p.PropertyType}"); - sb.AppendLine($"CanWrite:{p.CanWrite}"); - sb.AppendLine($"CanRead:{p.CanRead}"); - } - - if(val is FieldInfo f) { - sb.AppendLine($"Name:{f.Name}"); - sb.AppendLine($"Type:{f.FieldType}"); - } + if(val is FieldInfo f) { + sb.AppendLine($"Name:{f.Name}"); + sb.AppendLine($"Type:{f.FieldType}"); + } + + if(val is EventInfo ev) { + sb.AppendLine($"Name:{ev.Name}"); + sb.AppendLine($"Parameters:"); + foreach(var parameter in ev.EventHandlerType.GetMethod("Invoke").GetParameters()) { + sb.AppendLine($" {parameter.ParameterType} {parameter.Name}"); + } + } - if(val is EventInfo ev) { - sb.AppendLine($"Name:{ev.Name}"); - sb.AppendLine($"Parameters:"); - foreach(var parameter in ev.EventHandlerType.GetMethod("Invoke").GetParameters()) { - sb.AppendLine($" {parameter.ParameterType} {parameter.Name}"); + if(val is MethodInfo method) { + sb.AppendLine($"Name:{method.Name}"); + sb.AppendLine($"IsPublic:{method.IsPublic}"); + sb.AppendLine($"IsStatic:{method.IsStatic}"); + sb.AppendLine($"Parameters:{(method.GetParameters().Any() ? "":"None")}"); + foreach(var parameter in method.GetParameters()) { + sb.AppendLine($" {parameter.ParameterType} {parameter.Name}"); + } } - } - - if(val is MethodInfo method) { - sb.AppendLine($"Name:{method.Name}"); - sb.AppendLine($"IsPublic:{method.IsPublic}"); - sb.AppendLine($"IsStatic:{method.IsStatic}"); - sb.AppendLine($"Parameters:{(method.GetParameters().Any() ? "":"None")}"); - foreach(var parameter in method.GetParameters()) { - sb.AppendLine($" {parameter.ParameterType} {parameter.Name}"); + + + if(val is ConstructorInfo ctor) { + sb.AppendLine($"Name:{ctor.Name}"); + sb.AppendLine($"Parameters:{(ctor.GetParameters().Any() ? "":"None")}"); + foreach(var parameter in ctor.GetParameters()) { + sb.AppendLine($" {parameter.ParameterType} {parameter.Name}"); + } } - } - - - if(val is ConstructorInfo ctor) { - sb.AppendLine($"Name:{ctor.Name}"); - sb.AppendLine($"Parameters:{(ctor.GetParameters().Any() ? "":"None")}"); - foreach(var parameter in ctor.GetParameters()) { - sb.AppendLine($" {parameter.ParameterType} {parameter.Name}"); - } - } - - textView.Text = sb.ToString().Replace("\r\n","\n"); + textView.Text = sb.ToString().Replace("\r\n","\n"); + } + } catch (Exception ex) { textView.Text = ex.Message;