|
@@ -236,6 +236,16 @@ namespace Terminal.Gui {
|
|
|
/// </summary>
|
|
|
public event Action<SelectedCellChangedEventArgs> SelectedCellChanged;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// This event is raised when a cell is activated e.g. by double clicking or pressing <see cref="CellActivationKey"/>
|
|
|
+ /// </summary>
|
|
|
+ public event Action<CellActivatedEventArgs> CellActivated;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// The key which when pressed should trigger <see cref="CellActivated"/> event. Defaults to Enter.
|
|
|
+ /// </summary>
|
|
|
+ public Key CellActivationKey {get;set;} = Key.Enter;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Initialzies a <see cref="TableView"/> class using <see cref="LayoutStyle.Computed"/> layout.
|
|
|
/// </summary>
|
|
@@ -551,6 +561,11 @@ namespace Terminal.Gui {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ if(keyEvent.Key == CellActivationKey && Table != null) {
|
|
|
+ OnCellActivated(new CellActivatedEventArgs(Table,SelectedColumn,SelectedRow));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
switch (keyEvent.Key) {
|
|
|
case Key.CursorLeft:
|
|
|
case Key.CursorLeft | Key.ShiftMask:
|
|
@@ -769,6 +784,14 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Double clicking a cell activates
|
|
|
+ if(me.Flags == MouseFlags.Button1DoubleClicked) {
|
|
|
+ var hit = ScreenToCell(me.OfX,me.OfY);
|
|
|
+ if(hit!= null) {
|
|
|
+ OnCellActivated(new CellActivatedEventArgs(Table,hit.Value.X,hit.Value.Y));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -922,6 +945,15 @@ namespace Terminal.Gui {
|
|
|
{
|
|
|
SelectedCellChanged?.Invoke(args);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Invokes the <see cref="CellActivated"/> event
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="args"></param>
|
|
|
+ protected virtual void OnCellActivated (CellActivatedEventArgs args)
|
|
|
+ {
|
|
|
+ CellActivated?.Invoke(args);
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// Calculates which columns should be rendered given the <paramref name="bounds"/> in which to display and the <see cref="ColumnOffset"/>
|
|
@@ -1117,7 +1149,8 @@ namespace Terminal.Gui {
|
|
|
/// <summary>
|
|
|
/// Describes a selected region of the table
|
|
|
/// </summary>
|
|
|
- public class TableSelection{
|
|
|
+ public class TableSelection
|
|
|
+ {
|
|
|
|
|
|
/// <summary>
|
|
|
/// Corner of the <see cref="Rect"/> where selection began
|
|
@@ -1141,6 +1174,43 @@ namespace Terminal.Gui {
|
|
|
Origin = origin;
|
|
|
Rect = rect;
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Defines the event arguments for <see cref="TableView.CellActivated"/> event
|
|
|
+ /// </summary>
|
|
|
+ public class CellActivatedEventArgs : EventArgs
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// The current table to which the new indexes refer. May be null e.g. if selection change is the result of clearing the table from the view
|
|
|
+ /// </summary>
|
|
|
+ /// <value></value>
|
|
|
+ public DataTable Table {get;}
|
|
|
+
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// The column index of the <see cref="Table"/> cell that is being activated
|
|
|
+ /// </summary>
|
|
|
+ /// <value></value>
|
|
|
+ public int Col {get;}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// The row index of the <see cref="Table"/> cell that is being activated
|
|
|
+ /// </summary>
|
|
|
+ /// <value></value>
|
|
|
+ public int Row {get;}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a new instance of arguments describing a cell being activated in <see cref="TableView"/>
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="t"></param>
|
|
|
+ /// <param name="col"></param>
|
|
|
+ /// <param name="row"></param>
|
|
|
+ public CellActivatedEventArgs(DataTable t, int col, int row)
|
|
|
+ {
|
|
|
+ Table = t;
|
|
|
+ Col = col;
|
|
|
+ Row = row;
|
|
|
+ }
|
|
|
}
|
|
|
}
|