Skip to content

Commit

Permalink
Allow newlines in Definition (Custom Word) and Extra info (Custom Nam…
Browse files Browse the repository at this point in the history
…e) fields
  • Loading branch information
rampaa committed Jan 16, 2025
1 parent 73b3ed8 commit 8f782d9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ internal static void Load(Dict dict, CancellationToken cancellationToken)
{
extraInfo = null;
}
else
{
extraInfo = extraInfo.Replace("\\n", "\n", StringComparison.Ordinal);
}
}

AddToDictionary(spelling, reading, nameType, extraInfo, customNameDictionary);
Expand Down
2 changes: 1 addition & 1 deletion JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal static void Load(Dict dict, CancellationToken cancellationToken)
readings = null;
}

string[] definitions = lParts[2].Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
string[] definitions = lParts[2].Replace("\\n", "\n", StringComparison.Ordinal).Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
string partOfSpeech = lParts[3];

string[]? wordClasses = null;
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/AddNameWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<TextBlock Text="Reading" HorizontalAlignment="Left" Margin="0,0,0,10" Style="{StaticResource TextBlockDefault}" />
<TextBox x:Name="ReadingTextBox" TextWrapping="Wrap" HorizontalAlignment="Stretch" Width="300" Margin="0,0,0,20" />
<TextBlock Text="Extra Info" HorizontalAlignment="Left" Margin="0,0,0,10" Style="{StaticResource TextBlockDefault}" />
<TextBox x:Name="ExtraInfoTextBox" TextWrapping="Wrap" HorizontalAlignment="Stretch" Width="300" />
<TextBox x:Name="ExtraInfoTextBox" AcceptsReturn="True" AcceptsTab="False" TextWrapping="Wrap" HorizontalAlignment="Stretch" Width="300" />
</StackPanel>
<StackPanel x:Name="NameTypeStackPanel" HorizontalAlignment="Right" VerticalAlignment="Top"
Margin="0,20,20,70">
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/AddNameWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private Task HandleSaveButtonClick()
Close();

string path = Path.GetFullPath(dict.Path, Utils.ApplicationPath);
string line = $"{spelling}\t{reading}\t{nameType}\t{extraInfo}\n";
string line = $"{spelling}\t{reading}\t{nameType}\t{extraInfo?.ReplaceLineEndings("\\n")}\n";
return File.AppendAllTextAsync(path, line);
}

Expand Down Expand Up @@ -105,7 +105,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
// ReSharper disable once AsyncVoidMethod
private async void Window_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On)
if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On && !ExtraInfoTextBox.IsFocused)
{
e.Handled = true;
await HandleSaveButtonClick().ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/AddWordWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<TextBox x:Name="ReadingsTextBox" HorizontalAlignment="Left" TextWrapping="Wrap" Width="300" Margin="0,0,0,20"
Cursor="Help" ToolTip="Separated by a semicolon" />
<TextBlock Text="Definitions" TextWrapping="Wrap" Margin="0,0,0,10" HorizontalAlignment="Left" Style="{StaticResource TextBlockDefault}" />
<TextBox x:Name="DefinitionsTextBox" HorizontalAlignment="Left" TextWrapping="Wrap" Width="300" Margin="0,0,0,20"
<TextBox x:Name="DefinitionsTextBox" HorizontalAlignment="Left" AcceptsReturn="True" AcceptsTab="False" TextWrapping="Wrap" Width="300" Margin="0,0,0,20"
Cursor="Help" ToolTip="Separated by a semicolon" />
<StackPanel x:Name="WordClassStackPanel" Visibility="Visible">
<TextBlock Text="Word Classes" TextWrapping="Wrap" Margin="0,0,0,10" HorizontalAlignment="Left" Style="{StaticResource TextBlockDefault}" />
Expand Down
6 changes: 3 additions & 3 deletions JL.Windows/GUI/AddWordWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private Task HandleSaveButtonClick()
Close();

string line = string.IsNullOrWhiteSpace(rawWordClasses)
? $"{rawSpellings}\t{rawReadings}\t{rawDefinitions}\t{rawPartOfSpeech}\n"
: $"{rawSpellings}\t{rawReadings}\t{rawDefinitions}\t{rawPartOfSpeech}\t{rawWordClasses}\n";
? $"{rawSpellings}\t{rawReadings}\t{rawDefinitions.ReplaceLineEndings("\\n")}\t{rawPartOfSpeech}\n"
: $"{rawSpellings}\t{rawReadings}\t{rawDefinitions.ReplaceLineEndings("\\n")}\t{rawPartOfSpeech}\t{rawWordClasses}\n";

string path = Path.GetFullPath(dict.Path, Utils.ApplicationPath);
return File.AppendAllTextAsync(path, line);
Expand Down Expand Up @@ -172,7 +172,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
// ReSharper disable once AsyncVoidMethod
private async void Window_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On)
if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On && !DefinitionsTextBox.IsFocused)
{
e.Handled = true;
await HandleSaveButtonClick().ConfigureAwait(false);
Expand Down

0 comments on commit 8f782d9

Please sign in to comment.