|
@@ -4,6 +4,7 @@ using System.Data;
|
|
|
using Terminal.Gui;
|
|
|
using System.Linq;
|
|
|
using System.Globalization;
|
|
|
+using static Terminal.Gui.TableView;
|
|
|
|
|
|
namespace UICatalog.Scenarios {
|
|
|
|
|
@@ -24,6 +25,7 @@ namespace UICatalog.Scenarios {
|
|
|
private MenuItem miCellLines;
|
|
|
private MenuItem miFullRowSelect;
|
|
|
private MenuItem miExpandLastColumn;
|
|
|
+ private MenuItem miSmoothScrolling;
|
|
|
private MenuItem miAlternatingColors;
|
|
|
private MenuItem miCursor;
|
|
|
|
|
@@ -62,14 +64,23 @@ namespace UICatalog.Scenarios {
|
|
|
miFullRowSelect =new MenuItem ("_FullRowSelect", "", () => ToggleFullRowSelect()){Checked = tableView.FullRowSelect, CheckType = MenuItemCheckStyle.Checked },
|
|
|
miCellLines =new MenuItem ("_CellLines", "", () => ToggleCellLines()){Checked = tableView.Style.ShowVerticalCellLines, CheckType = MenuItemCheckStyle.Checked },
|
|
|
miExpandLastColumn = new MenuItem ("_ExpandLastColumn", "", () => ToggleExpandLastColumn()){Checked = tableView.Style.ExpandLastColumn, CheckType = MenuItemCheckStyle.Checked },
|
|
|
+ miSmoothScrolling = new MenuItem ("_SmoothHorizontalScrolling", "", () => ToggleSmoothScrolling()){Checked = tableView.Style.SmoothHorizontalScrolling, CheckType = MenuItemCheckStyle.Checked },
|
|
|
new MenuItem ("_AllLines", "", () => ToggleAllCellLines()),
|
|
|
new MenuItem ("_NoLines", "", () => ToggleNoCellLines()),
|
|
|
miAlternatingColors = new MenuItem ("Alternating Colors", "", () => ToggleAlternatingColors()){CheckType = MenuItemCheckStyle.Checked},
|
|
|
miCursor = new MenuItem ("Invert Selected Cell First Character", "", () => ToggleInvertSelectedCellFirstCharacter()){Checked = tableView.Style.InvertSelectedCellFirstCharacter,CheckType = MenuItemCheckStyle.Checked},
|
|
|
new MenuItem ("_ClearColumnStyles", "", () => ClearColumnStyles()),
|
|
|
}),
|
|
|
+ new MenuBarItem ("_Column", new MenuItem [] {
|
|
|
+ new MenuItem ("_Set Max Width", "", SetMaxWidth),
|
|
|
+ new MenuItem ("_Set Min Width", "", SetMinWidth),
|
|
|
+ new MenuItem ("_Set MinAcceptableWidth", "",SetMinAcceptableWidth),
|
|
|
+ new MenuItem ("_Set All MinAcceptableWidth=1", "",SetMinAcceptableWidthToOne),
|
|
|
+ }),
|
|
|
});
|
|
|
- Top.Add (menu);
|
|
|
+
|
|
|
+
|
|
|
+ Top.Add (menu);
|
|
|
|
|
|
var statusBar = new StatusBar (new StatusItem [] {
|
|
|
new StatusItem(Key.F2, "~F2~ OpenExample", () => OpenExample(true)),
|
|
@@ -92,7 +103,7 @@ namespace UICatalog.Scenarios {
|
|
|
|
|
|
Win.Add(selectedCellLabel);
|
|
|
|
|
|
- tableView.SelectedCellChanged += (e)=>{selectedCellLabel.Text = $"{tableView.SelectedRow},{tableView.SelectedColumn}";};
|
|
|
+ tableView.SelectedCellChanged += (e) => { selectedCellLabel.Text = $"{tableView.SelectedRow},{tableView.SelectedColumn}"; };
|
|
|
tableView.CellActivated += EditCurrentCell;
|
|
|
tableView.KeyPress += TableViewKeyPress;
|
|
|
|
|
@@ -121,6 +132,85 @@ namespace UICatalog.Scenarios {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private DataColumn GetColumn ()
|
|
|
+ {
|
|
|
+ if (tableView.Table == null)
|
|
|
+ return null;
|
|
|
+
|
|
|
+ if (tableView.SelectedColumn < 0 || tableView.SelectedColumn > tableView.Table.Columns.Count)
|
|
|
+ return null;
|
|
|
+
|
|
|
+ return tableView.Table.Columns [tableView.SelectedColumn];
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetMinAcceptableWidthToOne ()
|
|
|
+ {
|
|
|
+ foreach (DataColumn c in tableView.Table.Columns)
|
|
|
+ {
|
|
|
+ var style = tableView.Style.GetOrCreateColumnStyle (c);
|
|
|
+ style.MinAcceptableWidth = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void SetMinAcceptableWidth ()
|
|
|
+ {
|
|
|
+ var col = GetColumn ();
|
|
|
+ RunColumnWidthDialog (col, "MinAcceptableWidth", (s,v)=>s.MinAcceptableWidth = v,(s)=>s.MinAcceptableWidth);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetMinWidth ()
|
|
|
+ {
|
|
|
+ var col = GetColumn ();
|
|
|
+ RunColumnWidthDialog (col, "MinWidth", (s, v) => s.MinWidth = v, (s) => s.MinWidth);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetMaxWidth ()
|
|
|
+ {
|
|
|
+ var col = GetColumn ();
|
|
|
+ RunColumnWidthDialog (col, "MaxWidth", (s, v) => s.MaxWidth = v, (s) => s.MaxWidth);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RunColumnWidthDialog (DataColumn col, string prompt, Action<ColumnStyle,int> setter,Func<ColumnStyle,int> getter)
|
|
|
+ {
|
|
|
+ var accepted = false;
|
|
|
+ var ok = new Button ("Ok", is_default: true);
|
|
|
+ ok.Clicked += () => { accepted = true; Application.RequestStop (); };
|
|
|
+ var cancel = new Button ("Cancel");
|
|
|
+ cancel.Clicked += () => { Application.RequestStop (); };
|
|
|
+ var d = new Dialog (prompt, 60, 20, ok, cancel);
|
|
|
+
|
|
|
+ var style = tableView.Style.GetOrCreateColumnStyle (col);
|
|
|
+
|
|
|
+ var lbl = new Label () {
|
|
|
+ X = 0,
|
|
|
+ Y = 1,
|
|
|
+ Text = col.ColumnName
|
|
|
+ };
|
|
|
+
|
|
|
+ var tf = new TextField () {
|
|
|
+ Text = getter(style).ToString (),
|
|
|
+ X = 0,
|
|
|
+ Y = 2,
|
|
|
+ Width = Dim.Fill ()
|
|
|
+ };
|
|
|
+
|
|
|
+ d.Add (lbl, tf);
|
|
|
+ tf.SetFocus ();
|
|
|
+
|
|
|
+ Application.Run (d);
|
|
|
+
|
|
|
+ if (accepted) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ setter (style, int.Parse (tf.Text.ToString()));
|
|
|
+ } catch (Exception ex) {
|
|
|
+ MessageBox.ErrorQuery (60, 20, "Failed to set", ex.Message, "Ok");
|
|
|
+ }
|
|
|
+
|
|
|
+ tableView.Update ();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void SetupScrollBar ()
|
|
|
{
|
|
|
var _scrollBar = new ScrollBarView (tableView, true);
|
|
@@ -228,6 +318,14 @@ namespace UICatalog.Scenarios {
|
|
|
|
|
|
tableView.Update();
|
|
|
|
|
|
+ }
|
|
|
+ private void ToggleSmoothScrolling()
|
|
|
+ {
|
|
|
+ miSmoothScrolling.Checked = !miSmoothScrolling.Checked;
|
|
|
+ tableView.Style.SmoothHorizontalScrolling = miSmoothScrolling.Checked;
|
|
|
+
|
|
|
+ tableView.Update ();
|
|
|
+
|
|
|
}
|
|
|
private void ToggleCellLines()
|
|
|
{
|