/// <summary>Constructor.</summary> public SingleLexReference(ICmObject lexRef, int hvoCrossRef) { m_lexRef = lexRef as ILexReference; m_hvoCrossRef = hvoCrossRef; m_cache = lexRef.Cache; m_cmObjectRepository = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>(); }
public void SenseTreeLexicalRelationName() { NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => { ILexEntry entry1 = m_cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphStem), m_cache.TsStrFactory.MakeString("form1", m_cache.DefaultVernWs), "gloss1", new SandboxGenericMSA()); ILexEntry entry2 = m_cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphStem), m_cache.TsStrFactory.MakeString("form2", m_cache.DefaultVernWs), "gloss2", new SandboxGenericMSA()); ILexEntry entry3 = m_cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphStem), m_cache.TsStrFactory.MakeString("form3", m_cache.DefaultVernWs), "gloss3", new SandboxGenericMSA()); m_cache.LangProject.LexDbOA.ReferencesOA = m_cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); ILexRefType senseLexRefType = m_cache.ServiceLocator.GetInstance <ILexRefTypeFactory>().Create(); m_cache.LangProject.LexDbOA.ReferencesOA.PossibilitiesOS.Add(senseLexRefType); senseLexRefType.MappingType = (int)LexRefTypeTags.MappingTypes.kmtSenseTree; senseLexRefType.Name.SetAnalysisDefaultWritingSystem("Part"); senseLexRefType.ReverseName.SetAnalysisDefaultWritingSystem("Whole"); ILexReference senseLexRef = m_cache.ServiceLocator.GetInstance <ILexReferenceFactory>().Create(); senseLexRefType.MembersOC.Add(senseLexRef); senseLexRef.TargetsRS.Add(entry1.SensesOS[0]); senseLexRef.TargetsRS.Add(entry2.SensesOS[0]); senseLexRef.TargetsRS.Add(entry3.SensesOS[0]); }); Lexeme lexeme = m_lexicon.FindMatchingLexemes("form1").Single(); Assert.That(lexeme.LexicalRelations.Select(lr => lr.Name), Is.EquivalentTo(new[] { "Part", "Part" })); lexeme = m_lexicon.FindMatchingLexemes("form2").Single(); Assert.That(lexeme.LexicalRelations.Select(lr => lr.Name), Is.EquivalentTo(new[] { "Whole", "Other" })); }
/// <summary> /// This method is called when a user selects "Edit Reference Set Details" for a Lexical Relation slice. /// </summary> /// <param name="hvo"></param> public void EditReferenceDetails(ILexReference lr) { CheckDisposed(); if (lr == null) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { using (var dlg = new LexReferenceDetailsDlg(m_mediator.HelpTopicProvider)) { dlg.ReferenceName = lr.Name.AnalysisDefaultWritingSystem.Text; dlg.ReferenceComment = lr.Comment.AnalysisDefaultWritingSystem.Text; if (dlg.ShowDialog() == DialogResult.OK) { using (UndoableUnitOfWorkHelper helper = new UndoableUnitOfWorkHelper(m_cache.ActionHandlerAccessor, LexEdStrings.ksUndoEditRefSetDetails, LexEdStrings.ksRedoEditRefSetDetails)) { lr.Name.SetAnalysisDefaultWritingSystem(dlg.ReferenceName); lr.Comment.SetAnalysisDefaultWritingSystem(dlg.ReferenceComment); helper.RollBack = false; } } } } }
private ILexReference MakeLexReference(ILexRefType owner, ILexSense firstTarget) { ILexReference result = null; result = Cache.ServiceLocator.GetInstance <ILexReferenceFactory>().Create(); owner.MembersOC.Add(result); result.TargetsRS.Add(firstTarget); return(result); }
/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: Pair relation (eg. Antonym) /// tree relation (parts/whole when deleting a Parts slice) /// </summary> /// <param name="hvo"></param> public void DeleteReference(ILexReference lr) { CheckDisposed(); if (lr == null) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { var mainWindow = m_propertyTable.GetValue <Form>("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"))) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); ui.Mediator = Mediator; ui.PropTable = m_propertyTable; //We need this to determine which kind of relation we are deleting var lrtOwner = lr.Owner as ILexRefType; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsStringUtils.MakeIncStrBldr(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseTree: case LexRefTypeTags.MappingTypes.kmtEntryTree: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree: case LexRefTypeTags.MappingTypes.kmtSenseUnidirectional: case LexRefTypeTags.MappingTypes.kmtEntryUnidirectional: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseUnidirectional: tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, StringUtils.kChHardLB)); dlg.SetDlgInfo(ui, m_cache, Mediator, m_propertyTable, tisb.GetString()); break; default: dlg.SetDlgInfo(ui, m_cache, Mediator, m_propertyTable); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { m_cache.DomainDataByFlid.DeleteObj(lr.Hvo); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: Pair relation (eg. Antonym) /// tree relation (parts/whole when deleting a Parts slice) /// </summary> /// <param name="hvo"></param> public void DeleteReference(int hvo) { CheckDisposed(); if (hvo <= 0) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { Form mainWindow = (Form)Mediator.PropertyTable.GetValue("window"); mainWindow.Cursor = Cursors.WaitCursor; using (ConfirmDeleteObjectDlg dlg = new ConfirmDeleteObjectDlg()) { CmObjectUi ui = CmObjectUi.MakeUi(m_cache, hvo); ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvo); //We need this to determine which kind of relation we are deleting LexRefType lrtOwner = (LexRefType)CmObject.CreateFromDBObject(m_cache, lr.OwnerHVO); int analWs = m_cache.DefaultAnalWs; int userWs = m_cache.DefaultUserWs; ITsIncStrBldr tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefType.MappingTypes)lrtOwner.MappingType) { case LexRefType.MappingTypes.kmtSenseTree: case LexRefType.MappingTypes.kmtEntryTree: case LexRefType.MappingTypes.kmtEntryOrSenseTree: tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, "\x2028")); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString()); break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { lr.DeleteUnderlyingObject(); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(hvo); mainWindow.Cursor = Cursors.Default; } else //If the user selected Cancel in the delete dialog do nothing { mainWindow.Cursor = Cursors.Default; return; } } } }
private string GetLexReferenceName(ILexEntry lexEntry, ILexReference lexRef, out ILexEntry parentEntry) { parentEntry = null; ILexRefType lexRefType = lexRef.OwnerOfClass <ILexRefType>(); string name = lexRefType.ShortName; if (string.IsNullOrEmpty(name)) { name = lexRefType.Abbreviation.BestAnalysisAlternative.Text; } var mappingType = (LexRefTypeTags.MappingTypes)lexRefType.MappingType; switch (mappingType) { case LexRefTypeTags.MappingTypes.kmtSenseTree: case LexRefTypeTags.MappingTypes.kmtEntryTree: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree: case LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair: // Sense Pair with different Forward/Reverse names case LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair: // Entry Pair with different Forward/Reverse names case LexRefTypeTags.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense Pair with different Forward/Reverse names if (lexRef.TargetsRS.Count > 0) { ICmObject firstObj = lexRef.TargetsRS[0]; ILexEntry firstEntry = null; switch (firstObj.ClassID) { case LexEntryTags.kClassId: firstEntry = (ILexEntry)firstObj; break; case LexSenseTags.kClassId: firstEntry = firstObj.OwnerOfClass <ILexEntry>(); break; } if (firstEntry != lexEntry) { name = lexRefType.ReverseName.BestAnalysisAlternative.Text; if (string.IsNullOrEmpty(name)) { name = lexRefType.ReverseAbbreviation.BestAnalysisAlternative.Text; } } if (mappingType == LexRefTypeTags.MappingTypes.kmtSenseTree || mappingType == LexRefTypeTags.MappingTypes.kmtEntryTree || mappingType == LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree) { parentEntry = firstEntry; } } break; } return(name.Normalize()); }
private void UpdateForDelete(ILexReference lr) { // This slice might get disposed by one of the calling methods. See FWR-3291. if (IsDisposed) { return; } m_refs.Remove(lr); // if this flickers too annoyingly, we can probably optimize by extracting relevant lines from Collapse. Collapse(); Expand(); }
public override void AddItem(int hvoNew) { CheckDisposed(); ILexReference lr = m_obj as ILexReference; List <int> senses = new List <int>(); foreach (int hvo in lr.TargetsRS.HvoArray) { // Don't duplicate entries for simple collections. if (hvo == hvoNew) { return; } senses.Add(hvo); } senses.Add(hvoNew); SetItems(senses); Debug.Assert(senses.Count == lr.TargetsRS.Count && senses[0] == lr.TargetsRS[0].Hvo); (lr as LexReference).UpdateTargetTimestamps(); }
/// <summary> /// This method is called when a user selects "Edit Reference Set Details" for a Lexical Relation slice. /// </summary> /// <param name="hvo"></param> public void EditReferenceDetails(int hvo) { CheckDisposed(); if (hvo <= 0) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvo); using (LexReferenceDetailsDlg dlg = new LexReferenceDetailsDlg()) { dlg.ReferenceName = lr.Name.AnalysisDefaultWritingSystem; dlg.ReferenceComment = lr.Comment.AnalysisDefaultWritingSystem.Text; if (dlg.ShowDialog() == DialogResult.OK) { lr.Name.AnalysisDefaultWritingSystem = dlg.ReferenceName; lr.Comment.SetAnalysisDefaultWritingSystem(dlg.ReferenceComment); } } } }
/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: Pair relation (eg. Antonym) /// tree relation (parts/whole when deleting a Parts slice) /// </summary> /// <param name="hvo"></param> public void DeleteReference(ILexReference lr) { CheckDisposed(); if (lr == null) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { var mainWindow = Mediator.PropertyTable.GetValue("window") as Form; using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); //We need this to determine which kind of relation we are deleting var lrtOwner = lr.Owner as ILexRefType; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseTree: case LexRefTypeTags.MappingTypes.kmtEntryTree: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree: tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteLexTree, StringUtils.kChHardLB)); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString() ); break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { m_cache.DomainDataByFlid.DeleteObj(lr.Hvo); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
private string GetLexReferenceName(ILexEntry lexEntry, ILexReference lexRef, out ILexEntry parentEntry) { parentEntry = null; ILexRefType lexRefType = lexRef.OwnerOfClass<ILexRefType>(); string name = lexRefType.ShortName; if (string.IsNullOrEmpty(name)) name = lexRefType.Abbreviation.BestAnalysisAlternative.Text; var mappingType = (LexRefTypeTags.MappingTypes) lexRefType.MappingType; switch (mappingType) { case LexRefTypeTags.MappingTypes.kmtSenseTree: case LexRefTypeTags.MappingTypes.kmtEntryTree: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree: case LexRefTypeTags.MappingTypes.kmtSenseAsymmetricPair: // Sense Pair with different Forward/Reverse names case LexRefTypeTags.MappingTypes.kmtEntryAsymmetricPair: // Entry Pair with different Forward/Reverse names case LexRefTypeTags.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense Pair with different Forward/Reverse names if (lexRef.TargetsRS.Count > 0) { ICmObject firstObj = lexRef.TargetsRS[0]; ILexEntry firstEntry = null; switch (firstObj.ClassID) { case LexEntryTags.kClassId: firstEntry = (ILexEntry) firstObj; break; case LexSenseTags.kClassId: firstEntry = firstObj.OwnerOfClass<ILexEntry>(); break; } if (firstEntry != lexEntry) { name = lexRefType.ReverseName.BestAnalysisAlternative.Text; if (string.IsNullOrEmpty(name)) name = lexRefType.ReverseAbbreviation.BestAnalysisAlternative.Text; } if (mappingType == LexRefTypeTags.MappingTypes.kmtSenseTree || mappingType == LexRefTypeTags.MappingTypes.kmtEntryTree || mappingType == LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree) { parentEntry = firstEntry; } } break; } return name.Normalize(); }
public void HandleCreateMenuItem(object sender, EventArgs ea) { CheckDisposed(); if (!m_cache.VerifyValidObject(m_obj)) { return; } int itemIndex = (((ToolStripItem)(sender)).Owner as ContextMenuStrip).Items.IndexOf((ToolStripItem)sender); int hvoType = m_refTypesAvailable[itemIndex]; bool fReverseRef = m_rgfReversedRefType[itemIndex]; ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, hvoType); int hvoNew = 0; int hvoFirst = 0; if (fReverseRef) { // When creating a tree Lexical Relation and the user is choosing // the root of the tree, first see if the user selects a lexical entry. // If they do not select anything (hvoFirst==0) return and do not create the slice. hvoFirst = GetRootObjectHvo(lrt); if (hvoFirst == 0) { return; // the user cancelled out of the operation. } if (lrt.MappingType == (int)LexRefType.MappingTypes.kmtSenseTree || lrt.MappingType == (int)LexRefType.MappingTypes.kmtEntryTree || lrt.MappingType == (int)LexRefType.MappingTypes.kmtEntryOrSenseTree) { // Use an existing LexReference if one exists. foreach (ILexReference lr in lrt.MembersOC) { if (lr.TargetsRS.Count > 0 && lr.TargetsRS.HvoArray[0] == hvoFirst) { lr.TargetsRS.Append(m_obj.Hvo); hvoNew = lr.Hvo; break; } } } } else { // Launch the dialog that allows the user to choose a lexical entry. // If they choose an entry, it is returned in hvoFirst so go ahead and // create the lexical relation and add this lexical entry to that relation. hvoFirst = GetChildObjectHvo(lrt); if (hvoFirst == 0) { return; // the user cancelled out of the operation. } } if (hvoNew == 0) { hvoNew = m_cache.CreateObject((int)LexReference.kclsidLexReference, hvoType, (int)LexRefType.LexRefTypeTags.kflidMembers, 0); ILexReference lr = LexReference.CreateFromDBObject(m_cache, hvoNew); if (fReverseRef) { lr.TargetsRS.InsertAt(hvoFirst, 0); lr.TargetsRS.InsertAt(m_obj.Hvo, 1); } else { //When creating a lexical relation slice, //add the current lexical entry to the lexical relation as the first item lr.TargetsRS.InsertAt(m_obj.Hvo, 0); //then also add the lexical entry that the user selected in the chooser dialog. lr.TargetsRS.InsertAt(hvoFirst, 1); } } m_refs.Add(hvoNew); this.ExpandNewNode(); // update the cache through our virtual handler. if (m_vh != null) { IVwCacheDa cda = m_cache.VwCacheDaAccessor; int flid = m_vh.Tag; m_vh.Load(m_obj.Hvo, flid, 0, cda); m_cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_obj.Hvo, flid, 0, 1, 0); } (m_obj as CmObject).UpdateTimestampForVirtualChange(); if (hvoFirst != 0) { ICmObject cmoFirst = CmObject.CreateFromDBObject(m_cache, hvoFirst); (cmoFirst as CmObject).UpdateTimestampForVirtualChange(); } }
/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: sequence relations (eg. Calendar) /// collection relations (eg. Synonym) /// tree relation (parts/whole when deleting a Whole slice) /// </summary> /// <param name="hvo"></param> public void DeleteFromReference(ILexReference lr) { CheckDisposed(); if (lr == null) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { var mainWindow = (Form) Mediator.PropertyTable.GetValue("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); //We need this to determine which kind of relation we are deleting var lrtOwner = (ILexRefType) lr.Owner; var analWs = lrtOwner.Services.WritingSystems.DefaultAnalysisWritingSystem.Handle; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntrySequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseCollection: case LexRefTypeTags.MappingTypes.kmtEntryCollection: case LexRefTypeTags.MappingTypes.kmtSenseCollection: if (lr.TargetsRS.Count > 2) { tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteSequenceCollectionA, StringUtils.kChHardLB.ToString())); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, analWs); tisb.Append(lrtOwner.ShortName); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(LexEdStrings.ksDeleteSequenceCollectionB); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString()); } else { dlg.SetDlgInfo(ui, m_cache, Mediator); } break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { //If the user selected Yes, then we need to delete 'this' sense or entry lr.TargetsRS.Remove(m_obj); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
public override void FixtureSetup() { base.FixtureSetup(); m_entryFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>(); m_senseFactory = Cache.ServiceLocator.GetInstance<ILexSenseFactory>(); m_exampleFactory = Cache.ServiceLocator.GetInstance<ILexExampleSentenceFactory>(); m_lexEntryRefFactory = Cache.ServiceLocator.GetInstance<ILexEntryRefFactory>(); m_lexRefTypeFactory = Cache.ServiceLocator.GetInstance<ILexRefTypeFactory>(); m_lexRefFactory = Cache.ServiceLocator.GetInstance<ILexReferenceFactory>(); m_possListFactory = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>(); m_flidReferringSenses = Cache.MetaDataCacheAccessor.GetFieldId2(CmSemanticDomainTags.kClassId, "ReferringSenses", false); UndoableUnitOfWorkHelper.Do("do", "undo", Cache.ActionHandlerAccessor, () => { m_domainBadWords = Cache.ServiceLocator.GetInstance<ICmSemanticDomainFactory>().Create(); m_domainTemperature = Cache.ServiceLocator.GetInstance<ICmSemanticDomainFactory>().Create(); Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainBadWords); Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainTemperature); m_mainDict = Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS[0]; m_blank = MakeEntry("blank", "swear word", true); m_blank.SensesOS[0].SemanticDomainsRC.Add(m_domainBadWords); m_hot = MakeEntry("hot", "high temperature", false); m_hotTemp = m_hot.SensesOS[0]; m_hotTemp.SemanticDomainsRC.Add(m_domainTemperature); m_trouble = MakeSense(m_hot, "trouble"); m_trouble.DoNotPublishInRC.Add(m_mainDict); m_trouble.PicturesOS.Add(Cache.ServiceLocator.GetInstance<ICmPictureFactory>().Create()); m_desirable = MakeSense(m_hot, "desirable"); m_fastCar = MakeSense(m_desirable, "fast (car)"); m_badHot = MakeExample(m_hotTemp, "a hot pile of blank", true); m_goodHot = MakeExample(m_hotTemp, "a hot bath", false); m_water = MakeEntry("water", "H2O", false); m_waterH2O = m_water.SensesOS[0]; m_hotWater = MakeEntry("hot water", "trouble", false); m_hotWaterComponents = MakeEntryRef(m_hotWater, new ICmObject[] { m_trouble, m_waterH2O }, new[] { m_trouble, m_waterH2O }, LexEntryRefTags.krtComplexForm); m_blank2 = MakeEntry("blank", "vacant", false); m_blank3 = MakeEntry("blank", "erase", false); m_water2 = MakeEntry("water", "urinate", true); m_waterPrefix = MakeEntry("water", "aquatic", false); m_waterPrefix.LexemeFormOA.MorphTypeRA = Cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>() .GetObject(MoMorphTypeTags.kguidMorphPrefix); m_synonym = MakeRefType("synonym", null, (int)LexRefTypeTags.MappingTypes.kmtSenseCollection); m_blip = MakeEntry("blip", "rude word", true); m_bother = MakeEntry("bother", "I'm annoyed by that", false); m_ouch = MakeEntry("ouch", "that hurt", false); m_blipOuch = MakeSense(m_blip.SensesOS[0], "rude ouch"); m_blankSynonyms = MakeLexRef(m_synonym, new ICmObject[] {m_blank, m_ouch.SensesOS[0], m_blip.SensesOS[0], m_blipOuch, m_bother}); m_problem = MakeEntry("problem", "difficulty", false); m_problemSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_problem, m_trouble }); m_body = MakeEntry("body", "body", true); m_arm = MakeEntry("arm", "arm", false); m_leg = MakeEntry("leg", "leg", false); m_belly = MakeEntry("belly", "belly", true); m_torso = MakeEntry("torso", "torso", false); m_partWhole = MakeRefType("partWhole", null, (int)LexRefTypeTags.MappingTypes.kmtEntryTree); m_bodyParts = MakeLexRef(m_partWhole, new ICmObject[] {m_body, m_arm, m_leg.SensesOS[0], m_torso, m_belly}); m_torsoParts = MakeLexRef(m_partWhole, new ICmObject[] {m_torso, m_arm, m_belly}); m_hotBlank = MakeEntry("hotBlank", "problem rude word", false); MakeEntryRef(m_hotBlank, new ICmObject[] { m_trouble, m_water2 }, new ICmObject[] { m_trouble, m_water2 }, LexEntryRefTags.krtComplexForm); m_blueColor = MakeEntry("blue", "color blue", false); m_blueCold = MakeEntry("blue", "cold", false); m_blueMusic = MakeEntry("blue", "jazzy", false); m_blueSad = MakeEntry("blue", "sad", false); m_blueMusic.HomographNumber = 2; // will duplicate blue cold; pathological, but should not crash. m_blueSad.HomographNumber = 3; // will conflict with renumbered blueMusic m_bluer = m_blueColor.SensesOS[0]; m_sky = MakeEntry("sky", "interface between atmosphere and space", false, true); // true excludes as headword m_skyReal = m_sky.SensesOS[0]; m_blueSky = MakeEntry("blue sky", "clear, huge potential", false, false); m_blueSkyComponents = MakeEntryRef(m_blueSky, new ICmObject[] { m_blueColor, m_skyReal }, new[] { m_bluer, m_skyReal }, LexEntryRefTags.krtComplexForm); m_ringBell = MakeEntry("ring", "bell", false, false); m_ringCircle = MakeEntry("ring", "circle", false, true); m_ringGold = MakeEntry("ring", "gold", false, false); m_blackVerb = MakeEntry("black", "darken", false, true); m_blackColor = MakeEntry("black", "dark", false, false); m_hotArm = MakeEntry("hotarm", "pitcher", false, false); m_hotArmComponents = MakeEntryRef(m_hotArm, new ICmObject[] { m_hot, m_arm }, new[] { m_hot, m_arm }, LexEntryRefTags.krtComplexForm); m_hotArm.DoNotPublishInRC.Add(m_mainDict); m_hotArmComponents.ShowComplexFormsInRS.Add(m_hot); m_nolanryan = MakeEntry("Nolan_Ryan", "pitcher", false, false); m_nolanryanComponents = MakeEntryRef(m_nolanryan, new ICmObject[] { m_hot }, new[] { m_hot }, LexEntryRefTags.krtVariant); m_nolanryanComponents.VariantEntryTypesRS.Add( (ILexEntryType)Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0]); m_nolanryan.DoNotPublishInRC.Add(m_mainDict); m_edName = MakeEntry("ed", "someone called ed", false); m_edSuffix = MakeEntry("ed", "past", false, false, true); m_publisher = new MockPublisher((ISilDataAccessManaged)Cache.DomainDataByFlid, kmainFlid); m_publisher.SetOwningPropValue(Cache.LangProject.LexDbOA.Entries.Select(le => le.Hvo).ToArray()); m_decorator = new DictionaryPublicationDecorator(Cache, m_publisher, ObjectListPublisher.OwningFlid); }); }
private void WriteLexReference(TextWriter w, ILexReference lref, ICmObject lexItem) { var slr = new SingleLexReference(lref, lref.TargetsRS[0].Hvo); var nMappingType = slr.MappingType; var hvoOpen = lexItem.Hvo; for (var i = 0; i < lref.TargetsRS.Count; i++) { var target = lref.TargetsRS[i]; // If the LexReference vector element is the currently open object, ignore // it unless it's a sequence type relation. if (nMappingType != (int)LexRefTypeTags.MappingTypes.kmtSenseSequence && nMappingType != (int)LexRefTypeTags.MappingTypes.kmtEntrySequence && nMappingType != (int)LexRefTypeTags.MappingTypes.kmtEntryOrSenseSequence) { if (target.Hvo == hvoOpen) continue; } slr.CrossRefHvo = target.Hvo; w.Write("<relation"); WriteLiftDates(w, lref); var typeName = slr.TypeName((int)SpecialWritingSystemCodes.BestAnalysisOrVernacular, lexItem.Hvo); w.Write(" type=\"{0}\"", MakeSafeAndNormalizedAttribute(typeName)); w.Write(" ref=\"{0}\"", XmlUtils.MakeSafeXmlAttribute(slr.RefLIFTid)); var refOrder = slr.RefOrder; if (!String.IsNullOrEmpty(refOrder)) w.Write(" order=\"{0}\"", refOrder); var residue = slr.LiftResidueContent; if (String.IsNullOrEmpty(residue)) { w.WriteLine("/>"); } else { w.WriteLine(">"); w.Write(residue); w.WriteLine("</relation>"); } // If this is a tree type relation, show only the first element if the // currently open object is not the first element. if (nMappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseTree || nMappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryTree || nMappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree) { if (hvoOpen != lref.TargetsRS[0].Hvo) break; } } }
public override void FixtureSetup() { base.FixtureSetup(); m_entryFactory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>(); m_senseFactory = Cache.ServiceLocator.GetInstance <ILexSenseFactory>(); m_exampleFactory = Cache.ServiceLocator.GetInstance <ILexExampleSentenceFactory>(); m_lexEntryRefFactory = Cache.ServiceLocator.GetInstance <ILexEntryRefFactory>(); m_lexRefTypeFactory = Cache.ServiceLocator.GetInstance <ILexRefTypeFactory>(); m_lexRefFactory = Cache.ServiceLocator.GetInstance <ILexReferenceFactory>(); m_possListFactory = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>(); m_flidReferringSenses = Cache.MetaDataCacheAccessor.GetFieldId2(CmSemanticDomainTags.kClassId, "ReferringSenses", false); UndoableUnitOfWorkHelper.Do("do", "undo", Cache.ActionHandlerAccessor, () => { m_domainBadWords = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>().Create(); m_domainTemperature = Cache.ServiceLocator.GetInstance <ICmSemanticDomainFactory>().Create(); Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainBadWords); Cache.LangProject.SemanticDomainListOA.PossibilitiesOS.Add(m_domainTemperature); m_mainDict = Cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS[0]; m_blank = MakeEntry("blank", "swear word", true); m_blank.SensesOS[0].SemanticDomainsRC.Add(m_domainBadWords); m_hot = MakeEntry("hot", "high temperature", false); m_hotTemp = m_hot.SensesOS[0]; m_hotTemp.SemanticDomainsRC.Add(m_domainTemperature); m_trouble = MakeSense(m_hot, "trouble"); m_trouble.DoNotPublishInRC.Add(m_mainDict); m_trouble.PicturesOS.Add(Cache.ServiceLocator.GetInstance <ICmPictureFactory>().Create()); m_desirable = MakeSense(m_hot, "desirable"); m_fastCar = MakeSense(m_desirable, "fast (car)"); m_badHot = MakeExample(m_hotTemp, "a hot pile of blank", true); m_goodHot = MakeExample(m_hotTemp, "a hot bath", false); m_water = MakeEntry("water", "H2O", false); m_waterH2O = m_water.SensesOS[0]; m_hotWater = MakeEntry("hot water", "trouble", false); m_hotWaterComponents = MakeEntryRef(m_hotWater, new ICmObject[] { m_trouble, m_waterH2O }, new[] { m_trouble, m_waterH2O }, LexEntryRefTags.krtComplexForm); m_blank2 = MakeEntry("blank", "vacant", false); m_blank3 = MakeEntry("blank", "erase", false); m_water2 = MakeEntry("water", "urinate", true); m_waterPrefix = MakeEntry("water", "aquatic", false); m_waterPrefix.LexemeFormOA.MorphTypeRA = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>() .GetObject(MoMorphTypeTags.kguidMorphPrefix); m_synonym = MakeRefType("synonym", null, (int)LexRefTypeTags.MappingTypes.kmtSenseCollection); m_blip = MakeEntry("blip", "rude word", true); m_bother = MakeEntry("bother", "I'm annoyed by that", false); m_ouch = MakeEntry("ouch", "that hurt", false); m_blipOuch = MakeSense(m_blip.SensesOS[0], "rude ouch"); m_blankSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_blank, m_ouch.SensesOS[0], m_blip.SensesOS[0], m_blipOuch, m_bother }); m_problem = MakeEntry("problem", "difficulty", false); m_problemSynonyms = MakeLexRef(m_synonym, new ICmObject[] { m_problem, m_trouble }); m_body = MakeEntry("body", "body", true); m_arm = MakeEntry("arm", "arm", false); m_leg = MakeEntry("leg", "leg", false); m_belly = MakeEntry("belly", "belly", true); m_torso = MakeEntry("torso", "torso", false); m_partWhole = MakeRefType("partWhole", null, (int)LexRefTypeTags.MappingTypes.kmtEntryTree); m_bodyParts = MakeLexRef(m_partWhole, new ICmObject[] { m_body, m_arm, m_leg.SensesOS[0], m_torso, m_belly }); m_torsoParts = MakeLexRef(m_partWhole, new ICmObject[] { m_torso, m_arm, m_belly }); m_hotBlank = MakeEntry("hotBlank", "problem rude word", false); MakeEntryRef(m_hotBlank, new ICmObject[] { m_trouble, m_water2 }, new ICmObject[] { m_trouble, m_water2 }, LexEntryRefTags.krtComplexForm); m_blueColor = MakeEntry("blue", "color blue", false); m_blueCold = MakeEntry("blue", "cold", false); m_blueMusic = MakeEntry("blue", "jazzy", false); m_blueSad = MakeEntry("blue", "sad", false); m_blueMusic.HomographNumber = 2; // will duplicate blue cold; pathological, but should not crash. m_blueSad.HomographNumber = 3; // will conflict with renumbered blueMusic m_bluer = m_blueColor.SensesOS[0]; m_sky = MakeEntry("sky", "interface between atmosphere and space", false, true); // true excludes as headword m_skyReal = m_sky.SensesOS[0]; m_blueSky = MakeEntry("blue sky", "clear, huge potential", false, false); m_blueSkyComponents = MakeEntryRef(m_blueSky, new ICmObject[] { m_blueColor, m_skyReal }, new[] { m_bluer, m_skyReal }, LexEntryRefTags.krtComplexForm); m_ringBell = MakeEntry("ring", "bell", false, false); m_ringCircle = MakeEntry("ring", "circle", false, true); m_ringGold = MakeEntry("ring", "gold", false, false); m_blackVerb = MakeEntry("black", "darken", false, true); m_blackColor = MakeEntry("black", "dark", false, false); m_hotArm = MakeEntry("hotarm", "pitcher", false, false); m_hotArmComponents = MakeEntryRef(m_hotArm, new ICmObject[] { m_hot, m_arm }, new[] { m_hot, m_arm }, LexEntryRefTags.krtComplexForm); m_hotArm.DoNotPublishInRC.Add(m_mainDict); m_hotArmComponents.ShowComplexFormsInRS.Add(m_hot); m_nolanryan = MakeEntry("Nolan_Ryan", "pitcher", false, false); m_nolanryanComponents = MakeEntryRef(m_nolanryan, new ICmObject[] { m_hot }, new[] { m_hot }, LexEntryRefTags.krtVariant); m_nolanryanComponents.VariantEntryTypesRS.Add( (ILexEntryType)Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS[0]); m_nolanryan.DoNotPublishInRC.Add(m_mainDict); m_publisher = new MockPublisher((ISilDataAccessManaged)Cache.DomainDataByFlid, kmainFlid); m_publisher.SetOwningPropValue(Cache.LangProject.LexDbOA.Entries.Select(le => le.Hvo).ToArray()); m_decorator = new DictionaryPublicationDecorator(Cache, m_publisher, ObjectListPublisher.OwningFlid); }); }
private void GenerateChildNode(int iChild, XmlNode node, XmlNode caller, int indent, ref int insPos, ArrayList path, ObjSeqHashMap reuseMap) { ILexReference lr = LexReference.CreateFromDBObject(m_cache, (int)m_refs[iChild]); ILexRefType lrt = LexRefType.CreateFromDBObject(m_cache, lr.OwnerHVO); string sLabel = lrt.ShortName; if (sLabel == null || sLabel == string.Empty) { sLabel = lrt.Abbreviation.BestAnalysisAlternative.Text; } bool fTreeRoot = true; ISilDataAccess sda = m_cache.MainCacheAccessor; int chvoTargets = sda.get_VecSize(lr.Hvo, (int)LexReference.LexReferenceTags.kflidTargets); // change the label for a Tree relationship. switch ((LexRefType.MappingTypes)lrt.MappingType) { case LexRefType.MappingTypes.kmtSenseTree: case LexRefType.MappingTypes.kmtEntryTree: case LexRefType.MappingTypes.kmtEntryOrSenseTree: case LexRefType.MappingTypes.kmtSenseAsymmetricPair: // Sense Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryAsymmetricPair: // Entry Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense Pair with different Forward/Reverse names //int chvo = sda.get_VecSize(lr.Hvo, (int)LexReference.LexReferenceTags.kflidTargets); if (chvoTargets > 0) { int hvoFirst = sda.get_VecItem(lr.Hvo, (int)LexReference.LexReferenceTags.kflidTargets, 0); if (hvoFirst != m_obj.Hvo) { sLabel = lrt.ReverseName.BestAnalysisAlternative.Text; if (sLabel == null || sLabel == string.Empty) { sLabel = lrt.ReverseAbbreviation.BestAnalysisAlternative.Text; } fTreeRoot = false; } } break; } if (sLabel == null || sLabel == string.Empty) { sLabel = LexEdStrings.ksStars; } string sXml = "<slice label=\"" + sLabel + "\" field=\"Targets\"" + " editor=\"Custom\" assemblyPath=\"LexEdDll.dll\""; //string sMenu = "mnuDataTree-DeleteFromLexSenseReference"; we used to have distinct strings in the menu string sMenu = "mnuDataTree-DeleteAddLexReference"; // generate Xml for a specific slice matching this reference switch ((LexRefType.MappingTypes)lrt.MappingType) { case LexRefType.MappingTypes.kmtSenseCollection: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceCollectionSlice\""; break; case LexRefType.MappingTypes.kmtSensePair: case LexRefType.MappingTypes.kmtSenseAsymmetricPair: // Sense Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryPair: case LexRefType.MappingTypes.kmtEntryAsymmetricPair: // Entry Pair with different Forward/Reverse names case LexRefType.MappingTypes.kmtEntryOrSensePair: case LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair: // Entry or sense Pair with different forward/Reverse names sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferencePairSlice\""; sMenu = "mnuDataTree-DeleteReplaceLexReference"; break; case LexRefType.MappingTypes.kmtSenseTree: if (fTreeRoot) { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeBranchesSlice\""; sMenu = "mnuDataTree-DeleteAddLexReference"; } else { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeRootSlice\""; sMenu = "mnuDataTree-DeleteReplaceLexReference"; } break; case LexRefType.MappingTypes.kmtSenseSequence: case LexRefType.MappingTypes.kmtEntrySequence: case LexRefType.MappingTypes.kmtEntryOrSenseSequence: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceSequenceSlice\""; break; case LexRefType.MappingTypes.kmtEntryCollection: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceCollectionSlice\""; //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; break; case LexRefType.MappingTypes.kmtEntryTree: //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; if (fTreeRoot) { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeBranchesSlice\""; sMenu = "mnuDataTree-DeleteAddLexReference"; } else { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeRootSlice\""; sMenu = "mnuDataTree-DeleteReplaceLexReference"; } break; case LexRefType.MappingTypes.kmtEntryOrSenseCollection: sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceCollectionSlice\""; if (m_obj is LexEntry) { //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; } break; case LexRefType.MappingTypes.kmtEntryOrSenseTree: if (m_obj is LexEntry) { //sMenu = "mnuDataTree-DeleteFromLexEntryReference"; we used to have distinct strings in the menu sMenu = "mnuDataTree-DeleteAddLexReference"; } if (fTreeRoot) { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeBranchesSlice\""; sMenu = "mnuDataTree-DeleteAddLexReference"; } else { sXml += " class=\"SIL.FieldWorks.XWorks.LexEd.LexReferenceTreeRootSlice\""; } break; } sXml += " mappingType=\"" + lrt.MappingType + "\" hvoDisplayParent=\"" + m_obj.Hvo + "\"" + " menu=\"" + sMenu + "\"><deParams displayProperty=\"HeadWord\"/></slice>"; node.InnerXml = sXml; int firstNewSliceIndex = insPos; CreateIndentedNodes(caller, lr, indent, ref insPos, path, reuseMap, node); for (int islice = firstNewSliceIndex; islice < insPos; islice++) { Slice child = Parent.Controls[islice] as Slice; if (child is ILexReferenceSlice) { (child as ILexReferenceSlice).MasterSlice = this; } } node.InnerXml = ""; }
public void HandleCreateMenuItem(object sender, EventArgs ea) { CheckDisposed(); var tsItem = sender as ToolStripItem; int itemIndex = (tsItem.Owner as ContextMenuStrip).Items.IndexOf(tsItem); var lrt = m_refTypesAvailable[itemIndex]; bool fReverseRef = m_rgfReversedRefType[itemIndex]; ILexReference newRef = null; ICmObject first = null; if (fReverseRef) { // When creating a tree Lexical Relation and the user is choosing // the root of the tree, first see if the user selects a lexical entry. // If they do not select anything (hvoFirst==0) return and do not create the slice. first = GetRootObject(lrt); if (first == null) { return; // the user cancelled out of the operation. } if (lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtSenseTree || lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryTree || lrt.MappingType == (int)LexRefTypeTags.MappingTypes.kmtEntryOrSenseTree) { // Use an existing ILexReference if one exists. foreach (var lr in lrt.MembersOC) { if (lr.TargetsRS.Count > 0 && lr.TargetsRS[0] == first) { newRef = lr; break; } } } } else { // Launch the dialog that allows the user to choose a lexical entry. // If they choose an entry, it is returned in hvoFirst so go ahead and // create the lexical relation and add this lexical entry to that relation. first = GetChildObject(lrt); if (first == null) { return; // the user cancelled out of the operation. } } UndoableUnitOfWorkHelper.Do(string.Format(LexEdStrings.ksUndoInsertRelation, tsItem.Text), string.Format(LexEdStrings.ksRedoInsertRelation, tsItem.Text), m_obj, () => { if (newRef != null) { newRef.TargetsRS.Add(m_obj); } else { newRef = m_cache.ServiceLocator.GetInstance <ILexReferenceFactory>().Create(); lrt.MembersOC.Add(newRef); if (fReverseRef) { newRef.TargetsRS.Insert(0, first); newRef.TargetsRS.Insert(1, m_obj); } else { //When creating a lexical relation slice, //add the current lexical entry to the lexical relation as the first item newRef.TargetsRS.Insert(0, m_obj); //then also add the lexical entry that the user selected in the chooser dialog. newRef.TargetsRS.Insert(1, first); } } m_refs.Add(newRef); }); }
/// <summary> /// This method is called when a user selects Delete Relation on a Lexical Relation slice. /// For: sequence relations (eg. Calendar) /// collection relations (eg. Synonym) /// tree relation (parts/whole when deleting a Whole slice) /// </summary> /// <param name="hvo"></param> public void DeleteFromReference(ILexReference lr) { CheckDisposed(); if (lr == null) { throw new ConfigurationException("Slice:GetObjectHvoForMenusToOperateOn is either messed up or should not have been called, because it could not find the object to be deleted.", m_configurationNode); } else { var mainWindow = (Form)Mediator.PropertyTable.GetValue("window"); using (new WaitCursor(mainWindow)) { using (var dlg = new ConfirmDeleteObjectDlg(m_mediator.HelpTopicProvider)) { var ui = CmObjectUi.MakeUi(m_cache, lr.Hvo); //We need this to determine which kind of relation we are deleting var lrtOwner = (ILexRefType)lr.Owner; var analWs = lrtOwner.Services.WritingSystems.DefaultAnalysisWritingSystem.Handle; var userWs = m_cache.WritingSystemFactory.UserWs; var tisb = TsIncStrBldrClass.Create(); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); switch ((LexRefTypeTags.MappingTypes)lrtOwner.MappingType) { case LexRefTypeTags.MappingTypes.kmtSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntrySequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseSequence: case LexRefTypeTags.MappingTypes.kmtEntryOrSenseCollection: case LexRefTypeTags.MappingTypes.kmtEntryCollection: case LexRefTypeTags.MappingTypes.kmtSenseCollection: if (lr.TargetsRS.Count > 2) { tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(String.Format(LexEdStrings.ksDeleteSequenceCollectionA, StringUtils.kChHardLB.ToString())); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, analWs); tisb.Append(lrtOwner.ShortName); tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); tisb.Append(LexEdStrings.ksDeleteSequenceCollectionB); dlg.SetDlgInfo(ui, m_cache, Mediator, tisb.GetString()); } else { dlg.SetDlgInfo(ui, m_cache, Mediator); } break; default: dlg.SetDlgInfo(ui, m_cache, Mediator); break; } if (DialogResult.Yes == dlg.ShowDialog(mainWindow)) { UndoableUnitOfWorkHelper.Do(LexEdStrings.ksUndoDeleteRelation, LexEdStrings.ksRedoDeleteRelation, m_obj, () => { //If the user selected Yes, then we need to delete 'this' sense or entry lr.TargetsRS.Remove(m_obj); }); //Update the display because we have removed this slice from the Lexical entry. UpdateForDelete(lr); } } } } }
private void UpdateForDelete(ILexReference lr) { // This slice might get disposed by one of the calling methods. See FWR-3291. if (IsDisposed) return; m_refs.Remove(lr); // if this flickers too annoyingly, we can probably optimize by extracting relevant lines from Collapse. Collapse(); Expand(); }