Skip to content

Commit

Permalink
Minor code clean up (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman authored Oct 11, 2024
1 parent 036dcfa commit fe61e17
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 162 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ insert_final_newline = true
#### .NET Coding Conventions ####

# File header
file_header_template = Copyright 2020-2023 Conglomo Limited. Please see LICENSE.md for license details.
file_header_template = Copyright 2020-2024 Conglomo Limited. Please see LICENSE.md for license details.

# Organize usings
dotnet_separate_import_directive_groups = false
Expand Down
6 changes: 3 additions & 3 deletions GoToBible.Model/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="ExtensionMethods.cs" company="Conglomo">
// Copyright 2020-2024 Conglomo Limited. Please see LICENSE.md for license details.
// </copyright>
Expand Down Expand Up @@ -349,7 +349,7 @@ public static PassageReference AsPassageReference(this string passage, int defau
{
ChapterReference = passageReference.ChapterReference,
Display = $"{book} {chapter}:{sb}",
HighlightedVerses = [..highlightedVerses],
HighlightedVerses = [.. highlightedVerses],
};
}
else
Expand Down Expand Up @@ -638,7 +638,7 @@ internal static string[] GetRanges(this string passage)
ranges.AddRange($"Book{semiParts[i]}".GetRanges());
}

return [..ranges];
return [.. ranges];
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions GoToBible.Model/GoToBible.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsAotCompatible>true</IsAotCompatible>
<Authors>Peter Chapman</Authors>
<Company>Conglomo Limited</Company>
<Product>GoTo.Bible Model</Product>
Expand Down
6 changes: 3 additions & 3 deletions GoToBible.Providers/BundledTranslations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public async Task<Chapter> GetChapterAsync(
else if (
this.renderer is not null
&& translation == "TRWHAPP"
&& this.renderer.Providers.Any(r => r.Id == "BibliaApi")
&& this.renderer.Providers.Any(r => r.Id == nameof(BibliaApi))
)
{
// Use the renderer to generate this apparatus
Expand All @@ -234,10 +234,10 @@ this.renderer is not null
InterlinearIgnoresDiacritics = true,
InterlinearIgnoresPunctuation = true,
PassageReference = book.AsPassageReference(chapterNumber),
PrimaryProvider = "BibliaApi",
PrimaryProvider = nameof(BibliaApi),
PrimaryTranslation = "tr1894mr",
RenderNeighbourForAddition = true,
SecondaryProvider = "BibliaApi",
SecondaryProvider = nameof(BibliaApi),
SecondaryTranslation = "wh1881mr",
};
RenderedPassage renderedPassage = await this.renderer.RenderAsync(
Expand Down
1 change: 1 addition & 0 deletions GoToBible.Web/Client/GoToBible.Web.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<BlazorEnableTimeZoneSupport>false</BlazorEnableTimeZoneSupport>
<InvariantGlobalization>true</InvariantGlobalization>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
221 changes: 66 additions & 155 deletions GoToBible.Windows/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ or SecurityException
{
return Path.GetTempPath();
}
else
{
throw;
}

throw;
}
}
}
Expand Down Expand Up @@ -314,10 +312,7 @@ private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
Program.Forms.Remove(this);

// Disable autocomplete
if (this.ToolStripTextBoxPassage.TextBox is not null)
{
AutoSuggest.Disable(this.ToolStripTextBoxPassage.TextBox);
}
AutoSuggest.Disable(this.ToolStripTextBoxPassage.TextBox);

// If there are no forms left, exit
if (Program.Forms.Count == 0)
Expand Down Expand Up @@ -400,31 +395,22 @@ private async void FormMain_Load(object sender, EventArgs e)
}

// Setup the tool strip controls
if (this.ToolStripComboBoxPrimaryTranslation.ComboBox is not null)
{
this.ToolStripComboBoxPrimaryTranslation.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
this.ToolStripComboBoxPrimaryTranslation.ComboBox.DrawItem +=
this.ToolStripComboBox_DrawItem;
this.ToolStripComboBoxPrimaryTranslation.ComboBox.DropDownClosed +=
this.ToolStripComboBox_DropDownClosed;
}

if (this.ToolStripComboBoxSecondaryTranslation.ComboBox is not null)
{
this.ToolStripComboBoxSecondaryTranslation.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
this.ToolStripComboBoxSecondaryTranslation.ComboBox.DrawItem +=
this.ToolStripComboBox_DrawItem;
this.ToolStripComboBoxSecondaryTranslation.ComboBox.DropDownClosed +=
this.ToolStripComboBox_DropDownClosed;
}

if (this.ToolStripComboBoxResource.ComboBox is not null)
{
this.ToolStripComboBoxResource.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
this.ToolStripComboBoxResource.ComboBox.DrawItem += this.ToolStripComboBox_DrawItem;
this.ToolStripComboBoxResource.ComboBox.DropDownClosed +=
this.ToolStripComboBox_DropDownClosed;
}
this.ToolStripComboBoxPrimaryTranslation.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
this.ToolStripComboBoxPrimaryTranslation.ComboBox.DrawItem +=
this.ToolStripComboBox_DrawItem;
this.ToolStripComboBoxPrimaryTranslation.ComboBox.DropDownClosed +=
this.ToolStripComboBox_DropDownClosed;

this.ToolStripComboBoxSecondaryTranslation.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
this.ToolStripComboBoxSecondaryTranslation.ComboBox.DrawItem +=
this.ToolStripComboBox_DrawItem;
this.ToolStripComboBoxSecondaryTranslation.ComboBox.DropDownClosed +=
this.ToolStripComboBox_DropDownClosed;

this.ToolStripComboBoxResource.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
this.ToolStripComboBoxResource.ComboBox.DrawItem += this.ToolStripComboBox_DrawItem;
this.ToolStripComboBoxResource.ComboBox.DropDownClosed +=
this.ToolStripComboBox_DropDownClosed;

this.ToolStripMenuItemIgnoreCase.Checked = Settings.Default.InterlinearIgnoresCase;
this.ToolStripMenuItemIgnoreDiacritics.Checked = Settings
Expand Down Expand Up @@ -1119,7 +1105,7 @@ private async void ToolStripButtonExport_Click(object sender, EventArgs e)
RenderedPassage renderedPassageForExport = await this.renderer.RenderAsync(
this.parameters with
{
Format = RenderFormat.Accordance
Format = RenderFormat.Accordance,
},
false
);
Expand All @@ -1140,7 +1126,7 @@ private void ToolStripButtonGitHub_Click(object sender, EventArgs e) =>
new ProcessStartInfo("https://github.com/pmachapman/GoTo.Bible")
{
UseShellExecute = true,
Verb = "open"
Verb = "open",
}
);

Expand Down Expand Up @@ -1237,11 +1223,8 @@ Book book in provider.GetBooksAsync(secondaryComboBoxItem.Code, false)
}

// Enable autocomplete
if (this.ToolStripTextBoxPassage.TextBox is not null)
{
AutoSuggest.Disable(this.ToolStripTextBoxPassage.TextBox);
AutoSuggest.Enable(this.ToolStripTextBoxPassage.TextBox, [.. suggestions]);
}
AutoSuggest.Disable(this.ToolStripTextBoxPassage.TextBox);
AutoSuggest.Enable(this.ToolStripTextBoxPassage.TextBox, [.. suggestions]);
}

/// <summary>
Expand Down Expand Up @@ -1342,7 +1325,7 @@ this.parameters with
{
PrimaryProvider = resourceProvider,
PrimaryTranslation = resource,
SecondaryTranslation = null
SecondaryTranslation = null,
},
false
);
Expand Down Expand Up @@ -1521,75 +1504,26 @@ private void ToolStripButtonWebBrowser_Click(object sender, EventArgs e) =>
);

/// <summary>
/// Handles the SelectedIndexChanged event of the Resource ToolStripComboBox.
/// Handles the SelectedIndexChanged event of the Translation ToolStripComboBoxes.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private async void ToolStripComboBoxResource_SelectedIndexChanged(object sender, EventArgs e)
/// <param name="toolStripComboBox">The Tool Strip Combo Box.</param>
/// <returns>An asynchronous task.</returns>
private async Task ToolStripComboBoxTranslation_SelectedIndexChanged(ToolStripComboBox toolStripComboBox)
{
if (this.ToolStripComboBoxResource.SelectedItem is ComboBoxItem { Selectable: false })
if (toolStripComboBox.SelectedItem is ComboBoxItem { Selectable: false })
{
// Handle the non-selectable items
if (
this.ToolStripComboBoxResource.Items.Count - 1
> this.ToolStripComboBoxResource.SelectedIndex
)
if (toolStripComboBox.Items.Count - 1 > toolStripComboBox.SelectedIndex)
{
this.ToolStripComboBoxResource.SelectedIndex++;
toolStripComboBox.SelectedIndex++;
}
else if (this.ToolStripComboBoxResource.SelectedIndex > 0)
else if (toolStripComboBox.SelectedIndex > 0)
{
this.ToolStripComboBoxResource.SelectedIndex--;
toolStripComboBox.SelectedIndex--;
}
else
{
this.ToolStripComboBoxResource.SelectedIndex = -1;
}
}
else
{
await this.SetupAutoCompleteAsync();
this.SplitContainerMain.Panel2Collapsed =
this.ToolStripComboBoxResource.SelectedIndex < 1;
if (!string.IsNullOrWhiteSpace(this.ToolStripTextBoxPassage.Text))
{
await this.ShowPassage(false, true);
}
}
}

