Skip to content

Commit

Permalink
Losetcommand (#49)
Browse files Browse the repository at this point in the history
* Made server log API list in markdown list format.

* LoSetCommand file now external, iCommands searchable

* All iCommands contained in file iCommands.txt which user can export, info in wiki
* iCommands can be searched

* Compile
  • Loading branch information
jdahlblom authored Nov 26, 2023
1 parent d577ddf commit a652c9a
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 38 deletions.
9 changes: 5 additions & 4 deletions src/client/DCSInsight/DCSInsight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
<UseWPF>true</UseWPF>
<AssemblyName>dcs-insight</AssemblyName>
<Version>1.0.0</Version>
<AssemblyVersion>1.7.9</AssemblyVersion>
<AssemblyVersion>1.8.0</AssemblyVersion>
<ApplicationIcon>Images\Magnifier_icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<None Remove="Images\clear_search_result.png" />
<None Remove="Images\cue_banner_search.png" />
<None Remove="Images\Icon_green_lamp_off.png" />
<None Remove="Images\Icon_green_lamp_on.png" />
<None Remove="Images\Magnifier_icon.ico" />
<None Remove="Images\Magnifier_icon.png" />
<None Remove="Images\search_api.png" />
<None Remove="Items\iCommands.txt" />
<None Remove="Magnifier_icon.png" />
</ItemGroup>
<ItemGroup>
Expand All @@ -28,14 +28,15 @@
</ItemGroup>
<ItemGroup>
<Resource Include="Images\clear_search_result.png" />
<Resource Include="Images\cue_banner_search.png" />
<Resource Include="Images\Icon_green_lamp_off.png" />
<Resource Include="Images\Icon_green_lamp_on.png" />
<Resource Include="Images\Magnifier_icon.ico" />
<Resource Include="Images\Magnifier_icon.png" />
<Resource Include="Images\search_api.png" />
<Resource Include="Items\iCommands.txt">
<Content Include="iCommands.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Update="UserControls\UserControlLoSetCommandAPI.xaml.cs">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/client/DCSInsight/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<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">
<TextBlock Name="TextBlockAppWiki" MouseDown="TextBlockAppWiki_OnMouseDown">wiki</TextBlock>
</StatusBarItem>
<StatusBarItem VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Right">
<TextBlock Name="TextBlockMessage" ></TextBlock>
</StatusBarItem>
Expand Down
19 changes: 19 additions & 0 deletions src/client/DCSInsight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,5 +511,24 @@ private void ButtonRangeTest_OnClick(object sender, RoutedEventArgs e)
Common.ShowErrorMessageBox(ex);
}
}

private void TextBlockAppWiki_OnMouseDown(object sender, MouseButtonEventArgs e)
{
Process.Start(new ProcessStartInfo
{
FileName = "https://github.com/DCS-Skunkworks/dcs-insight/wiki",
UseShellExecute = true
});
}

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

private void UIElement_OnMouseLeave(object sender, MouseEventArgs e)
{
Mouse.OverrideCursor = Cursors.Arrow;
}
}
}
26 changes: 17 additions & 9 deletions src/client/DCSInsight/Misc/LoSetCommand.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
using System;
using NLog;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Shapes;

