UICatalog.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. using NStack;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using Terminal.Gui;
  10. using Microsoft.DotNet.PlatformAbstractions;
  11. using Rune = System.Rune;
  12. /// <summary>
  13. /// UI Catalog is a comprehensive sample library for Terminal.Gui. It provides a simple UI for adding to the catalog of scenarios.
  14. /// </summary>
  15. /// <remarks>
  16. /// <para>
  17. /// UI Catalog attempts to satisfy the following goals:
  18. /// </para>
  19. /// <para>
  20. /// <list type="number">
  21. /// <item>
  22. /// <description>
  23. /// Be an easy to use showcase for Terminal.Gui concepts and features.
  24. /// </description>
  25. /// </item>
  26. /// <item>
  27. /// <description>
  28. /// Provide sample code that illustrates how to properly implement said concepts & features.
  29. /// </description>
  30. /// </item>
  31. /// <item>
  32. /// <description>
  33. /// Make it easy for contributors to add additional samples in a structured way.
  34. /// </description>
  35. /// </item>
  36. /// </list>
  37. /// </para>
  38. /// <para>
  39. /// See the project README for more details (https://github.com/gui-cs/Terminal.Gui/tree/master/UICatalog/README.md).
  40. /// </para>
  41. /// </remarks>
  42. namespace UICatalog {
  43. /// <summary>
  44. /// UI Catalog is a comprehensive sample app and scenario library for <see cref="Terminal.Gui"/>
  45. /// </summary>
  46. class UICatalogApp {
  47. static void Main (string [] args)
  48. {
  49. Console.OutputEncoding = Encoding.Default;
  50. if (Debugger.IsAttached) {
  51. CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
  52. }
  53. _scenarios = Scenario.GetScenarios ();
  54. _categories = Scenario.GetAllCategories ();
  55. _nameColumnWidth = _scenarios.OrderByDescending (s => s.GetName ().Length).FirstOrDefault ().GetName ().Length;
  56. if (args.Length > 0 && args.Contains ("-usc")) {
  57. _useSystemConsole = true;
  58. args = args.Where (val => val != "-usc").ToArray ();
  59. }
  60. // If a Scenario name has been provided on the commandline
  61. // run it and exit when done.
  62. if (args.Length > 0) {
  63. var item = _scenarios.FindIndex (s => s.GetName ().Equals (args [0], StringComparison.OrdinalIgnoreCase));
  64. _selectedScenario = (Scenario)Activator.CreateInstance (_scenarios [item].GetType ());
  65. Application.UseSystemConsole = _useSystemConsole;
  66. Application.Init ();
  67. _selectedScenario.Init (_colorScheme);
  68. _selectedScenario.Setup ();
  69. _selectedScenario.Run ();
  70. _selectedScenario.Dispose ();
  71. _selectedScenario = null;
  72. Application.Shutdown ();
  73. return;
  74. }
  75. _aboutMessage = new StringBuilder ();
  76. _aboutMessage.AppendLine (@"A comprehensive sample library for");
  77. _aboutMessage.AppendLine (@"");
  78. _aboutMessage.AppendLine (@" _______ _ _ _____ _ ");
  79. _aboutMessage.AppendLine (@" |__ __| (_) | | / ____| (_) ");
  80. _aboutMessage.AppendLine (@" | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _ ");
  81. _aboutMessage.AppendLine (@" | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | | ");
  82. _aboutMessage.AppendLine (@" | | __/ | | | | | | | | | | | (_| | || |__| | |_| | | ");
  83. _aboutMessage.AppendLine (@" |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_| ");
  84. _aboutMessage.AppendLine (@"");
  85. _aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");
  86. Scenario scenario;
  87. while ((scenario = RunUICatalogTopLevel ()) != null) {
  88. VerifyObjectsWereDisposed ();
  89. scenario.Init (_colorScheme);
  90. scenario.Setup ();
  91. scenario.Run ();
  92. scenario.Dispose ();
  93. // This call to Application.Shutdown brackets the Application.Init call
  94. // made by Scenario.Init() above
  95. Application.Shutdown ();
  96. VerifyObjectsWereDisposed ();
  97. }
  98. VerifyObjectsWereDisposed ();
  99. }
  100. /// <summary>
  101. /// Shows the UI Catalog selection UI. When the user selects a Scenario to run, the
  102. /// UI Catalog main app UI is killed and the Scenario is run as though it were Application.Top.
  103. /// When the Scenario exits, this function exits.
  104. /// </summary>
  105. /// <returns></returns>
  106. static Scenario RunUICatalogTopLevel ()
  107. {
  108. Application.UseSystemConsole = _useSystemConsole;
  109. // Run UI Catalog UI. When it exits, if _selectedScenario is != null then
  110. // a Scenario was selected. Otherwise, the user wants to exit UI Catalog.
  111. Application.Init ();
  112. Application.Run<UICatalogTopLevel> ();
  113. Application.Shutdown ();
  114. return _selectedScenario;
  115. }
  116. static List<Scenario> _scenarios;
  117. static List<string> _categories;
  118. static int _nameColumnWidth;
  119. // When a scenario is run, the main app is killed. These items
  120. // are therefore cached so that when the scenario exits the
  121. // main app UI can be restored to previous state
  122. static int _cachedScenarioIndex = 0;
  123. static int _cachedCategoryIndex = 0;
  124. static StringBuilder _aboutMessage;
  125. // If set, holds the scenario the user selected
  126. static Scenario _selectedScenario = null;
  127. static bool _useSystemConsole = false;
  128. static ConsoleDriver.DiagnosticFlags _diagnosticFlags;
  129. static bool _isFirstRunning = true;
  130. static ColorScheme _colorScheme;
  131. /// <summary>
  132. /// This is the main UI Catalog app view. It is run fresh when the app loads (if a Scenario has not been passed on
  133. /// the command line) and each time a Scenario ends.
  134. /// </summary>
  135. class UICatalogTopLevel : Toplevel {
  136. public MenuItem miIsMouseDisabled;
  137. public FrameView LeftPane;
  138. public ListView CategoryListView;
  139. public FrameView RightPane;
  140. public ListView ScenarioListView;
  141. public StatusItem Capslock;
  142. public StatusItem Numlock;
  143. public StatusItem Scrolllock;
  144. public StatusItem DriverName;
  145. public StatusItem OS;
  146. public UICatalogTopLevel ()
  147. {
  148. ColorScheme = _colorScheme = Colors.Base;
  149. MenuBar = new MenuBar (new MenuBarItem [] {
  150. new MenuBarItem ("_File", new MenuItem [] {
  151. new MenuItem ("_Quit", "Quit UI Catalog", () => RequestStop(), null, null, Key.Q | Key.CtrlMask)
  152. }),
  153. new MenuBarItem ("_Color Scheme", CreateColorSchemeMenuItems()),
  154. new MenuBarItem ("Diag_nostics", CreateDiagnosticMenuItems()),
  155. new MenuBarItem ("_Help", new MenuItem [] {
  156. new MenuItem ("_gui.cs API Overview", "", () => OpenUrl ("https://gui-cs.github.io/Terminal.Gui/articles/overview.html"), null, null, Key.F1),
  157. new MenuItem ("gui.cs _README", "", () => OpenUrl ("https://github.com/gui-cs/Terminal.Gui"), null, null, Key.F2),
  158. new MenuItem ("_About...",
  159. "About UI Catalog", () => MessageBox.Query ("About UI Catalog", _aboutMessage.ToString(), "_Ok"), null, null, Key.CtrlMask | Key.A),
  160. }),
  161. });
  162. Capslock = new StatusItem (Key.CharMask, "Caps", null);
  163. Numlock = new StatusItem (Key.CharMask, "Num", null);
  164. Scrolllock = new StatusItem (Key.CharMask, "Scroll", null);
  165. DriverName = new StatusItem (Key.CharMask, "Driver:", null);
  166. OS = new StatusItem (Key.CharMask, "OS:", null);
  167. StatusBar = new StatusBar () {
  168. Visible = true,
  169. };
  170. StatusBar.Items = new StatusItem [] {
  171. new StatusItem(Key.Q | Key.CtrlMask, "~CTRL-Q~ Quit", () => {
  172. if (_selectedScenario is null){
  173. // This causes GetScenarioToRun to return null
  174. _selectedScenario = null;
  175. RequestStop();
  176. } else {
  177. _selectedScenario.RequestStop();
  178. }
  179. }),
  180. new StatusItem(Key.F10, "~F10~ Status Bar", () => {
  181. StatusBar.Visible = !StatusBar.Visible;
  182. LeftPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
  183. RightPane.Height = Dim.Fill(StatusBar.Visible ? 1 : 0);
  184. LayoutSubviews();
  185. SetChildNeedsDisplay();
  186. }),
  187. DriverName,
  188. OS
  189. };
  190. LeftPane = new FrameView ("Categories") {
  191. X = 0,
  192. Y = 1, // for menu
  193. Width = 25,
  194. Height = Dim.Fill (1),
  195. CanFocus = true,
  196. Shortcut = Key.CtrlMask | Key.C
  197. };
  198. LeftPane.Title = $"{LeftPane.Title} ({LeftPane.ShortcutTag})";
  199. LeftPane.ShortcutAction = () => LeftPane.SetFocus ();
  200. CategoryListView = new ListView (_categories) {
  201. X = 0,
  202. Y = 0,
  203. Width = Dim.Fill (0),
  204. Height = Dim.Fill (0),
  205. AllowsMarking = false,
  206. CanFocus = true,
  207. };
  208. CategoryListView.OpenSelectedItem += (a) => {
  209. RightPane.SetFocus ();
  210. };
  211. CategoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
  212. LeftPane.Add (CategoryListView);
  213. RightPane = new FrameView ("Scenarios") {
  214. X = 25,
  215. Y = 1, // for menu
  216. Width = Dim.Fill (),
  217. Height = Dim.Fill (1),
  218. CanFocus = true,
  219. Shortcut = Key.CtrlMask | Key.S
  220. };
  221. RightPane.Title = $"{RightPane.Title} ({RightPane.ShortcutTag})";
  222. RightPane.ShortcutAction = () => RightPane.SetFocus ();
  223. ScenarioListView = new ListView () {
  224. X = 0,
  225. Y = 0,
  226. Width = Dim.Fill (0),
  227. Height = Dim.Fill (0),
  228. AllowsMarking = false,
  229. CanFocus = true,
  230. };
  231. ScenarioListView.OpenSelectedItem += ScenarioListView_OpenSelectedItem;
  232. RightPane.Add (ScenarioListView);
  233. KeyDown += KeyDownHandler;
  234. Add (MenuBar);
  235. Add (LeftPane);
  236. Add (RightPane);
  237. Add (StatusBar);
  238. Loaded += LoadedHandler;
  239. // Restore previous selections
  240. CategoryListView.SelectedItem = _cachedCategoryIndex;
  241. ScenarioListView.SelectedItem = _cachedScenarioIndex;
  242. }
  243. void LoadedHandler ()
  244. {
  245. if (_colorScheme == null) {
  246. ColorScheme = _colorScheme = Colors.Base;
  247. }
  248. miIsMouseDisabled.Checked = Application.IsMouseDisabled;
  249. DriverName.Title = $"Driver: {Driver.GetType ().Name}";
  250. OS.Title = $"OS: {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem} {Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion}";
  251. if (_selectedScenario != null) {
  252. _selectedScenario = null;
  253. _isFirstRunning = false;
  254. }
  255. if (!_isFirstRunning) {
  256. RightPane.SetFocus ();
  257. }
  258. Loaded -= LoadedHandler;
  259. }
  260. /// <summary>
  261. /// Launches the selected scenario, setting the global _selectedScenario
  262. /// </summary>
  263. /// <param name="e"></param>
  264. void ScenarioListView_OpenSelectedItem (EventArgs e)
  265. {
  266. if (_selectedScenario is null) {
  267. // Save selected item state
  268. _cachedCategoryIndex = CategoryListView.SelectedItem;
  269. _cachedScenarioIndex = ScenarioListView.SelectedItem;
  270. // Create new instance of scenario (even though Scenarios contains instances)
  271. _selectedScenario = (Scenario)Activator.CreateInstance (ScenarioListView.Source.ToList () [ScenarioListView.SelectedItem].GetType ());
  272. // Tell the main app to stop
  273. Application.RequestStop ();
  274. }
  275. }
  276. List<MenuItem []> CreateDiagnosticMenuItems ()
  277. {
  278. List<MenuItem []> menuItems = new List<MenuItem []> ();
  279. menuItems.Add (CreateDiagnosticFlagsMenuItems ());
  280. menuItems.Add (new MenuItem [] { null });
  281. menuItems.Add (CreateDisabledEnabledMouseItems ());
  282. menuItems.Add (CreateKeybindingsMenuItems ());
  283. return menuItems;
  284. }
  285. MenuItem [] CreateDisabledEnabledMouseItems ()
  286. {
  287. List<MenuItem> menuItems = new List<MenuItem> ();
  288. miIsMouseDisabled = new MenuItem ();
  289. miIsMouseDisabled.Title = "_Disable Mouse";
  290. miIsMouseDisabled.Shortcut = Key.CtrlMask | Key.AltMask | (Key)miIsMouseDisabled.Title.ToString ().Substring (1, 1) [0];
  291. miIsMouseDisabled.CheckType |= MenuItemCheckStyle.Checked;
  292. miIsMouseDisabled.Action += () => {
  293. miIsMouseDisabled.Checked = Application.IsMouseDisabled = !miIsMouseDisabled.Checked;
  294. };
  295. menuItems.Add (miIsMouseDisabled);
  296. return menuItems.ToArray ();
  297. }
  298. MenuItem [] CreateKeybindingsMenuItems ()
  299. {
  300. List<MenuItem> menuItems = new List<MenuItem> ();
  301. var item = new MenuItem ();
  302. item.Title = "_Key Bindings";
  303. item.Help = "Change which keys do what";
  304. item.Action += () => {
  305. var dlg = new KeyBindingsDialog ();
  306. Application.Run (dlg);
  307. };
  308. menuItems.Add (null);
  309. menuItems.Add (item);
  310. return menuItems.ToArray ();
  311. }
  312. MenuItem [] CreateDiagnosticFlagsMenuItems ()
  313. {
  314. const string OFF = "Diagnostics: _Off";
  315. const string FRAME_RULER = "Diagnostics: Frame _Ruler";
  316. const string FRAME_PADDING = "Diagnostics: _Frame Padding";
  317. var index = 0;
  318. List<MenuItem> menuItems = new List<MenuItem> ();
  319. foreach (Enum diag in Enum.GetValues (_diagnosticFlags.GetType ())) {
  320. var item = new MenuItem ();
  321. item.Title = GetDiagnosticsTitle (diag);
  322. item.Shortcut = Key.AltMask + index.ToString () [0];
  323. index++;
  324. item.CheckType |= MenuItemCheckStyle.Checked;
  325. if (GetDiagnosticsTitle (ConsoleDriver.DiagnosticFlags.Off) == item.Title) {
  326. item.Checked = (_diagnosticFlags & (ConsoleDriver.DiagnosticFlags.FramePadding
  327. | ConsoleDriver.DiagnosticFlags.FrameRuler)) == 0;
  328. } else {
  329. item.Checked = _diagnosticFlags.HasFlag (diag);
  330. }
  331. item.Action += () => {
  332. var t = GetDiagnosticsTitle (ConsoleDriver.DiagnosticFlags.Off);
  333. if (item.Title == t && !item.Checked) {
  334. _diagnosticFlags &= ~(ConsoleDriver.DiagnosticFlags.FramePadding | ConsoleDriver.DiagnosticFlags.FrameRuler);
  335. item.Checked = true;
  336. } else if (item.Title == t && item.Checked) {
  337. _diagnosticFlags |= (ConsoleDriver.DiagnosticFlags.FramePadding | ConsoleDriver.DiagnosticFlags.FrameRuler);
  338. item.Checked = false;
  339. } else {
  340. var f = GetDiagnosticsEnumValue (item.Title);
  341. if (_diagnosticFlags.HasFlag (f)) {
  342. SetDiagnosticsFlag (f, false);
  343. } else {
  344. SetDiagnosticsFlag (f, true);
  345. }
  346. }
  347. foreach (var menuItem in menuItems) {
  348. if (menuItem.Title == t) {
  349. menuItem.Checked = !_diagnosticFlags.HasFlag (ConsoleDriver.DiagnosticFlags.FrameRuler)
  350. && !_diagnosticFlags.HasFlag (ConsoleDriver.DiagnosticFlags.FramePadding);
  351. } else if (menuItem.Title != t) {
  352. menuItem.Checked = _diagnosticFlags.HasFlag (GetDiagnosticsEnumValue (menuItem.Title));
  353. }
  354. }
  355. ConsoleDriver.Diagnostics = _diagnosticFlags;
  356. Application.Top.SetNeedsDisplay ();
  357. };
  358. menuItems.Add (item);
  359. }
  360. return menuItems.ToArray ();
  361. string GetDiagnosticsTitle (Enum diag)
  362. {
  363. switch (Enum.GetName (_diagnosticFlags.GetType (), diag)) {
  364. case "Off":
  365. return OFF;
  366. case "FrameRuler":
  367. return FRAME_RULER;
  368. case "FramePadding":
  369. return FRAME_PADDING;
  370. }
  371. return "";
  372. }
  373. Enum GetDiagnosticsEnumValue (ustring title)
  374. {
  375. switch (title.ToString ()) {
  376. case FRAME_RULER:
  377. return ConsoleDriver.DiagnosticFlags.FrameRuler;
  378. case FRAME_PADDING:
  379. return ConsoleDriver.DiagnosticFlags.FramePadding;
  380. }
  381. return null;
  382. }
  383. void SetDiagnosticsFlag (Enum diag, bool add)
  384. {
  385. switch (diag) {
  386. case ConsoleDriver.DiagnosticFlags.FrameRuler:
  387. if (add) {
  388. _diagnosticFlags |= ConsoleDriver.DiagnosticFlags.FrameRuler;
  389. } else {
  390. _diagnosticFlags &= ~ConsoleDriver.DiagnosticFlags.FrameRuler;
  391. }
  392. break;
  393. case ConsoleDriver.DiagnosticFlags.FramePadding:
  394. if (add) {
  395. _diagnosticFlags |= ConsoleDriver.DiagnosticFlags.FramePadding;
  396. } else {
  397. _diagnosticFlags &= ~ConsoleDriver.DiagnosticFlags.FramePadding;
  398. }
  399. break;
  400. default:
  401. _diagnosticFlags = default;
  402. break;
  403. }
  404. }
  405. }
  406. MenuItem [] CreateColorSchemeMenuItems ()
  407. {
  408. List<MenuItem> menuItems = new List<MenuItem> ();
  409. foreach (var sc in Colors.ColorSchemes) {
  410. var item = new MenuItem ();
  411. item.Title = $"_{sc.Key}";
  412. item.Shortcut = Key.AltMask | (Key)sc.Key.Substring (0, 1) [0];
  413. item.CheckType |= MenuItemCheckStyle.Radio;
  414. item.Checked = sc.Value == _colorScheme;
  415. item.Action += () => {
  416. ColorScheme = _colorScheme = sc.Value;
  417. SetNeedsDisplay ();
  418. foreach (var menuItem in menuItems) {
  419. menuItem.Checked = menuItem.Title.Equals ($"_{sc.Key}") && sc.Value == _colorScheme;
  420. }
  421. };
  422. menuItems.Add (item);
  423. }
  424. return menuItems.ToArray ();
  425. }
  426. void KeyDownHandler (View.KeyEventEventArgs a)
  427. {
  428. if (a.KeyEvent.IsCapslock) {
  429. Capslock.Title = "Caps: On";
  430. StatusBar.SetNeedsDisplay ();
  431. } else {
  432. Capslock.Title = "Caps: Off";
  433. StatusBar.SetNeedsDisplay ();
  434. }
  435. if (a.KeyEvent.IsNumlock) {
  436. Numlock.Title = "Num: On";
  437. StatusBar.SetNeedsDisplay ();
  438. } else {
  439. Numlock.Title = "Num: Off";
  440. StatusBar.SetNeedsDisplay ();
  441. }
  442. if (a.KeyEvent.IsScrolllock) {
  443. Scrolllock.Title = "Scroll: On";
  444. StatusBar.SetNeedsDisplay ();
  445. } else {
  446. Scrolllock.Title = "Scroll: Off";
  447. StatusBar.SetNeedsDisplay ();
  448. }
  449. }
  450. void CategoryListView_SelectedChanged (ListViewItemEventArgs e)
  451. {
  452. var item = _categories [e.Item];
  453. List<Scenario> newlist;
  454. if (e.Item == 0) {
  455. // First category is "All"
  456. newlist = _scenarios;
  457. } else {
  458. newlist = _scenarios.Where (s => s.GetCategories ().Contains (item)).ToList ();
  459. }
  460. ScenarioListView.SetSource (newlist.ToList ());
  461. }
  462. }
  463. static void VerifyObjectsWereDisposed ()
  464. {
  465. #if DEBUG_IDISPOSABLE
  466. // Validate there are no outstanding Responder-based instances
  467. // after a scenario was selected to run. This proves the main UI Catalog
  468. // 'app' closed cleanly.
  469. foreach (var inst in Responder.Instances) {
  470. Debug.Assert (inst.WasDisposed);
  471. }
  472. Responder.Instances.Clear ();
  473. // Validate there are no outstanding Application.RunState-based instances
  474. // after a scenario was selected to run. This proves the main UI Catalog
  475. // 'app' closed cleanly.
  476. foreach (var inst in Application.RunState.Instances) {
  477. Debug.Assert (inst.WasDisposed);
  478. }
  479. Application.RunState.Instances.Clear ();
  480. #endif
  481. }
  482. static void OpenUrl (string url)
  483. {
  484. try {
  485. if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
  486. url = url.Replace ("&", "^&");
  487. Process.Start (new ProcessStartInfo ("cmd", $"/c start {url}") { CreateNoWindow = true });
  488. } else if (RuntimeInformation.IsOSPlatform (OSPlatform.Linux)) {
  489. using (var process = new Process {
  490. StartInfo = new ProcessStartInfo {
  491. FileName = "xdg-open",
  492. Arguments = url,
  493. RedirectStandardError = true,
  494. RedirectStandardOutput = true,
  495. CreateNoWindow = true,
  496. UseShellExecute = false
  497. }
  498. }) {
  499. process.Start ();
  500. }
  501. } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
  502. Process.Start ("open", url);
  503. }
  504. } catch {
  505. throw;
  506. }
  507. }
  508. }
  509. }