mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
StatusBar conversion progress.
Fixed CSvEditor
This commit is contained in:
@@ -12,7 +12,10 @@ namespace Terminal.Gui;
|
||||
public class Bar : View
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public Bar ()
|
||||
public Bar () : this ([]) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Bar (IEnumerable<Shortcut> shortcuts)
|
||||
{
|
||||
CanFocus = true;
|
||||
|
||||
@@ -23,12 +26,16 @@ public class Bar : View
|
||||
|
||||
Initialized += Bar_Initialized;
|
||||
|
||||
foreach (Shortcut shortcut in shortcuts)
|
||||
{
|
||||
Add (shortcut);
|
||||
}
|
||||
}
|
||||
|
||||
private void Bar_Initialized (object sender, EventArgs e)
|
||||
{
|
||||
ColorScheme = Colors.ColorSchemes ["Menu"];
|
||||
AdjustSubviewBorders();
|
||||
AdjustSubviewBorders ();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -44,7 +51,10 @@ public class Bar : View
|
||||
/// </summary>
|
||||
public Orientation Orientation { get; set; } = Orientation.Horizontal;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="AlignmentModes"/> for this <see cref="Bar"/>. The default is <see cref="AlignmentModes.StartToEnd"/>.
|
||||
/// </summary>
|
||||
public AlignmentModes AlignmentModes { get; set; } = AlignmentModes.StartToEnd;
|
||||
|
||||
public bool StatusBarStyle { get; set; } = true;
|
||||
|
||||
@@ -52,7 +62,6 @@ public class Bar : View
|
||||
{
|
||||
base.Add (view);
|
||||
AdjustSubviewBorders ();
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -62,6 +71,49 @@ public class Bar : View
|
||||
AdjustSubviewBorders ();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>Inserts a <see cref="Shortcut"/> in the specified index of <see cref="Items"/>.</summary>
|
||||
/// <param name="index">The zero-based index at which item should be inserted.</param>
|
||||
/// <param name="item">The item to insert.</param>
|
||||
public void AddShortcutAt (int index, Shortcut item)
|
||||
{
|
||||
List<View> savedSubViewList = Subviews.ToList ();
|
||||
int count = savedSubViewList.Count;
|
||||
RemoveAll ();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (i == index)
|
||||
{
|
||||
Add (item);
|
||||
}
|
||||
Add (savedSubViewList [i]);
|
||||
}
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
|
||||
/// <summary>Removes a <see cref="Shortcut"/> at specified index of <see cref="Items"/>.</summary>
|
||||
/// <param name="index">The zero-based index of the item to remove.</param>
|
||||
/// <returns>The <see cref="Shortcut"/> removed.</returns>
|
||||
public Shortcut RemoveShortcut (int index)
|
||||
{
|
||||
View toRemove = null;
|
||||
for (int i = 0; i < Subviews.Count; i++)
|
||||
{
|
||||
if (i == index)
|
||||
{
|
||||
toRemove = Subviews [i];
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove is { })
|
||||
{
|
||||
Remove (toRemove);
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
|
||||
return toRemove as Shortcut;
|
||||
}
|
||||
|
||||
private void AdjustSubviewBorders ()
|
||||
{
|
||||
for (var index = 0; index < Subviews.Count; index++)
|
||||
@@ -72,7 +124,6 @@ public class Bar : View
|
||||
barItem.SuperViewRendersLineCanvas = true;
|
||||
barItem.ColorScheme = ColorScheme;
|
||||
|
||||
|
||||
if (!barItem.Visible)
|
||||
{
|
||||
continue;
|
||||
@@ -80,18 +131,20 @@ public class Bar : View
|
||||
|
||||
if (StatusBarStyle)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
|
||||
}
|
||||
barItem.BorderStyle = LineStyle.Dashed;
|
||||
|
||||
if (index == Subviews.Count - 1)
|
||||
{
|
||||
barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
barItem.BorderStyle = LineStyle.None;
|
||||
if (index == 0)
|
||||
{
|
||||
barItem.Border.Thickness = new Thickness (1, 1, 1, 0);
|
||||
@@ -121,25 +174,33 @@ public class Bar : View
|
||||
continue;
|
||||
}
|
||||
|
||||
if (StatusBarStyle)
|
||||
//if (StatusBarStyle)
|
||||
//{
|
||||
// barItem.BorderStyle = LineStyle.Dashed;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// barItem.BorderStyle = LineStyle.None;
|
||||
//}
|
||||
|
||||
//if (index == Subviews.Count - 1)
|
||||
//{
|
||||
// barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
|
||||
//}
|
||||
|
||||
if (barItem is Shortcut shortcut)
|
||||
{
|
||||
barItem.BorderStyle = LineStyle.Dashed;
|
||||
shortcut.X = Pos.Align (Alignment.Start, AlignmentModes);
|
||||
}
|
||||
else
|
||||
{
|
||||
barItem.BorderStyle = LineStyle.None;
|
||||
barItem.X = Pos.Align (Alignment.Start, AlignmentModes);
|
||||
}
|
||||
|
||||
if (index == Subviews.Count - 1)
|
||||
{
|
||||
barItem.Border.Thickness = new Thickness (0, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
barItem.Border.Thickness = new Thickness (0, 0, 1, 0);
|
||||
}
|
||||
|
||||
barItem.X = Pos.Align (Alignment.Start, StatusBarStyle ? AlignmentModes.IgnoreFirstOrLast : 0);
|
||||
|
||||
barItem.Y = Pos.Center ();
|
||||
prevBarItem = barItem;
|
||||
}
|
||||
@@ -189,7 +250,7 @@ public class Bar : View
|
||||
else
|
||||
{
|
||||
// Align the view to the bottom of the previous view
|
||||
barItem.Y = Pos.Bottom(prevBarItem);
|
||||
barItem.Y = Pos.Bottom (prevBarItem);
|
||||
}
|
||||
|
||||
prevBarItem = barItem;
|
||||
|
||||
@@ -53,14 +53,18 @@ public enum ShortcutStyles
|
||||
/// </remarks>
|
||||
public class Shortcut : View
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Shortcut"/>.
|
||||
/// Creates a new instance of <see cref="Shortcut"/>;
|
||||
/// </summary>
|
||||
public Shortcut ()
|
||||
/// <param name="key"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="action"></param>
|
||||
public Shortcut (Key key, string commandText, Action action, string helpText = null)
|
||||
{
|
||||
Id = "_shortcut";
|
||||
//HighlightStyle = HighlightStyle.Pressed;
|
||||
//Highlight += Shortcut_Highlight;
|
||||
HighlightStyle = HighlightStyle.Pressed;
|
||||
Highlight += Shortcut_Highlight;
|
||||
CanFocus = true;
|
||||
Width = GetWidthDimAuto ();
|
||||
Height = Dim.Auto (DimAutoStyle.Content, 1);
|
||||
@@ -80,23 +84,24 @@ public class Shortcut : View
|
||||
|
||||
HelpView.Id = "_helpView";
|
||||
HelpView.CanFocus = false;
|
||||
SetHelpViewDefaultLayout ();
|
||||
HelpView.Text = helpText;
|
||||
Add (HelpView);
|
||||
|
||||
KeyView.Id = "_keyView";
|
||||
KeyView.CanFocus = false;
|
||||
SetKeyViewDefaultLayout ();
|
||||
Add (KeyView);
|
||||
|
||||
// If the user clicks anywhere on the Shortcut, other than the CommandView, invoke the Command
|
||||
MouseClick += Shortcut_MouseClick;
|
||||
HelpView.MouseClick += Shortcut_MouseClick;
|
||||
KeyView.MouseClick += Shortcut_MouseClick;
|
||||
|
||||
LayoutStarted += OnLayoutStarted;
|
||||
|
||||
Initialized += OnInitialized;
|
||||
|
||||
Key = key;
|
||||
Title = commandText;
|
||||
Action = action;
|
||||
|
||||
return;
|
||||
|
||||
void OnInitialized (object sender, EventArgs e)
|
||||
@@ -112,17 +117,26 @@ public class Shortcut : View
|
||||
_minimumDimAutoWidth = Frame.Width;
|
||||
Width = savedDim;
|
||||
|
||||
//SetColorScheme ();
|
||||
SetCommandViewDefaultLayout ();
|
||||
SetHelpViewDefaultLayout ();
|
||||
SetKeyViewDefaultLayout ();
|
||||
|
||||
SetColorScheme ();
|
||||
}
|
||||
|
||||
// Helper to set Width consistently
|
||||
Dim GetWidthDimAuto ()
|
||||
{
|
||||
// TODO: PosAlign.CalculateMinDimension is a hack. Need to figure out a better way of doing this.
|
||||
return Dim.Auto (DimAutoStyle.Content, maximumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)));
|
||||
return Dim.Auto (DimAutoStyle.Content, minimumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)), maximumContentDim: Dim.Func (() => PosAlign.CalculateMinDimension (0, Subviews, Dimension.Width)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Shortcut"/>.
|
||||
/// </summary>
|
||||
public Shortcut () : this (Gui.Key.Empty, string.Empty, null) { }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="Orientation"/> for this <see cref="Shortcut"/>. The default is
|
||||
/// <see cref="Orientation.Horizontal"/>, which is ideal for status bars and toolbars. If set to <see cref="Orientation.Vertical"/>,
|
||||
@@ -130,6 +144,23 @@ public class Shortcut : View
|
||||
/// </summary>
|
||||
public Orientation Orientation { get; set; } = Orientation.Horizontal;
|
||||
|
||||
private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="AlignmentModes"/> for this <see cref="Shortcut"/>. The default is <see cref="AlignmentModes.StartToEnd"/>.
|
||||
/// </summary>
|
||||
public AlignmentModes AlignmentModes
|
||||
{
|
||||
get => _alignmentModes;
|
||||
set
|
||||
{
|
||||
_alignmentModes = value;
|
||||
SetCommandViewDefaultLayout ();
|
||||
SetHelpViewDefaultLayout ();
|
||||
SetKeyViewDefaultLayout ();
|
||||
}
|
||||
}
|
||||
|
||||
public ShortcutStyles ShortcutStyle { get; set; } = ShortcutStyles.None;
|
||||
|
||||
// When one of the subviews is "empty" we don't want to show it. So we
|
||||
@@ -211,7 +242,7 @@ public class Shortcut : View
|
||||
|
||||
if (maxHelpWidth > 0)
|
||||
{
|
||||
HelpView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
|
||||
HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
|
||||
|
||||
// Leverage Dim.Auto's max:
|
||||
HelpView.Width = Dim.Auto (DimAutoStyle.Text, maximumContentDim: maxHelpWidth);
|
||||
@@ -221,7 +252,9 @@ public class Shortcut : View
|
||||
else
|
||||
{
|
||||
// Reset to default
|
||||
//SetCommandViewDefaultLayout();
|
||||
SetHelpViewDefaultLayout ();
|
||||
//SetKeyViewDefaultLayout ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,23 +279,23 @@ public class Shortcut : View
|
||||
{
|
||||
if (!_savedForeColor.HasValue)
|
||||
{
|
||||
_savedForeColor = ColorScheme.Normal.Foreground;
|
||||
_savedForeColor = base.ColorScheme.Normal.Foreground;
|
||||
}
|
||||
|
||||
var cs = new ColorScheme (ColorScheme)
|
||||
var cs = new ColorScheme (base.ColorScheme)
|
||||
{
|
||||
Normal = new (ColorScheme.Normal.Foreground.GetHighlightColor (), ColorScheme.Normal.Background)
|
||||
Normal = new (ColorScheme.Normal.Foreground.GetHighlightColor (), base.ColorScheme.Normal.Background)
|
||||
};
|
||||
ColorScheme = cs;
|
||||
base.ColorScheme = cs;
|
||||
}
|
||||
|
||||
if (e.HighlightStyle == HighlightStyle.None && _savedForeColor.HasValue)
|
||||
{
|
||||
var cs = new ColorScheme (ColorScheme)
|
||||
var cs = new ColorScheme (base.ColorScheme)
|
||||
{
|
||||
Normal = new (_savedForeColor.Value, ColorScheme.Normal.Background)
|
||||
Normal = new (_savedForeColor.Value, base.ColorScheme.Normal.Background)
|
||||
};
|
||||
ColorScheme = cs;
|
||||
base.ColorScheme = cs;
|
||||
}
|
||||
|
||||
SuperView?.SetNeedsDisplay ();
|
||||
@@ -365,29 +398,8 @@ public class Shortcut : View
|
||||
_commandView = value;
|
||||
_commandView.Id = "_commandView";
|
||||
|
||||
// TODO: Determine if it makes sense to allow the CommandView to be focusable.
|
||||
// Right now, we don't set CanFocus to false here.
|
||||
//_commandView.CanFocus = true;
|
||||
|
||||
//// Bar will set the width of all CommandViews to the width of the widest CommandViews.
|
||||
////if (_commandView.Width == Dim.Absolute(0))
|
||||
//{
|
||||
// _commandView.Width = Dim.Auto ();
|
||||
//}
|
||||
|
||||
////if (_commandView.Height == Dim.Absolute (0))
|
||||
//{
|
||||
// _commandView.Height = Dim.Auto ();
|
||||
//}
|
||||
|
||||
_commandView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
|
||||
_commandView.Y = 0; //Pos.Center ();
|
||||
|
||||
_commandView.MouseClick += Shortcut_MouseClick;
|
||||
_commandView.Accept += CommandViewAccept;
|
||||
|
||||
_commandView.Margin.Thickness = GetMarginThickness ();
|
||||
|
||||
_commandView.HotKeyChanged += (s, e) =>
|
||||
{
|
||||
if (e.NewKey != Key.Empty)
|
||||
@@ -401,6 +413,7 @@ public class Shortcut : View
|
||||
|
||||
Title = _commandView.Text;
|
||||
|
||||
SetCommandViewDefaultLayout ();
|
||||
SetHelpViewDefaultLayout ();
|
||||
SetKeyViewDefaultLayout ();
|
||||
ShowHide ();
|
||||
@@ -431,6 +444,14 @@ public class Shortcut : View
|
||||
}
|
||||
}
|
||||
|
||||
private void SetCommandViewDefaultLayout ()
|
||||
{
|
||||
CommandView.Margin.Thickness = GetMarginThickness ();
|
||||
CommandView.X = Pos.Align (Alignment.End, AlignmentModes);
|
||||
CommandView.Y = 0; //Pos.Center (),
|
||||
}
|
||||
|
||||
|
||||
private void Shortcut_TitleChanged (object sender, StateEventArgs<string> e)
|
||||
{
|
||||
// If the Title changes, update the CommandView text.
|
||||
@@ -451,7 +472,7 @@ public class Shortcut : View
|
||||
private void SetHelpViewDefaultLayout ()
|
||||
{
|
||||
HelpView.Margin.Thickness = GetMarginThickness ();
|
||||
HelpView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
|
||||
HelpView.X = Pos.Align (Alignment.End, AlignmentModes);
|
||||
HelpView.Y = 0; //Pos.Center (),
|
||||
HelpView.Width = Dim.Auto (DimAutoStyle.Text);
|
||||
HelpView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
|
||||
@@ -546,6 +567,7 @@ public class Shortcut : View
|
||||
|
||||
private int _minimumKeyViewSize;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public int MinimumKeyViewSize
|
||||
@@ -572,7 +594,7 @@ public class Shortcut : View
|
||||
private void SetKeyViewDefaultLayout ()
|
||||
{
|
||||
KeyView.Margin.Thickness = GetMarginThickness ();
|
||||
KeyView.X = Pos.Align (Alignment.End, AlignmentModes.IgnoreFirstOrLast);
|
||||
KeyView.X = Pos.Align (Alignment.End, AlignmentModes);
|
||||
//KeyView.Y = Pos.Center ();
|
||||
KeyView.Width = Dim.Auto (DimAutoStyle.Text, Dim.Func (GetMinimumKeyViewSize));
|
||||
KeyView.Height = CommandView?.IsAdded == true ? Dim.Height (CommandView) : 1;
|
||||
@@ -631,25 +653,31 @@ public class Shortcut : View
|
||||
break;
|
||||
}
|
||||
|
||||
if (AcceptAction is null)
|
||||
{
|
||||
AcceptAction = () =>
|
||||
{
|
||||
var args = new HandledEventArgs ();
|
||||
Accept?.Invoke (this, args);
|
||||
};
|
||||
}
|
||||
|
||||
if (handled == false)
|
||||
{
|
||||
AcceptAction.Invoke();
|
||||
var args = new HandledEventArgs ();
|
||||
Accept?.Invoke (this, args);
|
||||
|
||||
if (args.Handled is false)
|
||||
{
|
||||
Action?.Invoke ();
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the action to be invoked when the shortcut key is pressed or the shortcut is clicked on with the mouse.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note, the <see cref="Accept"/> event is fired first, and if cancelled, <see cref="Action"/> will not be invoked.
|
||||
/// </remarks>
|
||||
[CanBeNull]
|
||||
public Action AcceptAction { get; set; }
|
||||
public Action Action { get; set; }
|
||||
|
||||
#endregion Accept Handling
|
||||
|
||||
@@ -673,7 +701,7 @@ public class Shortcut : View
|
||||
|
||||
if (HasFocus)
|
||||
{
|
||||
// When we have focus, we invert the SuperView's colors
|
||||
// When we have focus, we invert the colors
|
||||
base.ColorScheme = new (base.ColorScheme)
|
||||
{
|
||||
Normal = base.ColorScheme.Focus,
|
||||
@@ -687,34 +715,16 @@ public class Shortcut : View
|
||||
base.ColorScheme = SuperView?.ColorScheme;
|
||||
}
|
||||
|
||||
//// If the command view is focusable, invert the focus colors
|
||||
if (CommandView.CanFocus)
|
||||
// Set KeyView's colors to show "hot"
|
||||
if (IsInitialized)
|
||||
{
|
||||
ColorScheme commandViewCS = new (base.ColorScheme)
|
||||
var cs = new ColorScheme (base.ColorScheme)
|
||||
{
|
||||
Normal = base.ColorScheme.Focus,
|
||||
HotNormal = base.ColorScheme.HotFocus,
|
||||
HotFocus = base.ColorScheme.HotNormal,
|
||||
Focus = base.ColorScheme.Normal
|
||||
Normal = base.ColorScheme.HotNormal,
|
||||
HotNormal = base.ColorScheme.Normal
|
||||
};
|
||||
CommandView.ColorScheme = commandViewCS;
|
||||
KeyView.ColorScheme = cs;
|
||||
}
|
||||
else
|
||||
{
|
||||
CommandView.ColorScheme = base.ColorScheme;
|
||||
}
|
||||
|
||||
//HelpView.ColorScheme = base.ColorScheme;
|
||||
|
||||
//// Set KeyView's colors to show "hot"
|
||||
//var cs = new ColorScheme (ColorScheme)
|
||||
//{
|
||||
// Normal = base.ColorScheme.HotNormal,
|
||||
// HotNormal = base.ColorScheme.Normal
|
||||
//};
|
||||
|
||||
//KeyView.ColorScheme = cs;
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -727,8 +737,6 @@ public class Shortcut : View
|
||||
/// <inheritdoc/>
|
||||
public override bool OnLeave (View view)
|
||||
{
|
||||
// Reset the color scheme (to SuperView).
|
||||
//ColorScheme = null;
|
||||
SetColorScheme ();
|
||||
return base.OnLeave (view);
|
||||
}
|
||||
|
||||
@@ -9,60 +9,28 @@ namespace Terminal.Gui;
|
||||
/// </summary>
|
||||
public class StatusBar : Bar
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public StatusBar () : this ([]) { }
|
||||
|
||||
public StatusBar ()
|
||||
/// <inheritdoc />
|
||||
public StatusBar (IEnumerable<Shortcut> shortcuts) : base (shortcuts)
|
||||
{
|
||||
Orientation = Orientation.Horizontal;
|
||||
Y = Pos.AnchorEnd ();
|
||||
Width = Dim.Fill ();
|
||||
StatusBarStyle = true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Add (View view)
|
||||
{
|
||||
view.CanFocus = false;
|
||||
if (view is Shortcut shortcut)
|
||||
{
|
||||
shortcut.KeyBindingScope = KeyBindingScope.Application;
|
||||
shortcut.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
|
||||
}
|
||||
base.Add (view);
|
||||
}
|
||||
|
||||
/// <summary>Inserts a <see cref="Shortcut"/> in the specified index of <see cref="Items"/>.</summary>
|
||||
/// <param name="index">The zero-based index at which item should be inserted.</param>
|
||||
/// <param name="item">The item to insert.</param>
|
||||
public void AddShortcutAt (int index, Shortcut item)
|
||||
{
|
||||
List<View> savedSubViewList = Subviews.ToList ();
|
||||
int count = savedSubViewList.Count;
|
||||
RemoveAll ();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (i == index)
|
||||
{
|
||||
Add (item);
|
||||
}
|
||||
Add (savedSubViewList [i]);
|
||||
}
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
|
||||
/// <summary>Removes a <see cref="Shortcut"/> at specified index of <see cref="Items"/>.</summary>
|
||||
/// <param name="index">The zero-based index of the item to remove.</param>
|
||||
/// <returns>The <see cref="Shortcut"/> removed.</returns>
|
||||
public Shortcut RemoveItem (int index)
|
||||
{
|
||||
View toRemove = null;
|
||||
for (int i = 0; i < Subviews.Count; i++)
|
||||
{
|
||||
if (i == index)
|
||||
{
|
||||
toRemove = Subviews [i];
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove is { })
|
||||
{
|
||||
Remove (toRemove);
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
|
||||
return toRemove as Shortcut;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class Bars : Scenario
|
||||
|
||||
// SetupMenuBar ();
|
||||
//SetupContentMenu ();
|
||||
// SetupStatusBar ();
|
||||
SetupStatusBar ();
|
||||
|
||||
foreach (Bar barView in Application.Top.Subviews.Where (b => b is Bar)!)
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@ public class ConfigurationEditor : Scenario
|
||||
Application.Init ();
|
||||
|
||||
Toplevel top = new ();
|
||||
|
||||
_tileView = new TileView (0)
|
||||
{
|
||||
Width = Dim.Fill (), Height = Dim.Fill (1), Orientation = Orientation.Vertical, LineStyle = LineStyle.Single
|
||||
@@ -57,25 +58,24 @@ public class ConfigurationEditor : Scenario
|
||||
{
|
||||
Key = Application.QuitKey,
|
||||
Title = $"{Application.QuitKey} Quit",
|
||||
AcceptAction = Quit
|
||||
Action = Quit
|
||||
};
|
||||
|
||||
var reloadShortcut = new Shortcut ()
|
||||
{
|
||||
Key = KeyCode.F5,
|
||||
Key = Key.F5.WithShift,
|
||||
Title = "Reload",
|
||||
AcceptAction = Reload
|
||||
};
|
||||
reloadShortcut.Accept += (s, e) => { Reload (); };
|
||||
|
||||
var saveShortcut = new Shortcut ()
|
||||
{
|
||||
Key = Key.S.WithCtrl,
|
||||
Key = Key.F4,
|
||||
Title = "Save",
|
||||
AcceptAction = Save
|
||||
Action = Save
|
||||
};
|
||||
|
||||
|
||||
var statusBar = new StatusBar ();
|
||||
statusBar.Add (quitShortcut, reloadShortcut, saveShortcut, _lenShortcut);
|
||||
var statusBar = new StatusBar ([quitShortcut, reloadShortcut, saveShortcut, _lenShortcut]);
|
||||
|
||||
top.Add (statusBar);
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using CsvHelper;
|
||||
using SixLabors.ImageSharp.ColorSpaces;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace UICatalog.Scenarios;
|
||||
@@ -26,16 +26,23 @@ public class CsvEditor : Scenario
|
||||
private MenuItem _miCentered;
|
||||
private MenuItem _miLeft;
|
||||
private MenuItem _miRight;
|
||||
private TextField _selectedCellLabel;
|
||||
private TextField _selectedCellTextField;
|
||||
private TableView _tableView;
|
||||
|
||||
public override void Setup ()
|
||||
public override void Main ()
|
||||
{
|
||||
Win.Title = GetName ();
|
||||
Win.Y = 1; // menu
|
||||
Win.Height = Dim.Fill (1); // status bar
|
||||
// Init
|
||||
Application.Init ();
|
||||
|
||||
_tableView = new TableView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (1) };
|
||||
// Setup - Create a top-level application window and configure it.
|
||||
Toplevel appWindow = new ()
|
||||
{
|
||||
Title = $"{GetName ()}"
|
||||
};
|
||||
|
||||
//appWindow.Height = Dim.Fill (1); // status bar
|
||||
|
||||
_tableView = new () { X = 0, Y = 1, Width = Dim.Fill (), Height = Dim.Fill (2) };
|
||||
|
||||
var fileMenu = new MenuBarItem (
|
||||
"_File",
|
||||
@@ -53,99 +60,96 @@ public class CsvEditor : Scenario
|
||||
Menus =
|
||||
[
|
||||
fileMenu,
|
||||
new MenuBarItem (
|
||||
"_Edit",
|
||||
new MenuItem []
|
||||
{
|
||||
new ("_New Column", "", () => AddColumn ()),
|
||||
new ("_New Row", "", () => AddRow ()),
|
||||
new (
|
||||
"_Rename Column",
|
||||
"",
|
||||
() => RenameColumn ()
|
||||
),
|
||||
new ("_Delete Column", "", () => DeleteColum ()),
|
||||
new ("_Move Column", "", () => MoveColumn ()),
|
||||
new ("_Move Row", "", () => MoveRow ()),
|
||||
new ("_Sort Asc", "", () => Sort (true)),
|
||||
new ("_Sort Desc", "", () => Sort (false))
|
||||
}
|
||||
),
|
||||
new MenuBarItem (
|
||||
"_View",
|
||||
new []
|
||||
{
|
||||
_miLeft = new MenuItem (
|
||||
"_Align Left",
|
||||
"",
|
||||
() => Align (Alignment.Start)
|
||||
),
|
||||
_miRight = new MenuItem (
|
||||
"_Align Right",
|
||||
"",
|
||||
() => Align (Alignment.End)
|
||||
),
|
||||
_miCentered = new MenuItem (
|
||||
"_Align Centered",
|
||||
"",
|
||||
() => Align (Alignment.Center)
|
||||
),
|
||||
new (
|
||||
"_Edit",
|
||||
new MenuItem []
|
||||
{
|
||||
new ("_New Column", "", () => AddColumn ()),
|
||||
new ("_New Row", "", () => AddRow ()),
|
||||
new (
|
||||
"_Rename Column",
|
||||
"",
|
||||
() => RenameColumn ()
|
||||
),
|
||||
new ("_Delete Column", "", () => DeleteColum ()),
|
||||
new ("_Move Column", "", () => MoveColumn ()),
|
||||
new ("_Move Row", "", () => MoveRow ()),
|
||||
new ("_Sort Asc", "", () => Sort (true)),
|
||||
new ("_Sort Desc", "", () => Sort (false))
|
||||
}
|
||||
),
|
||||
new (
|
||||
"_View",
|
||||
new []
|
||||
{
|
||||
_miLeft = new (
|
||||
"_Align Left",
|
||||
"",
|
||||
() => Align (Alignment.Start)
|
||||
),
|
||||
_miRight = new (
|
||||
"_Align Right",
|
||||
"",
|
||||
() => Align (Alignment.End)
|
||||
),
|
||||
_miCentered = new (
|
||||
"_Align Centered",
|
||||
"",
|
||||
() => Align (Alignment.Center)
|
||||
),
|
||||
|
||||
// Format requires hard typed data table, when we read a CSV everything is untyped (string) so this only works for new columns in this demo
|
||||
_miCentered = new MenuItem (
|
||||
"_Set Format Pattern",
|
||||
"",
|
||||
() => SetFormat ()
|
||||
)
|
||||
}
|
||||
)
|
||||
// Format requires hard typed data table, when we read a CSV everything is untyped (string) so this only works for new columns in this demo
|
||||
_miCentered = new (
|
||||
"_Set Format Pattern",
|
||||
"",
|
||||
() => SetFormat ()
|
||||
)
|
||||
}
|
||||
)
|
||||
]
|
||||
};
|
||||
Top.Add (menu);
|
||||
appWindow.Add (menu);
|
||||
|
||||
#if V2_STATUSBAR
|
||||
var statusBar = new StatusBar (
|
||||
new StatusItem []
|
||||
{
|
||||
new (
|
||||
KeyCode.CtrlMask | KeyCode.O,
|
||||
"~^O~ Open",
|
||||
() => Open ()
|
||||
),
|
||||
new (
|
||||
KeyCode.CtrlMask | KeyCode.S,
|
||||
"~^S~ Save",
|
||||
() => Save ()
|
||||
),
|
||||
new (
|
||||
Application.QuitKey,
|
||||
$"{Application.QuitKey} to Quit",
|
||||
() => Quit ()
|
||||
)
|
||||
}
|
||||
);
|
||||
Top.Add (statusBar);
|
||||
#endif
|
||||
|
||||
Win.Add (_tableView);
|
||||
|
||||
_selectedCellLabel = new TextField
|
||||
_selectedCellTextField = new ()
|
||||
{
|
||||
X = 0,
|
||||
Y = Pos.Bottom (_tableView),
|
||||
Text = "0,0",
|
||||
Width = Dim.Fill (),
|
||||
TextAlignment = Alignment.End
|
||||
Width = 10,
|
||||
Height = 1,
|
||||
};
|
||||
_selectedCellLabel.TextChanged += SelectedCellLabel_TextChanged;
|
||||
_selectedCellTextField.TextChanged += SelectedCellLabel_TextChanged;
|
||||
|
||||
Win.Add (_selectedCellLabel);
|
||||
var statusBar = new StatusBar (
|
||||
[
|
||||
new (Application.QuitKey, "Quit", Quit, "Quit!"),
|
||||
new (Key.O.WithCtrl, "Open", Open, "Open a file."),
|
||||
new (Key.S.WithCtrl, "Save", Save, "Save current."),
|
||||
new ()
|
||||
{
|
||||
HelpText = "Cell:",
|
||||
CommandView = _selectedCellTextField,
|
||||
AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast,
|
||||
Enabled = false
|
||||
}
|
||||
])
|
||||
{
|
||||
AlignmentModes = AlignmentModes.IgnoreFirstOrLast
|
||||
};
|
||||
appWindow.Add (statusBar);
|
||||
|
||||
appWindow.Add (_tableView);
|
||||
|
||||
_tableView.SelectedCellChanged += OnSelectedCellChanged;
|
||||
_tableView.CellActivated += EditCurrentCell;
|
||||
_tableView.KeyDown += TableViewKeyPress;
|
||||
|
||||
SetupScrollBar ();
|
||||
|
||||
// Run - Start the application.
|
||||
Application.Run (appWindow);
|
||||
appWindow.Dispose ();
|
||||
|
||||
// Shutdown - Calling Application.Shutdown is required.
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
private void AddColumn ()
|
||||
@@ -302,10 +306,10 @@ public class CsvEditor : Scenario
|
||||
var ok = new Button { Text = "Ok", IsDefault = true };
|
||||
|
||||
ok.Accept += (s, e) =>
|
||||
{
|
||||
okPressed = true;
|
||||
Application.RequestStop ();
|
||||
};
|
||||
{
|
||||
okPressed = true;
|
||||
Application.RequestStop ();
|
||||
};
|
||||
var cancel = new Button { Text = "Cancel" };
|
||||
cancel.Accept += (s, e) => { Application.RequestStop (); };
|
||||
var d = new Dialog { Title = title, Buttons = [ok, cancel] };
|
||||
@@ -427,9 +431,9 @@ public class CsvEditor : Scenario
|
||||
private void OnSelectedCellChanged (object sender, SelectedCellChangedEventArgs e)
|
||||
{
|
||||
// only update the text box if the user is not manually editing it
|
||||
if (!_selectedCellLabel.HasFocus)
|
||||
if (!_selectedCellTextField.HasFocus)
|
||||
{
|
||||
_selectedCellLabel.Text = $"{_tableView.SelectedRow},{_tableView.SelectedColumn}";
|
||||
_selectedCellTextField.Text = $"{_tableView.SelectedRow},{_tableView.SelectedColumn}";
|
||||
}
|
||||
|
||||
if (_tableView.Table == null || _tableView.SelectedColumn == -1)
|
||||
@@ -448,7 +452,7 @@ public class CsvEditor : Scenario
|
||||
{
|
||||
var ofd = new FileDialog
|
||||
{
|
||||
AllowedTypes = new List<IAllowedType> { new AllowedType ("Comma Separated Values", ".csv") }
|
||||
AllowedTypes = new () { new AllowedType ("Comma Separated Values", ".csv") }
|
||||
};
|
||||
ofd.Style.OkButtonText = "Open";
|
||||
|
||||
@@ -458,6 +462,7 @@ public class CsvEditor : Scenario
|
||||
{
|
||||
Open (ofd.Path);
|
||||
}
|
||||
|
||||
ofd.Dispose ();
|
||||
}
|
||||
|
||||
@@ -498,7 +503,8 @@ public class CsvEditor : Scenario
|
||||
|
||||
// Only set the current filename if we successfully loaded the entire file
|
||||
_currentFile = filename;
|
||||
Win.Title = $"{GetName ()} - {Path.GetFileName (_currentFile)}";
|
||||
_selectedCellTextField.SuperView.Enabled = true;
|
||||
Application.Top.Title = $"{GetName ()} - {Path.GetFileName (_currentFile)}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -563,13 +569,13 @@ public class CsvEditor : Scenario
|
||||
private void SelectedCellLabel_TextChanged (object sender, StateEventArgs<string> e)
|
||||
{
|
||||
// if user is in the text control and editing the selected cell
|
||||
if (!_selectedCellLabel.HasFocus)
|
||||
if (!_selectedCellTextField.HasFocus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// change selected cell to the one the user has typed into the box
|
||||
Match match = Regex.Match (_selectedCellLabel.Text, "^(\\d+),(\\d+)$");
|
||||
Match match = Regex.Match (_selectedCellTextField.Text, "^(\\d+),(\\d+)$");
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
|
||||
@@ -237,29 +237,23 @@ public class Editor : Scenario
|
||||
};
|
||||
|
||||
_appWindow.Add (menu);
|
||||
#if V2_STATUSBAR
|
||||
|
||||
var siCursorPosition = new StatusItem (KeyCode.Null, "", null);
|
||||
var siCursorPosition = new Shortcut(KeyCode.Null, "", null);
|
||||
|
||||
var statusBar = new StatusBar (
|
||||
new []
|
||||
{
|
||||
new (Application.QuitKey, $"Quit", Quit),
|
||||
new (Key.F2, "Open", Open),
|
||||
new (Key.F3, "Save", () => Save ()),
|
||||
new (Key.F4, "Save As", () => SaveAs ()),
|
||||
new (Key.Empty, $"OS Clipboard IsSupported : {Clipboard.IsSupported}", null),
|
||||
siCursorPosition,
|
||||
new (KeyCode.F2, "~F2~ Open", () => Open ()),
|
||||
new (KeyCode.F3, "~F3~ Save", () => Save ()),
|
||||
new (KeyCode.F4, "~F4~ Save As", () => SaveAs ()),
|
||||
new (
|
||||
Application.QuitKey,
|
||||
$"{Application.QuitKey} to Quit",
|
||||
() => Quit ()
|
||||
),
|
||||
new (
|
||||
KeyCode.Null,
|
||||
$"OS Clipboard IsSupported : {Clipboard.IsSupported}",
|
||||
null
|
||||
)
|
||||
}
|
||||
);
|
||||
)
|
||||
{
|
||||
AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast
|
||||
};
|
||||
|
||||
_textView.UnwrappedCursorPosition += (s, e) =>
|
||||
{
|
||||
@@ -267,7 +261,6 @@ public class Editor : Scenario
|
||||
};
|
||||
|
||||
_appWindow.Add (statusBar);
|
||||
#endif
|
||||
|
||||
_scrollBar = new (_textView, true);
|
||||
|
||||
|
||||
@@ -261,6 +261,8 @@ public class Shortcuts : Scenario
|
||||
hShortcut1.CommandView.Width = 10;
|
||||
hShortcut1.CommandView.Height = 1;
|
||||
hShortcut1.CommandView.CanFocus = false;
|
||||
hShortcut1.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
|
||||
|
||||
Timer timer = new (10)
|
||||
{
|
||||
AutoReset = true,
|
||||
@@ -297,11 +299,12 @@ public class Shortcuts : Scenario
|
||||
X = Pos.Align (Alignment.Start, AlignmentModes.IgnoreFirstOrLast, 1),
|
||||
Y = Pos.Top (hShortcut1),
|
||||
Key = Key.F8,
|
||||
HelpText = "Edit",
|
||||
HelpText = "TextField",
|
||||
CanFocus = true,
|
||||
BorderStyle = LineStyle.Dashed,
|
||||
CommandView = textField,
|
||||
BorderStyle = LineStyle.Dashed,
|
||||
};
|
||||
hShortcut2.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
|
||||
hShortcut2.Border.Thickness = new (0, 0, 1, 0);
|
||||
|
||||
Application.Top.Add (hShortcut2);
|
||||
@@ -331,6 +334,7 @@ public class Shortcuts : Scenario
|
||||
};
|
||||
hShortcutBG.CommandView = bgColor;
|
||||
hShortcutBG.Border.Thickness = new (1, 0, 1, 0);
|
||||
hShortcutBG.AlignmentModes = AlignmentModes.EndToStart | AlignmentModes.IgnoreFirstOrLast;
|
||||
|
||||
Application.Top.Add (hShortcutBG);
|
||||
|
||||
@@ -365,6 +369,9 @@ public class Shortcuts : Scenario
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
((CheckBox)vShortcut5.CommandView).OnToggled ();
|
||||
((CheckBox)vShortcut5.CommandView).OnToggled ();
|
||||
}
|
||||
|
||||
private void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }
|
||||
|
||||
@@ -347,6 +347,7 @@ internal class UICatalogApp
|
||||
// 'app' closed cleanly.
|
||||
foreach (Responder? inst in Responder.Instances)
|
||||
{
|
||||
|
||||
Debug.Assert (inst.WasDisposed);
|
||||
}
|
||||
|
||||
@@ -457,14 +458,13 @@ internal class UICatalogApp
|
||||
StatusBar = new ()
|
||||
{
|
||||
Visible = ShowStatusBar,
|
||||
AlignmentModes = AlignmentModes.StartToEnd | AlignmentModes.IgnoreFirstOrLast
|
||||
};
|
||||
|
||||
Shortcut statusBarShortcut = new Shortcut ()
|
||||
{
|
||||
Key = Key.F10,
|
||||
KeyBindingScope = KeyBindingScope.Application,
|
||||
Title = "Status Bar",
|
||||
CanFocus = false,
|
||||
Title = "Show/Hide Status Bar",
|
||||
};
|
||||
statusBarShortcut.Accept += (sender, args) =>
|
||||
{
|
||||
@@ -473,15 +473,13 @@ internal class UICatalogApp
|
||||
|
||||
ShForce16Colors = new Shortcut ()
|
||||
{
|
||||
Key = Key.F6,
|
||||
KeyBindingScope = KeyBindingScope.Application,
|
||||
CommandView = new CheckBox()
|
||||
CommandView = new CheckBox ()
|
||||
{
|
||||
Title ="16 Colors",
|
||||
Title = "16 color mode",
|
||||
Checked = Application.Force16Colors,
|
||||
CanFocus = false,
|
||||
},
|
||||
CanFocus = false,
|
||||
}, HelpText = "",
|
||||
Key = Key.F6,
|
||||
};
|
||||
ShForce16Colors.Accept += (sender, args) =>
|
||||
{
|
||||
@@ -508,8 +506,6 @@ internal class UICatalogApp
|
||||
{
|
||||
Title = "Quit",
|
||||
Key = Application.QuitKey,
|
||||
KeyBindingScope = KeyBindingScope.Application,
|
||||
CanFocus = false,
|
||||
},
|
||||
statusBarShortcut,
|
||||
ShForce16Colors,
|
||||
@@ -542,7 +538,7 @@ internal class UICatalogApp
|
||||
X = Pos.Right (CategoryList) - 1,
|
||||
Y = 1,
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Height(CategoryList),
|
||||
Height = Dim.Height (CategoryList),
|
||||
|
||||
//AllowsMarking = false,
|
||||
CanFocus = true,
|
||||
|
||||
Reference in New Issue
Block a user