demo.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. using Terminal.Gui;
  2. using System;
  3. using System.Linq;
  4. using System.IO;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Globalization;
  8. using System.Reflection;
  9. using NStack;
  10. static class Demo {
  11. //class Box10x : View, IScrollView {
  12. class Box10x : View {
  13. int w = 40;
  14. int h = 50;
  15. public bool WantCursorPosition { get; set; } = false;
  16. public Box10x (int x, int y) : base (new Rect (x, y, 20, 10))
  17. {
  18. }
  19. public Size GetContentSize ()
  20. {
  21. return new Size (w, h);
  22. }
  23. public void SetCursorPosition (Point pos)
  24. {
  25. throw new NotImplementedException ();
  26. }
  27. public override void Redraw (Rect region)
  28. {
  29. //Point pos = new Point (region.X, region.Y);
  30. Driver.SetAttribute (ColorScheme.Focus);
  31. for (int y = 0; y < h; y++) {
  32. Move (0, y);
  33. Driver.AddStr (y.ToString ());
  34. for (int x = 0; x < w - y.ToString ().Length; x++) {
  35. //Driver.AddRune ((Rune)('0' + (x + y) % 10));
  36. if (y.ToString ().Length < w)
  37. Driver.AddStr (" ");
  38. }
  39. }
  40. //Move (pos.X, pos.Y);
  41. }
  42. }
  43. class Filler : View {
  44. public Filler (Rect rect) : base (rect)
  45. {
  46. }
  47. public override void Redraw (Rect region)
  48. {
  49. Driver.SetAttribute (ColorScheme.Focus);
  50. var f = Frame;
  51. for (int y = 0; y < f.Width; y++) {
  52. Move (0, y);
  53. for (int x = 0; x < f.Height; x++) {
  54. Rune r;
  55. switch (x % 3) {
  56. case 0:
  57. Driver.AddRune (y.ToString ().ToCharArray (0, 1) [0]);
  58. if (y > 9)
  59. Driver.AddRune (y.ToString ().ToCharArray (1, 1) [0]);
  60. r = '.';
  61. break;
  62. case 1:
  63. r = 'o';
  64. break;
  65. default:
  66. r = 'O';
  67. break;
  68. }
  69. Driver.AddRune (r);
  70. }
  71. }
  72. }
  73. }
  74. static void ShowTextAlignments ()
  75. {
  76. var container = new Window ($"Show Text Alignments") {
  77. X = 0,
  78. Y = 0,
  79. Width = Dim.Fill (),
  80. Height = Dim.Fill ()
  81. };
  82. container.KeyUp += (sender, e) => {
  83. if (e.KeyEvent.Key == Key.Esc)
  84. container.Running = false;
  85. };
  86. int i = 0;
  87. string txt = "Hello world, how are you doing today?";
  88. container.Add (
  89. new Label ($"{i+1}-{txt}") { TextAlignment = TextAlignment.Left, Y = 3, Width = Dim.Fill () },
  90. new Label ($"{i+2}-{txt}") { TextAlignment = TextAlignment.Right, Y = 5, Width = Dim.Fill () },
  91. new Label ($"{i+3}-{txt}") { TextAlignment = TextAlignment.Centered, Y = 7, Width = Dim.Fill () },
  92. new Label ($"{i+4}-{txt}") { TextAlignment = TextAlignment.Justified, Y = 9, Width = Dim.Fill () }
  93. );
  94. Application.Run (container);
  95. }
  96. static void ShowEntries (View container)
  97. {
  98. var scrollView = new ScrollView (new Rect (50, 10, 20, 8)) {
  99. ContentSize = new Size (20, 50),
  100. //ContentOffset = new Point (0, 0),
  101. ShowVerticalScrollIndicator = true,
  102. ShowHorizontalScrollIndicator = true
  103. };
  104. #if false
  105. scrollView.Add (new Box10x (0, 0));
  106. #else
  107. scrollView.Add (new Filler (new Rect (0, 0, 40, 40)));
  108. #endif
  109. // This is just to debug the visuals of the scrollview when small
  110. var scrollView2 = new ScrollView (new Rect (72, 10, 3, 3)) {
  111. ContentSize = new Size (100, 100),
  112. ShowVerticalScrollIndicator = true,
  113. ShowHorizontalScrollIndicator = true
  114. };
  115. scrollView2.Add (new Box10x (0, 0));
  116. var progress = new ProgressBar (new Rect (68, 1, 10, 1));
  117. bool timer (MainLoop caller)
  118. {
  119. progress.Pulse ();
  120. return true;
  121. }
  122. Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (300), timer);
  123. // A little convoluted, this is because I am using this to test the
  124. // layout based on referencing elements of another view:
  125. var login = new Label ("Login: ") { X = 3, Y = 6 };
  126. var password = new Label ("Password: ") {
  127. X = Pos.Left (login),
  128. Y = Pos.Bottom (login) + 1
  129. };
  130. var loginText = new TextField ("") {
  131. X = Pos.Right (password),
  132. Y = Pos.Top (login),
  133. Width = 40
  134. };
  135. var passText = new TextField ("") {
  136. Secret = true,
  137. X = Pos.Left (loginText),
  138. Y = Pos.Top (password),
  139. Width = Dim.Width (loginText)
  140. };
  141. var tf = new Button (3, 19, "Ok");
  142. // Add some content
  143. container.Add (
  144. login,
  145. loginText,
  146. password,
  147. passText,
  148. new FrameView (new Rect (3, 10, 25, 6), "Options"){
  149. new CheckBox (1, 0, "Remember me"),
  150. new RadioGroup (1, 2, new [] { "_Personal", "_Company" }),
  151. },
  152. new ListView (new Rect (59, 6, 16, 4), new string [] {
  153. "First row",
  154. "<>",
  155. "This is a very long row that should overflow what is shown",
  156. "4th",
  157. "There is an empty slot on the second row",
  158. "Whoa",
  159. "This is so cool"
  160. }),
  161. scrollView,
  162. scrollView2,
  163. tf,
  164. new Button (10, 19, "Cancel"),
  165. new TimeField (3, 20, DateTime.Now),
  166. new TimeField (23, 20, DateTime.Now, true),
  167. new DateField (3, 22, DateTime.Now),
  168. new DateField (23, 22, DateTime.Now, true),
  169. progress,
  170. new Label (3, 24, "Press F9 (on Unix, ESC+9 is an alias) or Ctrl+T to activate the menubar"),
  171. menuKeysStyle,
  172. menuAutoMouseNav
  173. );
  174. container.SendSubviewToBack (tf);
  175. }
  176. public static Label ml2;
  177. static void NewFile ()
  178. {
  179. var d = new Dialog (
  180. "New File", 50, 20,
  181. new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } },
  182. new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } });
  183. ml2 = new Label (1, 1, "Mouse Debug Line");
  184. d.Add (ml2);
  185. Application.Run (d);
  186. }
  187. //
  188. // Creates a nested editor
  189. static void Editor (Toplevel top)
  190. {
  191. var tframe = top.Frame;
  192. var ntop = new Toplevel (tframe);
  193. var menu = new MenuBar (new MenuBarItem [] {
  194. new MenuBarItem ("_File", new MenuItem [] {
  195. new MenuItem ("_Close", "", () => {Application.RequestStop ();}),
  196. }),
  197. new MenuBarItem ("_Edit", new MenuItem [] {
  198. new MenuItem ("_Copy", "", null),
  199. new MenuItem ("C_ut", "", null),
  200. new MenuItem ("_Paste", "", null)
  201. }),
  202. });
  203. ntop.Add (menu);
  204. string fname = null;
  205. foreach (var s in new [] { "/etc/passwd", "c:\\windows\\win.ini" })
  206. if (System.IO.File.Exists (s)) {
  207. fname = s;
  208. break;
  209. }
  210. var win = new Window (fname ?? "Untitled") {
  211. X = 0,
  212. Y = 1,
  213. Width = Dim.Fill (),
  214. Height = Dim.Fill ()
  215. };
  216. ntop.Add (win);
  217. var text = new TextView (new Rect (0, 0, tframe.Width - 2, tframe.Height - 3));
  218. if (fname != null)
  219. text.Text = System.IO.File.ReadAllText (fname);
  220. win.Add (text);
  221. Application.Run (ntop);
  222. }
  223. static bool Quit ()
  224. {
  225. var n = MessageBox.Query (50, 7, "Quit Demo", "Are you sure you want to quit this demo?", "Yes", "No");
  226. return n == 0;
  227. }
  228. static void Close ()
  229. {
  230. MessageBox.ErrorQuery (50, 7, "Error", "There is nothing to close", "Ok");
  231. }
  232. // Watch what happens when I try to introduce a newline after the first open brace
  233. // it introduces a new brace instead, and does not indent. Then watch me fight
  234. // the editor as more oddities happen.
  235. public static void Open ()
  236. {
  237. var d = new OpenDialog ("Open", "Open a file") { AllowsMultipleSelection = true };
  238. Application.Run (d);
  239. if (!d.Canceled)
  240. MessageBox.Query (50, 7, "Selected File", string.Join (", ", d.FilePaths), "Ok");
  241. }
  242. public static void ShowHex (Toplevel top)
  243. {
  244. var tframe = top.Frame;
  245. var ntop = new Toplevel (tframe);
  246. var menu = new MenuBar (new MenuBarItem [] {
  247. new MenuBarItem ("_File", new MenuItem [] {
  248. new MenuItem ("_Close", "", () => {Application.RequestStop ();}),
  249. }),
  250. });
  251. ntop.Add (menu);
  252. var win = new Window ("/etc/passwd") {
  253. X = 0,
  254. Y = 1,
  255. Width = Dim.Fill (),
  256. Height = Dim.Fill ()
  257. };
  258. ntop.Add (win);
  259. var source = System.IO.File.OpenRead ("/etc/passwd");
  260. var hex = new HexView (source) {
  261. X = 0,
  262. Y = 0,
  263. Width = Dim.Fill (),
  264. Height = Dim.Fill ()
  265. };
  266. win.Add (hex);
  267. Application.Run (ntop);
  268. }
  269. public class MenuItemDetails : MenuItem {
  270. ustring title;
  271. string help;
  272. Action action;
  273. public MenuItemDetails (ustring title, string help, Action action) : base (title, help, action)
  274. {
  275. this.title = title;
  276. this.help = help;
  277. this.action = action;
  278. }
  279. public static MenuItemDetails Instance (MenuItem mi)
  280. {
  281. return (MenuItemDetails)mi.GetMenuItem ();
  282. }
  283. }
  284. public delegate MenuItem MenuItemDelegate (MenuItemDetails menuItem);
  285. public static void ShowMenuItem (MenuItem mi)
  286. {
  287. BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
  288. MethodInfo minfo = typeof (MenuItemDetails).GetMethod ("Instance", flags);
  289. MenuItemDelegate mid = (MenuItemDelegate)Delegate.CreateDelegate (typeof (MenuItemDelegate), minfo);
  290. MessageBox.Query (70, 7, mi.Title.ToString (),
  291. $"{mi.Title.ToString ()} selected. Is from submenu: {mi.GetMenuBarItem ()}", "Ok");
  292. }
  293. static void MenuKeysStyle_Toggled (object sender, EventArgs e)
  294. {
  295. menu.UseKeysUpDownAsKeysLeftRight = menuKeysStyle.Checked;
  296. }
  297. static void MenuAutoMouseNav_Toggled (object sender, EventArgs e)
  298. {
  299. menu.WantMousePositionReports = menuAutoMouseNav.Checked;
  300. }
  301. static void Copy ()
  302. {
  303. TextField textField = menu.LastFocused as TextField;
  304. if (textField != null && textField.SelectedLength != 0) {
  305. textField.Copy ();
  306. }
  307. }
  308. static void Cut ()
  309. {
  310. TextField textField = menu.LastFocused as TextField;
  311. if (textField != null && textField.SelectedLength != 0) {
  312. textField.Cut ();
  313. }
  314. }
  315. static void Paste ()
  316. {
  317. TextField textField = menu.LastFocused as TextField;
  318. if (textField != null) {
  319. textField.Paste ();
  320. }
  321. }
  322. static void Help ()
  323. {
  324. MessageBox.Query (50, 7, "Help", "This is a small help\nBe kind.", "Ok");
  325. }
  326. #region Selection Demo
  327. static void ListSelectionDemo (bool multiple)
  328. {
  329. var d = new Dialog ("Selection Demo", 60, 20,
  330. new Button ("Ok", is_default: true) { Clicked = () => { Application.RequestStop (); } },
  331. new Button ("Cancel") { Clicked = () => { Application.RequestStop (); } });
  332. var animals = new List<string> () { "Alpaca", "Llama", "Lion", "Shark", "Goat" };
  333. var msg = new Label ("Use space bar or control-t to toggle selection") {
  334. X = 1,
  335. Y = 1,
  336. Width = Dim.Fill () - 1,
  337. Height = 1
  338. };
  339. var list = new ListView (animals) {
  340. X = 1,
  341. Y = 3,
  342. Width = Dim.Fill () - 4,
  343. Height = Dim.Fill () - 4,
  344. AllowsMarking = true,
  345. AllowsMultipleSelection = multiple
  346. };
  347. d.Add (msg, list);
  348. Application.Run (d);
  349. var result = "";
  350. for (int i = 0; i < animals.Count; i++) {
  351. if (list.Source.IsMarked (i)) {
  352. result += animals [i] + " ";
  353. }
  354. }
  355. MessageBox.Query (60, 10, "Selected Animals", result == "" ? "No animals selected" : result, "Ok");
  356. }
  357. static void ComboBoxDemo ()
  358. {
  359. IList<string> items = new List<string> ();
  360. foreach (var dir in new [] { "/etc", @"\windows\System32" }) {
  361. if (Directory.Exists (dir)) {
  362. items = Directory.GetFiles (dir)
  363. .Select (Path.GetFileName)
  364. .Where (x => char.IsLetterOrDigit (x [0]))
  365. .Distinct ()
  366. .OrderBy (x => x).ToList ();
  367. }
  368. }
  369. var list = new ComboBox (0, 0, 36, 7, items);
  370. list.Changed += (object sender, ustring text) => { Application.RequestStop (); };
  371. var d = new Dialog ("Select source file", 40, 12) { list };
  372. Application.Run (d);
  373. MessageBox.Query (60, 10, "Selected file", list.Text.ToString() == "" ? "Nothing selected" : list.Text.ToString(), "Ok");
  374. }
  375. #endregion
  376. #region KeyDown / KeyPress / KeyUp Demo
  377. private static void OnKeyDownPressUpDemo ()
  378. {
  379. var container = new Dialog (
  380. "KeyDown & KeyPress & KeyUp demo", 80, 20,
  381. new Button ("Close") { Clicked = () => { Application.RequestStop (); } }) {
  382. Width = Dim.Fill (),
  383. Height = Dim.Fill (),
  384. };
  385. var list = new List<string> ();
  386. var listView = new ListView (list) {
  387. X = 0,
  388. Y = 0,
  389. Width = Dim.Fill () - 1,
  390. Height = Dim.Fill () - 2,
  391. };
  392. listView.ColorScheme = Colors.TopLevel;
  393. container.Add (listView);
  394. void KeyDownPressUp (KeyEvent keyEvent, string updown)
  395. {
  396. const int ident = -5;
  397. switch (updown) {
  398. case "Down":
  399. case "Up":
  400. case "Press":
  401. var msg = $"Key{updown,ident}: ";
  402. if ((keyEvent.Key & Key.ShiftMask) != 0)
  403. msg += "Shift ";
  404. if ((keyEvent.Key & Key.CtrlMask) != 0)
  405. msg += "Ctrl ";
  406. if ((keyEvent.Key & Key.AltMask) != 0)
  407. msg += "Alt ";
  408. msg += $"{(((uint)keyEvent.KeyValue & (uint)Key.CharMask) > 26 ? $"{(char)keyEvent.KeyValue}" : $"{keyEvent.Key}")}";
  409. list.Add (msg);
  410. break;
  411. default:
  412. if ((keyEvent.Key & Key.ShiftMask) != 0) {
  413. list.Add ($"Key{updown,ident}: Shift ");
  414. } else if ((keyEvent.Key & Key.CtrlMask) != 0) {
  415. list.Add ($"Key{updown,ident}: Ctrl ");
  416. } else if ((keyEvent.Key & Key.AltMask) != 0) {
  417. list.Add ($"Key{updown,ident}: Alt ");
  418. } else {
  419. list.Add ($"Key{updown,ident}: {(((uint)keyEvent.KeyValue & (uint)Key.CharMask) > 26 ? $"{(char)keyEvent.KeyValue}" : $"{keyEvent.Key}")}");
  420. }
  421. break;
  422. }
  423. listView.MoveDown ();
  424. }
  425. container.KeyDown += (o, e) => KeyDownPressUp (e.KeyEvent, "Down");
  426. container.KeyPress += (o, e) => KeyDownPressUp (e.KeyEvent, "Press");
  427. container.KeyUp += (o, e) => KeyDownPressUp (e.KeyEvent, "Up");
  428. Application.Run (container);
  429. }
  430. #endregion
  431. public static Label ml;
  432. public static MenuBar menu;
  433. public static CheckBox menuKeysStyle;
  434. public static CheckBox menuAutoMouseNav;
  435. static void Main ()
  436. {
  437. if (Debugger.IsAttached)
  438. CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
  439. //Application.UseSystemConsole = true;
  440. Application.Init ();
  441. var top = Application.Top;
  442. //Open ();
  443. #if true
  444. int margin = 3;
  445. var win = new Window ("Hello") {
  446. X = 1,
  447. Y = 1,
  448. Width = Dim.Fill () - margin,
  449. Height = Dim.Fill () - margin
  450. };
  451. #else
  452. var tframe = top.Frame;
  453. var win = new Window (new Rect (0, 1, tframe.Width, tframe.Height - 1), "Hello");
  454. #endif
  455. MenuItemDetails [] menuItems = {
  456. new MenuItemDetails ("F_ind", "", null),
  457. new MenuItemDetails ("_Replace", "", null),
  458. new MenuItemDetails ("_Item1", "", null),
  459. new MenuItemDetails ("_Not From Sub Menu", "", null)
  460. };
  461. menuItems [0].Action = () => ShowMenuItem (menuItems [0]);
  462. menuItems [1].Action = () => ShowMenuItem (menuItems [1]);
  463. menuItems [2].Action = () => ShowMenuItem (menuItems [2]);
  464. menuItems [3].Action = () => ShowMenuItem (menuItems [3]);
  465. menu = new MenuBar (new MenuBarItem [] {
  466. new MenuBarItem ("_File", new MenuItem [] {
  467. new MenuItem ("Text _Editor Demo", "", () => { Editor (top); }),
  468. new MenuItem ("_New", "Creates new file", NewFile),
  469. new MenuItem ("_Open", "", Open),
  470. new MenuItem ("_Hex", "", () => ShowHex (top)),
  471. new MenuItem ("_Close", "", () => Close ()),
  472. new MenuItem ("_Disabled", "", () => { }, () => false),
  473. null,
  474. new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; })
  475. }),
  476. new MenuBarItem ("_Edit", new MenuItem [] {
  477. new MenuItem ("_Copy", "", Copy),
  478. new MenuItem ("C_ut", "", Cut),
  479. new MenuItem ("_Paste", "", Paste),
  480. new MenuItem ("_Find and Replace",
  481. new MenuBarItem (new MenuItem[] {menuItems [0], menuItems [1] })),
  482. menuItems[3]
  483. }),
  484. new MenuBarItem ("_List Demos", new MenuItem [] {
  485. new MenuItem ("Select _Multiple Items", "", () => ListSelectionDemo (true)),
  486. new MenuItem ("Select _Single Item", "", () => ListSelectionDemo (false)),
  487. new MenuItem ("Search Single Item", "", ComboBoxDemo)
  488. }),
  489. new MenuBarItem ("A_ssorted", new MenuItem [] {
  490. new MenuItem ("_Show text alignments", "", () => ShowTextAlignments ()),
  491. new MenuItem ("_OnKeyDown/Press/Up", "", () => OnKeyDownPressUpDemo ())
  492. }),
  493. new MenuBarItem ("_Test Menu and SubMenus", new MenuItem [] {
  494. new MenuItem ("SubMenu1Item_1",
  495. new MenuBarItem (new MenuItem[] {
  496. new MenuItem ("SubMenu2Item_1",
  497. new MenuBarItem (new MenuItem [] {
  498. new MenuItem ("SubMenu3Item_1",
  499. new MenuBarItem (new MenuItem [] { menuItems [2] })
  500. )
  501. })
  502. )
  503. })
  504. )
  505. }),
  506. new MenuBarItem ("_About...", "Demonstrates top-level menu item", () => MessageBox.ErrorQuery (50, 7, "About Demo", "This is a demo app for gui.cs", "Ok")),
  507. });
  508. menuKeysStyle = new CheckBox (3, 25, "UseKeysUpDownAsKeysLeftRight", true);
  509. menuKeysStyle.Toggled += MenuKeysStyle_Toggled;
  510. menuAutoMouseNav = new CheckBox (40, 25, "UseMenuAutoNavigation", true);
  511. menuAutoMouseNav.Toggled += MenuAutoMouseNav_Toggled;
  512. ShowEntries (win);
  513. int count = 0;
  514. ml = new Label (new Rect (3, 17, 47, 1), "Mouse: ");
  515. Application.RootMouseEvent += delegate (MouseEvent me) {
  516. ml.TextColor = Colors.TopLevel.Normal;
  517. ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}";
  518. };
  519. var test = new Label (3, 18, "Se iniciará el análisis");
  520. win.Add (test);
  521. win.Add (ml);
  522. var drag = new Label ("Drag: ") { X = 70, Y = 24 };
  523. var dragText = new TextField ("") {
  524. X = Pos.Right (drag),
  525. Y = Pos.Top (drag),
  526. Width = 40
  527. };
  528. var statusBar = new StatusBar (new StatusItem [] {
  529. new StatusItem(Key.F1, "~F1~ Help", () => Help()),
  530. new StatusItem(Key.F2, "~F2~ Load", null),
  531. new StatusItem(Key.F3, "~F3~ Save", null),
  532. new StatusItem(Key.ControlQ, "~^Q~ Quit", () => { if (Quit ()) top.Running = false; }),
  533. }) {
  534. Parent = null,
  535. };
  536. win.Add (drag, dragText);
  537. #if true
  538. // FIXED: This currently causes a stack overflow, because it is referencing a window that has not had its size allocated yet
  539. var bottom = new Label ("This should go on the bottom of the same top-level!");
  540. win.Add (bottom);
  541. var bottom2 = new Label ("This should go on the bottom of another top-level!");
  542. top.Add (bottom2);
  543. Application.Loaded += (sender, e) => {
  544. bottom.X = win.X;
  545. bottom.Y = Pos.Bottom (win) - Pos.Top (win) - margin;
  546. bottom2.X = Pos.Left (win);
  547. bottom2.Y = Pos.Bottom (win);
  548. };
  549. #endif
  550. win.KeyPress += Win_KeyPress;
  551. top.Add (win);
  552. //top.Add (menu);
  553. top.Add (menu, statusBar);
  554. Application.Run ();
  555. }
  556. private static void Win_KeyPress (object sender, View.KeyEventEventArgs e)
  557. {
  558. if (e.KeyEvent.Key == Key.ControlT) {
  559. if (menu.IsMenuOpen)
  560. menu.CloseMenu ();
  561. else
  562. menu.OpenMenu ();
  563. e.Handled = true;
  564. }
  565. }
  566. }