Exemple #1
0
        /// <summary>
        /// This shows the selection UI. Each time it is run, it calls Application.Init to reset everything.
        /// </summary>
        /// <returns></returns>
        private static Scenario GetScenarioToRun()
        {
            Application.UseSystemConsole = false;
            Application.Init();

            // Set this here because not initilzied until driver is loaded
            _baseColorScheme = Colors.Base;

            _menu = MenuHelper.GetStandardMenuBar(_baseColorScheme);

            _leftPane = new FrameView("API")
            {
                X        = 0,
                Y        = 1, // for menu
                Width    = 30,
                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) =>
            {
                _rightPane.SetFocus();
            };
            _categoryListView.SelectedItemChanged += CategoryListView_SelectedChanged;
            _leftPane.Add(_categoryListView);

            Label appNameView = new Label()
            {
                X = 0, Y = 0, Height = Dim.Fill(), Width = Dim.Fill(), CanFocus = false, Text = MenuHelper.GetAppTitle()
            };

            _appTitlePane = new FrameView()
            {
                X        = 30,
                Y        = 1, // for menu
                Width    = Dim.Fill(),
                Height   = 9,
                CanFocus = false,
            };
            _appTitlePane.Add(appNameView);

            _rightPane = new FrameView("API Description")
            {
                X = 30,
                //Y = 1, // for menu
                Y        = Pos.Bottom(_appTitlePane),
                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 = _categoryListViewItem;
            _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.F5, "~F5~ Refresh Data", () => {
                    _stClient.ResetData();
                }),
                new StatusItem(Key.F9, "~F9~ Menu", () => {
                    _stClient.ResetData();
                }),
                new StatusItem(Key.Q | Key.CtrlMask, "~CTRL-Q~ Quit", () => {
                    if (_runningScenario is null)
                    {
                        // This causes GetScenarioToRun to return null
                        _runningScenario = null;
                        Application.RequestStop();
                    }
                    else
                    {
                        _runningScenario.RequestStop();
                    }
                }),
            });
        public virtual void ConfigureWindows <T>(
            Dictionary <string, string> displayItemList,
            Dictionary <string, dynamic> dataItemList,
            bool configureLeftPane = true,
            bool configureHostPane = true)
        {
            _dataItemList = dataItemList;

            if (configureLeftPane)
            {
                ConfigureLeftPane(GetName());
            }
            if (configureHostPane)
            {
                ConfigureHostPane("");
            }

            ConfigureStatusBar();

            MenuBar menubar = null;

            if (displayItemList?.Count > 0)
            {
                var itemListView = GetClassListView <T>(displayItemList);
                LeftPane.Add(itemListView);

                string typeName = dataItemList.FirstOrDefault().Value.GetType().Name;
                switch ((T)dataItemList.FirstOrDefault().Value)
                {
                case Device d:
                case InstalledApp app:
                case SceneSummary s:
                case Subscription sub:
                case CapabilitySummary cs:
                    menubar = MenuHelper.GetStandardMenuBar(Top.ColorScheme, typeName, ExportItem, null);
                    break;

                default:
                    menubar = MenuHelper.GetStandardMenuBar(Top.ColorScheme, typeName, ExportItem, ImportItem);
                    break;
                }
            }
            else
            {
                menubar = MenuHelper.GetStandardMenuBar(Top.ColorScheme);
            }

            if (menubar != null)
            {
                Top.Add(menubar);
            }
            Top.Add(LeftPane);
            if (SettingsPane != null)
            {
                Top.Add(SettingsPane);
            }
            Top.Add(HostPane);
            Top.Add(StatusBar);

            if (displayItemList?.Count > 0)
            {
                dynamic itemToSelect = SelectedItem ?? dataItemList?.FirstOrDefault().Value;
                UpdateJsonView(itemToSelect.ToJson());
                if (SettingsPane != null)
                {
                    UpdateSettings <T>(itemToSelect);
                }
            }
        }