Beispiel #1
0
        /// <summary>
        /// Create all controls. This gets called once and the controls remain with their state between Sceanrio runs.
        /// </summary>
        private static void Setup()
        {
            // Set this here because not initilzied until driver is loaded
            _baseColorScheme = Colors.Base;

            StringBuilder aboutMessage = new StringBuilder();

            aboutMessage.AppendLine("UI Catalog is a comprehensive sample library for Terminal.Gui");
            aboutMessage.AppendLine("");
            aboutMessage.AppendLine($"Version: {typeof (UICatalogApp).Assembly.GetName ().Version}");
            aboutMessage.AppendLine($"Using Terminal.Gui Version: {typeof (Terminal.Gui.Application).Assembly.GetName ().Version}");
            aboutMessage.AppendLine("");

            _menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_Quit", "", () => Application.RequestStop())
                }),
                new MenuBarItem("_Color Scheme", CreateColorSchemeMenuItems()),
                new MenuBarItem("_Diagostics", CreateDiagnosticMenuItems()),
                new MenuBarItem("_About...", "About this app", () => MessageBox.Query("About UI Catalog", aboutMessage.ToString(), "Ok")),
            });

            _leftPane = new FrameView("Categories")
            {
                X        = 0,
                Y        = 1,          // for menu
                Width    = 25,
                Height   = Dim.Fill(1),
                CanFocus = false,
            };


            _categories       = Scenario.GetAllCategories().OrderBy(c => c).ToList();
            _categoryListView = new ListView(_categories)
            {
                X             = 0,
                Y             = 0,
                Width         = Dim.Fill(0),
                Height        = Dim.Fill(0),
                AllowsMarking = false,
                CanFocus      = true,
            };
            _categoryListView.OpenSelectedItem += (a) => {
                _top.SetFocus(_rightPane);
            };
            _categoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
            _leftPane.Add(_categoryListView);

            _rightPane = new FrameView("Scenarios")
            {
                X        = 25,
                Y        = 1,          // for menu
                Width    = Dim.Fill(),
                Height   = Dim.Fill(1),
                CanFocus = true,
            };

            _nameColumnWidth = Scenario.ScenarioMetadata.GetName(_scenarios.OrderByDescending(t => Scenario.ScenarioMetadata.GetName(t).Length).FirstOrDefault()).Length;

            _scenarioListView = new ListView()
            {
                X             = 0,
                Y             = 0,
                Width         = Dim.Fill(0),
                Height        = Dim.Fill(0),
                AllowsMarking = false,
                CanFocus      = true,
            };

            _scenarioListView.OpenSelectedItem += _scenarioListView_OpenSelectedItem;
            _rightPane.Add(_scenarioListView);

            _categoryListView.SelectedItem = 0;
            _categoryListView.OnSelectedChanged();

            _capslock   = new StatusItem(Key.CharMask, "Caps", null);
            _numlock    = new StatusItem(Key.CharMask, "Num", null);
            _scrolllock = new StatusItem(Key.CharMask, "Scroll", null);

            _statusBar = new StatusBar(new StatusItem [] {
                _capslock,
                _numlock,
                _scrolllock,
                new StatusItem(Key.ControlQ, "~CTRL-Q~ Quit", () => {
                    if (_runningScenario is null)
                    {
                        // This causes GetScenarioToRun to return null
                        _runningScenario = null;
                        Application.RequestStop();
                    }
                    else
                    {
                        _runningScenario.RequestStop();
                    }
                }),
            });