Skip to content

Commit

Permalink
Moved creation of UI controls to base class for UserControlAPI (#68)
Browse files Browse the repository at this point in the history
* Moved creation of UI controls to base class for UserControlAPI

* Version bump
  • Loading branch information
jdahlblom authored Jan 30, 2024
1 parent 51dbc7e commit 99f0904
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 247 deletions.
2 changes: 1 addition & 1 deletion src/client/DCSInsight/DCSInsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- for WinForms -->
<AssemblyName>dcs-insight</AssemblyName>
<Version>1.0.0</Version>
<AssemblyVersion>1.9.0</AssemblyVersion>
<AssemblyVersion>1.9.1</AssemblyVersion>
<ApplicationIcon>Images\Magnifier_icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions src/client/DCSInsight/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Icon="/dcs-insight;component/Images/Magnifier_icon.png"
xmlns:local="clr-namespace:DCSInsight"
xmlns:misc="clr-namespace:DCSInsight.Misc"

mc:Ignorable="d"
Title="DCS-Insight" Height="560" Width="750" WindowStartupLocation="CenterScreen" Closing="MainWindow_OnClosing" Loaded="MainWindow_OnLoaded">
Expand Down Expand Up @@ -44,13 +45,13 @@
<StatusBarItem VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" >
<TextBlock Name="TextBlockAppInfo" MouseDown="TextBlockAppInfo_OnMouseDown">dcs-insight</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave">
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="{x:Static misc:Common.MouseEnter}" MouseLeave="{x:Static misc:Common.MouseLeave}" >
<TextBlock Name="TextBlockAppWiki" MouseDown="TextBlockAppWiki_OnMouseDown">wiki</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave">
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="{x:Static misc:Common.MouseEnter}" MouseLeave="{x:Static misc:Common.MouseLeave}" >
<TextBlock Name="TextBlockCheckNewVersion" MouseDown="TextBlockCheckNewVersion_OnMouseDown">check version</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="UIElement_OnMouseEnter" MouseLeave="UIElement_OnMouseLeave">
<StatusBarItem VerticalAlignment="Stretch" Foreground="#0000FF" HorizontalAlignment="Stretch" Margin="20,0,0,0" HorizontalContentAlignment="Left" MouseEnter="{x:Static misc:Common.MouseEnter}" MouseLeave="{x:Static misc:Common.MouseLeave}" >
<TextBlock Name="TextBlockSetDCSBIOSLocation" MouseDown="TextBlockSetDCSBIOSLocation_OnMouseDown">set dcs-bios</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right">
Expand Down
10 changes: 0 additions & 10 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,6 @@ private void TextBlockAppWiki_OnMouseDown(object sender, MouseButtonEventArgs e)
});
}

private void UIElement_OnMouseEnter(object sender, MouseEventArgs e)
{
Mouse.OverrideCursor = Cursors.Hand;
}

private void UIElement_OnMouseLeave(object sender, MouseEventArgs e)
{
Mouse.OverrideCursor = Cursors.Arrow;
}

private async void TextBlockCheckNewVersion_OnMouseDown(object sender, MouseButtonEventArgs e)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/client/DCSInsight/Misc/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ internal static class Common
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
internal static bool LuaConsoleIsLoaded;
internal static bool LuaConsoleSearchWarningGiven;
public static MouseEventHandler MouseEnter => UIElement_OnMouseEnterHandIcon;
public static MouseEventHandler MouseLeave => UIElement_OnMouseLeaveNormalIcon;

internal static void ShowMessageBox(string message)
{
Expand Down
3 changes: 2 additions & 1 deletion src/client/DCSInsight/UserControls/UserControlAPI.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:userControls="clr-namespace:DCSInsight.UserControls"
xmlns:misc="clr-namespace:DCSInsight.Misc"
Loaded="UserControlAPI_OnLoaded"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="800" Height="auto" IsTabStop="True">
Expand All @@ -23,7 +24,7 @@
<StackPanel Grid.Row="0" Background="#ffffcc" ></StackPanel>

<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="TextBoxSyntax_OnMouseEnter" MouseLeave="TextBoxSyntax_OnMouseLeave" PreviewMouseDown="TextBoxSyntax_OnPreviewMouseDown"></TextBox>
<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>

Expand Down
115 changes: 13 additions & 102 deletions src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ private void BuildLuaConsoleUI()
};

