diff --git a/Terminal.Gui/Core/Trees/Branch.cs b/Terminal.Gui/Core/Trees/Branch.cs index a6d43cb0b1..2dab4dc98f 100644 --- a/Terminal.Gui/Core/Trees/Branch.cs +++ b/Terminal.Gui/Core/Trees/Branch.cs @@ -5,23 +5,23 @@ 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 @@ class Branch where T : class { /// /// 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 @@ public Branch (TreeView tree, Branch parentBranchIfAny, T model) /// - /// 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 @@ public virtual int GetWidth (ConsoleDriver driver) } /// - /// Renders the current on the specified line + /// Renders the current on the specified line . /// /// /// @@ -89,10 +89,9 @@ public virtual int GetWidth (ConsoleDriver driver) 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);// && tree.HasFocus; - Attribute lineColor = isSelected ? (tree.HasFocus ? colorScheme.HotFocus : colorScheme.HotNormal) : colorScheme.Normal ; - - driver.SetAttribute (lineColor); + bool isSelected = tree.IsSelected (Model); + Attribute textColor = isSelected ? (tree.HasFocus ? colorScheme.HotFocus : colorScheme.HotNormal) : colorScheme.Normal; + Attribute symbolColor = tree.Style.HighlightModelTextOnly ? colorScheme.Normal : textColor; // Everything on line before the expansion run and branch text Rune [] prefix = GetLinePrefix (driver).ToArray (); @@ -104,7 +103,8 @@ public virtual void Draw (ConsoleDriver driver, ColorScheme colorScheme, int y, // if we have scrolled to the right then bits of the prefix will have dispeared off the screen int toSkip = tree.ScrollOffsetHorizontal; - // Draw the line prefix (all paralell lanes or whitespace and an expand/collapse/leaf symbol) + driver.SetAttribute (symbolColor); + // Draw the line prefix (all parallel lanes or whitespace and an expand/collapse/leaf symbol) foreach (Rune r in prefix) { if (toSkip > 0) { @@ -117,12 +117,12 @@ public virtual void Draw (ConsoleDriver driver, ColorScheme colorScheme, int y, // pick color for expanded symbol if (tree.Style.ColorExpandSymbol || tree.Style.InvertExpandSymbolColors) { - Attribute color; + Attribute color = symbolColor; if (tree.Style.ColorExpandSymbol) { color = isSelected ? tree.ColorScheme.HotFocus : tree.ColorScheme.HotNormal; } else { - color = lineColor; + color = symbolColor; } if (tree.Style.InvertExpandSymbolColors) { @@ -162,16 +162,14 @@ public virtual void Draw (ConsoleDriver driver, ColorScheme colorScheme, int y, // default behaviour is for model to use the color scheme // of the tree view - var modelColor = lineColor; + var modelColor = textColor; // 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; } @@ -179,24 +177,23 @@ public virtual void Draw (ConsoleDriver driver, ColorScheme colorScheme, int y, 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 (' '); @@ -224,7 +221,7 @@ private IEnumerable GetLinePrefix (ConsoleDriver driver) } /// - /// 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 () @@ -240,7 +237,7 @@ private IEnumerable> GetParentBranches () /// /// 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). /// /// /// @@ -261,7 +258,7 @@ public Rune GetExpandableSymbol (ConsoleDriver driver) /// /// 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 () @@ -283,7 +280,7 @@ public bool CanExpand () } /// - /// Expands the current branch if possible + /// Expands the current branch if possible. /// public void Expand () { @@ -297,7 +294,7 @@ public void Expand () } /// - /// Marks the branch as collapsed ( false) + /// Marks the branch as collapsed ( false). /// public void Collapse () { @@ -305,10 +302,10 @@ public void Collapse () } /// - /// 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 @@ -351,7 +348,7 @@ public void Refresh (bool startAtTop) } /// - /// Calls on the current branch and all expanded children + /// Calls on the current branch and all expanded children. /// internal void Rebuild () { @@ -375,7 +372,7 @@ internal void Rebuild () /// /// 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 () @@ -389,7 +386,7 @@ private bool IsLast () /// /// 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. /// /// /// @@ -415,7 +412,7 @@ internal bool IsHitOnExpandableSymbol (ConsoleDriver driver, int x) } /// - /// Expands the current branch and all children branches + /// Expands the current branch and all children branches. /// internal void ExpandAll () { @@ -430,7 +427,7 @@ internal void ExpandAll () /// /// 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 f6cc30e4cc..744ed6974d 100644 --- a/Terminal.Gui/Core/Trees/TreeStyle.cs +++ b/Terminal.Gui/Core/Trees/TreeStyle.cs @@ -2,46 +2,51 @@ 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 { /// - /// True to render vertical lines under expanded nodes to show which node belongs to which - /// parent. False to use only whitespace + /// to render vertical lines under expanded nodes to show which node belongs to which + /// parent. 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 true to highlight expand/collapse symbols in hot key color + /// Set to 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; } /// - /// 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 + /// 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. /// 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 baab64642f..7b8942c398 100644 --- a/Terminal.Gui/Views/TreeView.cs +++ b/Terminal.Gui/Views/TreeView.cs @@ -689,8 +689,10 @@ public void MovePageDown (bool expandSelection = false) /// public void ScrollDown () { - ScrollOffsetVertical++; - SetNeedsDisplay (); + if (ScrollOffsetVertical <= ContentHeight - 2) { + ScrollOffsetVertical++; + SetNeedsDisplay (); + } } /// @@ -698,8 +700,10 @@ public void ScrollDown () /// public void ScrollUp () { - ScrollOffsetVertical--; - SetNeedsDisplay (); + if (scrollOffsetVertical > 0) { + ScrollOffsetVertical--; + SetNeedsDisplay (); + } } /// diff --git a/UICatalog/Scenarios/ClassExplorer.cs b/UICatalog/Scenarios/ClassExplorer.cs index c7b5798bda..adddae5388 100644 --- a/UICatalog/Scenarios/ClassExplorer.cs +++ b/UICatalog/Scenarios/ClassExplorer.cs @@ -53,6 +53,8 @@ public override string ToString () } } + MenuItem highlightModelTextOnly; + public override void Setup () { Win.Title = this.GetName (); @@ -63,15 +65,20 @@ public override void Setup () 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 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 + }, + }) }); Top.Add (menu); @@ -82,7 +89,6 @@ public override void Setup () Height = Dim.Fill (), }; - treeView.AddObjects (AppDomain.CurrentDomain.GetAssemblies ()); treeView.AspectGetter = GetRepresentation; treeView.TreeBuilder = new DelegateTreeBuilder (ChildGetter, CanExpand); @@ -100,6 +106,13 @@ public override void Setup () 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;