diff --git a/Terminal.Gui/Core/Trees/Branch.cs b/Terminal.Gui/Core/Trees/Branch.cs index 2dab4dc98..a6d43cb0b 100644 --- a/Terminal.Gui/Core/Trees/Branch.cs +++ b/Terminal.Gui/Core/Trees/Branch.cs @@ -5,23 +5,23 @@ using System.Linq; namespace Terminal.Gui.Trees { class Branch where T : class { /// - /// True if the branch is expanded to reveal child branches. + /// True if the branch is expanded to reveal child branches /// public bool IsExpanded { get; set; } /// - /// The users object that is being displayed by this branch of the tree. + /// The users object that is being displayed by this branch of the tree /// public T Model { get; private set; } /// - /// The depth of the current branch. Depth of 0 indicates root level branches. + /// The depth of the current branch. Depth of 0 indicates root level branches /// public int Depth { get; private set; } = 0; /// /// The children of the current branch. This is null until the first call to - /// to avoid enumerating the entire underlying hierarchy. + /// to avoid enumerating the entire underlying hierarchy /// public Dictionary> ChildBranches { get; set; } @@ -34,12 +34,12 @@ namespace Terminal.Gui.Trees { /// /// Declares a new branch of in which the users object - /// is presented. + /// is presented /// - /// The UI control in which the branch resides. + /// The UI control in which the branch resides /// Pass null for root level branches, otherwise - /// pass the parent. - /// The user's object that should be displayed. + /// pass the parent + /// The user's object that should be displayed public Branch (TreeView tree, Branch parentBranchIfAny, T model) { this.tree = tree; @@ -53,7 +53,7 @@ namespace Terminal.Gui.Trees { /// - /// Fetch the children of this branch. This method populates . + /// Fetch the children of this branch. This method populates /// public virtual void FetchChildren () { @@ -80,7 +80,7 @@ namespace Terminal.Gui.Trees { } /// - /// Renders the current on the specified line . + /// Renders the current on the specified line /// /// /// @@ -89,9 +89,10 @@ namespace Terminal.Gui.Trees { public virtual void Draw (ConsoleDriver driver, ColorScheme colorScheme, int y, int availableWidth) { // true if the current line of the tree is the selected one and control has focus - bool isSelected = tree.IsSelected (Model); - Attribute textColor = isSelected ? (tree.HasFocus ? colorScheme.HotFocus : colorScheme.HotNormal) : colorScheme.Normal; - Attribute symbolColor = tree.Style.HighlightModelTextOnly ? colorScheme.Normal : textColor; + bool isSelected = tree.IsSelected (Model);// && tree.HasFocus; + Attribute lineColor = isSelected ? (tree.HasFocus ? colorScheme.HotFocus : colorScheme.HotNormal) : colorScheme.Normal ; + + driver.SetAttribute (lineColor); // Everything on line before the expansion run and branch text Rune [] prefix = GetLinePrefix (driver).ToArray (); @@ -103,8 +104,7 @@ namespace Terminal.Gui.Trees { // if we have scrolled to the right then bits of the prefix will have dispeared off the screen int toSkip = tree.ScrollOffsetHorizontal; - driver.SetAttribute (symbolColor); - // Draw the line prefix (all parallel lanes or whitespace and an expand/collapse/leaf symbol) + // Draw the line prefix (all paralell lanes or whitespace and an expand/collapse/leaf symbol) foreach (Rune r in prefix) { if (toSkip > 0) { @@ -117,12 +117,12 @@ namespace Terminal.Gui.Trees { // pick color for expanded symbol if (tree.Style.ColorExpandSymbol || tree.Style.InvertExpandSymbolColors) { - Attribute color = symbolColor; + Attribute color; if (tree.Style.ColorExpandSymbol) { color = isSelected ? tree.ColorScheme.HotFocus : tree.ColorScheme.HotNormal; } else { - color = symbolColor; + color = lineColor; } if (tree.Style.InvertExpandSymbolColors) { @@ -162,14 +162,16 @@ namespace Terminal.Gui.Trees { // default behaviour is for model to use the color scheme // of the tree view - var modelColor = textColor; + var modelColor = lineColor; // if custom color delegate invoke it - if (tree.ColorGetter != null) { - var modelScheme = tree.ColorGetter (Model); + if(tree.ColorGetter != null) + { + var modelScheme = tree.ColorGetter(Model); // if custom color scheme is defined for this Model - if (modelScheme != null) { + if(modelScheme != null) + { // use it modelColor = isSelected ? modelScheme.Focus : modelScheme.Normal; } @@ -177,23 +179,24 @@ namespace Terminal.Gui.Trees { driver.SetAttribute (modelColor); driver.AddStr (lineBody); + driver.SetAttribute (lineColor); if (availableWidth > 0) { - driver.SetAttribute (symbolColor); driver.AddStr (new string (' ', availableWidth)); } + driver.SetAttribute (colorScheme.Normal); } /// /// Gets all characters to render prior to the current branches line. This includes indentation - /// whitespace and any tree branches (if enabled). + /// whitespace and any tree branches (if enabled) /// /// /// private IEnumerable GetLinePrefix (ConsoleDriver driver) { - // If not showing line branches or this is a root object. + // If not showing line branches or this is a root object if (!tree.Style.ShowBranchLines) { for (int i = 0; i < Depth; i++) { yield return new Rune (' '); @@ -221,7 +224,7 @@ namespace Terminal.Gui.Trees { } /// - /// Returns all parents starting with the immediate parent and ending at the root. + /// Returns all parents starting with the immediate parent and ending at the root /// /// private IEnumerable> GetParentBranches () @@ -237,7 +240,7 @@ namespace Terminal.Gui.Trees { /// /// Returns an appropriate symbol for displaying next to the string representation of /// the object to indicate whether it or - /// not (or it is a leaf). + /// not (or it is a leaf) /// /// /// @@ -258,7 +261,7 @@ namespace Terminal.Gui.Trees { /// /// Returns true if the current branch can be expanded according to - /// the or cached children already fetched. + /// the or cached children already fetched /// /// public bool CanExpand () @@ -280,7 +283,7 @@ namespace Terminal.Gui.Trees { } /// - /// Expands the current branch if possible. + /// Expands the current branch if possible /// public void Expand () { @@ -294,7 +297,7 @@ namespace Terminal.Gui.Trees { } /// - /// Marks the branch as collapsed ( false). + /// Marks the branch as collapsed ( false) /// public void Collapse () { @@ -302,10 +305,10 @@ namespace Terminal.Gui.Trees { } /// - /// Refreshes cached knowledge in this branch e.g. what children an object has. + /// Refreshes cached knowledge in this branch e.g. what children an object has /// /// True to also refresh all - /// branches (starting with the root). + /// branches (starting with the root) public void Refresh (bool startAtTop) { // if we must go up and refresh from the top down @@ -348,7 +351,7 @@ namespace Terminal.Gui.Trees { } /// - /// Calls on the current branch and all expanded children. + /// Calls on the current branch and all expanded children /// internal void Rebuild () { @@ -372,7 +375,7 @@ namespace Terminal.Gui.Trees { /// /// Returns true if this branch has parents and it is the last node of it's parents - /// branches (or last root of the tree). + /// branches (or last root of the tree) /// /// private bool IsLast () @@ -386,7 +389,7 @@ namespace Terminal.Gui.Trees { /// /// Returns true if the given x offset on the branch line is the +/- symbol. Returns - /// false if not showing expansion symbols or leaf node etc. + /// false if not showing expansion symbols or leaf node etc /// /// /// @@ -412,7 +415,7 @@ namespace Terminal.Gui.Trees { } /// - /// Expands the current branch and all children branches. + /// Expands the current branch and all children branches /// internal void ExpandAll () { @@ -427,7 +430,7 @@ namespace Terminal.Gui.Trees { /// /// Collapses the current branch and all children branches (even though those branches are - /// no longer visible they retain collapse/expansion state). + /// no longer visible they retain collapse/expansion state) /// internal void CollapseAll () { diff --git a/Terminal.Gui/Core/Trees/TreeStyle.cs b/Terminal.Gui/Core/Trees/TreeStyle.cs index 744ed6974..f6cc30e4c 100644 --- a/Terminal.Gui/Core/Trees/TreeStyle.cs +++ b/Terminal.Gui/Core/Trees/TreeStyle.cs @@ -2,51 +2,46 @@ namespace Terminal.Gui.Trees { /// - /// Defines rendering options that affect how the tree is displayed. + /// Defines rendering options that affect how the tree is displayed /// public class TreeStyle { /// - /// to render vertical lines under expanded nodes to show which node belongs to which - /// parent. to use only whitespace. + /// True to render vertical lines under expanded nodes to show which node belongs to which + /// parent. False to use only whitespace /// /// public bool ShowBranchLines { get; set; } = true; /// - /// Symbol to use for branch nodes that can be expanded to indicate this to the user. - /// Defaults to '+'. Set to null to hide. + /// Symbol to use for branch nodes that can be expanded to indicate this to the user. + /// Defaults to '+'. Set to null to hide /// public Rune? ExpandableSymbol { get; set; } = '+'; /// /// Symbol to use for branch nodes that can be collapsed (are currently expanded). - /// Defaults to '-'. Set to null to hide. + /// Defaults to '-'. Set to null to hide /// public Rune? CollapseableSymbol { get; set; } = '-'; /// - /// Set to to highlight expand/collapse symbols in hot key color. + /// Set to true to highlight expand/collapse symbols in hot key color /// public bool ColorExpandSymbol { get; set; } /// - /// Invert console colours used to render the expand symbol. + /// Invert console colours used to render the expand symbol /// public bool InvertExpandSymbolColors { get; set; } /// - /// to leave the last row of the control free for overwritting (e.g. by a scrollbar) - /// When scrolling will be triggered on the second last row of the control rather than. + /// True to leave the last row of the control free for overwritting (e.g. by a scrollbar) + /// When True scrolling will be triggered on the second last row of the control rather than /// the last. /// /// public bool LeaveLastRow { get; set; } - /// - /// Set to to cause the selected item to be rendered with only the text - /// to be highlighted. If (the default), the entire row will be highlighted. - /// - public bool HighlightModelTextOnly { get; set; } = false; } } \ No newline at end of file diff --git a/Terminal.Gui/Views/TreeView.cs b/Terminal.Gui/Views/TreeView.cs index 7b8942c39..baab64642 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -689,10 +689,8 @@ namespace Terminal.Gui { /// public void ScrollDown () { - if (ScrollOffsetVertical <= ContentHeight - 2) { - ScrollOffsetVertical++; - SetNeedsDisplay (); - } + ScrollOffsetVertical++; + SetNeedsDisplay (); } /// @@ -700,10 +698,8 @@ namespace Terminal.Gui { /// public void ScrollUp () { - if (scrollOffsetVertical > 0) { - ScrollOffsetVertical--; - SetNeedsDisplay (); - } + ScrollOffsetVertical--; + SetNeedsDisplay (); } /// diff --git a/UICatalog/Scenarios/ClassExplorer.cs b/UICatalog/Scenarios/ClassExplorer.cs index adddae538..c7b5798bd 100644 --- a/UICatalog/Scenarios/ClassExplorer.cs +++ b/UICatalog/Scenarios/ClassExplorer.cs @@ -53,8 +53,6 @@ namespace UICatalog.Scenarios { } } - MenuItem highlightModelTextOnly; - public override void Setup () { Win.Title = this.GetName (); @@ -65,20 +63,15 @@ namespace UICatalog.Scenarios { var menu = new MenuBar (new MenuBarItem [] { new MenuBarItem ("_File", new MenuItem [] { new MenuItem ("_Quit", "", () => Quit()), - }), + }) + , new MenuBarItem ("_View", new MenuItem [] { miShowPrivate = new MenuItem ("_Include Private", "", () => ShowPrivate()){ Checked = false, CheckType = MenuItemCheckStyle.Checked }, - new MenuItem ("_Expand All", "", () => treeView.ExpandAll()), - new MenuItem ("_Collapse All", "", () => treeView.CollapseAll()) - }), - new MenuBarItem ("_Style", new MenuItem [] { - highlightModelTextOnly = new MenuItem ("_Highlight Model Text Only", "", () => OnCheckHighlightModelTextOnly()) { - CheckType = MenuItemCheckStyle.Checked - }, - }) + new MenuItem ("_Expand All", "", () => treeView.ExpandAll()), + new MenuItem ("_Collapse All", "", () => treeView.CollapseAll()) }), }); Top.Add (menu); @@ -89,6 +82,7 @@ namespace UICatalog.Scenarios { Height = Dim.Fill (), }; + treeView.AddObjects (AppDomain.CurrentDomain.GetAssemblies ()); treeView.AspectGetter = GetRepresentation; treeView.TreeBuilder = new DelegateTreeBuilder (ChildGetter, CanExpand); @@ -106,13 +100,6 @@ namespace UICatalog.Scenarios { Win.Add (textView); } - private void OnCheckHighlightModelTextOnly () - { - treeView.Style.HighlightModelTextOnly = !treeView.Style.HighlightModelTextOnly; - highlightModelTextOnly.Checked = treeView.Style.HighlightModelTextOnly; - treeView.SetNeedsDisplay (); - } - private void ShowPrivate () { miShowPrivate.Checked = !miShowPrivate.Checked;