TextBoxSyntax.PreviewMouseDown -= TextBoxSyntax_OnPreviewMouseDown;
TextBoxSyntax.MouseEnter -= TextBoxSyntax_OnMouseEnter;
TextBoxSyntax.MouseLeave -= TextBoxSyntax_OnMouseLeave;
TextBoxSyntax.MouseEnter -= Common.MouseEnter;
TextBoxSyntax.MouseLeave -= Common.MouseLeave;
TextBoxSyntax.ToolTip = null;


Expand Down Expand Up @@ -158,17 +158,7 @@ void LabelDefaultLuaOnMouseDown(object sender, MouseButtonEventArgs e)
controlList.Add(textBoxLuaCode);
TextBoxParameterList.Add(textBoxLuaCode);

ButtonSend = new Button
{
Content = "Send",
Height = 20,
Width = 50,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(20, 0, 0, 0)
};
ButtonSend.Click += ButtonSend_OnClick;

StackPanelBottom.Children.Add(ButtonSend);
StackPanelBottom.Children.Add(GetButtonSend());

ItemsControlParameters.ItemsSource = controlList;
Common.LuaConsoleIsLoaded = true;
Expand Down Expand Up @@ -200,104 +190,25 @@ private void BuildGenericUI()

var controlList = new List<Control>();

foreach (var dcsAPIParameterType in DCSAPI.Parameters)
foreach (var dcsAPIParameter in DCSAPI.Parameters)
{
var label = new Label
{
Content = dcsAPIParameterType.ParameterName.Replace("_", "__"),
VerticalAlignment = VerticalAlignment.Center
};
controlList.Add(label);


var textBoxParameter = new TextBox
{
Name = "TextBox" + dcsAPIParameterType.Id,
Tag = dcsAPIParameterType.Id,
MinWidth = 50,
Height = 20,
IsTabStop = true
};

if (dcsAPIParameterType.Type == ParameterTypeEnum.number)
{
textBoxParameter.KeyDown += TextBoxParameter_OnKeyDown_Number;
}
textBoxParameter.KeyUp += TextBoxParameter_OnKeyUp;
controlList.Add(GetLabelParameterName(dcsAPIParameter.ParameterName));

var textBoxParameter = GetTextBoxParameter(dcsAPIParameter);
controlList.Add(textBoxParameter);
TextBoxParameterList.Add(textBoxParameter);
}

ButtonSend = new Button
{
Content = "Send",
Height = 20,
Width = 50,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(20, 0, 0, 0)
};
ButtonSend.Click += ButtonSend_OnClick;

controlList.Add(ButtonSend);
controlList.Add(GetButtonSend());

if (DCSAPI.ReturnsData)
{
LabelKeepResults = new Label
{
Content = "Keep results",
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 0)
};
controlList.Add(LabelKeepResults);

CheckBoxKeepResults = new CheckBox
{
Margin = new Thickness(0, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center
};
CheckBoxKeepResults.Checked += CheckBoxKeepResults_OnChecked;
CheckBoxKeepResults.Unchecked += CheckBoxKeepResults_OnUnchecked;
controlList.Add(CheckBoxKeepResults);

LabelPolling = new Label
{
Content = "Poll",
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 0)
};
controlList.Add(LabelPolling);

CheckBoxPolling = new CheckBox
{
Margin = new Thickness(0, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center

};
CheckBoxPolling.Checked += CheckBoxPolling_OnChecked;
CheckBoxPolling.Unchecked += CheckBoxPolling_OnUnchecked;
controlList.Add(CheckBoxPolling);

LabelPollingInterval = new Label
{
Content = "Interval (ms) :",
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 0)
};
controlList.Add(LabelPollingInterval);

ComboBoxPollTimes = new ComboBox
{
Height = 20,
Margin = new Thickness(2, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center,
};
ComboBoxPollTimes.DataContextChanged += ComboBoxPollTimes_OnDataContextChanged;
ComboBoxPollTimes.Items.Add(100);
ComboBoxPollTimes.Items.Add(500);
ComboBoxPollTimes.Items.Add(1000);
ComboBoxPollTimes.Items.Add(2000);
ComboBoxPollTimes.SelectedIndex = 0;
controlList.Add(GetLabelKeepResults());
controlList.Add(GetCheckBoxKeepResults());
controlList.Add(GetLabelPolling());
controlList.Add(GetCheckBoxPolling());
controlList.Add(GetLabelPollingInterval());
controlList.Add(GetComboBoxPollTimes());
controlList.Add(ComboBoxPollTimes);
}