namespace DCSInsight.Misc
{
internal class LoSetCommand
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private const string CommandsFile = "iCommands.txt";

public string Description { get; private set; }
public string Code { get; private set; }

internal static List<LoSetCommand> LoadCommands()
{
var result = new List<LoSetCommand>();
var resourceStream = Application.GetResourceStream(new Uri(@"/dcs-insight;component/Items/iCommands.txt", UriKind.Relative));
if (resourceStream == null) return result;
var loSetCommandsFile = $"{AppDomain.CurrentDomain.BaseDirectory}{CommandsFile}";
if (!File.Exists(loSetCommandsFile))
{
Logger.Error($"Failed to find {CommandsFile} in base directory.");
return result;
}

var streamReader = new StreamReader(resourceStream.Stream);
string line;
var stringArray = File.ReadAllLines(loSetCommandsFile);

while ((line = streamReader.ReadLine()) != null)
foreach (var s in stringArray)
{
if(!line.Trim().StartsWith("i") || !line.Contains('\t') || line.Contains('/')) continue;
if (string.IsNullOrEmpty(s) || !s.Trim().StartsWith("i") || !s.Contains('\t') || s.Contains('/') || s.Contains(':')) continue;

var array = line.Split('\t');
result.Add(new LoSetCommand{Code = array[1].Trim(), Description = array[0].Trim() });
var array = s.Split('\t');
result.Add(new LoSetCommand { Code = array[1].Trim(), Description = array[0].Trim() });
}

result = result.OrderBy(o => o.Description).ToList();
Expand Down
84 changes: 84 additions & 0 deletions src/client/DCSInsight/Misc/TextBoxSearchCommon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace DCSInsight.Misc
{
internal static class TextBoxSearchCommon
{
internal static void SetBackgroundSearchBanner(TextBox textBoxSearch)
{
try
{
//new Uri(@"/dcs-insight;component/Images/cue_banner_search.png", UriKind.Relative)),
if (string.IsNullOrEmpty(textBoxSearch.Text))
{
// Create an ImageBrush.
var textImageBrush = new ImageBrush
{
ImageSource = new BitmapImage(
new Uri("pack://application:,,,/dcs-insight;component/Images/cue_banner_search.png", UriKind.RelativeOrAbsolute)),
AlignmentX = AlignmentX.Left,
Stretch = Stretch.Uniform
};

// Use the brush to paint the button's background.
textBoxSearch.Background = textImageBrush;
}
else
{
textBoxSearch.Background = null;
}
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex);
}
}

internal static void AdjustShownPopupData(TextBox textBoxSearch, Popup popupSearch, DataGrid dataGridValues, IEnumerable<LoSetCommand> loSetCommands)
{
try
{
popupSearch.PlacementTarget = textBoxSearch;
popupSearch.Placement = PlacementMode.Bottom;
dataGridValues.Tag = textBoxSearch;
if (!popupSearch.IsOpen)
{
popupSearch.IsOpen = true;
}

if (string.IsNullOrEmpty(textBoxSearch.Text))
{
dataGridValues.DataContext = loSetCommands;
dataGridValues.ItemsSource = loSetCommands;
dataGridValues.Items.Refresh();
return;
}
var subList = loSetCommands.Where(loSetCommand => (!string.IsNullOrWhiteSpace(loSetCommand.Description) &&
loSetCommand.Description.ToUpper().Contains(textBoxSearch.Text.ToUpper()))
|| (!string.IsNullOrWhiteSpace(loSetCommand.Code) && loSetCommand.Code.ToUpper().Contains(textBoxSearch.Text.ToUpper())));
dataGridValues.DataContext = subList;
dataGridValues.ItemsSource = subList;
dataGridValues.Items.Refresh();
}
catch (Exception ex)
{
Common.ShowErrorMessageBox(ex, "AdjustShownPopupData()");
}
}

internal static void HandleFirstSpace(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space && ((TextBox)sender).Text == "")
{
e.Handled = true;
}
}
}
}
1 change: 0 additions & 1 deletion src/client/DCSInsight/UserControls/UserControlAPIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public abstract partial class UserControlAPIBase : UserControl, IDisposable, IAs
protected readonly DCSAPI DCSAPI;
protected bool IsControlLoaded;
protected readonly List<TextBox> TextBoxParameterList = new();
protected readonly List<ComboBox> ComboBoxParameterList = new();
protected bool IsConnected;
protected readonly Timer PollingTimer;
protected bool CanSend;
Expand Down
16 changes: 16 additions & 0 deletions src/client/DCSInsight/UserControls/UserControlLoSetCommandAPI.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@
Loaded="UserControlLoSetCommandAPI_OnLoaded"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="800" Height="auto" IsTabStop="True">
<UserControl.Resources>
<Popup x:Key="PopUpSearchResults" Width="600" Height="150" PlacementTarget="{Binding ElementName=text}" StaysOpen="False">
<Grid HorizontalAlignment="Stretch">
<DataGrid AutoGenerateColumns="false"
Background="White" ItemsSource="{Binding}" SelectionMode="Single" SelectionUnit="FullRow"
HorizontalAlignment="Stretch" Name="DataGridValues" VerticalAlignment="Stretch"
VerticalScrollBarVisibility="Visible" MouseDown="UIElement_OnMouseDown" MouseDoubleClick="Control_OnMouseDoubleClick"
SelectionChanged="Selector_OnSelectionChanged" CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="False">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Description}" Width="*" />
<DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Code}" Width="*" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Popup>
</UserControl.Resources>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
Expand Down
Loading

0 comments on commit a652c9a

Please sign in to comment.