Skip to content

Commit

Permalink
Merge branch 'release/9.1' into LT-21911
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeOliver28 authored Oct 3, 2024
2 parents 1129168 + 133ae42 commit c666d79
Show file tree
Hide file tree
Showing 18 changed files with 692 additions and 217 deletions.
7 changes: 6 additions & 1 deletion Src/GenerateHCConfig/ConsoleLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using SIL.LCModel;
using SIL.FieldWorks.WordWorks.Parser;
Expand Down Expand Up @@ -103,5 +103,10 @@ public void InvalidReduplicationForm(IMoForm form, string reason, IMoMorphSynAna
{
Console.WriteLine("The reduplication form \"{0}\" is invalid. Reason: {1}", form.Form.VernacularDefaultWritingSystem.Text, reason);
}

public void InvalidRewriteRule(IPhRegularRule rule, string reason)
{
Console.WriteLine("The rewrite rule \"{0}\" is invalid. Reason: {1}", rule.Name.BestAnalysisVernacularAlternative.Text, reason);
}
}
}
34 changes: 4 additions & 30 deletions Src/LexText/Interlinear/FocusBoxController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,27 +346,9 @@ private void UpdateButtonState()
if (InterlinDoc == null || !InterlinDoc.IsFocusBoxInstalled)
return;
// we're fully installed, so update the buttons.
if (ShowLinkWordsIcon)
{
btnLinkNextWord.Visible = true;
btnLinkNextWord.Enabled = true;
}
else
{
btnLinkNextWord.Visible = false;
btnLinkNextWord.Enabled = false;
}
btnLinkNextWord.Visible = btnLinkNextWord.Enabled = ShowLinkWordsIcon;
btnBreakPhrase.Visible = btnBreakPhrase.Enabled = ShowBreakPhraseIcon;

if (ShowBreakPhraseIcon)
{
btnBreakPhrase.Visible = true;
btnBreakPhrase.Enabled = true;
}
else
{
btnBreakPhrase.Visible = false;
btnBreakPhrase.Enabled = false;
}
UpdateButtonState_Undo();
// LT-11406: Somehow JoinWords (and BreakPhrase) leaves the selection elsewhere,
// this should make it select the default location.
Expand All @@ -376,16 +358,8 @@ private void UpdateButtonState()

private void UpdateButtonState_Undo()
{
if (InterlinWordControl != null && InterlinWordControl.HasChanged)
{
btnUndoChanges.Visible = true;
btnUndoChanges.Enabled = true;
}
else
{
btnUndoChanges.Visible = false;
btnUndoChanges.Enabled = false;
}
bool shouldEnable = InterlinWordControl != null && InterlinWordControl.HasChanged;
btnUndoChanges.Visible = btnUndoChanges.Enabled = shouldEnable;
}

