Skip to content

Commit

Permalink
Make spelling field required for custom names
Browse files Browse the repository at this point in the history
Make word classes field required for verbs and adjectives while adding custom words
  • Loading branch information
rampaa committed Jan 30, 2025
1 parent 0eb5ce3 commit d077ce5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 38 deletions.
8 changes: 8 additions & 0 deletions JL.Windows/GUI/AddNameWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using JL.Core.Dicts;
using JL.Core.Dicts.CustomNameDict;
using JL.Core.Utilities;
Expand Down Expand Up @@ -47,6 +48,13 @@ private Task HandleSaveButtonClick()
#pragma warning restore CA1308 // Normalize strings to uppercase

string spelling = SpellingTextBox.Text.Replace("\t", " ", StringComparison.Ordinal).Trim();
if (spelling.Length is 0)
{
SpellingTextBox.BorderBrush = Brushes.Red;
SpellingTextBox.Cursor = Cursors.Help;
SpellingTextBox.ToolTip = "Spelling field cannot be left empty!";
return Task.CompletedTask;
}

string? reading = ReadingTextBox.Text.Replace("\t", " ", StringComparison.Ordinal).Trim();
if (reading.Length is 0 || reading == spelling)
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/AddWordWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
Margin="0,20,20,70">
<TextBlock Text="Part of Speech" HorizontalAlignment="Stretch" Margin="0,0,0,10" Style="{StaticResource TextBlockDefault}" />
<RadioButton Content="Noun" HorizontalAlignment="Stretch" FontSize="16" Height="40" Checked="OtherRadioButtons_Checked" />
<RadioButton Content="Verb" HorizontalAlignment="Stretch" FontSize="16" Height="40" Checked="VerbRadioButton_Checked" />
<RadioButton Content="Adjective" HorizontalAlignment="Stretch" FontSize="16" Height="40" Checked="OtherRadioButtons_Checked" />
<RadioButton Content="Verb" HorizontalAlignment="Stretch" FontSize="16" Height="40" Checked="VerbOrAdjectiveRadioButton_Checked" />
<RadioButton Content="Adjective" HorizontalAlignment="Stretch" FontSize="16" Height="40" Checked="VerbOrAdjectiveRadioButton_Checked" />
<RadioButton Content="Other" HorizontalAlignment="Stretch" FontSize="16" Height="40" Checked="OtherRadioButtons_Checked" IsChecked="True" />
</StackPanel>
</Grid>
Expand Down
102 changes: 66 additions & 36 deletions JL.Windows/GUI/AddWordWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using JL.Core.Dicts;
using JL.Core.Dicts.CustomWordDict;
using JL.Core.Utilities;
using JL.Core.WordClass;
using JL.Windows.Utilities;

namespace JL.Windows.GUI;
Expand All @@ -15,6 +16,37 @@ namespace JL.Windows.GUI;
/// </summary>
internal sealed partial class AddWordWindow
{
private const string SupportedAdjectiveWordClasses =
"""
adj-i: Adjective (keiyoushi)
adj-na: Adjectival nouns or quasi-adjectives (keiyodoshi)
""";

private const string SupportedVerbWordClasses =
"""
v1: Ichidan verb
v1-s: Ichidan verb - kureru special class
v4r: Yodan verb with `ru' ending (archaic)
v5aru: Godan verb - -aru special class
v5b: Godan verb with 'bu' ending
v5g: Godan verb with 'gu' ending
v5k: Godan verb with 'ku' ending
v5k-s: Godan verb - Iku/Yuku special class
v5m: Godan verb with 'mu' ending
v5n: Godan verb with 'nu' ending
v5r: Godan verb with 'ru' ending
v5r-i: Godan verb with 'ru' ending (irregular verb)
v5s: Godan verb with 'su' ending
v5t: Godan verb with 'tsu' ending
v5u: Godan verb with 'u' ending
v5u-s: Godan verb with 'u' ending (special class)
vk: Kuru verb - special class
vs-c: su verb - precursor to the modern suru (limited support)
vs-i: suru verb - included
vs-s: suru verb - special class
vz: Ichidan verb - zuru verb (alternative form of -jiru verbs)
""";

private static AddWordWindow? s_instance;

public static AddWordWindow Instance => s_instance ??= new AddWordWindow();
Expand Down Expand Up @@ -46,23 +78,48 @@ private Task HandleSaveButtonClick()
DefinitionsTextBox.ClearValue(CursorProperty);
DefinitionsTextBox.ClearValue(ToolTipProperty);

string rawSpellings = SpellingsTextBox.Text.Replace("\t", " ", StringComparison.Ordinal);
string[] spellings = rawSpellings.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
if (spellings.Length is 0)
{
SpellingsTextBox.BorderBrush = Brushes.Red;
SpellingsTextBox.Cursor = Cursors.Help;
SpellingsTextBox.ToolTip = "Spellings field cannot be left empty!";
return Task.CompletedTask;
}

string rawDefinitions = DefinitionsTextBox.Text.Replace("\t", " ", StringComparison.Ordinal);
string[] definitions = rawDefinitions.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
if (definitions.Length is 0)
{
DefinitionsTextBox.BorderBrush = Brushes.Red;
DefinitionsTextBox.Cursor = Cursors.Help;
DefinitionsTextBox.ToolTip = "Definitions cannot be left empty!";
DefinitionsTextBox.ToolTip = "Definitions field cannot be left empty!";
return Task.CompletedTask;
}

string rawSpellings = SpellingsTextBox.Text.Replace("\t", " ", StringComparison.Ordinal);
string rawWordClasses = WordClassTextBox.Text.Replace("\t", " ", StringComparison.Ordinal);
string[]? wordClasses = rawWordClasses.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
bool noWordClass = wordClasses.Length is 0;

if (WordClassStackPanel.Visibility is Visibility.Visible
&& (noWordClass
|| !wordClasses.All(JmdictWordClassUtils.UsedWordClasses.Contains)))

Check failure on line 107 in JL.Windows/GUI/AddWordWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

'JmdictWordClassUtils' is inaccessible due to its protection level

Check failure on line 107 in JL.Windows/GUI/AddWordWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

'JmdictWordClassUtils' is inaccessible due to its protection level
{
WordClassTextBox.BorderBrush = Brushes.Red;
WordClassTextBox.Cursor = Cursors.Help;
WordClassTextBox.ToolTip = noWordClass ? "Word Classes field cannot be left empty!" : "Invalid word class!";
return Task.CompletedTask;
}

if (noWordClass)
{
wordClasses = null;
}

string rawReadings = ReadingsTextBox.Text.Replace("\t", " ", StringComparison.Ordinal);
string rawPartOfSpeech = PartOfSpeechStackPanel.Children.OfType<RadioButton>()
.First(static r => r.IsChecked.HasValue && r.IsChecked.Value).Content.ToString()!;
string rawWordClasses = WordClassTextBox.Text.Replace("\t", " ", StringComparison.Ordinal);

string[] spellings = rawSpellings.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);

