/// <summary> /// Bring up a chooser for selecting a natural class, and insert it into the string /// representation stored in the rootbox. This static method is used by /// SIL.FieldWorks.Common.Framework.DetailControls.PhoneEnvReferenceSlice and /// SIL.FieldWorks.XWorks.MorphologyEditor.PhEnvStrRepresentationSlice. /// </summary> /// <param name="rootb"></param> /// <param name="cache"></param> /// <param name="persistenceProvider"></param> /// <param name="mediator"></param> /// <returns></returns> public static bool ChooseNaturalClass(IVwRootBox rootb, FdoCache cache, IPersistenceProvider persistenceProvider, XCore.Mediator mediator) { List<int> candidates = null; int hvoPhonData = cache.LangProject.PhonologicalDataOA.Hvo; int flidNatClasses = (int)PhPhonData.PhPhonDataTags.kflidNaturalClasses; int[] targetHvos = cache.GetVectorProperty(hvoPhonData, flidNatClasses, false); if (targetHvos.Length > 0) candidates = new List<int>(targetHvos); else candidates = new List<int>(0); ObjectLabelCollection labels = new ObjectLabelCollection(cache, candidates, "", cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(cache.DefaultAnalWs)); using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(persistenceProvider, labels, "NaturalClass")) { string sTitle = null; string sDescription = null; string sJumpLabel = null; if (mediator != null && mediator.HasStringTable) { sTitle = mediator.StringTbl.GetString("kstidChooseNaturalClass", "Linguistics/Morphology/NaturalClassChooser"); sDescription = mediator.StringTbl.GetString("kstidNaturalClassListing", "Linguistics/Morphology/NaturalClassChooser"); sJumpLabel = mediator.StringTbl.GetString("kstidGotoNaturalClassList", "Linguistics/Morphology/NaturalClassChooser"); } if (sTitle == null || sTitle.Length == 0 || sTitle == "kstidChooseNaturalClass") sTitle = XMLViewsStrings.ksChooseNaturalClass; if (sDescription == null || sDescription.Length == 0 || sDescription == "kstidNaturalClassListing") sDescription = XMLViewsStrings.ksNaturalClassDesc; if (sJumpLabel == null || sJumpLabel.Length == 0 || sJumpLabel == "kstidGotoNaturalClassList") sJumpLabel = XMLViewsStrings.ksEditNaturalClasses; chooser.Cache = cache; chooser.SetObjectAndFlid(0, 0); chooser.InitializeRaw(mediator, sTitle, sDescription, sJumpLabel, "naturalClassedit", "analysis vernacular"); System.Windows.Forms.DialogResult res = chooser.ShowDialog(); if (System.Windows.Forms.DialogResult.Cancel == res) return true; if (chooser.HandleAnyJump()) return true; if (chooser.ChosenOne != null) { int hvo = chooser.ChosenOne.Hvo; IPhNaturalClass pnc = PhNaturalClass.CreateFromDBObject(cache, hvo); ITsString tss = pnc.Abbreviation.BestAnalysisVernacularAlternative; string sName = tss.Text; string sIns = String.Format("[{0}]", sName); int wsPending = cache.DefaultVernWs; IVwRootSite site = rootb.Site; IVwGraphics vg = null; if (site != null) vg = site.get_ScreenGraphics(rootb); rootb.OnTyping(vg, sIns, 0, 0, '[', ref wsPending); } } return true; }