private void btnLinkNextWord_Click(object sender, EventArgs e)
Expand Down
11 changes: 8 additions & 3 deletions Src/LexText/LexTextControls/PatternView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
Expand Down Expand Up @@ -134,11 +134,16 @@ protected override void OnKeyDown(KeyEventArgs e)
/// <param name="e"></param>
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (e.KeyChar == (char) Keys.Back)
e.Handled = true;
if (e.KeyChar == (char)Keys.Back || e.KeyChar == (char)Keys.Delete)
{
if (RemoveItemsRequested != null)
RemoveItemsRequested(this, new RemoveItemsRequestedEventArgs(false));
e.Handled = true;
}
else
{
// Ignore all other characters (fixes LT-21888).
return;
}
base.OnKeyPress(e);
}
Expand Down
8 changes: 5 additions & 3 deletions Src/LexText/Morphology/AffixRuleFormulaControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015 SIL International
// Copyright (c) 2015 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand Down Expand Up @@ -176,7 +176,7 @@ private bool DisplayVariableOption(object option)
private bool DisplayColumnOption(object option)
{
SelectionHelper sel = SelectionHelper.Create(m_view);
if (sel.IsRange)
if (sel == null || sel.IsRange)
return false;

int cellId = GetCell(sel);
Expand Down Expand Up @@ -599,6 +599,8 @@ protected override int RemoveItems(SelectionHelper sel, bool forward, out int ce
int prevCellId = GetPrevCell(seqCtxt.Hvo);
cellIndex = GetCellCount(prevCellId) - 1;
Rule.InputOS.Remove(seqCtxt);
// Unschedule the removal of the column.
m_removeCol = null;
return prevCellId;
}
bool reconstruct = RemoveContextsFrom(forward, sel, seqCtxt, false, out cellIndex);
Expand Down Expand Up @@ -716,7 +718,7 @@ protected bool RemoveFromOutput(bool forward, SelectionHelper sel, out int index
else
{
int idx = GetIndexToRemove(mappings, sel, forward);
if (idx > -1)
if (idx > -1 && idx < mappings.Count())
{
var mapping = (IMoRuleMapping) mappings[idx];
index = idx - 1;
Expand Down
8 changes: 7 additions & 1 deletion Src/LexText/Morphology/RuleFormulaControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015 SIL International
// Copyright (c) 2015 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand Down Expand Up @@ -569,6 +569,12 @@ private void m_insertionControl_Insert(object sender, InsertEventArgs e)
var redo = string.Format(MEStrings.ksRuleRedoInsert, option);

SelectionHelper sel = SelectionHelper.Create(m_view);
if (sel == null)
{
// The selection can become invalid because of an undo (see LT-20588).
m_insertionControl.UpdateOptionsDisplay();
return;
}
int cellId = -1;
int cellIndex = -1;
switch (option.Type)
Expand Down
22 changes: 20 additions & 2 deletions Src/LexText/ParserCore/HCLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,13 @@ private void LoadLanguage()
if (regRule.StrucDescOS.Count > 0 || regRule.RightHandSidesOS.Any(rhs => rhs.StrucChangeOS.Count > 0))
{
RewriteRule hcRegRule = LoadRewriteRule(regRule);
m_morphophonemic.PhonologicalRules.Add(hcRegRule);
if (hcRegRule == null)
continue;
// Choose which stratum the phonological rules apply on.
if (!m_notOnClitics)
m_clitic.PhonologicalRules.Add(hcRegRule);
else
m_morphophonemic.PhonologicalRules.Add(hcRegRule);
m_language.PhonologicalRules.Add(hcRegRule);
}
break;
Expand All @@ -248,9 +252,12 @@ private void LoadLanguage()
if (metaRule.LeftSwitchIndex != -1 && metaRule.RightSwitchIndex != -1)
{
MetathesisRule hcMetaRule = LoadMetathesisRule(metaRule);
m_morphophonemic.PhonologicalRules.Add(hcMetaRule);

// Choose which stratum the phonological rules apply on.
if (!m_notOnClitics)
m_clitic.PhonologicalRules.Add(hcMetaRule);
else
m_morphophonemic.PhonologicalRules.Add(hcMetaRule);
m_language.PhonologicalRules.Add(hcMetaRule);
}
break;
Expand Down Expand Up @@ -1698,6 +1705,11 @@ private RewriteRule LoadRewriteRule(IPhRegularRule prule)
}
hcPrule.Properties[HCParser.PRuleID] = prule.Hvo;

if (hcPrule.Lhs.Children.Count > 1)
{
m_logger.InvalidRewriteRule(prule, ParserCoreStrings.ksMaxElementsInRule);
return null;
}
foreach (IPhSegRuleRHS rhs in prule.RightHandSidesOS)
{
var psubrule = new RewriteSubrule();
Expand Down Expand Up @@ -1748,6 +1760,12 @@ private RewriteRule LoadRewriteRule(IPhRegularRule prule)
psubrule.RightEnvironment = rightPattern;
}

if (psubrule.Rhs.Children.Count > 1)
{
m_logger.InvalidRewriteRule(prule, ParserCoreStrings.ksMaxElementsInRule);
return null;
}

hcPrule.Subrules.Add(psubrule);
}

Expand Down
8 changes: 8 additions & 0 deletions Src/LexText/ParserCore/HCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ public void InvalidReduplicationForm(IMoForm form, string reason, IMoMorphSynAna
m_xmlWriter.WriteElementString("Reason", reason);
m_xmlWriter.WriteEndElement();
}
public void InvalidRewriteRule(IPhRegularRule rule, string reason)
{
m_xmlWriter.WriteStartElement("LoadError");
m_xmlWriter.WriteAttributeString("type", "invalid-rewrite-rule");
m_xmlWriter.WriteElementString("Rule", rule.Name.BestAnalysisVernacularAlternative.Text);
m_xmlWriter.WriteElementString("Reason", reason);
m_xmlWriter.WriteEndElement();
}
}
}
}
3 changes: 2 additions & 1 deletion Src/LexText/ParserCore/IHCLoadErrorLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SIL.LCModel;
using SIL.LCModel;

namespace SIL.FieldWorks.WordWorks.Parser
{
Expand All @@ -10,5 +10,6 @@ public interface IHCLoadErrorLogger
void DuplicateGrapheme(IPhPhoneme phoneme);
void InvalidEnvironment(IMoForm form, IPhEnvironment env, string reason, IMoMorphSynAnalysis msa);
void InvalidReduplicationForm(IMoForm form, string reason, IMoMorphSynAnalysis msa);
void InvalidRewriteRule(IPhRegularRule prule, string reason);
}
}
9 changes: 9 additions & 0 deletions Src/LexText/ParserCore/ParserCoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Src/LexText/ParserCore/ParserCoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,7 @@
<data name="ksTestX" xml:space="preserve">
<value>Tested {0}</value>
</data>
<data name="ksMaxElementsInRule" xml:space="preserve">
<value>A rule can't have more than one element in its left-hand side or its right-hand side.</value>
</data>
</root>
13 changes: 8 additions & 5 deletions Src/LexText/ParserCore/ParserCoreTests/HCLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ private enum LoadErrorType
InvalidPhoneme,
DuplicateGrapheme,
InvalidEnvironment,
InvalidRedupForm
InvalidRedupForm,
InvalidRewriteRule
}