string[]? readings = rawReadings.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
if (readings.Length is 0
Expand All @@ -71,12 +128,6 @@ private Task HandleSaveButtonClick()
readings = null;
}

string[]? wordClasses = rawWordClasses.Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
if (wordClasses.Length is 0)
{
wordClasses = null;
}

DictType dictType = ComboBoxDictType.SelectedValue.ToString() is "Global"
? DictType.CustomWordDictionary
: DictType.ProfileCustomWordDictionary;
Expand Down Expand Up @@ -105,7 +156,7 @@ private void Window_Closed(object sender, EventArgs e)
_ = MainWindow.Instance.Focus();
}

private void VerbRadioButton_Checked(object sender, RoutedEventArgs e)
private void VerbOrAdjectiveRadioButton_Checked(object sender, RoutedEventArgs e)
{
WordClassStackPanel.Visibility = Visibility.Visible;
}
Expand All @@ -118,37 +169,16 @@ private void OtherRadioButtons_Checked(object sender, RoutedEventArgs e)

private void InfoButton_Click(object sender, RoutedEventArgs e)
{
const string supportedWordClasses = """
v1: Ichidan verb
v1-s: Ichidan verb - kureru special class
v4r: Yodan verb with `ru' ending (archaic)
v5aru: Godan verb - -aru special class
v5b: Godan verb with 'bu' ending
v5g: Godan verb with 'gu' ending
v5k: Godan verb with 'ku' ending
v5k-s: Godan verb - Iku/Yuku special class
v5m: Godan verb with 'mu' ending
v5n: Godan verb with 'nu' ending
v5r: Godan verb with 'ru' ending
v5r-i: Godan verb with 'ru' ending (irregular verb)
v5s: Godan verb with 'su' ending
v5t: Godan verb with 'tsu' ending
v5u: Godan verb with 'u' ending
v5u-s: Godan verb with 'u' ending (special class)
vk: Kuru verb - special class
vs-c: su verb - precursor to the modern suru (limited support)
vs-i: suru verb - included
vs-s: suru verb - special class
vz: Ichidan verb - zuru verb (alternative form of -jiru verbs)
""";
bool verbSelected = PartOfSpeechStackPanel.Children.OfType<RadioButton>()
.First(static r => r.IsChecked.HasValue && r.IsChecked.Value).Content.ToString() is "Verb";

InfoWindow infoWindow = new()
{
Owner = this,
Title = "Supported Word Classes",
InfoTextBox =
{
Text = supportedWordClasses
Text = verbSelected ? SupportedVerbWordClasses : SupportedAdjectiveWordClasses
},
WindowStartupLocation = WindowStartupLocation.CenterScreen
};
Expand Down

0 comments on commit d077ce5

Please sign in to comment.