From aae9237fdaf101f37e001063b786bfff4ee0f2e7 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sat, 26 Sep 2020 16:48:55 -0700 Subject: [PATCH] fixed formatting and added tests in scenario --- Terminal.Gui/Views/ListView.cs | 34 +++++++++++++-------------- UICatalog/Scenarios/ListsAndCombos.cs | 18 ++++++++++++++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Terminal.Gui/Views/ListView.cs b/Terminal.Gui/Views/ListView.cs index d268cbd19..79ad7cc1b 100644 --- a/Terminal.Gui/Views/ListView.cs +++ b/Terminal.Gui/Views/ListView.cs @@ -448,18 +448,18 @@ namespace Terminal.Gui { /// public virtual bool MoveDown () { - if (source.Count == 0){ + if (source.Count == 0) { // Do we set lastSelectedItem to zero here? - return false; //Nothing for us to move to - } - if (selected >= source.Count) { + return false; //Nothing for us to move to + } + if (selected >= source.Count) { // If for some reason we are currently outside of the // valid values range, we should select the bottommost valid value. // This can occur if the backing data source changes. - selected = source.Count - 1; + selected = source.Count - 1; OnSelectedChanged (); SetNeedsDisplay (); - } else if (selected + 1 < source.Count) { //can move by down by one. + } else if (selected + 1 < source.Count) { //can move by down by one. selected++; if (selected >= top + Frame.Height) @@ -480,22 +480,22 @@ namespace Terminal.Gui { /// public virtual bool MoveUp () { - if (source.Count == 0){ + if (source.Count == 0) { // Do we set lastSelectedItem to zero here? - return false; //Nothing for us to move to - } - if (selected >= source.Count) { + return false; //Nothing for us to move to + } + if (selected >= source.Count) { // If for some reason we are currently outside of the // valid values range, we should select the bottommost valid value. // This can occur if the backing data source changes. - selected = source.Count - 1; + selected = source.Count - 1; OnSelectedChanged (); SetNeedsDisplay (); - } else if (selected > 0) { + } else if (selected > 0) { selected--; if (selected > Source.Count) { - selected = Source.Count - 1; - } + selected = Source.Count - 1; + } if (selected < top) top = selected; OnSelectedChanged (); @@ -560,8 +560,8 @@ namespace Terminal.Gui { /// public virtual bool OnOpenSelectedItem () { - if (source.Count <= selected ||selected < 0) return false; - var value = source.ToList () [selected]; + if (source.Count <= selected || selected < 0) return false; + var value = source.ToList () [selected]; OpenSelectedItem?.Invoke (new ListViewItemEventArgs (selected, value)); return true; @@ -599,7 +599,7 @@ namespace Terminal.Gui { } /// - public override bool MouseEvent(MouseEvent me) + public override bool MouseEvent (MouseEvent me) { if (!me.Flags.HasFlag (MouseFlags.Button1Clicked) && !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked) && me.Flags != MouseFlags.WheeledDown && me.Flags != MouseFlags.WheeledUp) diff --git a/UICatalog/Scenarios/ListsAndCombos.cs b/UICatalog/Scenarios/ListsAndCombos.cs index 7d44e8a89..910d3496d 100644 --- a/UICatalog/Scenarios/ListsAndCombos.cs +++ b/UICatalog/Scenarios/ListsAndCombos.cs @@ -56,6 +56,24 @@ namespace UICatalog.Scenarios { comboBox.SelectedItemChanged += (ListViewItemEventArgs text) => lbComboBox.Text = items[comboBox.SelectedItem]; Win.Add (lbComboBox, comboBox); + + var btnMoveUp = new Button ("Move _Up") { + X = 1, + Y = Pos.Bottom(lbListView), + }; + btnMoveUp.Clicked += () => { + listview.MoveUp (); + }; + + var btnMoveDown = new Button ("Move _Down") { + X = Pos.Right (btnMoveUp) + 1, + Y = Pos.Bottom (lbListView), + }; + btnMoveDown.Clicked += () => { + listview.MoveDown (); + }; + + Win.Add (btnMoveUp, btnMoveDown); } } }