private class TestHCLoadErrorLogger : IHCLoadErrorLogger
Expand Down Expand Up @@ -82,6 +83,11 @@ public void InvalidReduplicationForm(IMoForm form, string reason, IMoMorphSynAna
{
m_loadErrors.Add(Tuple.Create(LoadErrorType.InvalidRedupForm, (ICmObject) msa));
}

public void InvalidRewriteRule(IPhRegularRule rule, string reason)
{
m_loadErrors.Add(Tuple.Create(LoadErrorType.InvalidRedupForm, (ICmObject) rule));
}
}

private readonly List<Tuple<LoadErrorType, ICmObject>> m_loadErrors = new List<Tuple<LoadErrorType, ICmObject>>();
Expand Down Expand Up @@ -986,9 +992,6 @@ public void PhonologicalRule()
Cache.LanguageProject.PhonologicalDataOA.PhonRulesOS.Add(prule);
prule.Name.SetAnalysisDefaultWritingSystem("prule");
prule.Direction = 2;
IPhSimpleContextSeg segCtxt = Cache.ServiceLocator.GetInstance<IPhSimpleContextSegFactory>().Create();
prule.StrucDescOS.Add(segCtxt);
segCtxt.FeatureStructureRA = GetPhoneme("a");
IPhSimpleContextNC ncCtxt = Cache.ServiceLocator.GetInstance<IPhSimpleContextNCFactory>().Create();
prule.StrucDescOS.Add(ncCtxt);
ncCtxt.FeatureStructureRA = m_vowel;
Expand Down Expand Up @@ -1019,7 +1022,7 @@ public void PhonologicalRule()

Assert.That(hcPrule.Direction, Is.EqualTo(Machine.DataStructures.Direction.LeftToRight));
Assert.That(hcPrule.ApplicationMode, Is.EqualTo(RewriteApplicationMode.Simultaneous));
Assert.That(hcPrule.Lhs.ToString(), Is.EqualTo(m_lang.Strata[0].CharacterDefinitionTable["a"].FeatureStruct + VowelFS));
Assert.That(hcPrule.Lhs.ToString(), Is.EqualTo(VowelFS));

Assert.That(hcPrule.Subrules.Count, Is.EqualTo(1));
RewriteSubrule subrule = hcPrule.Subrules[0];
Expand Down
2 changes: 1 addition & 1 deletion Src/MasterVersionInfo.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FWMAJOR=9
FWMINOR=2
FWREVISION=3
FWREVISION=4
FWBETAVERSION=Alpha
9 changes: 9 additions & 0 deletions Src/Transforms/Presentation/FormatCommon.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
</span>
</li>
</xsl:when>
<xsl:when test="@type = 'invalid-rewrite-rule'">
<li>
<xsl:text>The rewrite rule "</xsl:text>
<xsl:value-of select="Rule" />
<xsl:text>" is invalid. Reason: </xsl:text>
<xsl:value-of select="Reason" />
<xsl:text> </xsl:text>
</li>
</xsl:when>
<xsl:otherwise>
<!-- Do not expect any others to happen, but just in case, we show them in all their HC glory -->
<li><xsl:value-of select="."/></li>
Expand Down
4 changes: 2 additions & 2 deletions Src/xWorks/CssGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,12 +1262,12 @@ internal static List<StyleDeclaration> GenerateCssStyleFromLcmStyleSheet(string
string customBullet = exportStyleInfo.BulletInfo.m_bulletCustom;
declaration.Add(new Property("content") { Term = new PrimitiveTerm(UnitType.String, customBullet) });
}
else if (BulletSymbolsCollection.ContainsKey(exportStyleInfo.NumberScheme.ToString()))
else if (BulletSymbolsCollection.ContainsKey(numScheme))
{
string selectedBullet = BulletSymbolsCollection[numScheme];
declaration.Add(new Property("content") { Term = new PrimitiveTerm(UnitType.String, selectedBullet) });
}
else if (NumberingStylesCollection.ContainsKey(exportStyleInfo.NumberScheme.ToString()))
else if (NumberingStylesCollection.ContainsKey(numScheme))
{
if (node != null)
{
Expand Down
Loading

0 comments on commit c666d79

Please sign in to comment.