Skip to content

Commit

Permalink
Table : Automatically select and finalize item when only one item is …
Browse files Browse the repository at this point in the history
…in the list . Default false.
  • Loading branch information
Fernando Cerqueira committed Sep 29, 2023
1 parent 1605ec9 commit 21fb158
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Samples/TableBasicSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ static void Main()


PromptPlus.DoubleDash("Control:Table - Autofill UserInteraction with many columns and RowNavigation(Default)");
var newid = -1;
PromptPlus.Table<MyTableManyCols>("Your Prompt", "Descripion Table")
.Interaction<object>(new Array[5], (ctrl, _) =>
{
ctrl.AddItem(new MyTableManyCols() { MyText = "x" });
newid++;
ctrl.AddItem(new MyTableManyCols() { Id = newid, MyText = "x" });
})
.AutoFill()
.FilterByColumns(FilterMode.Contains)
.AddFormatType<DateTime>(FmtDate)
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
Expand Down
2 changes: 1 addition & 1 deletion Src/Controls/SelectColletion/IControlSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public interface IControlSelect<T> : IPromptControls<T>
IControlSelect<T> EqualItems(Func<T, T, bool> comparer);

/// <summary>
/// Automatically select item when only one item is in the list . Default false.
/// Automatically select and finalize item when only one item is in the list . Default false.
/// </summary>
/// <param name="value">Automatically select</param>
/// <returns><see cref="IControlSelect{T}"/></returns>
Expand Down
7 changes: 7 additions & 0 deletions Src/Controls/Table/IControlTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,12 @@ public interface IControlTable<T> : IPromptControls<ResultTable<T>> where T : cl
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> ColumnsNavigation(bool value = true);

/// <summary>
/// Automatically select and finalize item when only one item is in the list . Default false.
/// </summary>
/// <param name="value">Automatically select</param>
/// <returns><see cref="IControlTable{T}"/></returns>
IControlTable<T> AutoSelect(bool value = true);

}
}
10 changes: 10 additions & 0 deletions Src/Controls/Table/TableControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ public override ResultPrompt<ResultTable<T>> TryResult(CancellationToken cancell
{
_localpaginator.UpdateFilter(_filterBuffer.ToString());
isvalidkey = true;
if (_localpaginator.Count == 1 && !_localpaginator.IsUnSelected && _options.AutoSelect)
{
endinput = true;
}
}
else
{
Expand Down Expand Up @@ -649,6 +653,12 @@ public override ResultPrompt<ResultTable<T>> TryResult(CancellationToken cancell

#region IControlTable

public IControlTable<T> AutoSelect(bool value = true)
{
_options.AutoSelect = value;
return this;
}

public IControlTable<T> AutoFill(params ushort?[] minmaxwidth)
{
if (_options.Columns.Count > 0)
Expand Down
2 changes: 2 additions & 0 deletions Src/Controls/Table/TableOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal TableOptions(StyleSchema styleSchema, ConfigControls config, IConsoleCo
SelectedContentStyle = styleSchema.Selected();
}

public bool AutoSelect { get; set; }

public bool IsOrderDescending { get; set; }

public Func<T, object> OrderBy { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion docs/apis/pplus.controls.icontrolselect-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Append group text on description

### <a id="methods-autoselect"/>**AutoSelect(Boolean)**

Automatically select item when only one item is in the list . Default false.
Automatically select and finalize item when only one item is in the list . Default false.

```csharp
IControlSelect<T> AutoSelect(bool value)
Expand Down
17 changes: 17 additions & 0 deletions docs/apis/pplus.controls.icontroltable-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ List (cardinality) of columns that will be affected.

[IControlTable&lt;T&gt;](./pplus.controls.icontroltable-1.md)

### <a id="methods-autoselect"/>**AutoSelect(Boolean)**

Automatically select and finalize item when only one item is in the list . Default false.

```csharp
IControlTable<T> AutoSelect(bool value)
```

#### Parameters

`value` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
Automatically select

#### Returns

[IControlTable&lt;T&gt;](./pplus.controls.icontroltable-1.md)

### <a id="methods-changedescription"/>**ChangeDescription(Func&lt;T, Int32, Int32, String&gt;)**

Dynamically change the description using a user role
Expand Down

0 comments on commit 21fb158

Please sign in to comment.