Commit 23dff09d authored by Kad Venku's avatar Kad Venku

Added change menu.

parent a0fa2db4
<simpleChildWindow:ChildWindow
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:local="clr-namespace:eaw_texteditor.client.ui.dialogs.edit"
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" x:Class="eaw_texteditor.client.ui.dialogs.edit.EditTextKeyWindow"
BorderBrush="{DynamicResource AccentBaseColorBrush}"
BorderThickness="1"
GlowBrush="{DynamicResource AccentColorBrush}"
mc:Ignorable="d"
ShowTitleBar="False"
HorizontalContentAlignment="Stretch"
EnableDropShadow="False"
CloseOnOverlay="True">
<simpleChildWindow:ChildWindow.OverlayBrush>
<SolidColorBrush Opacity="0.35" Color="{StaticResource BlackColor}" />
</simpleChildWindow:ChildWindow.OverlayBrush>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="_keyTextBox" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,20,0,0" Text="{Binding Key, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsKeyEditable, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Background="{Binding BackgroundColor}"/>
<Rectangle Fill="Crimson" Grid.Row="0" Grid.Column="2" Height="25" Width="15" Margin="5,20,0,0" Visibility="{Binding IsBoltVisible}">
<Rectangle.OpacityMask>
<VisualBrush Visual="{iconPacks:FontAwesome BoltSolid}"/>
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Grid.Row="1" Grid.Column="1" Foreground="Crimson" Text="The text key should only contain uppercase letters, numbers and underscores. Some hardcoded vanilla keys do not follow this convention, so the message can be disregarded for those keys." Visibility="{Binding IsBoltVisible}" Margin="0"/>
<TextBox x:Name="_valueTextBox" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="5"/>
<CheckBox x:Name="_editKeyCheckBox" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,0,20" Content="Edit Key" IsChecked="{Binding IsKeyEditable, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
</simpleChildWindow:ChildWindow>
using eaw_texteditor.shared.data.dialogs.edit;
using MahApps.Metro.SimpleChildWindow;
using ts.translation.data.holder.observables;
namespace eaw_texteditor.client.ui.dialogs.edit
{
/// <summary>
/// Interaction logic for EditTextKeyWindow.xaml
/// </summary>
public partial class EditTextKeyWindow : ChildWindow
{
public EditTextKeyWindow(ObservableTranslationData translation)
{
InitializeComponent();
DataContext = new EditTextKeyWindowData() {Translation = translation};
}
}
}
......@@ -4,15 +4,12 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:eaw_texteditor"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:serializable="clr-namespace:ts.translation.data.definitions.serializable;assembly=ts.translation"
xmlns:observables="clr-namespace:ts.translation.data.holder.observables;assembly=ts.translation"
mc:Ignorable="d"
Title="Star Wars: Empire at War - Text Editor" Height="450" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip"
BorderBrush="{DynamicResource AccentColorBrush}"
BorderThickness="1"
SaveWindowPosition="True" Icon="/eaw-texteditor;component/eaw-icon.ico" MinWidth="800" MinHeight="600" VerticalAlignment="Bottom" Loaded="MetroWindow_Loaded">
SaveWindowPosition="True" Icon="/eaw-texteditor;component/eaw-icon.ico" MinWidth="800" MinHeight="600" VerticalAlignment="Bottom">
<Controls:MetroWindow.RightWindowCommands>
<Controls:WindowCommands>
<Button x:Name="_importButton" Content="{iconPacks:FontAwesome FileImportSolid}" ToolTip="Import from file ..." Click="_importExecuteButton_Click"/>
......@@ -21,7 +18,7 @@
</Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>
<TabControl x:Name="_mainBoxTabControl" Margin="0">
<TabItem x:Name="_basicTextEditorTab" Header="Basic Text Editor" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" Controls:ScrollViewerHelper.IsHorizontalScrollWheelEnabled="True" >
<TabItem x:Name="_basicTextEditorTab" Header="Basic Text Editor" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1.5*"/>
......@@ -32,7 +29,8 @@
<RowDefinition Height="1*" MinHeight="150"/>
</Grid.RowDefinitions>
<!--<ScrollViewer Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">-->
<DataGrid x:Name="_basicEditorDataGrid" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" BindingGroup="{Binding ObservableTranslationData}" AutoGenerateColumns="False" CanUserReorderColumns="False" SelectionUnit="FullRow" MouseDoubleClick="_basicEditorDataGrid_OnDoubleClick" EnableColumnVirtualization="True" >
<!--<DataGrid x:Name="_basicEditorDataGrid" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" BindingGroup="{Binding ObservableTranslationData}" AutoGenerateColumns="False" CanUserReorderColumns="False" SelectionUnit="FullRow" MouseDoubleClick="_basicEditorDataGrid_OnDoubleClick" EnableColumnVirtualization="True" >-->
<DataGrid x:Name="_basicEditorDataGrid" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" ItemsSource="{Binding ListItemCollection}" AutoGenerateColumns="False" CanUserReorderColumns="False" SelectionUnit="FullRow" MouseDoubleClick="_basicEditorDataGrid_OnDoubleClick" EnableColumnVirtualization="True" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Key}" CanUserReorder="False" Header="Text Key" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Value}" CanUserReorder="False" Header="Translation" IsReadOnly="True"/>
......@@ -53,23 +51,18 @@
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBox x:Name="_searchBox" Grid.Column="0" Grid.Row="0" VerticalAlignment="Top" Grid.ColumnSpan="3" Margin="0,2,10,0" Padding="0" />
<CheckBox Content="Search keys" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3"/>
<CheckBox Content="Search translation" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3"/>
<CheckBox x:Name="_enableAdvancedSearchCheckBox" Content="Enable advanced search options" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" IsChecked="{Binding Path=IsAdvancedSearchCheckBoxChecked, Mode=TwoWay}" Checked="AdvancedSearchCheckBoxCheckedChanged" Unchecked="AdvancedSearchCheckBoxCheckedChanged"/>
<Grid Grid.Column="3" Grid.Row="0" Height="30" MinHeight="30" MaxHeight="30" VerticalAlignment="Top">
<TextBox x:Name="_searchBox" Grid.Column="0" Grid.Row="0" VerticalAlignment="Top" Grid.ColumnSpan="3" Margin="10,2,10,0" Padding="0" Text="{Binding Path=SearchTerm, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Grid Grid.Column="3" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="35"/>
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" Content="{iconPacks:FontAwesome ChevronLeftSolid}" Margin="0,0,5,0" ToolTip="Previous result" IsEnabled="False"/>
<Button x:Name="_searchExecuteButton" Grid.Column="1" Grid.Row="0" Content="{iconPacks:FontAwesome SearchSolid}" ToolTip="Find" IsEnabled="False" Click="_searchExecuteButton_Click"/>
<Button Grid.Column="2" Grid.Row="0" Content="{iconPacks:FontAwesome ChevronRightSolid}" Margin="5,0,0,0" ToolTip="Next result" IsEnabled="False"/>
<Button x:Name="_refreshButton" Content="{iconPacks:FontAwesome SyncSolid}" Grid.Column="0" Click="OnRefreshClick" ToolTip="Refresh..."/>
<Button x:Name="_clearButton" Content="{iconPacks:FontAwesome TrashSolid}" Grid.Column="1" Click="OnClearClick" ToolTip="Clear..."/>
</Grid>
<RadioButton Content="Search keys" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Margin="10,0,0,0" IsChecked="{Binding Path=UseKeySearch, Mode=TwoWay}" />
<RadioButton Content="Search translation" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3" Margin="10,0,0,0" IsChecked="{Binding Path=UseValueSearch, Mode=TwoWay}"/>
<CheckBox x:Name="_enableAdvancedSearchCheckBox" Content="Enable advanced search options" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" Margin="10,0,0,0" IsChecked="{Binding Path=IsAdvancedSearchCheckBoxChecked, Mode=TwoWay}" Checked="AdvancedSearchCheckBoxCheckedChanged" Unchecked="AdvancedSearchCheckBoxCheckedChanged"/>
</Grid>
</GroupBox>
<GroupBox Name="_advancedSearchFormGroupBox" Grid.Column="1" Grid.Row="1" Header="Advanced Search" IsEnabled="False">
......@@ -84,10 +77,12 @@
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<CheckBox x:Name="_matchCaseCheckBox" Content="Match case" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3"/>
<CheckBox x:Name="_matchWordCheckBox" Content="Match word" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3"/>
<CheckBox x:Name="_regExSearch" Content="RegEx Search" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3"/>
<CheckBox x:Name="_matchCaseCheckBox" Content="Match case" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" IsChecked="{Binding Path=MatchCase, Mode=TwoWay}"/>
<RadioButton x:Name="_normalCheckBox" Content="Simple Search" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" IsChecked="{Binding Path=UseSimpleSearch, Mode=TwoWay}"/>
<RadioButton x:Name="_wildCardCheckBox" Content="Wildcard Search" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="3" IsChecked="{Binding Path=UseWildCardSearch, Mode=TwoWay}"/>
<RadioButton x:Name="_regExSearch" Content="RegEx Search" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" IsChecked="{Binding Path=UseRegExSearch, Mode=TwoWay}"/>
</Grid>
</GroupBox>
</Grid>
......
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Data;
using System.Windows.Input;
using eaw_texteditor.client.ui.dialogs.edit;
using eaw_texteditor.shared.common.util.ui;
using eaw_texteditor.shared.data.main;
using MahApps.Metro.Controls;
using MahApps.Metro.SimpleChildWindow;
using ts.translation;
using ts.translation.common.typedefs;
using ts.translation.common.util.observable;
......@@ -18,8 +20,7 @@ namespace eaw_texteditor.client.ui.main
/// </summary>
public partial class MainWindow : MetroWindow
{
private static bool IsInSetup = true;
private MainWindowData _formData { get; set; }
private MainWindowData FormData { get; set; }
public MainWindow()
{
......@@ -27,59 +28,44 @@ namespace eaw_texteditor.client.ui.main
ImportFormData(new MainWindowData());
}
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
private void ImportFormData(MainWindowData data)
{
IsInSetup = false;
}
internal void ImportFormData(MainWindowData data)
{
_formData = data;
data.UseKeySearch = true;
data.UseSimpleSearch = true;
data.MatchCase = true;
FormData = data;
DataContext = data;
}
private void _searchExecuteButton_Click(object sender, RoutedEventArgs e)
{
Console.Write("Search executed!");
}
private void AdvancedSearchCheckBoxCheckedChanged(object sender, RoutedEventArgs e)
{
Console.WriteLine($"Stuff changed! {_formData.IsAdvancedSearchCheckBoxChecked}");
_advancedSearchFormGroupBox.IsEnabled = _formData.IsAdvancedSearchCheckBoxChecked;
_formData.ObservableTranslationDataHolder.Add(new ObservableTranslationData($"{Guid.NewGuid()}", "Value"));
Random rnd = new Random();
int index = rnd.Next(0, _formData.ObservableTranslationDataHolder.Count);
_formData.ObservableTranslationDataHolder[index].Value += "EDIT!";
}
private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
{
Console.WriteLine("TEST");
}
private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
_advancedSearchFormGroupBox.IsEnabled = FormData.IsAdvancedSearchCheckBoxChecked;
}
private void _translationDataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
private async void _settingsExecuteButton_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("TEST");
}
private void _settingsExecuteButton_Click(object sender, RoutedEventArgs e)
private async void _basicEditorDataGrid_OnDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton != MouseButton.Left)
{
e.Handled = true;
return;
}
}
private void _basicEditorDataGrid_OnDoubleClick(object sender, MouseButtonEventArgs e)
{
DependencyObject source = (DependencyObject)e.OriginalSource;
DataGridRow row = UiUtility.TryFindParent<DataGridRow>(source);
if (row == null) return;
Console.WriteLine("Click Event!");
if (!(row.Item is ObservableTranslationData translationItem))
{
e.Handled = true;
return;
}
Console.WriteLine($"{translationItem.Key} = {translationItem.Value}");
var result = await this.ShowChildWindowAsync<bool>(new EditTextKeyWindow(translationItem) { IsModal = true }, ChildWindowManager.OverlayFillBehavior.FullWindow);
e.Handled = true;
}
......@@ -87,8 +73,8 @@ namespace eaw_texteditor.client.ui.main
private void _importExecuteButton_Click(object sender, RoutedEventArgs e)
{
PGTEXTS.LoadFromFile("I:\\Workspace\\eaw-texteditor\\test\\TranslationManifest.xml");
_formData.ObservableTranslationDataHolder = ObservableTranslationUtility.GetTranslationDataAsObservable();
_basicEditorDataGrid.ItemsSource = _formData.ObservableTranslationDataHolder;
CollectionViewSource collectionViewSource = new CollectionViewSource {Source = ObservableTranslationUtility.GetTranslationDataAsObservable()};
FormData.ListItemCollection = collectionViewSource.View;
}
private void _exportExecuteButton_Click(object sender, RoutedEventArgs e)
......@@ -96,5 +82,15 @@ namespace eaw_texteditor.client.ui.main
PGTEXTS.SaveToFile("I:\\Workspace\\eaw-texteditor\\test\\export");
PGTEXTS.SaveToFile("I:\\Workspace\\eaw-texteditor\\test\\export", TSFileTypes.FileTypeDat);
}
private void OnRefreshClick(object sender, RoutedEventArgs e)
{
FormData.TryRefresh();
}
private void OnClearClick(object sender, RoutedEventArgs e)
{
FormData.SearchTerm = string.Empty;
}
}
}
......@@ -61,6 +61,9 @@
<Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll</HintPath>
</Reference>
<Reference Include="DotNetToolkit.Wpf.Metro.Dialogs, Version=1.0.3.27, Culture=neutral, PublicKeyToken=fc15a78dc7f484d4, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetToolkit.Wpf.Metro.Dialogs.1.0.3.27\lib\net451\DotNetToolkit.Wpf.Metro.Dialogs.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
......@@ -70,6 +73,9 @@
<Reference Include="MahApps.Metro.IconPacks, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net45\MahApps.Metro.IconPacks.dll</HintPath>
</Reference>
<Reference Include="MahApps.Metro.SimpleChildWindow, Version=1.5.0.16, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.SimpleChildWindow.1.5.0\lib\net45\MahApps.Metro.SimpleChildWindow.dll</HintPath>
</Reference>
<Reference Include="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
<Reference Include="System" />
<Reference Include="System.Data" />
......@@ -96,11 +102,20 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="client\ui\dialogs\edit\EditTextKeyWindow.xaml.cs">
<DependentUpon>EditTextKeyWindow.xaml</DependentUpon>
</Compile>
<Compile Include="ObservableTranslationDataHolder.xaml.cs">
<DependentUpon>ObservableTranslationDataHolder.xaml</DependentUpon>
</Compile>
<Compile Include="shared\common\util\ui\UiUtility.cs" />
<Compile Include="shared\data\dialogs\edit\EditTextKeyWindowData.cs" />
<Compile Include="shared\data\AWindowData.cs" />
<Compile Include="shared\data\main\MainWindowData.cs" />
<Page Include="client\ui\dialogs\edit\EditTextKeyWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="client\ui\main\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ControlzEx" version="3.0.2.4" targetFramework="net45" requireReinstallation="true" />
<package id="DotNetToolkit.Wpf.Metro.Dialogs" version="1.0.3.27" targetFramework="net471" />
<package id="log4net" version="2.0.8" targetFramework="net45" />
<package id="MahApps.Metro" version="1.6.5" targetFramework="net45" requireReinstallation="true" />
<package id="MahApps.Metro.IconPacks" version="2.3.0" targetFramework="net45" requireReinstallation="true" />
<package id="MahApps.Metro.SimpleChildWindow" version="1.5.0" targetFramework="net471" />
</packages>
\ No newline at end of file
using System.ComponentModel;
using System.Runtime.CompilerServices;
using ts.translation.Annotations;
namespace eaw_texteditor.shared.data
{
public abstract class AWindowData : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
\ No newline at end of file
using System.ComponentModel;
using System.Windows.Media;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Windows;
using ts.translation.Annotations;
using ts.translation.data.holder.observables;
namespace eaw_texteditor.shared.data.dialogs.edit
{
class EditTextKeyWindowData : INotifyPropertyChanged
{
private ObservableTranslationData _translation;
public ObservableTranslationData Translation
{
get => _translation;
set
{
_translation = value;
OnPropertyChanged(nameof(Translation));
}
}
public string Key
{
get => DoValidate(_translation?.Key);
set
{
if (_translation == null) return;
_translation.Key = DoValidate(value); ;
OnPropertyChanged(nameof(Key));
}
}
public string Value
{
get => _translation?.Value;
set
{
if (_translation == null) return;
_translation.Value = value;
OnPropertyChanged(nameof(Value));
}
}
private bool _isKeyEditable;
public bool IsKeyEditable
{
get => _isKeyEditable;
set
{
_isKeyEditable = value;
OnPropertyChanged(nameof(IsKeyEditable));
}
}
private bool _isValidKey;
public bool IsValidKey
{
get => _isValidKey;
set
{
_isValidKey = value;
SetValidStateForKeyTextBox();
OnPropertyChanged(nameof(IsValidKey));
}
}
private void SetValidStateForKeyTextBox()
{
if (!IsValidKey)
{
BackgroundColor = new SolidColorBrush() {Color = Color.FromArgb(100, 220, 20, 60)};
IsBoltVisible = Visibility.Visible;
}
else{
BackgroundColor = new SolidColorBrush() {Color = Color.FromArgb(255, 255, 255, 255)};
IsBoltVisible = Visibility.Collapsed;
}
}
private Brush _backgroundBrush;
public Brush BackgroundColor
{
get => _backgroundBrush;
set
{
_backgroundBrush = value;
OnPropertyChanged(nameof(BackgroundColor));
}
}
private string DoValidate(string value)
{
string newValue = value.TrimEnd();
Regex regEx = new Regex("^[A-Z0-9_]*$");
IsValidKey = regEx.Match(newValue).Success;
return newValue;
}
private Visibility _isBoltVisible = Visibility.Collapsed;
public Visibility IsBoltVisible
{
get => _isBoltVisible;
set
{
_isBoltVisible = value;
OnPropertyChanged(nameof(IsBoltVisible));
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
using System.Collections.ObjectModel;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using ts.translation.Annotations;
......@@ -9,19 +9,190 @@ namespace eaw_texteditor.shared.data.main
public class MainWindowData : INotifyPropertyChanged
{
public bool IsAdvancedSearchCheckBoxChecked { get; set; }
public string SearchTerm { get; set; }
private ObservableCollection<ObservableTranslationData> _observableTranslationDataHolder = new ObservableCollection<ObservableTranslationData>();
private bool _useSearchKey;
public ObservableCollection<ObservableTranslationData> ObservableTranslationDataHolder
public bool UseKeySearch
{
get => _observableTranslationDataHolder;
get => _useSearchKey;
set
{
_observableTranslationDataHolder = value;
OnPropertyChanged();
_useSearchKey = value;
TryRefresh();
}
}
private bool _useValueSearch;
public bool UseValueSearch
{
get => _useValueSearch;
set
{
_useValueSearch = value;
TryRefresh();
}
}
private bool _useSimpleSearch;
public bool UseSimpleSearch
{
get => _useSimpleSearch;
set
{
_useSimpleSearch = value;
TryRefresh();
}
}
private bool _useWildCardSearch;
public bool UseWildCardSearch
{
get => _useWildCardSearch;
set
{
_useWildCardSearch = value;
TryRefresh();
}
}
private bool _useRegExSearch;
public bool UseRegExSearch
{
get => _useRegExSearch;
set
{
_useRegExSearch = value;
TryRefresh();
}
}
private bool _matchCase;
public bool MatchCase
{
get => _matchCase;
set
{
_matchCase = value;
TryRefresh();
}
}
private string _searchTerm;
public string SearchTerm
{
get => _searchTerm;
set
{
_searchTerm = value;
OnPropertyChanged(nameof(SearchTerm));
if (_listItemCollection == null) return;
_listItemCollection.Filter = GetFilter();
_listItemCollection.Refresh();
}
}
private Predicate<object> GetFilter()
{
if (UseSimpleSearch)
{
if (UseKeySearch)
{
if (MatchCase)
{
return Key_UseSimpleSearch_MatchCase;
}
else
{
return Key_UseSimpleSearch_IgnoreCase;
}
}
else
{
if (MatchCase)
{
return Value_UseSimpleSearch_MatchCase;
}
else
{
return Value_UseSimpleSearch_IgnoreCase;
}
}
}
else
{
if (UseKeySearch)
{
if (MatchCase)
{
return Key_UseSimpleSearch_MatchCase;
}
else
{
return Key_UseSimpleSearch_IgnoreCase;
}
}
else
{
if (MatchCase)
{
return Value_UseSimpleSearch_MatchCase;
}
else
{
return Value_UseSimpleSearch_IgnoreCase;
}
}
}
}
private bool Key_UseSimpleSearch_MatchCase(object value)
{
if (!(value is ObservableTranslationData entry)) return false;
return string.IsNullOrEmpty(_searchTerm) || entry.Key.Contains(_searchTerm);
}
private bool Key_UseSimpleSearch_IgnoreCase(object value)
{
if (!(value is ObservableTranslationData entry)) return false;
return string.IsNullOrEmpty(_searchTerm) || entry.Key.ToLower().Contains(_searchTerm.ToLower());
}
private bool Value_UseSimpleSearch_MatchCase(object value)
{
if (!(value is ObservableTranslationData entry)) return false;
return string.IsNullOrEmpty(_searchTerm) || entry.Value.Contains(_searchTerm);
}
private bool Value_UseSimpleSearch_IgnoreCase(object value)
{
if (!(value is ObservableTranslationData entry)) return false;
return string.IsNullOrEmpty(_searchTerm) || entry.Value.ToLower().Contains(_searchTerm.ToLower());
}
private ICollectionView _listItemCollection;
public ICollectionView ListItemCollection
{
get => _listItemCollection;
set {
_listItemCollection = value;
OnPropertyChanged(nameof(ListItemCollection));
}
}
public void TryRefresh()
{
string t = SearchTerm;
SearchTerm = t;
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment