Skip to content

Commit

Permalink
Change GUI, fix nullable bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlblom committed Mar 5, 2024
1 parent e404ac5 commit 49b58c6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
7 changes: 5 additions & 2 deletions src/client/DCSInsight/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<DockPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="3">
<StatusBar DockPanel.Dock="Bottom" Margin="5,0,5,0">
<StatusBarItem VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" >
<TextBlock Name="TextBlockAppInfo" MouseDown="TextBlockAppInfo_OnMouseDown">dcs-insight</TextBlock>
<TextBlock Name="TextBlockAppInfo">dcs-insight</TextBlock>
</StatusBarItem>
<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>
Expand All @@ -55,7 +55,10 @@
<TextBlock Name="TextBlockSetDCSBIOSLocation" MouseDown="TextBlockSetDCSBIOSLocation_OnMouseDown">set dcs-bios</TextBlock>
</StatusBarItem>
<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="TextBlockAPIReload" MouseDown="TextBlockAPIReload_OnMouseDown">API Reload Setting</TextBlock>
<TextBlock Name="TextBlockAPIReload" MouseDown="TextBlockAPIReload_OnMouseDown">api reload setting</TextBlock>
</StatusBarItem>
<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="TextBlockViewLog" MouseDown="TextBlockViewLog_OnMouseDown">view client log</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right">
<TextBlock Name="TextBlockMessage" ></TextBlock>
Expand Down
32 changes: 16 additions & 16 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,22 +487,7 @@ private void ShowVersionInfo()
Common.ShowErrorMessageBox(ex);
}
}

private void TextBlockAppInfo_OnMouseDown(object sender, MouseButtonEventArgs e)
{
try
{
TryOpenLogFileWithTarget("logfile");
if (_tcpClientHandler == null) return;

_tcpClientHandler.LogJSON = true;
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}


private void ButtonRangeTest_OnClick(object sender, RoutedEventArgs e)
{
try
Expand Down Expand Up @@ -645,5 +630,20 @@ private void TextBlockAPIReload_OnMouseDown(object sender, MouseButtonEventArgs
Common.ShowErrorMessageBox(ex);
}
}

private void TextBlockViewLog_OnMouseDown(object sender, MouseButtonEventArgs e)
{
try
{
TryOpenLogFileWithTarget("logfile");
if (_tcpClientHandler == null) return;

_tcpClientHandler.LogJSON = true;
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}
}
}
3 changes: 1 addition & 2 deletions src/client/DCSInsight/Misc/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ internal static string GetApplicationPath()

internal static void ShowErrorMessageBox(Exception ex, string? message = null)
{
if(message != null) Logger.Error(ex, message);

Logger.Error(ex, message ?? "");
MessageBox.Show(ex.Message, $"Details logged to error log.{Environment.NewLine}{ex.Source}", MessageBoxButton.OK, MessageBoxImage.Error);
}

Expand Down
19 changes: 8 additions & 11 deletions src/client/DCSInsight/UserControls/UserControlAPI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ namespace DCSInsight.UserControls
/// </summary>
public partial class UserControlAPI : UserControlAPIBase
{
private readonly DockPanel _dockPanelParameters;

public UserControlAPI(DCSAPI dcsAPI, bool isConnected) : base(dcsAPI, isConnected)
{
InitializeComponent();
LabelResultBase = LabelResult;
TextBoxResultBase = TextBoxResult;
_dockPanelParameters = Application.Current.MainWindow.FindChild<DockPanel>("DockPanelParameters") ?? throw new Exception("Failed to find DockPanelParameters");

}

private void UserControlAPI_OnLoaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -85,9 +84,12 @@ private void BuildLuaConsoleUI()
try
{
TextBoxSyntax.Text = DCSAPI.Syntax;
TextBoxSyntax.ToolTip = $"Click to copy syntax. (API Id = {DCSAPI.Id})";
TextBoxSyntax.MouseEnter -= Common.MouseEnter;
TextBoxSyntax.MouseLeave -= Common.MouseLeave;

StackPanelBottom.Visibility = Visibility.Visible;
_dockPanelParameters.LastChildFill = true;
var dockPanelParameters = Application.Current.MainWindow.FindChild<DockPanel>("DockPanelParameters") ?? throw new Exception("Failed to find DockPanelParameters");
dockPanelParameters.LastChildFill = true;
var controlList = new List<Control>();

var textBoxLuaCode = new TextBox
Expand All @@ -106,10 +108,7 @@ private void BuildLuaConsoleUI()
VerticalScrollBarVisibility = ScrollBarVisibility.Auto
};

TextBoxSyntax.PreviewMouseDown -= TextBoxSyntax_OnPreviewMouseDown;
TextBoxSyntax.MouseEnter -= Common.MouseEnter;
TextBoxSyntax.MouseLeave -= Common.MouseLeave;
TextBoxSyntax.ToolTip = null;
textBoxLuaCode.PreviewKeyDown += TextBoxLuaCode_OnPreviewKeyDown;

var brushConverter = new BrushConverter().ConvertFromString("#0000FF");
var labelConsoleWarning = new Label
Expand Down Expand Up @@ -164,9 +163,7 @@ void LabelDefaultLuaOnMouseDown(object sender, MouseButtonEventArgs e)

labelDefaultLua.Tag = textBoxLuaCode;
StackPanelLinks.Children.Add(labelDefaultLua);

textBoxLuaCode.KeyUp += TextBoxParameter_OnKeyUp;


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

Expand Down
41 changes: 30 additions & 11 deletions src/client/DCSInsight/UserControls/UserControlAPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private string ResultTextBoxFirstLine()

if (string.IsNullOrEmpty(textBoxResultText)) return "";

return textBoxResultText.Contains('\n', StringComparison.Ordinal) ? textBoxResultText : textBoxResultText[..textBoxResultText.IndexOf("\n", StringComparison.Ordinal)];
return textBoxResultText.Contains('\n', StringComparison.Ordinal) == false ? textBoxResultText : textBoxResultText[..textBoxResultText.IndexOf("\n", StringComparison.Ordinal)];
}

internal void SetResult(DCSAPI dcsApi)
Expand Down Expand Up @@ -155,7 +155,7 @@ public void SetConnectionStatus(bool connected)
}
}

protected void ButtonSend_OnClick(object sender, RoutedEventArgs e)
private void ButtonSend_OnClick(object sender, RoutedEventArgs e)
{
try
{
Expand Down Expand Up @@ -266,15 +266,25 @@ private void TextBoxParameter_OnKeyDown_Number(object sender, KeyEventArgs e)
Common.ShowErrorMessageBox(ex);
}
}

private void CheckBoxKeepResults_OnUnchecked(object sender, RoutedEventArgs e)
{
try
{
_keepResults = false;
SetFormState();
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}

protected void TextBoxParameter_OnKeyUp(object sender, KeyEventArgs e)
private void CheckBoxKeepResults_OnChecked(object sender, RoutedEventArgs e)
{
try
{
if (e.Key == Key.Enter && CanSend)
{
SendCommand();
}
_keepResults = true;
SetFormState();
}
catch (Exception ex)
Expand All @@ -283,11 +293,17 @@ protected void TextBoxParameter_OnKeyUp(object sender, KeyEventArgs e)
}
}

private void CheckBoxKeepResults_OnUnchecked(object sender, RoutedEventArgs e)
protected void TextBoxLuaCode_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
try
{
_keepResults = false;
if (e.Key == Key.Enter && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control && CanSend)
{
SendCommand();
e.Handled = true;
return;
}

SetFormState();
}
catch (Exception ex)
Expand All @@ -296,11 +312,14 @@ private void CheckBoxKeepResults_OnUnchecked(object sender, RoutedEventArgs e)
}
}

private void CheckBoxKeepResults_OnChecked(object sender, RoutedEventArgs e)
private void TextBoxParameter_OnKeyUp(object sender, KeyEventArgs e)
{
try
{
_keepResults = true;
if (e.Key == Key.Enter && CanSend)
{
SendCommand();
}
SetFormState();
}
catch (Exception ex)
Expand Down

0 comments on commit 49b58c6

Please sign in to comment.