Skip to content

Commit 01d2ad5

Browse files
authored
Merge pull request #1207 from sillsdev/94_PTX-22668
Fire event when invalid reference pasted. Prevent input of too long v…
2 parents 734a5a7 + c506716 commit 01d2ad5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2424
- [SIL.Core] ErrorReport exposes a NotifyUserOfProblemWrapper() protected function, which is designed to make it easier for subclasses to add additional NotifyUserOfProblem options
2525
- [SIL.Core] Added AltImplGetUnicodeCategory function to StringExtensions
2626
- [SIL.WritingSystems] Added static class IcuUCharCategoryExtensions with a method ToUnicodeCategory to translate from Character.UCharCategory to System.Globalization.UnicodeCategory.
27+
- [SIL.Windows.Forms.Scripture] Added event InvalidReferencePasted to VerseControl, which is fired whenever an attempt to paste an invalid scripture reference is made.
2728

2829
### Changed
2930
- [SIL.Windows.Forms.WritingSystems] Moved (internal) extension method InitializeWithAvailableUILocales to SIL.Windows.Forms.

SIL.Windows.Forms.Scripture/VerseControl.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public partial class VerseControl : UserControl
5757
public event EventHandler InvalidBookEntered;
5858
/// <summary>Fired when any part of the reference is invalid</summary>
5959
public event EventHandler InvalidReferenceEntered;
60+
/// <summary>Fired when any part of the pasted reference is invalid</summary>
61+
public event EventHandler InvalidReferencePasted;
6062
/// <summary>Fired when any textbox for the reference gets focus</summary>
6163
public event EventHandler TextBoxGotFocus;
6264

@@ -488,6 +490,12 @@ private void OnInvalidReference()
488490
InvalidReferenceEntered(this, EventArgs.Empty);
489491
}
490492

493+
private void OnInvalidPastedReference()
494+
{
495+
if (InvalidReferencePasted != null)
496+
InvalidReferencePasted(this, EventArgs.Empty);
497+
}
498+
491499
private void OnTextBoxGotFocus()
492500
{
493501
if (TextBoxGotFocus != null)
@@ -782,9 +790,12 @@ private string GetCleanClipboardText()
782790
/// Updates verse control with pasted verse reference, if pasted reference is valid.
783791
/// </summary>
784792
private void HandlePasteScriptureRef()
785-
{
793+
{
786794
if (!IsValidReference(GetCleanClipboardText(), out var book, out var chapter, out var verse))
795+
{
796+
OnInvalidPastedReference();
787797
return;
798+
}
788799

789800
uiBook.Text = book;
790801
uiChapter.Text = chapter;
@@ -817,8 +828,12 @@ private bool IsValidReference(string text, out string book, out string chapter,
817828
// chapter and verse is optional in regex, make it 1 if not given
818829
if (string.IsNullOrEmpty(chapter))
819830
chapter ="1";
831+
else if (chapter.Length > 3)
832+
return false;
820833
if (string.IsNullOrEmpty(verse))
821834
verse = "1";
835+
else if (verse.Length > 3)
836+
return false;
822837
if (Canon.IsBookIdValid(searchBook))
823838
{
824839
book = searchBook;

0 commit comments

Comments
 (0)