/// <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(); } }), });
/// <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(); aboutMessage.AppendLine(GetAppTitle()); aboutMessage.AppendLine(); aboutMessage.AppendLine("SmartThings Terminal - a terminal for the SmartThings REST API"); aboutMessage.AppendLine(); aboutMessage.AppendLine("SmartThings REST API: https://smartthings.developer.samsung.com/docs/api-ref/st-api.html"); aboutMessage.AppendLine(); aboutMessage.AppendLine($"Version: {typeof(Program).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 SmartThings Terminal", aboutMessage.ToString(), "Ok")), }); _leftPane = new FrameView("API") { X = 0, Y = 1, // for menu Width = 40, 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); Label appNameView = new Label() { X = 0, Y = 0, Height = Dim.Fill(), Width = Dim.Fill() }; StringBuilder sbTitle = new StringBuilder(); appNameView.Text = GetAppTitle(); _appTitlePane = new FrameView() { X = 25, Y = 1, // for menu Width = Dim.Fill(), Height = 9, CanFocus = false }; _appTitlePane.Add(appNameView); _rightPane = new FrameView("API Description") { X = 25, //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 = 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.ControlR, "~CTRL-R~ Refresh Data", () => { _stClient.ResetData(); }), new StatusItem(Key.ControlQ, "~CTRL-Q~ Back/Quit", () => { if (_runningScenario is null) { // This causes GetScenarioToRun to return null _runningScenario = null; Application.RequestStop(); } else { _runningScenario.RequestStop(); } }), });