Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polling possible via LuaConsole #78

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading