UICatalogTop.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. using System.Collections.ObjectModel;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using System.Text.Json.Serialization;
  6. using Microsoft.Extensions.Logging;
  7. using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;
  8. #nullable enable
  9. namespace UICatalog;
  10. /// <summary>
  11. /// This is the main UI Catalog app view. It is run fresh when the app loads (if a Scenario has not been passed on
  12. /// the command line) and each time a Scenario ends.
  13. /// </summary>
  14. public class UICatalogTop : Toplevel
  15. {
  16. // When a scenario is run, the main app is killed. The static
  17. // members are cached so that when the scenario exits the
  18. // main app UI can be restored to previous state
  19. // Note, we used to pass this to scenarios that run, but it just added complexity
  20. // So that was removed. But we still have this here to demonstrate how changing
  21. // the scheme works.
  22. public static string? CachedTopLevelScheme { get; set; }
  23. // Diagnostics
  24. private static ViewDiagnosticFlags _diagnosticFlags;
  25. public UICatalogTop ()
  26. {
  27. _diagnosticFlags = Diagnostics;
  28. _menuBar = CreateMenuBar ();
  29. _statusBar = CreateStatusBar ();
  30. _categoryList = CreateCategoryList ();
  31. _scenarioList = CreateScenarioList ();
  32. Add (_menuBar, _categoryList, _scenarioList, _statusBar);
  33. Loaded += LoadedHandler;
  34. Unloaded += UnloadedHandler;
  35. // Restore previous selections
  36. _categoryList.SelectedItem = _cachedCategoryIndex;
  37. _scenarioList.SelectedRow = _cachedScenarioIndex;
  38. SchemeName = CachedTopLevelScheme = SchemeManager.SchemesToSchemeName (Schemes.Base);
  39. ConfigurationManager.Applied += ConfigAppliedHandler;
  40. }
  41. private static bool _isFirstRunning = true;
  42. private void LoadedHandler (object? sender, EventArgs? args)
  43. {
  44. if (_disableMouseCb is { })
  45. {
  46. _disableMouseCb.CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked;
  47. }
  48. if (_shVersion is { })
  49. {
  50. _shVersion.Title = $"{RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}, {Application.Driver!.GetVersionInfo ()}";
  51. }
  52. if (CachedSelectedScenario != null)
  53. {
  54. CachedSelectedScenario = null;
  55. _isFirstRunning = false;
  56. }
  57. if (!_isFirstRunning)
  58. {
  59. _scenarioList.SetFocus ();
  60. }
  61. if (_statusBar is { })
  62. {
  63. _statusBar.VisibleChanged += (s, e) => { ShowStatusBar = _statusBar.Visible; };
  64. }
  65. Loaded -= LoadedHandler;
  66. _categoryList!.EnsureSelectedItemVisible ();
  67. _scenarioList.EnsureSelectedCellIsVisible ();
  68. }
  69. private void UnloadedHandler (object? sender, EventArgs? args)
  70. {
  71. ConfigurationManager.Applied -= ConfigAppliedHandler;
  72. Unloaded -= UnloadedHandler;
  73. }
  74. #region MenuBar
  75. private readonly MenuBarv2? _menuBar;
  76. private CheckBox? _force16ColorsMenuItemCb;
  77. private OptionSelector? _themesSelector;
  78. private OptionSelector? _topSchemesSelector;
  79. private OptionSelector? _logLevelSelector;
  80. private FlagSelector<ViewDiagnosticFlags>? _diagnosticFlagsSelector;
  81. private CheckBox? _disableMouseCb;
  82. private MenuBarv2 CreateMenuBar ()
  83. {
  84. MenuBarv2 menuBar = new (
  85. [
  86. new (
  87. "_File",
  88. [
  89. new MenuItemv2 ()
  90. {
  91. Title ="_Quit",
  92. HelpText = "Quit UI Catalog",
  93. Key = Application.QuitKey,
  94. // By not specifying TargetView the Key Binding will be Application-level
  95. Command = Command.Quit
  96. }
  97. ]),
  98. new ("_Themes", CreateThemeMenuItems ()),
  99. new ("Diag_nostics", CreateDiagnosticMenuItems ()),
  100. new ("_Logging", CreateLoggingMenuItems ()),
  101. new (
  102. "_Help",
  103. [
  104. new MenuItemv2 (
  105. "_Documentation",
  106. "API docs",
  107. () => OpenUrl ("https://gui-cs.github.io/Terminal.Gui"),
  108. Key.F1
  109. ),
  110. new MenuItemv2 (
  111. "_README",
  112. "Project readme",
  113. () => OpenUrl ("https://github.com/gui-cs/Terminal.Gui"),
  114. Key.F2
  115. ),
  116. new MenuItemv2 (
  117. "_About...",
  118. "About UI Catalog",
  119. () => MessageBox.Query (
  120. "",
  121. GetAboutBoxMessage (),
  122. wrapMessage: false,
  123. buttons: "_Ok"
  124. ),
  125. Key.A.WithCtrl
  126. )
  127. ])
  128. ])
  129. {
  130. Title = "menuBar",
  131. Id = "menuBar"
  132. };
  133. return menuBar;
  134. View [] CreateThemeMenuItems ()
  135. {
  136. List<View> menuItems = [];
  137. _force16ColorsMenuItemCb = new ()
  138. {
  139. Title = "Force _16 Colors",
  140. CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
  141. // Best practice for CheckBoxes in menus is to disable focus and highlight states
  142. CanFocus = false,
  143. HighlightStates = MouseState.None
  144. };
  145. _force16ColorsMenuItemCb.CheckedStateChanging += (sender, args) =>
  146. {
  147. if (Application.Force16Colors
  148. && args.Result == CheckState.UnChecked
  149. && !Application.Driver!.SupportsTrueColor)
  150. {
  151. args.Handled = true;
  152. }
  153. };
  154. _force16ColorsMenuItemCb.CheckedStateChanged += (sender, args) =>
  155. {
  156. Application.Force16Colors = args.Value == CheckState.Checked;
  157. _force16ColorsShortcutCb!.CheckedState = args.Value;
  158. Application.LayoutAndDraw ();
  159. };
  160. menuItems.Add (
  161. new MenuItemv2
  162. {
  163. CommandView = _force16ColorsMenuItemCb
  164. });
  165. menuItems.Add (new Line ());
  166. if (ConfigurationManager.IsEnabled)
  167. {
  168. _themesSelector = new ()
  169. {
  170. // HighlightStates = MouseState.In,
  171. CanFocus = true,
  172. // InvertFocusAttribute = true
  173. };
  174. _themesSelector.ValueChanged += (_, args) =>
  175. {
  176. if (args.Value is null)
  177. {
  178. return;
  179. }
  180. ThemeManager.Theme = ThemeManager.GetThemeNames () [(int)args.Value];
  181. };
  182. var menuItem = new MenuItemv2
  183. {
  184. CommandView = _themesSelector,
  185. HelpText = "Cycle Through Themes",
  186. Key = Key.T.WithCtrl
  187. };
  188. menuItems.Add (menuItem);
  189. menuItems.Add (new Line ());
  190. _topSchemesSelector = new ()
  191. {
  192. // HighlightStates = MouseState.In,
  193. };
  194. _topSchemesSelector.ValueChanged += (_, args) =>
  195. {
  196. if (args.Value is null)
  197. {
  198. return;
  199. }
  200. CachedTopLevelScheme = SchemeManager.GetSchemesForCurrentTheme ()!.Keys.ToArray () [(int)args.Value];
  201. SchemeName = CachedTopLevelScheme;
  202. SetNeedsDraw ();
  203. };
  204. menuItem = new ()
  205. {
  206. Title = "Scheme for Toplevel",
  207. SubMenu = new (
  208. [
  209. new ()
  210. {
  211. CommandView = _topSchemesSelector,
  212. HelpText = "Cycle Through schemes",
  213. Key = Key.S.WithCtrl
  214. }
  215. ])
  216. };
  217. menuItems.Add (menuItem);
  218. UpdateThemesMenu ();
  219. }
  220. else
  221. {
  222. menuItems.Add (new MenuItemv2 ()
  223. {
  224. Title = "Configuration Manager is not Enabled",
  225. Enabled = false
  226. });
  227. }
  228. return menuItems.ToArray ();
  229. }
  230. View [] CreateDiagnosticMenuItems ()
  231. {
  232. List<View> menuItems = [];
  233. _diagnosticFlagsSelector = new ()
  234. {
  235. Styles = SelectorStyles.ShowNoneFlag,
  236. CanFocus = true
  237. };
  238. _diagnosticFlagsSelector.UsedHotKeys.Add (Key.D);
  239. _diagnosticFlagsSelector.AssignHotKeys = true;
  240. _diagnosticFlagsSelector.Value = Diagnostics;
  241. _diagnosticFlagsSelector.ValueChanged += (sender, args) =>
  242. {
  243. _diagnosticFlags = (ViewDiagnosticFlags)_diagnosticFlagsSelector.Value;
  244. Diagnostics = _diagnosticFlags;
  245. };
  246. menuItems.Add (
  247. new MenuItemv2
  248. {
  249. CommandView = _diagnosticFlagsSelector,
  250. HelpText = "View Diagnostics"
  251. });
  252. menuItems.Add (new Line ());
  253. _disableMouseCb = new ()
  254. {
  255. Title = "_Disable Mouse",
  256. CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked,
  257. // Best practice for CheckBoxes in menus is to disable focus and highlight states
  258. CanFocus = false,
  259. HighlightStates = MouseState.None
  260. };
  261. _disableMouseCb.CheckedStateChanged += (_, args) => { Application.IsMouseDisabled = args.Value == CheckState.Checked; };
  262. menuItems.Add (
  263. new MenuItemv2
  264. {
  265. CommandView = _disableMouseCb,
  266. HelpText = "Disable Mouse"
  267. });
  268. return menuItems.ToArray ();
  269. }
  270. View [] CreateLoggingMenuItems ()
  271. {
  272. List<View?> menuItems = [];
  273. LogLevel [] logLevels = Enum.GetValues<LogLevel> ();
  274. _logLevelSelector = new ()
  275. {
  276. AssignHotKeys = true,
  277. Labels = Enum.GetNames<LogLevel> (),
  278. Value = logLevels.ToList ().IndexOf (Enum.Parse<LogLevel> (UICatalog.Options.DebugLogLevel)),
  279. // HighlightStates = MouseState.In,
  280. };
  281. _logLevelSelector.ValueChanged += (_, args) =>
  282. {
  283. UICatalog.Options = UICatalog.Options with { DebugLogLevel = Enum.GetName (logLevels [args.Value!.Value])! };
  284. UICatalog.LogLevelSwitch.MinimumLevel =
  285. UICatalog.LogLevelToLogEventLevel (Enum.Parse<LogLevel> (UICatalog.Options.DebugLogLevel));
  286. };
  287. menuItems.Add (
  288. new MenuItemv2
  289. {
  290. CommandView = _logLevelSelector,
  291. HelpText = "Cycle Through Log Levels",
  292. Key = Key.L.WithCtrl
  293. });
  294. // add a separator
  295. menuItems.Add (new Line ());
  296. menuItems.Add (
  297. new MenuItemv2 (
  298. "_Open Log Folder",
  299. string.Empty,
  300. () => OpenUrl (UICatalog.LOGFILE_LOCATION)
  301. ));
  302. return menuItems.ToArray ()!;
  303. }
  304. }
  305. private void UpdateThemesMenu ()
  306. {
  307. if (_themesSelector is null)
  308. {
  309. return;
  310. }
  311. _themesSelector.Value = null;
  312. _themesSelector.AssignHotKeys = true;
  313. _themesSelector.UsedHotKeys.Clear ();
  314. _themesSelector.Labels = ThemeManager.GetThemeNames ().ToArray ();
  315. _themesSelector.Value = ThemeManager.GetThemeNames ().IndexOf (ThemeManager.GetCurrentThemeName ());
  316. if (_topSchemesSelector is null)
  317. {
  318. return;
  319. }
  320. _topSchemesSelector.AssignHotKeys = true;
  321. _topSchemesSelector.UsedHotKeys.Clear ();
  322. int? selectedScheme = _topSchemesSelector.Value;
  323. _topSchemesSelector.Labels = SchemeManager.GetSchemeNames ().ToArray ();
  324. _topSchemesSelector.Value = selectedScheme;
  325. if (CachedTopLevelScheme is null || !SchemeManager.GetSchemeNames ().Contains (CachedTopLevelScheme))
  326. {
  327. CachedTopLevelScheme = SchemeManager.SchemesToSchemeName (Schemes.Base);
  328. }
  329. int newSelectedItem = SchemeManager.GetSchemeNames ().IndexOf (CachedTopLevelScheme!);
  330. // if the item is in bounds then select it
  331. if (newSelectedItem >= 0 && newSelectedItem < SchemeManager.GetSchemeNames ().Count)
  332. {
  333. _topSchemesSelector.Value = newSelectedItem;
  334. }
  335. }
  336. #endregion MenuBar
  337. #region Scenario List
  338. private readonly TableView _scenarioList;
  339. private static int _cachedScenarioIndex;
  340. public static ObservableCollection<Scenario>? CachedScenarios { get; set; }
  341. // If set, holds the scenario the user selected to run
  342. public static Scenario? CachedSelectedScenario { get; set; }
  343. private TableView CreateScenarioList ()
  344. {
  345. // Create the scenario list. The contents of the scenario list changes whenever the
  346. // Category list selection changes (to show just the scenarios that belong to the selected
  347. // category).
  348. TableView scenarioList = new ()
  349. {
  350. X = Pos.Right (_categoryList!) - 1,
  351. Y = Pos.Bottom (_menuBar!),
  352. Width = Dim.Fill (),
  353. Height = Dim.Fill (Dim.Func (v => v!.Frame.Height, _statusBar)),
  354. //AllowsMarking = false,
  355. CanFocus = true,
  356. Title = "_Scenarios",
  357. BorderStyle = _categoryList!.BorderStyle,
  358. SuperViewRendersLineCanvas = true
  359. };
  360. // TableView provides many options for table headers. For simplicity, we turn all
  361. // of these off. By enabling FullRowSelect and turning off headers, TableView looks just
  362. // like a ListView
  363. scenarioList.FullRowSelect = true;
  364. scenarioList.Style.ShowHeaders = false;
  365. scenarioList.Style.ShowHorizontalHeaderOverline = false;
  366. scenarioList.Style.ShowHorizontalHeaderUnderline = false;
  367. scenarioList.Style.ShowHorizontalBottomline = false;
  368. scenarioList.Style.ShowVerticalCellLines = false;
  369. scenarioList.Style.ShowVerticalHeaderLines = false;
  370. /* By default, TableView lays out columns at render time and only
  371. * measures y rows of data at a time. Where y is the height of the
  372. * console. This is for the following reasons:
  373. *
  374. * - Performance, when tables have a large amount of data
  375. * - Defensive, prevents a single wide cell value pushing other
  376. * columns off-screen (requiring horizontal scrolling
  377. *
  378. * In the case of UICatalog here, such an approach is overkill so
  379. * we just measure all the data ourselves and set the appropriate
  380. * max widths as ColumnStyles
  381. */
  382. int longestName = CachedScenarios!.Max (s => s.GetName ().Length);
  383. scenarioList.Style.ColumnStyles.Add (
  384. 0,
  385. new () { MaxWidth = longestName, MinWidth = longestName, MinAcceptableWidth = longestName }
  386. );
  387. scenarioList.Style.ColumnStyles.Add (1, new () { MaxWidth = 1 });
  388. scenarioList.CellActivated += ScenarioView_OpenSelectedItem;
  389. // TableView typically is a grid where nav keys are biased for moving left/right.
  390. scenarioList.KeyBindings.Remove (Key.Home);
  391. scenarioList.KeyBindings.Add (Key.Home, Command.Start);
  392. scenarioList.KeyBindings.Remove (Key.End);
  393. scenarioList.KeyBindings.Add (Key.End, Command.End);
  394. // Ideally, TableView.MultiSelect = false would turn off any keybindings for
  395. // multi-select options. But it currently does not. UI Catalog uses Ctrl-A for
  396. // a shortcut to About.
  397. scenarioList.MultiSelect = false;
  398. scenarioList.KeyBindings.Remove (Key.A.WithCtrl);
  399. return scenarioList;
  400. }
  401. /// <summary>Launches the selected scenario, setting the global _selectedScenario</summary>
  402. /// <param name="e"></param>
  403. private void ScenarioView_OpenSelectedItem (object? sender, EventArgs? e)
  404. {
  405. if (CachedSelectedScenario is null)
  406. {
  407. // Save selected item state
  408. _cachedCategoryIndex = _categoryList!.SelectedItem;
  409. _cachedScenarioIndex = _scenarioList.SelectedRow;
  410. // Create new instance of scenario (even though Scenarios contains instances)
  411. var selectedScenarioName = (string)_scenarioList.Table [_scenarioList.SelectedRow, 0];
  412. CachedSelectedScenario = (Scenario)Activator.CreateInstance (
  413. CachedScenarios!.FirstOrDefault (
  414. s => s.GetName ()
  415. == selectedScenarioName
  416. )!
  417. .GetType ()
  418. )!;
  419. // Tell the main app to stop
  420. Application.RequestStop ();
  421. }
  422. }
  423. #endregion Scenario List
  424. #region Category List
  425. private readonly ListView? _categoryList;
  426. private static int _cachedCategoryIndex;
  427. public static ObservableCollection<string>? CachedCategories { get; set; }
  428. private ListView CreateCategoryList ()
  429. {
  430. // Create the Category list view. This list never changes.
  431. ListView categoryList = new ()
  432. {
  433. X = 0,
  434. Y = Pos.Bottom (_menuBar!),
  435. Width = Dim.Auto (),
  436. Height = Dim.Fill (Dim.Func (v => v!.Frame.Height, _statusBar)),
  437. AllowsMarking = false,
  438. CanFocus = true,
  439. Title = "_Categories",
  440. BorderStyle = LineStyle.Rounded,
  441. SuperViewRendersLineCanvas = true,
  442. Source = new ListWrapper<string> (CachedCategories)
  443. };
  444. categoryList.OpenSelectedItem += (s, a) => { _scenarioList!.SetFocus (); };
  445. categoryList.SelectedItemChanged += CategoryView_SelectedChanged;
  446. // This enables the scrollbar by causing lazy instantiation to happen
  447. categoryList.VerticalScrollBar.AutoShow = true;
  448. return categoryList;
  449. }
  450. private void CategoryView_SelectedChanged (object? sender, ListViewItemEventArgs? e)
  451. {
  452. string item = CachedCategories! [e!.Item];
  453. ObservableCollection<Scenario> newScenarioList;
  454. if (e.Item == 0)
  455. {
  456. // First category is "All"
  457. newScenarioList = CachedScenarios!;
  458. }
  459. else
  460. {
  461. newScenarioList = new (CachedScenarios!.Where (s => s.GetCategories ().Contains (item)).ToList ());
  462. }
  463. _scenarioList.Table = new EnumerableTableSource<Scenario> (
  464. newScenarioList,
  465. new ()
  466. {
  467. { "Name", s => s.GetName () }, { "Description", s => s.GetDescription () }
  468. }
  469. );
  470. }
  471. #endregion Category List
  472. #region StatusBar
  473. private readonly StatusBar? _statusBar;
  474. [ConfigurationProperty (Scope = typeof (AppSettingsScope), OmitClassName = true)]
  475. [JsonPropertyName ("UICatalog.StatusBar")]
  476. public static bool ShowStatusBar { get; set; } = true;
  477. private Shortcut? _shQuit;
  478. private Shortcut? _shVersion;
  479. private CheckBox? _force16ColorsShortcutCb;
  480. private StatusBar CreateStatusBar ()
  481. {
  482. StatusBar statusBar = new ()
  483. {
  484. Visible = ShowStatusBar,
  485. AlignmentModes = AlignmentModes.IgnoreFirstOrLast,
  486. CanFocus = false
  487. };
  488. // ReSharper disable All
  489. statusBar.Height = Dim.Auto (
  490. DimAutoStyle.Auto,
  491. minimumContentDim: Dim.Func (_ => statusBar.Visible ? 1 : 0),
  492. maximumContentDim: Dim.Func (_ => statusBar.Visible ? 1 : 0));
  493. // ReSharper restore All
  494. _shQuit = new ()
  495. {
  496. CanFocus = false,
  497. Title = "Quit",
  498. Key = Application.QuitKey
  499. };
  500. _shVersion = new ()
  501. {
  502. Title = "Version Info",
  503. CanFocus = false
  504. };
  505. var statusBarShortcut = new Shortcut
  506. {
  507. Key = Key.F10,
  508. Title = "Show/Hide Status Bar",
  509. CanFocus = false
  510. };
  511. statusBarShortcut.Accepting += (sender, args) =>
  512. {
  513. statusBar.Visible = !_statusBar!.Visible;
  514. args.Handled = true;
  515. };
  516. _force16ColorsShortcutCb = new ()
  517. {
  518. Title = "16 color mode",
  519. CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
  520. CanFocus = false
  521. };
  522. _force16ColorsShortcutCb.CheckedStateChanging += (sender, args) =>
  523. {
  524. if (Application.Force16Colors
  525. && args.Result == CheckState.UnChecked
  526. && !Application.Driver!.SupportsTrueColor)
  527. {
  528. // If the driver does not support TrueColor, we cannot disable 16 colors
  529. args.Handled = true;
  530. }
  531. };
  532. _force16ColorsShortcutCb.CheckedStateChanged += (sender, args) =>
  533. {
  534. Application.Force16Colors = args.Value == CheckState.Checked;
  535. _force16ColorsMenuItemCb!.CheckedState = args.Value;
  536. Application.LayoutAndDraw ();
  537. };
  538. statusBar.Add (
  539. _shQuit,
  540. statusBarShortcut,
  541. new Shortcut
  542. {
  543. CanFocus = false,
  544. CommandView = _force16ColorsShortcutCb,
  545. HelpText = "",
  546. BindKeyToApplication = true,
  547. Key = Key.F7
  548. },
  549. _shVersion
  550. );
  551. if (UICatalog.Options.DontEnableConfigurationManagement)
  552. {
  553. statusBar.AddShortcutAt (statusBar.SubViews.ToList ().IndexOf (_shVersion), new Shortcut () { Title = "CM is Disabled" });
  554. }
  555. return statusBar;
  556. }
  557. #endregion StatusBar
  558. #region Configuration Manager
  559. /// <summary>
  560. /// Called when CM has applied changes.
  561. /// </summary>
  562. private void ConfigApplied ()
  563. {
  564. UpdateThemesMenu ();
  565. SchemeName = CachedTopLevelScheme;
  566. if (_shQuit is { })
  567. {
  568. _shQuit.Key = Application.QuitKey;
  569. }
  570. if (_statusBar is { })
  571. {
  572. _statusBar.Visible = ShowStatusBar;
  573. }
  574. _disableMouseCb!.CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked;
  575. _force16ColorsShortcutCb!.CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked;
  576. Application.Current?.SetNeedsDraw ();
  577. }
  578. private void ConfigAppliedHandler (object? sender, ConfigurationManagerEventArgs? a) { ConfigApplied (); }
  579. #endregion Configuration Manager
  580. /// <summary>
  581. /// Gets the message displayed in the About Box. `public` so it can be used from Unit tests.
  582. /// </summary>
  583. /// <returns></returns>
  584. public static string GetAboutBoxMessage ()
  585. {
  586. // NOTE: Do not use multiline verbatim strings here.
  587. // WSL gets all confused.
  588. StringBuilder msg = new ();
  589. msg.AppendLine ("UI Catalog: A comprehensive sample library and test app for");
  590. msg.AppendLine ();
  591. msg.AppendLine (
  592. """
  593. _______ _ _ _____ _
  594. |__ __| (_) | | / ____| (_)
  595. | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _
  596. | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
  597. | | __/ | | | | | | | | | | | (_| | || |__| | |_| | |
  598. |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
  599. """);
  600. msg.AppendLine ();
  601. msg.AppendLine ("v2 - Pre-Alpha");
  602. msg.AppendLine ();
  603. msg.AppendLine ("https://github.com/gui-cs/Terminal.Gui");
  604. return msg.ToString ();
  605. }
  606. public static void OpenUrl (string url)
  607. {
  608. if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows))
  609. {
  610. url = url.Replace ("&", "^&");
  611. Process.Start (new ProcessStartInfo ("cmd", $"/c start {url}") { CreateNoWindow = true });
  612. }
  613. else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux))
  614. {
  615. using var process = new Process
  616. {
  617. StartInfo = new ()
  618. {
  619. FileName = "xdg-open",
  620. Arguments = url,
  621. RedirectStandardError = true,
  622. RedirectStandardOutput = true,
  623. CreateNoWindow = true,
  624. UseShellExecute = false
  625. }
  626. };
  627. process.Start ();
  628. }
  629. else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX))
  630. {
  631. Process.Start ("open", url);
  632. }
  633. }
  634. }