Commit 63f861a7 authored by Kad Venku's avatar Kad Venku

Add window now has "Add" boxes for all loaded languages.

If left empty for a language the translation taken from the loaded language will be used with a TODO: prefix as a placeholder.
parent bcdb66de
......@@ -14,7 +14,7 @@
ShowTitleBar="False"
HorizontalContentAlignment="Stretch"
EnableDropShadow="False"
CloseByEscape="False">
CloseByEscape="False" Loaded="AddTextKeyWindow_Loaded">
<simpleChildWindow:ChildWindow.OverlayBrush>
<SolidColorBrush Opacity="0.35" Color="{StaticResource BlackColor}" />
</simpleChildWindow:ChildWindow.OverlayBrush>
......@@ -40,13 +40,25 @@
<Grid Margin="0" Grid.Row="2" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="English:" Grid.Row="0" Grid.Column="0"/>
<TextBox x:Name="_valueTextBox" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3"/>
<Label x:Name="_valueEnglishLabel" Content="English:" Grid.Row="0" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueEnglishTextBox" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding EnglishText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueGermanLabel" Content="German:" Grid.Row="1" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueGermanTextBox" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding GermanText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueFrenchLabel" Content="French:" Grid.Row="2" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueFrenchTextBox" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding FrenchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueItalianLabel" Content="Italian:" Grid.Row="3" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueItalianTextBox" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding ItalianText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueSpanishLabel" Content="Spanish:" Grid.Row="4" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueSpanishTextBox" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding SpanishText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
</Grid>
<UniformGrid Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" Columns="2">
<Button Content="Add" Margin="5" Click="OnAddClick" IsEnabled="{Binding IsValidKey, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Style="{DynamicResource AccentedSquareButtonStyle}"/>
......
using System.Windows;
using System;
using System.Windows;
using eaw_texteditor.shared.data.dialogs.edit;
using MahApps.Metro.SimpleChildWindow;
using ts.translation;
using ts.translation.common.typedefs;
using ts.translation.data.holder.observables;
namespace eaw_texteditor.client.ui.dialogs.add
......@@ -11,16 +14,18 @@ namespace eaw_texteditor.client.ui.dialogs.add
public partial class AddTextKeyWindow : ChildWindow
{
internal EditTextKeyWindowData FormData { get; set; }
public AddTextKeyWindow(ObservableTranslationData translation)
public AddTextKeyWindow(PGLanguage selectedLanguage, ObservableTranslationData translationEnglish, ObservableTranslationData translationGerman, ObservableTranslationData translationFrench, ObservableTranslationData translationItalian, ObservableTranslationData translationSpanish)
{
InitializeComponent();
FormData = new EditTextKeyWindowData() { Translation = translation };
FormData = new EditTextKeyWindowData() {SelectedLanguage = selectedLanguage, TranslationEnglish = translationEnglish, TranslationGerman = translationGerman, TranslationFrench = translationFrench, TranslationItalian = translationItalian, TranslationSpanish = translationSpanish};
DataContext = FormData;
FormData.IsKeyEditable = true;
FormData.IsValidKey = false;
FormData.IsBoltVisible = Visibility.Visible;
}
private void OnAddClick(object sender, RoutedEventArgs e)
{
this.Close(true);
......@@ -30,5 +35,37 @@ namespace eaw_texteditor.client.ui.dialogs.add
{
this.Close(false);
}
private void AddTextKeyWindow_Loaded(object sender, RoutedEventArgs e)
{
foreach (PGLanguage loadedLanguage in PGTEXTS.GetLoadedLanguages())
{
switch (loadedLanguage)
{
case PGLanguage.ENGLISH:
_valueEnglishLabel.Visibility = Visibility.Visible;
_valueEnglishTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.FRENCH:
_valueFrenchLabel.Visibility = Visibility.Visible;
_valueFrenchTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.ITALIAN:
_valueItalianLabel.Visibility = Visibility.Visible;
_valueItalianTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.GERMAN:
_valueGermanLabel.Visibility = Visibility.Visible;
_valueGermanTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.SPANISH:
_valueSpanishLabel.Visibility = Visibility.Visible;
_valueSpanishTextBox.Visibility = Visibility.Visible;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
}
......@@ -15,7 +15,7 @@
ShowTitleBar="False"
HorizontalContentAlignment="Stretch"
EnableDropShadow="False"
CloseOnOverlay="True" ClosingFinished="OnClosingFinished">
CloseOnOverlay="True" ClosingFinished="OnClosingFinished" Loaded="EditTextKeyWindow_Loaded">
<simpleChildWindow:ChildWindow.OverlayBrush>
<SolidColorBrush Opacity="0.35" Color="{StaticResource BlackColor}" />
</simpleChildWindow:ChildWindow.OverlayBrush>
......@@ -38,6 +38,28 @@
</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" TextWrapping="Wrap"/>
<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"/>
<Grid Margin="0" Grid.Row="2" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label x:Name="_valueEnglishLabel" Content="English:" Grid.Row="0" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueEnglishTextBox" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding EnglishText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueGermanLabel" Content="German:" Grid.Row="1" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueGermanTextBox" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding GermanText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueFrenchLabel" Content="French:" Grid.Row="2" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueFrenchTextBox" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding FrenchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueItalianLabel" Content="Italian:" Grid.Row="3" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueItalianTextBox" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding ItalianText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
<Label x:Name="_valueSpanishLabel" Content="Spanish:" Grid.Row="4" Grid.Column="0" Visibility="Collapsed"/>
<TextBox x:Name="_valueSpanishTextBox" Grid.Row="4" Grid.Column="1" HorizontalAlignment="Stretch" Margin="0,5" Text="{Binding SpanishText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" SpellCheck.IsEnabled="True" MinLines="3" Visibility="Collapsed"/>
</Grid>
</Grid>
</simpleChildWindow:ChildWindow>
using eaw_texteditor.Properties;
using System;
using System.Windows;
using eaw_texteditor.Properties;
using eaw_texteditor.shared.data.dialogs.edit;
using MahApps.Metro.SimpleChildWindow;
using ts.translation;
using ts.translation.common.typedefs;
using ts.translation.data.holder.observables;
namespace eaw_texteditor.client.ui.dialogs.edit
......@@ -12,11 +15,11 @@ namespace eaw_texteditor.client.ui.dialogs.edit
public partial class EditTextKeyWindow : ChildWindow
{
internal EditTextKeyWindowData FormData { get; set; }
public EditTextKeyWindow(ObservableTranslationData translation)
public EditTextKeyWindow(PGLanguage selectedLanguage, ObservableTranslationData translationEnglish, ObservableTranslationData translationGerman, ObservableTranslationData translationFrench, ObservableTranslationData translationItalian, ObservableTranslationData translationSpanish)
{
InitializeComponent();
FormData = new EditTextKeyWindowData() {Translation = translation};
if (FormData.Key == string.Empty && FormData.Value == string.Empty)
FormData = new EditTextKeyWindowData() { SelectedLanguage = selectedLanguage, TranslationEnglish = translationEnglish, TranslationGerman = translationGerman, TranslationFrench = translationFrench, TranslationItalian = translationItalian, TranslationSpanish = translationSpanish };
if (FormData.Key == string.Empty && (FormData.EnglishText == string.Empty || FormData.SpanishText == string.Empty || FormData.FrenchText == string.Empty || FormData.GermanText == string.Empty || FormData.ItalianText == string.Empty))
{
FormData.IsKeyEditable = true;
FormData.IsValidKey = false;
......@@ -26,7 +29,82 @@ namespace eaw_texteditor.client.ui.dialogs.edit
private void OnClosingFinished(object sender, System.Windows.RoutedEventArgs e)
{
PGTEXTS.SetText(FormData.Key, FormData.Value, Settings.Default.USR_LOADED_LANGUAGE);
foreach (PGLanguage loadedLanguage in PGTEXTS.GetLoadedLanguages())
{
switch (loadedLanguage)
{
case PGLanguage.ENGLISH:
if (string.IsNullOrEmpty(FormData.EnglishText))
{
FormData.EnglishText = $"TODO: {FormData.FallbackText}";
}
PGTEXTS.SetText(FormData.Key, FormData.EnglishText, loadedLanguage);
break;
case PGLanguage.FRENCH:
if (string.IsNullOrEmpty(FormData.FrenchText))
{
FormData.FrenchText = $"TODO: {FormData.FallbackText}";
}
PGTEXTS.SetText(FormData.Key, FormData.FrenchText, loadedLanguage);
break;
case PGLanguage.ITALIAN:
if (string.IsNullOrEmpty(FormData.ItalianText))
{
FormData.ItalianText = $"TODO: {FormData.FallbackText}";
}
PGTEXTS.SetText(FormData.Key, FormData.ItalianText, loadedLanguage);
break;
case PGLanguage.GERMAN:
if (string.IsNullOrEmpty(FormData.GermanText))
{
FormData.GermanText = $"TODO: {FormData.FallbackText}";
}
PGTEXTS.SetText(FormData.Key, FormData.GermanText, loadedLanguage);
break;
case PGLanguage.SPANISH:
if (string.IsNullOrEmpty(FormData.SpanishText))
{
FormData.SpanishText = $"TODO: {FormData.FallbackText}";
}
PGTEXTS.SetText(FormData.Key, FormData.SpanishText, loadedLanguage);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
private void EditTextKeyWindow_Loaded(object sender, RoutedEventArgs e)
{
foreach (PGLanguage loadedLanguage in PGTEXTS.GetLoadedLanguages())
{
switch (loadedLanguage)
{
case PGLanguage.ENGLISH:
_valueEnglishLabel.Visibility = Visibility.Visible;
_valueEnglishTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.FRENCH:
_valueFrenchLabel.Visibility = Visibility.Visible;
_valueFrenchTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.ITALIAN:
_valueItalianLabel.Visibility = Visibility.Visible;
_valueItalianTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.GERMAN:
_valueGermanLabel.Visibility = Visibility.Visible;
_valueGermanTextBox.Visibility = Visibility.Visible;
break;
case PGLanguage.SPANISH:
_valueSpanishLabel.Visibility = Visibility.Visible;
_valueSpanishTextBox.Visibility = Visibility.Visible;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}
}
using System.ComponentModel;
using System;
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.common.typedefs;
using ts.translation.data.holder.observables;
namespace eaw_texteditor.shared.data.dialogs.edit
{
class EditTextKeyWindowData : INotifyPropertyChanged
{
private ObservableTranslationData _translation;
private ObservableTranslationData _translationEnglish;
private ObservableTranslationData _translationGerman;
private ObservableTranslationData _translationFrench;
private ObservableTranslationData _translationItalian;
private ObservableTranslationData _translationSpanish;
public string FallbackText { get; set; }
public bool TranslationChanged = false;
public ObservableTranslationData Translation
public ObservableTranslationData TranslationEnglish
{
get => _translationEnglish;
set
{
_translationEnglish = value;
TranslationChanged = true;
OnPropertyChanged(nameof(TranslationEnglish));
}
}
public ObservableTranslationData TranslationGerman
{
get => _translationGerman;
set
{
_translationGerman = value;
TranslationChanged = true;
OnPropertyChanged(nameof(TranslationGerman));
}
}
public ObservableTranslationData TranslationFrench
{
get => _translationFrench;
set
{
_translationFrench = value;
TranslationChanged = true;
OnPropertyChanged(nameof(TranslationFrench));
}
}
public ObservableTranslationData TranslationItalian
{
get => _translationItalian;
set
{
_translationItalian = value;
TranslationChanged = true;
OnPropertyChanged(nameof(TranslationItalian));
}
}
public ObservableTranslationData TranslationSpanish
{
get => _translation;
get => _translationSpanish;
set
{
_translation = value;
_translationSpanish = value;
TranslationChanged = true;
OnPropertyChanged(nameof(Translation));
OnPropertyChanged(nameof(TranslationSpanish));
}
}
public string Key
{
get => DoValidate(_translation?.Key);
get
{
if (_translationEnglish != null)
{
return DoValidate(_translationEnglish?.Key);
}
if (_translationGerman != null)
{
return DoValidate(_translationGerman?.Key);
}
if (_translationFrench != null)
{
return DoValidate(_translationFrench?.Key);
}
if (_translationItalian != null)
{
return DoValidate(_translationItalian?.Key);
}
if (_translationSpanish != null)
{
return DoValidate(_translationSpanish?.Key);
}
return DoValidate(string.Empty);
}
set
{
if (_translation == null) return;
_translation.Key = DoValidate(value);
string validKey = DoValidate(value);
if (_translationEnglish != null)
{
_translationEnglish.Key = validKey;
}
if (_translationGerman != null)
{
_translationGerman.Key = validKey;
}
if (_translationFrench != null)
{
_translationFrench.Key = validKey;
}
if (_translationItalian != null)
{
_translationItalian.Key = validKey;
}
if (_translationSpanish != null)
{
_translationSpanish.Key = validKey;
}
OnPropertyChanged(nameof(Key));
}
}
public string Value
public string EnglishText
{
get => _translationEnglish?.Value;
set
{
if (_translationEnglish == null) return;
_translationEnglish.Value = value;
DoUpdateFallbackText();
OnPropertyChanged(nameof(EnglishText));
}
}
public string GermanText
{
get => _translationGerman?.Value;
set
{
if (_translationGerman == null) return;
_translationGerman.Value = value;
DoUpdateFallbackText();
OnPropertyChanged(nameof(GermanText));
}
}
public string FrenchText
{
get => _translation?.Value;
get => _translationFrench?.Value;
set
{
if (_translation == null) return;
_translation.Value = value;
OnPropertyChanged(nameof(Value));
if (_translationFrench == null) return;
_translationFrench.Value = value;
DoUpdateFallbackText();
OnPropertyChanged(nameof(FrenchText));
}
}
public string ItalianText
{
get => _translationItalian?.Value;
set
{
if (_translationItalian == null) return;
_translationItalian.Value = value;
DoUpdateFallbackText();
OnPropertyChanged(nameof(ItalianText));
}
}
private void DoUpdateFallbackText()
{
switch (SelectedLanguage)
{
case PGLanguage.ENGLISH:
FallbackText = EnglishText;
break;
case PGLanguage.FRENCH:
FallbackText = FrenchText;
break;
case PGLanguage.ITALIAN:
FallbackText = ItalianText;
break;
case PGLanguage.GERMAN:
FallbackText = GermanText;
break;
case PGLanguage.SPANISH:
FallbackText = SpanishText;
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public string SpanishText
{
get => _translationSpanish?.Value;
set
{
if (_translationSpanish == null) return;
_translationSpanish.Value = value;
DoUpdateFallbackText();
OnPropertyChanged(nameof(SpanishText));
}
}
......@@ -122,12 +291,15 @@ namespace eaw_texteditor.shared.data.dialogs.edit
}
}
public PGLanguage SelectedLanguage { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
DoUpdateFallbackText();
}
}
}
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