/// <summary>
/// Handles the SelectedIndexChanged event of the Primary Translation ToolStripComboBox.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private async void ToolStripComboBoxPrimaryTranslation_SelectedIndexChanged(
object sender,
EventArgs e
)
{
if (
this.ToolStripComboBoxPrimaryTranslation.SelectedItem is ComboBoxItem
{
Selectable: false
}
)
{
// Handle the non-selectable items
if (
this.ToolStripComboBoxPrimaryTranslation.Items.Count - 1
> this.ToolStripComboBoxPrimaryTranslation.SelectedIndex
)
{
this.ToolStripComboBoxPrimaryTranslation.SelectedIndex++;
}
else if (this.ToolStripComboBoxPrimaryTranslation.SelectedIndex > 0)
{
this.ToolStripComboBoxPrimaryTranslation.SelectedIndex--;
}
else
{
this.ToolStripComboBoxPrimaryTranslation.SelectedIndex = -1;
toolStripComboBox.SelectedIndex = -1;
}
}
else
Expand Down Expand Up @@ -1640,86 +1574,63 @@ is TranslationComboBoxItem secondaryItem
}

/// <summary>
/// Handles the SelectedIndexChanged event of the Secondary Translation ToolStripComboBox.
/// Handles the SelectedIndexChanged event of the Resource ToolStripComboBox.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private async void ToolStripComboBoxSecondaryTranslation_SelectedIndexChanged(
object sender,
EventArgs e
)
private async void ToolStripComboBoxResource_SelectedIndexChanged(object sender, EventArgs e)
{
if (
this.ToolStripComboBoxSecondaryTranslation.SelectedItem is ComboBoxItem
{
Selectable: false
}
)
if (this.ToolStripComboBoxResource.SelectedItem is ComboBoxItem { Selectable: false })
{
// Handle the non-selectable items
if (
this.ToolStripComboBoxSecondaryTranslation.Items.Count - 1
> this.ToolStripComboBoxSecondaryTranslation.SelectedIndex
this.ToolStripComboBoxResource.Items.Count - 1
> this.ToolStripComboBoxResource.SelectedIndex
)
{
this.ToolStripComboBoxSecondaryTranslation.SelectedIndex++;
this.ToolStripComboBoxResource.SelectedIndex++;
}
else if (this.ToolStripComboBoxSecondaryTranslation.SelectedIndex > 0)
else if (this.ToolStripComboBoxResource.SelectedIndex > 0)
{
this.ToolStripComboBoxSecondaryTranslation.SelectedIndex--;
this.ToolStripComboBoxResource.SelectedIndex--;
}
else
{
this.ToolStripComboBoxSecondaryTranslation.SelectedIndex = -1;
this.ToolStripComboBoxResource.SelectedIndex = -1;
}
}
else
{
// Make sure we are not showing an interlinear with the original language
if (
this.ToolStripComboBoxPrimaryTranslation.SelectedItem
is TranslationComboBoxItem primaryItem
&& this.ToolStripComboBoxSecondaryTranslation.SelectedItem
is TranslationComboBoxItem secondaryItem
&& (
(
primaryItem.Language == "Greek"
&& secondaryItem.Language is not ("Greek" or null)
)
|| (
primaryItem.Language == "Hebrew"
&& secondaryItem.Language is not ("Hebrew" or null)
)
|| (
secondaryItem.Language == "Greek"
&& primaryItem.Language is not ("Greek" or null)
)
|| (
secondaryItem.Language == "Hebrew"
&& primaryItem.Language is not ("Hebrew" or null)
)
)
)
{
MessageBox.Show(
Resources.CannotShowInterlinear,
Program.Title,
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
this.ToolStripComboBoxSecondaryTranslation.SelectedIndex = 0;
}

// Show the passage
await this.SetupAutoCompleteAsync();
this.SplitContainerMain.Panel2Collapsed =
this.ToolStripComboBoxResource.SelectedIndex < 1;
if (!string.IsNullOrWhiteSpace(this.ToolStripTextBoxPassage.Text))
{
await this.ShowPassage(true, false);
await this.ProcessSuggestions();
await this.ShowPassage(false, true);
}
}
}

/// <summary>
/// Handles the SelectedIndexChanged event of the Primary Translation ToolStripComboBox.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private async void ToolStripComboBoxPrimaryTranslation_SelectedIndexChanged(
object sender,
EventArgs e
) => await this.ToolStripComboBoxTranslation_SelectedIndexChanged(this.ToolStripComboBoxPrimaryTranslation);

/// <summary>
/// Handles the SelectedIndexChanged event of the Secondary Translation ToolStripComboBox.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private async void ToolStripComboBoxSecondaryTranslation_SelectedIndexChanged(
object sender,
EventArgs e
) => await this.ToolStripComboBoxTranslation_SelectedIndexChanged(this.ToolStripComboBoxSecondaryTranslation);

/// <summary>
/// Handles the DrawItem event of the ToolStripComboBox controls.
/// </summary>
Expand Down

0 comments on commit fe61e17

Please sign in to comment.