Expand Down
130 changes: 109 additions & 21 deletions src/client/DCSInsight/UserControls/UserControlAPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ public abstract partial class UserControlAPIBase : UserControl, IDisposable, IAs
protected bool CanSend;
private bool _keepResults;
protected Button ButtonSend;
protected Label LabelKeepResults;
protected CheckBox CheckBoxKeepResults;
protected Label LabelPolling;
protected CheckBox CheckBoxPolling;
protected Label LabelPollingInterval;
protected ComboBox ComboBoxPollTimes;
protected Label LabelResultBase;
protected TextBox TextBoxResultBase;
Expand Down Expand Up @@ -313,42 +309,134 @@ protected void CheckBoxKeepResults_OnChecked(object sender, RoutedEventArgs e)
}
}

protected void TextBoxSyntax_OnMouseEnter(object sender, MouseEventArgs e)
protected void TextBoxSyntax_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
try
{
Mouse.OverrideCursor = Cursors.Hand;
var textBox = (TextBox)sender;
Clipboard.SetText(textBox.Text);
SystemSounds.Asterisk.Play();
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}

protected void TextBoxSyntax_OnMouseLeave(object sender, MouseEventArgs e)
protected static Label GetLabelParameterName(string parameterName)
{
try
return new Label
{
Mouse.OverrideCursor = Cursors.Arrow;
}
catch (Exception ex)
Content = parameterName.Replace("_", "__"),
VerticalAlignment = VerticalAlignment.Center
};
}
protected TextBox GetTextBoxParameter(ParameterInfo parameterInfo)
{
var textBox = new TextBox
{
Name = "TextBox" + parameterInfo.Id,
Tag = parameterInfo.Id,
MinWidth = 50,
Height = 20,
IsTabStop = true
};


if (parameterInfo.Type == ParameterTypeEnum.number)
{
Common.ShowErrorMessageBox(ex);
textBox.KeyDown += TextBoxParameter_OnKeyDown_Number;
}
textBox.KeyUp += TextBoxParameter_OnKeyUp;

return textBox;
}

protected void TextBoxSyntax_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
protected Button GetButtonSend()
{
try
ButtonSend = new Button
{
Content = "Send",
Height = 20,
Width = 50,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(20, 0, 0, 0)
};
ButtonSend.Click += ButtonSend_OnClick;

return ButtonSend;
}

protected Label GetLabelKeepResults()
{
return new Label
{
var textBox = (TextBox)sender;
Clipboard.SetText(textBox.Text);
SystemSounds.Asterisk.Play();
}
catch (Exception ex)
Content = "Keep results",
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 0)
};
}

protected CheckBox GetCheckBoxKeepResults()
{
var checkBoxKeepResults = new CheckBox
{
Margin = new Thickness(0, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center
};
checkBoxKeepResults.Checked += CheckBoxKeepResults_OnChecked;
checkBoxKeepResults.Unchecked += CheckBoxKeepResults_OnUnchecked;
return checkBoxKeepResults;
}

protected static Label GetLabelPolling()
{
return new Label
{
Common.ShowErrorMessageBox(ex);
}
Content = "Poll",
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 0)
};
}

protected CheckBox GetCheckBoxPolling()
{
CheckBoxPolling = new CheckBox
{
Margin = new Thickness(0, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center

};
CheckBoxPolling.Checked += CheckBoxPolling_OnChecked;
CheckBoxPolling.Unchecked += CheckBoxPolling_OnUnchecked;
return CheckBoxPolling;
}

protected static Label GetLabelPollingInterval()
{
return new Label
{
Content = "Interval (ms) :",
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 0)
};
}

protected ComboBox GetComboBoxPollTimes()
{
ComboBoxPollTimes = new ComboBox
{
Height = 20,
Margin = new Thickness(2, 0, 0, 0),
VerticalAlignment = VerticalAlignment.Center
};
ComboBoxPollTimes.DataContextChanged += ComboBoxPollTimes_OnDataContextChanged;
ComboBoxPollTimes.Items.Add(100);
ComboBoxPollTimes.Items.Add(500);
ComboBoxPollTimes.Items.Add(1000);
ComboBoxPollTimes.Items.Add(2000);
ComboBoxPollTimes.SelectedIndex = 0;
return ComboBoxPollTimes;
}
}
}
Loading

0 comments on commit 99f0904

Please sign in to comment.