/// <summary> /// Override method to handle launching of a chooser for selecting lexical entries. /// </summary> protected override void HandleChooser() { string displayWs = "analysis vernacular"; #pragma warning disable 219 string postDialogMessageTrigger = null; #pragma warning restore 219 if (m_configurationNode != null) { XmlNode node = m_configurationNode.SelectSingleNode("deParams"); if (node != null) { displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower(); postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null); } } var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid), m_displayNameProperty, displayWs); using (MorphTypeChooser chooser = GetChooser(labels)) { chooser.InitializeExtras(m_configurationNode, Mediator, m_propertyTable); chooser.SetObjectAndFlid(m_obj.Hvo, m_flid); chooser.SetHelpTopic(Slice.GetChooserHelpTopicID()); var hvoType = m_cache.DomainDataByFlid.get_ObjectProp(m_obj.Hvo, m_flid); var morphTypeRep = m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>(); var type = hvoType != 0 ? morphTypeRep.GetObject(hvoType) : null; chooser.MakeSelection(type); // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically // when inserting. Thus, we need the check box in that environment as well. //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm) // chooser.ShowAllTypesCheckBoxVisible = false; if (chooser.ShowDialog() == DialogResult.OK) { var selected = (IMoMorphType)chooser.ChosenOne.Object; MakeMorphTypeChange(selected); } } }
protected override void HandleChooser() { string displayWs = "analysis vernacular"; #pragma warning disable 219 string postDialogMessageTrigger = null; #pragma warning restore 219 if (m_configurationNode != null) { XmlNode node = m_configurationNode.SelectSingleNode("deParams"); if (node != null) { displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower(); postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null); } } var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid), m_displayNameProperty, displayWs); using (MorphTypeChooser chooser = GetChooser(labels)) { bool fMadeMorphTypeChange = false; var entry = (ILexEntry)m_obj.Owner; chooser.InitializeExtras(m_configurationNode, Mediator); chooser.SetObjectAndFlid(m_obj.Hvo, m_flid); chooser.SetHelpTopic(Slice.GetChooserHelpTopicID()); var hvoType = m_cache.DomainDataByFlid.get_ObjectProp(m_obj.Hvo, m_flid); var morphTypeRep = m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>(); var type = hvoType != 0 ? morphTypeRep.GetObject(hvoType) : null; chooser.MakeSelection(type); // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically // when inserting. Thus, we need the check box in that environment as well. //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm) // chooser.ShowAllTypesCheckBoxVisible = false; if (chooser.ShowDialog() == DialogResult.OK) { var selected = (IMoMorphType)chooser.ChosenOne.Object; var original = Target as IMoMorphType; string sUndo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath); string sRedo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath); bool fRemoveComponents = false; if (selected.Guid == MoMorphTypeTags.kguidMorphRoot || selected.Guid == MoMorphTypeTags.kguidMorphBoundRoot) { // changing to root...not allowed to have complex forms. foreach (ILexEntryRef ler in entry.EntryRefsOS) { if (ler.RefType == LexEntryRefTags.krtComplexForm) { fRemoveComponents = true; // If there are no components we will delete without asking...but must then check for more // complex forms that DO have components. if (ler.ComponentLexemesRS.Count > 0) { // TODO-Linux: Help is not implemented in Mono if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage, DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, m_mediator.HelpTopicProvider.HelpFile, HelpNavigator.Topic, "/Using_Tools/Lexicon_tools/Lexicon_Edit/change_the_morph_type.htm") != DialogResult.Yes) { return; } break; } } } } UndoableUnitOfWorkHelper.Do(sUndo, sRedo, entry, () => { if (fRemoveComponents) { foreach (var ler in entry.EntryRefsOS.Where(entryRef => entryRef.RefType == LexEntryRefTags.krtComplexForm)) { entry.EntryRefsOS.Remove(ler); } } if (IsStemType(original) || m_obj is IMoStemAllomorph) { if (IsStemType(selected)) { Target = selected; } else { //have to switch from stem to affix fMadeMorphTypeChange = ChangeStemToAffix(entry, selected); } } else { // original is affix variety if (IsStemType(selected)) { //have to switch from affix to stem fMadeMorphTypeChange = ChangeAffixToStem(entry, selected); } else { Target = selected; } } if (selected.Guid == MoMorphTypeTags.kguidMorphPhrase) { ILexEntryRef ler = m_cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create(); entry.EntryRefsOS.Add(ler); ler.RefType = LexEntryRefTags.krtComplexForm; ler.HideMinorEntry = 1; } }); } } }
/// <summary> /// Override method to handle launching of a chooser for selecting lexical entries. /// </summary> protected override void HandleChooser() { string displayWs = "analysis vernacular"; string postDialogMessageTrigger = null; if (m_configurationNode != null) { XmlNode node = m_configurationNode.SelectSingleNode("deParams"); if (node != null) { displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower(); postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null); } } Set <int> candidates = m_obj.ReferenceTargetCandidates(m_flid); ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates, m_displayNameProperty, displayWs); using (MorphTypeChooser chooser = GetChooser(labels)) { bool fMadeMorphTypeChange = false; ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, m_obj.OwnerHVO); chooser.InitializeExtras(m_configurationNode, Mediator); chooser.SetObjectAndFlid(m_obj.Hvo, m_flid); int hvoType = m_cache.GetObjProperty(m_obj.Hvo, m_flid); chooser.MakeSelection(hvoType); // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically // when inserting. Thus, we need the check box in that environment as well. //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm) // chooser.ShowAllTypesCheckBoxVisible = false; if (chooser.ShowDialog() == DialogResult.OK) { ObjectLabel selected = chooser.ChosenOne; int hvoOriginal = TargetHvo; string sUndo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath); string sRedo = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath); bool fRemoveComponents = false; if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphRoot)) || selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphBoundRoot))) { // changing to root...not allowed to have complex forms. foreach (LexEntryRef ler in entry.EntryRefsOS) { if (ler.RefType == LexEntryRef.krtComplexForm) { fRemoveComponents = true; // If there are no components we will delete without asking...but must then check for more // complex forms that DO have components. if (ler.ComponentLexemesRS.Count > 0) { if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage, DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile, HelpNavigator.Topic, "khtRootCannotHaveComponents") != DialogResult.Yes) { return; } break; } } } } using (new UndoRedoTaskHelper(entry.Cache, sUndo, sRedo)) { if (fRemoveComponents) { Set <int> delObjs = new Set <int>(); foreach (LexEntryRef ler in entry.EntryRefsOS) { if (ler.RefType == LexEntryRef.krtComplexForm) { delObjs.Add(ler.Hvo); } } CmObject.DeleteObjects(delObjs, m_cache); } if (IsStemType(hvoOriginal) || m_obj is MoStemAllomorph) { if (IsStemType(selected.Hvo)) { TargetHvo = selected.Hvo; } else { //have to switch from stem to affix fMadeMorphTypeChange = ChangeStemToAffix(entry, selected.Hvo, sUndo, sRedo); } } else { // original is affix variety if (IsStemType(selected.Hvo)) { //have to switch from affix to stem fMadeMorphTypeChange = ChangeAffixToStem(entry, selected.Hvo, sUndo, sRedo); } else { TargetHvo = selected.Hvo; } } if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphPhrase))) { ILexEntryRef ler = new LexEntryRef(); entry.EntryRefsOS.Append(ler); ler.RefType = LexEntryRef.krtComplexForm; ler.HideMinorEntry = 1; // No automatic propchanged for new objects, need to let the view see it. // At that point our slice will be disposed, so don't do anything after this. entry.Cache.PropChanged(entry.Hvo, (int)LexEntry.LexEntryTags.kflidEntryRefs, 0, 1, 0); } } } } }