-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global dcs-bios control search added to ctrlref (#486)
- Loading branch information
Showing
6 changed files
with
342 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<Window x:Class="ControlReference.Windows.GlobalSearchWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:customControls="clr-namespace:ControlReference.CustomControls" | ||
mc:Ignorable="d" | ||
Title="Search in all dcs-bios modules" Height="500" Width="600" | ||
Loaded="GlobalSearchWindow_OnLoaded" | ||
WindowStartupLocation="CenterOwner" | ||
KeyDown="GlobalSearchWindow_OnKeyDown" KeyUp="GlobalSearchWindow_OnKeyUp" Icon="/Images/FlightPanels01.png"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="30" /> | ||
<RowDefinition Height="35" /> | ||
<RowDefinition Height="1*" /> | ||
<RowDefinition Height="30" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="1*" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
|
||
<DockPanel Grid.Row="0" Grid.Column="0" Background="#7ebbfc"> | ||
<Label Name="LabelControl" Width="Auto" Content="" Margin="10,0,0,0" DockPanel.Dock="Left"/> | ||
</DockPanel> | ||
|
||
<StackPanel Grid.Row="1" Grid.Column="0" Height="22" Orientation="Horizontal" Margin="5,0,0,0" HorizontalAlignment="Right"> | ||
<TextBox Name="TextBoxSearchControl" TextWrapping="NoWrap" IsReadOnly="False" Width="Auto" MinWidth="550" KeyDown="TextBoxSearchControl_OnKeyDown"/> | ||
<Button Width="22"> | ||
<Image Source="/Images/search_controls.png" Name="ButtonSearchControls" Tag="Search" MouseDown="ButtonSearchControls_OnMouseDown" ToolTip="Global Search for DCS-BIOS Control"/> | ||
</Button> | ||
</StackPanel> | ||
|
||
<ScrollViewer Grid.Row="2" Grid.Column="0"> | ||
<StackPanel Name="StackPanelControls" Height="Auto" Width="Auto" Margin="10,5,10,5"> | ||
<StackPanel.Resources> | ||
<Style TargetType="{x:Type Border}"> | ||
<Setter Property="Margin" Value="0,10,0,0" /> | ||
<Setter Property="Background" Value="WhiteSmoke" /> | ||
<Setter Property="BorderBrush" Value="Black" /> | ||
<Setter Property="BorderThickness" Value="2" /> | ||
<Setter Property="CornerRadius" Value="5" /> | ||
</Style> | ||
<Style TargetType="{x:Type customControls:TextBlockSelectable}"> | ||
<Setter Property="Margin" Value="5,5,5,5" /> | ||
<Setter Property="Background" Value="WhiteSmoke" /> | ||
</Style> | ||
</StackPanel.Resources> | ||
|
||
</StackPanel> | ||
</ScrollViewer> | ||
<DockPanel Grid.Row="3" Grid.Column="0" Background="White" /> | ||
</Grid> | ||
</Window> |
206 changes: 206 additions & 0 deletions
206
src/ControlReference/Windows/GlobalSearchWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Media; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Shapes; | ||
using ClassLibraryCommon; | ||
using ControlReference.CustomControls; | ||
using DCS_BIOS.ControlLocator; | ||
using DCS_BIOS.Json; | ||
|
||
namespace ControlReference.Windows | ||
{ | ||
/// <summary> | ||
/// Interaction logic for GlobalSearchWindow.xaml | ||
/// </summary> | ||
public partial class GlobalSearchWindow | ||
{ | ||
private bool _isLoaded; | ||
|
||
public GlobalSearchWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void SetFormState() | ||
{ | ||
} | ||
|
||
private void GlobalSearchWindow_OnLoaded(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
if (_isLoaded) | ||
{ | ||
return; | ||
} | ||
|
||
SetFormState(); | ||
TextBoxSearchControl.Focus(); | ||
_isLoaded = true; | ||
} | ||
catch (Exception exception) | ||
{ | ||
MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace); | ||
} | ||
} | ||
|
||
private void ShowControls(List<Tuple<string, DCSBIOSControl>> controls) | ||
{ | ||
StackPanelControls.Children.Clear(); | ||
var lastControl = ""; | ||
TextBlockSelectable textBlock = null; | ||
foreach (var tuple in controls) | ||
{ | ||
if (tuple.Item1 != lastControl) | ||
{ | ||
lastControl = tuple.Item1; | ||
textBlock = new TextBlockSelectable(tuple.Item1 + Environment.NewLine); | ||
textBlock.MouseEnter += Common.UIElement_OnMouseEnterHandIcon; | ||
textBlock.MouseLeave += Common.UIElement_OnMouseLeaveNormalIcon; | ||
SetContextMenu(textBlock); | ||
|
||
textBlock.FontFamily = new System.Windows.Media.FontFamily("Consolas"); | ||
textBlock.Width = double.NaN; | ||
|
||
var border = new Border | ||
{ | ||
Child = textBlock | ||
}; | ||
StackPanelControls.Children.Add(border); | ||
StackPanelControls.Children.Add(new Line()); | ||
|
||
StackPanelControls.UpdateLayout(); | ||
} | ||
|
||
if (textBlock != null) | ||
{ | ||
textBlock.Text += tuple.Item2.Identifier + "\t" + tuple.Item2.Description + Environment.NewLine; | ||
} | ||
} | ||
} | ||
|
||
private void GlobalSearchWindow_OnKeyDown(object sender, KeyEventArgs e) | ||
{ | ||
try | ||
{ | ||
if (e.Key == Key.F && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift)) | ||
{ | ||
TextBoxSearchControl.Focus(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Common.ShowErrorMessageBox(ex); | ||
} | ||
} | ||
|
||
private void SetContextMenu(TextBlockSelectable textBlock) | ||
{ | ||
try | ||
{ | ||
//_contextMenu.Opened += TextBlockContextMenuOpened; | ||
ContextMenu contextMenu = new(); | ||
contextMenu.Opened += TextBlock_ContextMenuOpened; | ||
contextMenu.Tag = textBlock; | ||
var menuItemCopy = new MenuItem | ||
{ | ||
Tag = textBlock, | ||
Header = "Copy" | ||
}; | ||
menuItemCopy.Click += MenuItemCopy_OnClick; | ||
contextMenu.Items.Add(menuItemCopy); | ||
textBlock.ContextMenu = contextMenu; | ||
} | ||
catch (Exception exception) | ||
{ | ||
Common.ShowMessageBox(exception.Message + Environment.NewLine + exception.StackTrace); | ||
} | ||
} | ||
|
||
private static void TextBlock_ContextMenuOpened(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
var contextMenu = (ContextMenu)sender; | ||
var textBlock = (TextBlockSelectable)contextMenu.Tag; | ||
|
||
((MenuItem)contextMenu.Items[0])!.IsEnabled = !string.IsNullOrEmpty(textBlock.SelectedText); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Common.ShowErrorMessageBox(ex); | ||
} | ||
} | ||
|
||
private void MenuItemCopy_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
try | ||
{ | ||
var textBlock = ((MenuItem)sender).Tag; | ||
CopyToClipboard((TextBlockSelectable)textBlock); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Common.ShowMessageBox(exception.Message + Environment.NewLine + exception.StackTrace); | ||
} | ||
} | ||
|
||
private static void CopyToClipboard(TextBlockSelectable textBlock) | ||
{ | ||
if (string.IsNullOrEmpty(textBlock.SelectedText)) textBlock.SelectAll(); | ||
|
||
Clipboard.SetText(textBlock.SelectedText ?? ""); | ||
SystemSounds.Asterisk.Play(); | ||
} | ||
|
||
private void GlobalSearchWindow_OnKeyUp(object sender, KeyEventArgs e) | ||
{ | ||
try | ||
{ | ||
if (e.Key != Key.Escape) return; | ||
|
||
Close(); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Common.ShowMessageBox(exception.Message + Environment.NewLine + exception.StackTrace); | ||
} | ||
} | ||
|
||
private void TextBoxSearchControl_OnKeyDown(object sender, KeyEventArgs e) | ||
{ | ||
try | ||
{ | ||
if (string.IsNullOrEmpty(TextBoxSearchControl.Text)) return; | ||
|
||
if (e.Key != Key.Enter) return; | ||
|
||
var controls = DCSBIOSControlLocator.GlobalControlSearch(TextBoxSearchControl.Text); | ||
ShowControls(controls); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Common.ShowErrorMessageBox(ex); | ||
} | ||
} | ||
|
||
private void ButtonSearchControls_OnMouseDown(object sender, MouseButtonEventArgs e) | ||
{ | ||
try | ||
{ | ||
if (string.IsNullOrEmpty(TextBoxSearchControl.Text)) return; | ||
|
||
var controls = DCSBIOSControlLocator.GlobalControlSearch(TextBoxSearchControl.Text); | ||
ShowControls(controls); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Common.ShowErrorMessageBox(ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters