mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* touching publish.yml * ColorScheme->Scheme * ColorScheme->Scheme 2 * Prototype of GetAttributeForRole * Badly broke CM * Further Badly broke CM * Refactored CM big-time. View still broken * All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Actually: All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Bug fixes. DeepMemberWiseClone cleanup * Further cleanup of Scope<T>, ConfigProperty, etc. * Made ConfigManager thread safe. * WIP: Broken * WIP: new deep clone impl * WIP: new deep clone impl is done. Now fixing CM * WIP: - config.md - Working on AOT clean up - Core CM is broken; but known. * WIP * Merged. Removed CM from Application.Init * WIP * More WIP; Less broke * All CM unit tests pass... Not sure if it actually works though * All unit tests pass... Themes are broken though in UI Cat * CM Ready for review? * Fixed failures due to TextStyles PR * Working on Scheme/Attribute * Working on Scheme/Attribute 2 * Working on Scheme/Attribute 3 * Working on Scheme/Attribute 4 * Working on Scheme/Attribute 5 * Working on Scheme/Attribute 6 * Added test to show how awful memory usage is * Improved schema. Updated config.json * Nade Scope<T> concurrentdictionary and added test to prove * Made Themes ConcrurrentDictionary. Added bunches of tests * Code cleanup * Code cleanup 2 * Code cleanup 3 * Tweaking Scheme * ClearJsonErrors * ClearJsonErrors2 * Updated Attribute API * It all (mostly) works! * Skip odd unit test * Messed with Themes * Theme tweaks * Code reorg. New .md stuff * Fixed Enabled. Added mock driver * Fixed a bunch of View.Enabled related issues * Scheme -> Get/SetScheme() * Cleanup * Cleanup2 * Broke something * Fixed everything * Made CM.Enable better * Text Style Scenario * Added comments * Fixed UI Catalog Theme Changing * Fixed more dynamic CM update stuff * Warning cleanup * New Default Theme * fixed unit test * Refactoring Scheme and Attribute to fix inheritance * more unit tests * ConfigProperty is not updating schemes correctly * All unit tests pass. Code cleanup * All unit tests pass. Code cleanup2 * Fixed unit tests * Upgraded TextField and TextView * Fixed TextView !Enabled bug * More updates to TextView. More unit tests for SchemeManager * Upgraded CharMap * API docs * Fixe HexView API * upgrade HexView * Fixed shortcut KeyView * Fixed more bugs. Added new themes * updated themes * upgraded Border * Fixed themes memory usage...mostly * Fixed themes memory usage...mostly2 * Fixed themes memory usage...2 * Fixed themes memory usage...3 * Added new colors * Fixed GetHardCodedConfig bug * Added Themes Scenario - WIP * Added Themes Scenario * Tweaked Themes Scenario * Code cleanup * Fixed json schmea * updated deepdives * updated deepdives * Tweaked Themes Scenario * Made Schemes a concurrent dict * Test cleanup * Thread safe ConfigProperty tests * trying to make things more thread safe * more trying to make things more thread safe * Fixing bugs in shadowview * Fixing bugs in shadowview 2 * Refactored GetViewsUnderMouse to GetViewsUnderLocation etc... * Fixed dupe unit tests? * Added better description of layout and coordiantes to deep dive * Added better description of layout and coordiantes to deep dive * Modified tests that call v2.AddTimeout; they were returning true which means restart the timer! This was causing mac/linux unit test failures. I think * Fixed auto scheme. Broke TextView/TextField selection * Realized Attribute.IsExplicitlySet is stupid; just use nullable * Fixed Attribute. Simplified. MOre theme testing * Updated themes again * GetViewsUnderMouse to GetViewsUnderLocation broke TransparentMouse. * Fixing mouseunder bugs * rewriting... * All working again. Shadows are now slick as snot. GetViewsUnderLocation is rewritten to actually work and be readable. Tons more low-level unit tests. Margin is now actually ViewportSettings.Transparent. * Code cleanup * Code cleanup * Code cleanup of color apis * Fixed Hover/Highlight * Update Examples/UICatalog/Scenarios/AllViewsTester.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/Clipping.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fixed race condition? * reverted * Simplified Attribute API by removing events from SetAttributeForRole * Removed recursion from GetViewsAtLocation * Removed unneeded code * Code clean up. Fixed Scheme bug. * reverted temporary disable * Adjusted scheme algo * Upgraded TextValidateField * Fixed TextValidate bugs * Tweaks * Frameview rounded border by default * API doc cleanup * Readme fix * Addressed tznind feeback * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true 2 * cleanup --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
564 lines
16 KiB
C#
564 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Terminal.Gui;
|
|
|
|
namespace UICatalog.Scenarios;
|
|
|
|
[ScenarioMetadata ("Bars", "Illustrates Bar views (e.g. StatusBar)")]
|
|
[ScenarioCategory ("Controls")]
|
|
public class Bars : Scenario
|
|
{
|
|
public override void Main ()
|
|
{
|
|
Application.Init ();
|
|
Toplevel app = new ();
|
|
|
|
app.Loaded += App_Loaded;
|
|
|
|
Application.Run (app);
|
|
app.Dispose ();
|
|
Application.Shutdown ();
|
|
}
|
|
|
|
|
|
// Setting everything up in Loaded handler because we change the
|
|
// QuitKey and it only sticks if changed after init
|
|
private void App_Loaded (object sender, EventArgs e)
|
|
{
|
|
Application.Top!.Title = GetQuitKeyAndName ();
|
|
|
|
ObservableCollection<string> eventSource = new ();
|
|
ListView eventLog = new ListView ()
|
|
{
|
|
Title = "Event Log",
|
|
X = Pos.AnchorEnd (),
|
|
Width = Dim.Auto (),
|
|
Height = Dim.Fill (), // Make room for some wide things
|
|
SchemeName = "Toplevel",
|
|
Source = new ListWrapper<string> (eventSource)
|
|
};
|
|
eventLog.Border.Thickness = new (0, 1, 0, 0);
|
|
Application.Top.Add (eventLog);
|
|
|
|
FrameView menuBarLikeExamples = new ()
|
|
{
|
|
Title = "MenuBar-Like Examples",
|
|
X = 0,
|
|
Y = 0,
|
|
Width = Dim.Fill () - Dim.Width (eventLog),
|
|
Height = Dim.Percent(33),
|
|
};
|
|
Application.Top.Add (menuBarLikeExamples);
|
|
|
|
Label label = new Label ()
|
|
{
|
|
Title = " Bar:",
|
|
X = 0,
|
|
Y = 0,
|
|
};
|
|
menuBarLikeExamples.Add (label);
|
|
|
|
Bar bar = new Bar
|
|
{
|
|
Id = "menuBar-like",
|
|
X = Pos.Right (label),
|
|
Y = Pos.Top (label),
|
|
Width = Dim.Fill (),
|
|
};
|
|
|
|
ConfigMenuBar (bar);
|
|
menuBarLikeExamples.Add (bar);
|
|
|
|
label = new Label ()
|
|
{
|
|
Title = " MenuBar:",
|
|
X = 0,
|
|
Y = Pos.Bottom (bar) + 1
|
|
};
|
|
menuBarLikeExamples.Add (label);
|
|
|
|
//bar = new MenuBarv2
|
|
//{
|
|
// Id = "menuBar",
|
|
// X = Pos.Right (label),
|
|
// Y = Pos.Top (label),
|
|
//};
|
|
|
|
//ConfigMenuBar (bar);
|
|
//menuBarLikeExamples.Add (bar);
|
|
|
|
FrameView menuLikeExamples = new ()
|
|
{
|
|
Title = "Menu-Like Examples",
|
|
X = 0,
|
|
Y = Pos.Center (),
|
|
Width = Dim.Fill () - Dim.Width (eventLog),
|
|
Height = Dim.Percent (33),
|
|
};
|
|
Application.Top.Add (menuLikeExamples);
|
|
|
|
label = new Label ()
|
|
{
|
|
Title = "Bar:",
|
|
X = 0,
|
|
Y = 0,
|
|
};
|
|
menuLikeExamples.Add (label);
|
|
|
|
bar = new Bar
|
|
{
|
|
Id = "menu-like",
|
|
X = 0,
|
|
Y = Pos.Bottom(label),
|
|
//Width = Dim.Percent (40),
|
|
Orientation = Orientation.Vertical,
|
|
};
|
|
ConfigureMenu (bar);
|
|
|
|
menuLikeExamples.Add (bar);
|
|
|
|
label = new Label ()
|
|
{
|
|
Title = "Menu:",
|
|
X = Pos.Right(bar) + 1,
|
|
Y = Pos.Top (label),
|
|
};
|
|
menuLikeExamples.Add (label);
|
|
|
|
bar = new Menuv2
|
|
{
|
|
Id = "menu",
|
|
X = Pos.Left (label),
|
|
Y = Pos.Bottom (label),
|
|
};
|
|
ConfigureMenu (bar);
|
|
bar.Arrangement = ViewArrangement.RightResizable;
|
|
|
|
menuLikeExamples.Add (bar);
|
|
|
|
label = new Label ()
|
|
{
|
|
Title = "PopOver Menu (Right click to show):",
|
|
X = Pos.Right (bar) + 1,
|
|
Y = Pos.Top (label),
|
|
};
|
|
menuLikeExamples.Add (label);
|
|
|
|
Menuv2 popOverMenu = new Menuv2
|
|
{
|
|
Id = "popupMenu",
|
|
X = Pos.Left (label),
|
|
Y = Pos.Bottom (label),
|
|
};
|
|
ConfigureMenu (popOverMenu);
|
|
|
|
popOverMenu.Arrangement = ViewArrangement.Overlapped;
|
|
popOverMenu.Visible = false;
|
|
//popOverMenu.Enabled = false;
|
|
|
|
var toggleShortcut = new Shortcut
|
|
{
|
|
Title = "Toggle Hide",
|
|
Text = "App",
|
|
BindKeyToApplication = true,
|
|
Key = Key.F4.WithCtrl,
|
|
};
|
|
popOverMenu.Add (toggleShortcut);
|
|
|
|
popOverMenu.Accepting += PopOverMenuOnAccept;
|
|
|
|
void PopOverMenuOnAccept (object o, CommandEventArgs args)
|
|
{
|
|
if (popOverMenu.Visible)
|
|
{
|
|
popOverMenu.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
popOverMenu.Visible = true;
|
|
popOverMenu.SetFocus ();
|
|
}
|
|
}
|
|
|
|
menuLikeExamples.Add (popOverMenu);
|
|
|
|
menuLikeExamples.MouseClick += MenuLikeExamplesMouseClick;
|
|
|
|
void MenuLikeExamplesMouseClick (object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Flags.HasFlag (MouseFlags.Button3Clicked))
|
|
{
|
|
popOverMenu.X = e.Position.X;
|
|
popOverMenu.Y = e.Position.Y;
|
|
popOverMenu.Visible = true;
|
|
//popOverMenu.Enabled = popOverMenu.Visible;
|
|
popOverMenu.SetFocus ();
|
|
}
|
|
else
|
|
{
|
|
popOverMenu.Visible = false;
|
|
//popOverMenu.Enabled = popOverMenu.Visible;
|
|
}
|
|
}
|
|
|
|
FrameView statusBarLikeExamples = new ()
|
|
{
|
|
Title = "StatusBar-Like Examples",
|
|
X = 0,
|
|
Y = Pos.AnchorEnd (),
|
|
Width = Dim.Width (menuLikeExamples),
|
|
Height = Dim.Percent (33),
|
|
};
|
|
Application.Top.Add (statusBarLikeExamples);
|
|
|
|
label = new Label ()
|
|
{
|
|
Title = " Bar:",
|
|
X = 0,
|
|
Y = 0,
|
|
};
|
|
statusBarLikeExamples.Add (label);
|
|
bar = new Bar
|
|
{
|
|
Id = "statusBar-like",
|
|
X = Pos.Right (label),
|
|
Y = Pos.Top (label),
|
|
Width = Dim.Fill (),
|
|
Orientation = Orientation.Horizontal,
|
|
};
|
|
ConfigStatusBar (bar);
|
|
statusBarLikeExamples.Add (bar);
|
|
|
|
label = new Label ()
|
|
{
|
|
Title = "StatusBar:",
|
|
X = 0,
|
|
Y = Pos.Bottom (bar) + 1,
|
|
};
|
|
statusBarLikeExamples.Add (label);
|
|
bar = new StatusBar ()
|
|
{
|
|
Id = "statusBar",
|
|
X = Pos.Right (label),
|
|
Y = Pos.Top (label),
|
|
Width = Dim.Fill (),
|
|
};
|
|
ConfigStatusBar (bar);
|
|
statusBarLikeExamples.Add (bar);
|
|
|
|
foreach (FrameView frameView in Application.Top.SubViews.Where (f => f is FrameView)!)
|
|
{
|
|
foreach (Bar barView in frameView.SubViews.Where (b => b is Bar)!)
|
|
{
|
|
foreach (Shortcut sh in barView.SubViews.Where (s => s is Shortcut)!)
|
|
{
|
|
sh.Accepting += (o, args) =>
|
|
{
|
|
eventSource.Add ($"Accept: {sh!.SuperView.Id} {sh!.CommandView.Text}");
|
|
eventLog.MoveDown ();
|
|
//args.Handled = true;
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//private void SetupContentMenu ()
|
|
//{
|
|
// Application.Top.Add (new Label { Text = "Right Click for Context Menu", X = Pos.Center (), Y = 4 });
|
|
// Application.Top.MouseClick += ShowContextMenu;
|
|
//}
|
|
|
|
//private void ShowContextMenu (object s, MouseEventEventArgs e)
|
|
//{
|
|
// if (e.Flags != MouseFlags.Button3Clicked)
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
// var contextMenu = new Bar
|
|
// {
|
|
// Id = "contextMenu",
|
|
// X = e.Position.X,
|
|
// Y = e.Position.Y,
|
|
// Width = Dim.Auto (DimAutoStyle.Content),
|
|
// Height = Dim.Auto (DimAutoStyle.Content),
|
|
// Orientation = Orientation.Vertical,
|
|
// StatusBarStyle = false,
|
|
// BorderStyle = LineStyle.Rounded,
|
|
// Modal = true,
|
|
// };
|
|
|
|
// var newMenu = new Shortcut
|
|
// {
|
|
// Title = "_New...",
|
|
// Text = "Create a new file",
|
|
// Key = Key.N.WithCtrl,
|
|
// CanFocus = true
|
|
// };
|
|
|
|
// newMenu.Accept += (s, e) =>
|
|
// {
|
|
// contextMenu.RequestStop ();
|
|
|
|
// Application.AddTimeout (
|
|
// new TimeSpan (0),
|
|
// () =>
|
|
// {
|
|
// MessageBox.Query ("File", "New");
|
|
|
|
// return false;
|
|
// });
|
|
// };
|
|
|
|
// var open = new Shortcut
|
|
// {
|
|
// Title = "_Open...",
|
|
// Text = "Show the File Open Dialog",
|
|
// Key = Key.O.WithCtrl,
|
|
// CanFocus = true
|
|
// };
|
|
|
|
// open.Accept += (s, e) =>
|
|
// {
|
|
// contextMenu.RequestStop ();
|
|
|
|
// Application.AddTimeout (
|
|
// new TimeSpan (0),
|
|
// () =>
|
|
// {
|
|
// MessageBox.Query ("File", "Open");
|
|
|
|
// return false;
|
|
// });
|
|
// };
|
|
|
|
// var save = new Shortcut
|
|
// {
|
|
// Title = "_Save...",
|
|
// Text = "Save",
|
|
// Key = Key.S.WithCtrl,
|
|
// CanFocus = true
|
|
// };
|
|
|
|
// save.Accept += (s, e) =>
|
|
// {
|
|
// contextMenu.RequestStop ();
|
|
|
|
// Application.AddTimeout (
|
|
// new TimeSpan (0),
|
|
// () =>
|
|
// {
|
|
// MessageBox.Query ("File", "Save");
|
|
|
|
// return false;
|
|
// });
|
|
// };
|
|
|
|
// var saveAs = new Shortcut
|
|
// {
|
|
// Title = "Save _As...",
|
|
// Text = "Save As",
|
|
// Key = Key.A.WithCtrl,
|
|
// CanFocus = true
|
|
// };
|
|
|
|
// saveAs.Accept += (s, e) =>
|
|
// {
|
|
// contextMenu.RequestStop ();
|
|
|
|
// Application.AddTimeout (
|
|
// new TimeSpan (0),
|
|
// () =>
|
|
// {
|
|
// MessageBox.Query ("File", "Save As");
|
|
|
|
// return false;
|
|
// });
|
|
// };
|
|
|
|
// contextMenu.Add (newMenu, open, save, saveAs);
|
|
|
|
// contextMenu.KeyBindings.Add (Key.Esc, Command.QuitToplevel);
|
|
|
|
// contextMenu.Initialized += Menu_Initialized;
|
|
|
|
// void Application_MouseEvent (object sender, MouseEventArgs e)
|
|
// {
|
|
// // If user clicks outside of the menuWindow, close it
|
|
// if (!contextMenu.Frame.Contains (e.Position.X, e.Position.Y))
|
|
// {
|
|
// if (e.Flags is (MouseFlags.Button1Clicked or MouseFlags.Button3Clicked))
|
|
// {
|
|
// contextMenu.RequestStop ();
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// Application.MouseEvent += Application_MouseEvent;
|
|
|
|
// Application.Run (contextMenu);
|
|
// contextMenu.Dispose ();
|
|
|
|
// Application.MouseEvent -= Application_MouseEvent;
|
|
//}
|
|
|
|
|
|
private void ConfigMenuBar (Bar bar)
|
|
{
|
|
var fileMenuBarItem = new Shortcut
|
|
{
|
|
Title = "_File",
|
|
HelpText = "File Menu",
|
|
Key = Key.D0.WithAlt,
|
|
HighlightStyle = HighlightStyle.Hover
|
|
};
|
|
|
|
var editMenuBarItem = new Shortcut
|
|
{
|
|
Title = "_Edit",
|
|
HelpText = "Edit Menu",
|
|
Key = Key.D1.WithAlt,
|
|
HighlightStyle = HighlightStyle.Hover
|
|
};
|
|
|
|
var helpMenuBarItem = new Shortcut
|
|
{
|
|
Title = "_Help",
|
|
HelpText = "Halp Menu",
|
|
Key = Key.D2.WithAlt,
|
|
HighlightStyle = HighlightStyle.Hover
|
|
};
|
|
|
|
bar.Add (fileMenuBarItem, editMenuBarItem, helpMenuBarItem);
|
|
}
|
|
|
|
private void ConfigureMenu (Bar bar)
|
|
{
|
|
|
|
var shortcut1 = new Shortcut
|
|
{
|
|
Title = "Z_igzag",
|
|
Key = Key.I.WithCtrl,
|
|
Text = "Gonna zig zag",
|
|
HighlightStyle = HighlightStyle.Hover
|
|
};
|
|
|
|
var shortcut2 = new Shortcut
|
|
{
|
|
Title = "Za_G",
|
|
Text = "Gonna zag",
|
|
Key = Key.G.WithAlt,
|
|
HighlightStyle = HighlightStyle.Hover
|
|
};
|
|
|
|
var shortcut3 = new Shortcut
|
|
{
|
|
Title = "_Three",
|
|
Text = "The 3rd item",
|
|
Key = Key.D3.WithAlt,
|
|
HighlightStyle = HighlightStyle.Hover
|
|
};
|
|
|
|
var line = new Line ()
|
|
{
|
|
X = -1,
|
|
Width = Dim.Fill ()! + 1
|
|
};
|
|
|
|
var shortcut4 = new Shortcut
|
|
{
|
|
Title = "_Four",
|
|
Text = "Below the line",
|
|
Key = Key.D3.WithAlt,
|
|
HighlightStyle = HighlightStyle.Hover
|
|
};
|
|
|
|
shortcut4.CommandView = new CheckBox ()
|
|
{
|
|
Title = shortcut4.Title,
|
|
HighlightStyle = HighlightStyle.None,
|
|
CanFocus = false
|
|
};
|
|
// This ensures the checkbox state toggles when the hotkey of Title is pressed.
|
|
shortcut4.Accepting += (sender, args) => args.Handled = true;
|
|
|
|
bar.Add (shortcut1, shortcut2, shortcut3, line, shortcut4);
|
|
}
|
|
|
|
public void ConfigStatusBar (Bar bar)
|
|
{
|
|
var shortcut = new Shortcut
|
|
{
|
|
Text = "Quit",
|
|
Title = "Q_uit",
|
|
Key = Key.Z.WithCtrl,
|
|
};
|
|
|
|
bar.Add (shortcut);
|
|
|
|
shortcut = new Shortcut
|
|
{
|
|
Text = "Help Text",
|
|
Title = "Help",
|
|
Key = Key.F1,
|
|
};
|
|
|
|
bar.Add (shortcut);
|
|
|
|
shortcut = new Shortcut
|
|
{
|
|
Title = "_Show/Hide",
|
|
Key = Key.F10,
|
|
CommandView = new CheckBox
|
|
{
|
|
CanFocus = false,
|
|
Text = "_Show/Hide"
|
|
},
|
|
};
|
|
|
|
bar.Add (shortcut);
|
|
|
|
var button1 = new Button
|
|
{
|
|
Text = "I'll Hide",
|
|
// Visible = false
|
|
};
|
|
button1.Accepting += Button_Clicked;
|
|
bar.Add (button1);
|
|
|
|
shortcut.Accepting += (s, e) =>
|
|
{
|
|
button1.Visible = !button1.Visible;
|
|
button1.Enabled = button1.Visible;
|
|
e.Handled = true;
|
|
};
|
|
|
|
bar.Add (new Label
|
|
{
|
|
HotKeySpecifier = new Rune ('_'),
|
|
Text = "Fo_cusLabel",
|
|
CanFocus = true
|
|
});
|
|
|
|
var button2 = new Button
|
|
{
|
|
Text = "Or me!",
|
|
};
|
|
button2.Accepting += (s, e) => Application.RequestStop ();
|
|
|
|
bar.Add (button2);
|
|
|
|
return;
|
|
|
|
void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }
|
|
|
|
}
|
|
|
|
}
|