Skip to content

Commit

Permalink
Polling possible via LuaConsole (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom authored Apr 10, 2024
1 parent e350330 commit 44cf7f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/client/DCSInsight/UserControls/UserControlAPI.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

<StackPanel Grid.Column="0" Grid.Row="1" Margin="5,5,5,5">
<TextBox Name="TextBoxSyntax" Text="GetDevice(device_id):SetCommand(command_id, new_value)" FontSize="15" FontStyle="Normal" IsReadOnly="True" Background="WhiteSmoke" BorderThickness="0" FontFamily="consolas" Margin="5,5,5,5" MouseEnter="{x:Static misc:Common.MouseEnter}" MouseLeave="{x:Static misc:Common.MouseLeave}" PreviewMouseDown="TextBoxSyntax_OnPreviewMouseDown"></TextBox>
<StackPanel Name="StackPanelLinks" Orientation="Horizontal"/>
<StackPanel Name="StackPanelLinks" Orientation="Horizontal" Visibility="Collapsed"/>
<StackPanel Name="StackPanelConsolePolling" Orientation="Horizontal" HorizontalAlignment="Right" Visibility="Collapsed" Margin="0,0,10,0"/>
</StackPanel>

<ItemsControl Name="ItemsControlParameters" Grid.Column="0" Grid.Row="2" KeyboardNavigation.TabNavigation="Cycle" Margin="5,5,5,5">
Expand Down
16 changes: 14 additions & 2 deletions src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ protected override void SetFormState()
if (ButtonSend == null) throw new Exception("ButtonSend is null.");

ButtonSend.IsEnabled = !TextBoxParameterList.Any(o => string.IsNullOrEmpty(o.Text)) && IsConnected;

if (DCSAPI.ReturnsData && !IsLuaConsole)
if (DCSAPI.ReturnsData)
{
if (ComboBoxPollTimes == null || CheckBoxPolling == null) throw new Exception("ComboBoxPollTimes or CheckBoxPolling is null.");

CheckBoxPolling.IsEnabled = ButtonSend.IsEnabled;
ComboBoxPollTimes.IsEnabled = CheckBoxPolling.IsChecked == false;
}

CanSend = ButtonSend.IsEnabled;
}
catch (Exception ex)
Expand Down Expand Up @@ -88,6 +89,9 @@ private void BuildLuaConsoleUI()
TextBoxSyntax.MouseLeave -= Common.MouseLeave;

StackPanelBottom.Visibility = Visibility.Visible;
StackPanelLinks.Visibility = Visibility.Visible;
StackPanelConsolePolling.Visibility = Visibility.Visible;

var dockPanelParameters = Application.Current.MainWindow.FindChild<DockPanel>("DockPanelParameters") ?? throw new Exception("Failed to find DockPanelParameters");
dockPanelParameters.LastChildFill = true;
var controlList = new List<Control>();
Expand Down Expand Up @@ -164,6 +168,14 @@ void LabelDefaultLuaOnMouseDown(object sender, MouseButtonEventArgs e)
labelDefaultLua.Tag = textBoxLuaCode;
StackPanelLinks.Children.Add(labelDefaultLua);

StackPanelConsolePolling.Children.Add(GetLabelKeepResults());
StackPanelConsolePolling.Children.Add(GetCheckBoxKeepResults());
StackPanelConsolePolling.Children.Add(GetLabelPolling());
StackPanelConsolePolling.Children.Add(GetCheckBoxPolling());
StackPanelConsolePolling.Children.Add(GetLabelPollingInterval());
StackPanelConsolePolling.Children.Add(GetComboBoxPollTimes());
StackPanelConsolePolling.UpdateLayout();

controlList.Add(textBoxLuaCode);
TextBoxParameterList.Add(textBoxLuaCode);

Expand Down
6 changes: 4 additions & 2 deletions src/client/DCSInsight/UserControls/UserControlAPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ private void CheckBoxPolling_OnChecked(object sender, RoutedEventArgs e)
{
try
{
var comboBoxPollTimes = (ComboBox)sender;
StartPolling(int.Parse(comboBoxPollTimes.SelectedValue.ToString() ?? "500"));
if (ComboBoxPollTimes == null)
throw new ArgumentException("ComboBoxPollTimes has not been created, cannot poll.");

StartPolling(int.Parse(ComboBoxPollTimes.SelectedValue.ToString() ?? "500"));
SetFormState();
}
catch (Exception ex)
Expand Down

0 comments on commit 44cf7f7

Please sign in to comment.