Skip to content

Commit b53d886

Browse files
authored
LT-21492: Remove WritingSystemUpdated & WritingSystemDeleted
Cherry-pick from the PubSub branch to the main branch using the following command: git cherry-pick --no-commit 492707b Removed the unused code (LT-21492 and LT-21493). Only test code was passing a mediator in to the FwWritingSystemSetupModel constructor, so only test code was calling SendMessage for both of these events. The two delete tests that were failing an assert when I removed the mediator, both contain other asserts that still fail if the writing system is not deleted.
1 parent 9b1e98b commit b53d886

3 files changed

Lines changed: 7 additions & 87 deletions

File tree

Src/FwCoreDlgs/FwCoreDlgsTests/FwWritingSystemSetupModelTests.cs

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,12 +1462,11 @@ public void Save_HiddenWsDeleted_WsDeleted()
14621462
{
14631463
using (var mediator = new Mediator())
14641464
{
1465-
var deleteListener = new WSDeletedListener(mediator);
14661465
var ws = GetOrSetWs("doa");
14671466
Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create().CitationForm.set_String(ws.Handle, "some data");
14681467
Cache.ActionHandlerAccessor.EndUndoTask();
14691468
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, FwWritingSystemSetupModel.ListType.Vernacular,
1470-
Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
1469+
Cache.ServiceLocator.WritingSystemManager, Cache)
14711470
{
14721471
ViewHiddenWritingSystems = model =>
14731472
model.Items.Add(new HiddenWSListItemModel(ws, false) { WillDelete = true })
@@ -1477,7 +1476,6 @@ public void Save_HiddenWsDeleted_WsDeleted()
14771476
testModel.GetAddMenuItems().First(item => item.MenuText.Contains("View hidden")).ClickHandler(this, EventArgs.Empty);
14781477
testModel.Save();
14791478

1480-
CollectionAssert.AreEqual(new[] {"doa"}, deleteListener.DeletedWSs);
14811479
Assert.That(WritingSystemServices.FindAllWritingSystemsWithText(Cache), Is.Not.Contains(ws.Handle));
14821480
}
14831481
}
@@ -1488,11 +1486,10 @@ public void Save_DeletedWs_WsDeleted(FwWritingSystemSetupModel.ListType type, st
14881486
{
14891487
using (var mediator = new Mediator())
14901488
{
1491-
var deleteListener = new WSDeletedListener(mediator);
14921489
SetUpProjectWithData();
14931490
Cache.ActionHandlerAccessor.EndUndoTask();
14941491
var wasDeleteConfirmed = false;
1495-
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
1492+
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
14961493
{
14971494
ConfirmDeleteWritingSystem = label =>
14981495
{
@@ -1521,7 +1518,6 @@ public void Save_DeletedWs_WsDeleted(FwWritingSystemSetupModel.ListType type, st
15211518
Assert.AreEqual("en", Cache.LangProject.AnalysisWss, "Only English should remain after save");
15221519
AssertFrenchDataIntact();
15231520
}
1524-
CollectionAssert.AreEqual(new[] {wsId}, deleteListener.DeletedWSs);
15251521
Assert.That(WritingSystemServices.FindAllWritingSystemsWithText(Cache), Is.Not.Contains(GetOrSetWs(wsId).Handle));
15261522
}
15271523
}
@@ -1533,15 +1529,14 @@ public void Save_DeletedWs_ExistsInOtherList_WsHidden(
15331529
{
15341530
using (var mediator = new Mediator())
15351531
{
1536-
var deleteListener = new WSDeletedListener(mediator);
15371532
SetupHomographLanguagesInCache();
15381533
var fr = GetOrSetWs("fr");
15391534
Cache.LangProject.AnalysisWritingSystems.Add(fr);
15401535
var entry = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create();
15411536
entry.Comment.set_String(fr.Handle, "commentary");
15421537
Cache.ActionHandlerAccessor.EndUndoTask();
15431538
var wasDeleteConfirmed = false;
1544-
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
1539+
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
15451540
{
15461541
ConfirmDeleteWritingSystem = label =>
15471542
{
@@ -1557,7 +1552,6 @@ public void Save_DeletedWs_ExistsInOtherList_WsHidden(
15571552

15581553
Assert.False(wasDeleteConfirmed, "shouldn't confirm 'deleting' a WS that will only be hidden");
15591554
AssertOnlyEnglishInList(type);
1560-
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
15611555
var comment = entry.Comment.get_String(fr.Handle);
15621556
Assert.AreEqual(fr.Handle, comment.get_WritingSystemAt(0));
15631557
Assert.AreEqual("commentary", comment.Text);
@@ -1570,18 +1564,16 @@ public void Save_HiddenWs_WsHidden(FwWritingSystemSetupModel.ListType type, stri
15701564
{
15711565
using (var mediator = new Mediator())
15721566
{
1573-
var deleteListener = new WSDeletedListener(mediator);
15741567
SetUpProjectWithData();
15751568
Cache.ActionHandlerAccessor.EndUndoTask();
1576-
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator);
1569+
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache);
15771570
testModel.SelectWs(wsId);
15781571

15791572
// SUT: click Hide, then save
15801573
testModel.GetRightClickMenuItems().First(item => item.MenuText.Contains("Hide")).ClickHandler(this, EventArgs.Empty);
15811574
testModel.Save();
15821575

15831576
AssertOnlyEnglishInList(type);
1584-
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
15851577
AssertProjectDataIntact();
15861578
}
15871579
}
@@ -1592,10 +1584,9 @@ public void Save_WsDeletedRestoredAndHidden_WsHidden(FwWritingSystemSetupModel.L
15921584
{
15931585
using (var mediator = new Mediator())
15941586
{
1595-
var deleteListener = new WSDeletedListener(mediator);
15961587
SetUpProjectWithData();
15971588
Cache.ActionHandlerAccessor.EndUndoTask();
1598-
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
1589+
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
15991590
{
16001591
AddNewVernacularLanguageWarning = () => true,
16011592
ConfirmDeleteWritingSystem = label => true,
@@ -1617,7 +1608,6 @@ public void Save_WsDeletedRestoredAndHidden_WsHidden(FwWritingSystemSetupModel.L
16171608
testModel.Save();
16181609

16191610
AssertOnlyEnglishInList(type);
1620-
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
16211611
AssertProjectDataIntact();
16221612
}
16231613
}
@@ -1629,10 +1619,9 @@ public void Save_WsDeletedAndRestored_NoChange(FwWritingSystemSetupModel.ListTyp
16291619
using (var mediator = new Mediator())
16301620
{
16311621
var ws = GetOrSetWs(wsId);
1632-
var deleteListener = new WSDeletedListener(mediator);
16331622
SetUpProjectWithData();
16341623
Cache.ActionHandlerAccessor.EndUndoTask();
1635-
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
1624+
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
16361625
{
16371626
AddNewVernacularLanguageWarning = () => true,
16381627
ConfirmDeleteWritingSystem = label => true,
@@ -1656,7 +1645,6 @@ public void Save_WsDeletedAndRestored_NoChange(FwWritingSystemSetupModel.ListTyp
16561645
Assert.AreEqual("en fr", Cache.LangProject.VernWss, "Both should remain after save");
16571646
Assert.AreEqual("en tpi", Cache.LangProject.CurAnalysisWss, "Both should remain selected after save");
16581647
Assert.AreEqual("en tpi", Cache.LangProject.AnalysisWss, "Both should remain after save");
1659-
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
16601648
AssertProjectDataIntact();
16611649
}
16621650
}
@@ -1907,33 +1895,5 @@ public void AddToCurrentVernacularWritingSystems(CoreWritingSystemDefinition ws)
19071895
/// </summary>
19081896
public IWritingSystemRepository Repo { get; set; }
19091897
}
1910-
1911-
private class WSDeletedListener : IxCoreColleague
1912-
{
1913-
public List<string> DeletedWSs { get; } = new List<string>();
1914-
1915-
public WSDeletedListener(Mediator mediator)
1916-
{
1917-
Init(mediator, null, null);
1918-
}
1919-
1920-
public void OnWritingSystemDeleted(object param)
1921-
{
1922-
DeletedWSs.AddRange((string[])param);
1923-
}
1924-
1925-
public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters)
1926-
{
1927-
mediator.AddColleague(this);
1928-
}
1929-
1930-
public IxCoreColleague[] GetMessageTargets()
1931-
{
1932-
return new IxCoreColleague[] { this };
1933-
}
1934-
1935-
public bool ShouldNotCall => false;
1936-
public int Priority => (int)ColleaguePriority.High;
1937-
}
19381898
}
19391899
}

Src/FwCoreDlgs/FwWritingSystemSetupModel.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ public List<WSListItemModel> WorkingList
7676
/// <summary/>
7777
public readonly LcmCache Cache;
7878

79-
private readonly Mediator _mediator;
80-
8179
/// <summary/>
8280
public event EventHandler WritingSystemListUpdated;
8381

@@ -178,7 +176,7 @@ public List<WSListItemModel> WorkingList
178176
public event EventHandler OnCurrentWritingSystemChanged = delegate { };
179177

180178
/// <summary/>
181-
public FwWritingSystemSetupModel(IWritingSystemContainer container, ListType type, IWritingSystemManager wsManager = null, LcmCache cache = null, Mediator mediator = null)
179+
public FwWritingSystemSetupModel(IWritingSystemContainer container, ListType type, IWritingSystemManager wsManager = null, LcmCache cache = null)
182180
{
183181
switch (type)
184182
{
@@ -197,7 +195,6 @@ public FwWritingSystemSetupModel(IWritingSystemContainer container, ListType typ
197195
_wsManager = wsManager;
198196
SetCurrentWsSetupModel(_currentWs);
199197
Cache = cache;
200-
_mediator = mediator;
201198
_wsContainer = container;
202199
_projectLexiconSettings = new ProjectLexiconSettings();
203200
// ignore on disk settings if we are testing without a cache
@@ -679,7 +676,6 @@ public void Save()
679676
{
680677
WritingSystemUpdated?.Invoke(this, EventArgs.Empty);
681678
}
682-
_mediator?.SendMessage("WritingSystemUpdated", origWs.Id);
683679
}
684680

685681
// whether or not the WS was created or changed, its list position may have changed (LT-19788)
@@ -818,22 +814,15 @@ private void RemoveWritingSystems(
818814
return;
819815
}
820816

821-
var deletedWsIds = new List<string>();
822817
foreach (var deleteCandidateId in _wsIdsToDelete)
823818
{
824819
if (Cache.ServiceLocator.WritingSystemManager.TryGet(deleteCandidateId, out var deleteCandidate)
825820
&& !otherWritingSystems.Contains(deleteCandidate)
826821
&& !_mergedWritingSystems.Keys.Contains(deleteCandidate))
827822
{
828823
WritingSystemServices.DeleteWritingSystem(Cache, deleteCandidate);
829-
deletedWsIds.Add(deleteCandidateId);
830824
}
831825
}
832-
833-
if (deletedWsIds.Count > 0)
834-
{
835-
_mediator?.SendMessage("WritingSystemDeleted", deletedWsIds.ToArray());
836-
}
837826
}
838827

839828
private static bool IsNew(WSListItemModel tempWs)

Src/xWorks/DictionaryConfigurationListener.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -416,35 +416,6 @@ public static void SetCurrentConfiguration(PropertyTable propertyTable, string c
416416
propertyTable.SetProperty(pubLayoutPropName, currentConfig, fUpdate);
417417
}
418418

419-
public bool OnWritingSystemUpdated(object param)
420-
{
421-
if (param == null)
422-
return false;
423-
424-
var currentConfig = GetCurrentConfiguration(m_propertyTable, true, null);
425-
var cache = m_propertyTable.GetValue<LcmCache>("cache");
426-
var configuration = new DictionaryConfigurationModel(currentConfig, cache);
427-
DictionaryConfigurationController.UpdateWritingSystemInModel(configuration, cache);
428-
configuration.Save();
429-
430-
return true;
431-
}
432-
433-
public bool OnWritingSystemDeleted(object param)
434-
{
435-
var currentConfig = GetCurrentConfiguration(m_propertyTable, true, null);
436-
var cache = m_propertyTable.GetValue<LcmCache>("cache");
437-
var configuration = new DictionaryConfigurationModel(currentConfig, cache);
438-
if (configuration.HomographConfiguration != null && ((string[])param).Any(x => x.ToString() == configuration.HomographConfiguration.HomographWritingSystem))
439-
{
440-
configuration.HomographConfiguration.HomographWritingSystem = string.Empty;
441-
configuration.HomographConfiguration.CustomHomographNumbers = string.Empty;
442-
configuration.Save();
443-
m_mediator.SendMessage("MasterRefresh", null);
444-
}
445-
return true;
446-
}
447-
448419
private static string GetInnerConfigDir(string configFilePath)
449420
{
450421
return Path.GetFileName(Path.GetDirectoryName(configFilePath));

0 commit comments

Comments
 (0)