Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 6 additions & 46 deletions Src/FwCoreDlgs/FwCoreDlgsTests/FwWritingSystemSetupModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,12 +1462,11 @@ public void Save_HiddenWsDeleted_WsDeleted()
{
using (var mediator = new Mediator())
{
var deleteListener = new WSDeletedListener(mediator);
var ws = GetOrSetWs("doa");
Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create().CitationForm.set_String(ws.Handle, "some data");
Cache.ActionHandlerAccessor.EndUndoTask();
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, FwWritingSystemSetupModel.ListType.Vernacular,
Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
Cache.ServiceLocator.WritingSystemManager, Cache)
{
ViewHiddenWritingSystems = model =>
model.Items.Add(new HiddenWSListItemModel(ws, false) { WillDelete = true })
Expand All @@ -1477,7 +1476,6 @@ public void Save_HiddenWsDeleted_WsDeleted()
testModel.GetAddMenuItems().First(item => item.MenuText.Contains("View hidden")).ClickHandler(this, EventArgs.Empty);
testModel.Save();

CollectionAssert.AreEqual(new[] {"doa"}, deleteListener.DeletedWSs);
Assert.That(WritingSystemServices.FindAllWritingSystemsWithText(Cache), Is.Not.Contains(ws.Handle));
}
}
Expand All @@ -1488,11 +1486,10 @@ public void Save_DeletedWs_WsDeleted(FwWritingSystemSetupModel.ListType type, st
{
using (var mediator = new Mediator())
{
var deleteListener = new WSDeletedListener(mediator);
SetUpProjectWithData();
Cache.ActionHandlerAccessor.EndUndoTask();
var wasDeleteConfirmed = false;
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
{
ConfirmDeleteWritingSystem = label =>
{
Expand Down Expand Up @@ -1521,7 +1518,6 @@ public void Save_DeletedWs_WsDeleted(FwWritingSystemSetupModel.ListType type, st
Assert.AreEqual("en", Cache.LangProject.AnalysisWss, "Only English should remain after save");
AssertFrenchDataIntact();
}
CollectionAssert.AreEqual(new[] {wsId}, deleteListener.DeletedWSs);
Assert.That(WritingSystemServices.FindAllWritingSystemsWithText(Cache), Is.Not.Contains(GetOrSetWs(wsId).Handle));
}
}
Expand All @@ -1533,15 +1529,14 @@ public void Save_DeletedWs_ExistsInOtherList_WsHidden(
{
using (var mediator = new Mediator())
{
var deleteListener = new WSDeletedListener(mediator);
SetupHomographLanguagesInCache();
var fr = GetOrSetWs("fr");
Cache.LangProject.AnalysisWritingSystems.Add(fr);
var entry = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create();
entry.Comment.set_String(fr.Handle, "commentary");
Cache.ActionHandlerAccessor.EndUndoTask();
var wasDeleteConfirmed = false;
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
{
ConfirmDeleteWritingSystem = label =>
{
Expand All @@ -1557,7 +1552,6 @@ public void Save_DeletedWs_ExistsInOtherList_WsHidden(

Assert.False(wasDeleteConfirmed, "shouldn't confirm 'deleting' a WS that will only be hidden");
AssertOnlyEnglishInList(type);
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
var comment = entry.Comment.get_String(fr.Handle);
Assert.AreEqual(fr.Handle, comment.get_WritingSystemAt(0));
Assert.AreEqual("commentary", comment.Text);
Expand All @@ -1570,18 +1564,16 @@ public void Save_HiddenWs_WsHidden(FwWritingSystemSetupModel.ListType type, stri
{
using (var mediator = new Mediator())
{
var deleteListener = new WSDeletedListener(mediator);
SetUpProjectWithData();
Cache.ActionHandlerAccessor.EndUndoTask();
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator);
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache);
testModel.SelectWs(wsId);

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

AssertOnlyEnglishInList(type);
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
AssertProjectDataIntact();
}
}
Expand All @@ -1592,10 +1584,9 @@ public void Save_WsDeletedRestoredAndHidden_WsHidden(FwWritingSystemSetupModel.L
{
using (var mediator = new Mediator())
{
var deleteListener = new WSDeletedListener(mediator);
SetUpProjectWithData();
Cache.ActionHandlerAccessor.EndUndoTask();
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
{
AddNewVernacularLanguageWarning = () => true,
ConfirmDeleteWritingSystem = label => true,
Expand All @@ -1617,7 +1608,6 @@ public void Save_WsDeletedRestoredAndHidden_WsHidden(FwWritingSystemSetupModel.L
testModel.Save();

AssertOnlyEnglishInList(type);
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
AssertProjectDataIntact();
}
}
Expand All @@ -1629,10 +1619,9 @@ public void Save_WsDeletedAndRestored_NoChange(FwWritingSystemSetupModel.ListTyp
using (var mediator = new Mediator())
{
var ws = GetOrSetWs(wsId);
var deleteListener = new WSDeletedListener(mediator);
SetUpProjectWithData();
Cache.ActionHandlerAccessor.EndUndoTask();
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache, mediator)
var testModel = new FwWritingSystemSetupModel(Cache.LangProject, type, Cache.ServiceLocator.WritingSystemManager, Cache)
{
AddNewVernacularLanguageWarning = () => true,
ConfirmDeleteWritingSystem = label => true,
Expand All @@ -1656,7 +1645,6 @@ public void Save_WsDeletedAndRestored_NoChange(FwWritingSystemSetupModel.ListTyp
Assert.AreEqual("en fr", Cache.LangProject.VernWss, "Both should remain after save");
Assert.AreEqual("en tpi", Cache.LangProject.CurAnalysisWss, "Both should remain selected after save");
Assert.AreEqual("en tpi", Cache.LangProject.AnalysisWss, "Both should remain after save");
CollectionAssert.IsEmpty(deleteListener.DeletedWSs);
AssertProjectDataIntact();
}
}
Expand Down Expand Up @@ -1907,33 +1895,5 @@ public void AddToCurrentVernacularWritingSystems(CoreWritingSystemDefinition ws)
/// </summary>
public IWritingSystemRepository Repo { get; set; }
}

private class WSDeletedListener : IxCoreColleague
{
public List<string> DeletedWSs { get; } = new List<string>();

public WSDeletedListener(Mediator mediator)
{
Init(mediator, null, null);
}

public void OnWritingSystemDeleted(object param)
{
DeletedWSs.AddRange((string[])param);
}

public void Init(Mediator mediator, PropertyTable propertyTable, XmlNode configurationParameters)
{
mediator.AddColleague(this);
}

public IxCoreColleague[] GetMessageTargets()
{
return new IxCoreColleague[] { this };
}

public bool ShouldNotCall => false;
public int Priority => (int)ColleaguePriority.High;
}
}
}
13 changes: 1 addition & 12 deletions Src/FwCoreDlgs/FwWritingSystemSetupModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public List<WSListItemModel> WorkingList
/// <summary/>
public readonly LcmCache Cache;

private readonly Mediator _mediator;

/// <summary/>
public event EventHandler WritingSystemListUpdated;

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

/// <summary/>
public FwWritingSystemSetupModel(IWritingSystemContainer container, ListType type, IWritingSystemManager wsManager = null, LcmCache cache = null, Mediator mediator = null)
public FwWritingSystemSetupModel(IWritingSystemContainer container, ListType type, IWritingSystemManager wsManager = null, LcmCache cache = null)
{
switch (type)
{
Expand All @@ -197,7 +195,6 @@ public FwWritingSystemSetupModel(IWritingSystemContainer container, ListType typ
_wsManager = wsManager;
SetCurrentWsSetupModel(_currentWs);
Cache = cache;
_mediator = mediator;
_wsContainer = container;
_projectLexiconSettings = new ProjectLexiconSettings();
// ignore on disk settings if we are testing without a cache
Expand Down Expand Up @@ -679,7 +676,6 @@ public void Save()
{
WritingSystemUpdated?.Invoke(this, EventArgs.Empty);
}
_mediator?.SendMessage("WritingSystemUpdated", origWs.Id);
}

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

var deletedWsIds = new List<string>();
foreach (var deleteCandidateId in _wsIdsToDelete)
{
if (Cache.ServiceLocator.WritingSystemManager.TryGet(deleteCandidateId, out var deleteCandidate)
&& !otherWritingSystems.Contains(deleteCandidate)
&& !_mergedWritingSystems.Keys.Contains(deleteCandidate))
{
WritingSystemServices.DeleteWritingSystem(Cache, deleteCandidate);
deletedWsIds.Add(deleteCandidateId);
}
}

if (deletedWsIds.Count > 0)
{
_mediator?.SendMessage("WritingSystemDeleted", deletedWsIds.ToArray());
}
}

private static bool IsNew(WSListItemModel tempWs)
Expand Down
29 changes: 0 additions & 29 deletions Src/xWorks/DictionaryConfigurationListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,35 +416,6 @@ public static void SetCurrentConfiguration(PropertyTable propertyTable, string c
propertyTable.SetProperty(pubLayoutPropName, currentConfig, fUpdate);
}

public bool OnWritingSystemUpdated(object param)
{
if (param == null)
return false;

var currentConfig = GetCurrentConfiguration(m_propertyTable, true, null);
var cache = m_propertyTable.GetValue<LcmCache>("cache");
var configuration = new DictionaryConfigurationModel(currentConfig, cache);
DictionaryConfigurationController.UpdateWritingSystemInModel(configuration, cache);
configuration.Save();

return true;
}

public bool OnWritingSystemDeleted(object param)
{
var currentConfig = GetCurrentConfiguration(m_propertyTable, true, null);
var cache = m_propertyTable.GetValue<LcmCache>("cache");
var configuration = new DictionaryConfigurationModel(currentConfig, cache);
if (configuration.HomographConfiguration != null && ((string[])param).Any(x => x.ToString() == configuration.HomographConfiguration.HomographWritingSystem))
{
configuration.HomographConfiguration.HomographWritingSystem = string.Empty;
configuration.HomographConfiguration.CustomHomographNumbers = string.Empty;
configuration.Save();
m_mediator.SendMessage("MasterRefresh", null);
}
return true;
}

private static string GetInnerConfigDir(string configFilePath)
{
return Path.GetFileName(Path.GetDirectoryName(configFilePath));
Expand Down
Loading