internal void SetupWritingSystemsForTitle(LcmCache cache) { m_ttpWsLabel = WritingSystemServices.AbbreviationTextProperties; m_writingSystems = new CoreWritingSystemDefinition[2]; m_writingSystems[0] = cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; m_writingSystems[1] = cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem; m_WsLabels = new ITsString[m_writingSystems.Length]; int wsEn = cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"); if (wsEn == 0) { wsEn = cache.DefaultUserWs; } if (wsEn == 0) { wsEn = WritingSystemServices.FallbackUserWs(cache); } for (int i = 0; i < m_writingSystems.Length; i++) { //m_WsLabels[i] = LgWritingSystem.UserAbbr(cache, m_writingSystems[i].Hvo); // For now (August 2008), try English abbreviation before UI writing system. // (See LT-8185.) m_WsLabels[i] = TsStringUtils.MakeString(m_writingSystems[i].Abbreviation, cache.DefaultUserWs); if (String.IsNullOrEmpty(m_WsLabels[i].Text)) { m_WsLabels[i] = TsStringUtils.MakeString(m_writingSystems[i].Abbreviation, cache.DefaultUserWs); } } }
public void ChangingLangProjDefaultAnalysisWs_ChangesCacheDefaultAnalWs() { using (var threadHelper = new ThreadHelper()) using ( var cache = FdoCache.CreateCacheWithNewBlankLangProj(new TestProjectId(FDOBackendProviderType.kMemoryOnly, null), "en", "fr", "en", threadHelper)) { var wsEn = cache.DefaultAnalWs; Assert.That(cache.LangProject.DefaultAnalysisWritingSystem.Handle, Is.EqualTo(wsEn)); IWritingSystem wsObjGerman = null; UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { WritingSystemServices.FindOrCreateWritingSystem(cache, "de", true, false, out wsObjGerman); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); cache.LangProject.DefaultAnalysisWritingSystem = wsObjGerman; Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle)); }); UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { cache.LangProject.CurAnalysisWss = "en"; Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); }); cache.ActionHandlerAccessor.Undo(); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle)); cache.ActionHandlerAccessor.Redo(); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); } }
public void MergeWritingSystemWithStyleDefnForToWs_DoesNotConvertStyleDefinition() { IWritingSystem fromWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-NO", true, false, out fromWs); IWritingSystem toWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en-SO", true, false, out toWs); EnsureAnalysisWs(new[] { fromWs, toWs }); var style1 = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); Cache.LangProject.StylesOC.Add(style1); var fontOverrides = new Dictionary <int, FontInfo>(); var fontOverride = new FontInfo(); fontOverride.m_italic.ExplicitValue = true; fontOverrides[fromWs.Handle] = fontOverride; fontOverride = new FontInfo(); fontOverride.m_bold.ExplicitValue = true; fontOverrides[toWs.Handle] = fontOverride; var bldr = TsPropsBldrClass.Create(); BaseStyleInfo.SaveFontOverridesToBuilder(fontOverrides, bldr); style1.Rules = bldr.GetTextProps(); m_actionHandler.EndUndoTask(); UndoableUnitOfWorkHelper.Do("doit", "undoit", m_actionHandler, () => WritingSystemServices.MergeWritingSystems(Cache, fromWs, toWs)); var styleInfo = new BaseStyleInfo(style1); var overrideInfo = styleInfo.OverrideCharacterStyleInfo(toWs.Handle); Assert.IsNotNull(overrideInfo); Assert.That(overrideInfo.Bold.Value, Is.True); Assert.That(overrideInfo.Italic.ValueIsSet, Is.False); }
public void UpdateWritingSystemListField_DoesNothingIfNotFound() { Cache.LangProject.AnalysisWss = "fr en qaa-x-kal"; WritingSystemServices.UpdateWritingSystemListField(Cache, Cache.LangProject, LangProjectTags.kflidAnalysisWss, "de", "de-NO"); Assert.That(Cache.LangProject.AnalysisWss, Is.EqualTo("fr en qaa-x-kal")); }
public void ChangingLangProjDefaultAnalysisWs_ChangesCacheDefaultAnalWs() { using (var cache = LcmCache.CreateCacheWithNewBlankLangProj(new TestProjectId(BackendProviderType.kMemoryOnly, null), "en", "fr", "en", m_ui, m_lcmDirectories, new LcmSettings())) { var wsEn = cache.DefaultAnalWs; Assert.That(cache.LangProject.DefaultAnalysisWritingSystem.Handle, Is.EqualTo(wsEn)); CoreWritingSystemDefinition wsObjGerman = null; UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { WritingSystemServices.FindOrCreateWritingSystem(cache, TestDirectoryFinder.TemplateDirectory, "de", true, false, out wsObjGerman); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); cache.LangProject.DefaultAnalysisWritingSystem = wsObjGerman; Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle)); }); UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { cache.LangProject.CurAnalysisWss = "en"; Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); }); cache.ActionHandlerAccessor.Undo(); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsObjGerman.Handle)); cache.ActionHandlerAccessor.Redo(); Assert.That(cache.DefaultAnalWs, Is.EqualTo(wsEn)); } }
public void GetMagicStringAlt_TestFirstPronunciation() { IWritingSystem mluWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "mlu", false, false, out mluWs); var mluId = mluWs.Handle; IWritingSystem senWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, false, out senWs); var senId = senWs.Handle; Cache.LangProject.CurrentPronunciationWritingSystems.Clear(); Cache.LangProject.CurrentPronunciationWritingSystems.Add(mluWs); Cache.LangProject.CurrentPronunciationWritingSystems.Add(senWs); var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); entry.CitationForm.set_String(mluId, Cache.TsStrFactory.MakeString("To'abaita", mluId)); entry.CitationForm.set_String(senId, Cache.TsStrFactory.MakeString("Sena", senId)); int wsId; //SUT magic gets first pronuciation when there is one. WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor, WritingSystemServices.kwsFirstPronunciation, entry.Hvo, entry.CitationForm.Flid, false, out wsId); Assert.AreEqual(wsId, mluId, "Did not pull first pronuciation language first."); //SUT magic gets second pronuciation when the first is empty entry.CitationForm.set_String(mluId, Cache.TsStrFactory.MakeString("", mluId)); //wipe Sena WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor, WritingSystemServices.kwsFirstPronunciation, entry.Hvo, entry.CitationForm.Flid, false, out wsId); Assert.AreEqual(wsId, senId, "Did not pull second pronuciation language when first was empty."); }
public InflectionFeatureEditor(XmlNode configurationNode) : this() { string displayWs = XmlUtils.GetOptionalAttributeValue(configurationNode, "displayWs", "best analorvern"); m_displayWs = WritingSystemServices.GetMagicWsIdFromName(displayWs); }
/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="hvoOwner"></param> /// <param name="flid"></param> /// <param name="flidSub">specify a subitems, /// other than CmPossibilityTags.kflidSubPossibilities</param> /// <param name="hvoTarget"></param> /// <param name="tagName"></param> /// <returns></returns> protected TreeNode AddNodes(TreeNodeCollection nodes, int hvoOwner, int flid, int flidSub, int hvoTarget, int tagName) { TreeNode result = null; int chvo = Cache.MainCacheAccessor.get_VecSize(hvoOwner, flid); for (int i = 0; i < chvo; i++) { int hvoChild = Cache.MainCacheAccessor.get_VecItem(hvoOwner, flid, i); ITsString tssLabel = WritingSystemServices.GetMagicStringAlt(Cache, WritingSystemServices.kwsFirstAnalOrVern, hvoChild, tagName); if (tssLabel == null) { tssLabel = TsStringUtils.MakeString(LexTextControls.ksStars, Cache.WritingSystemFactory.UserWs); } HvoTreeNode node = new HvoTreeNode(tssLabel, hvoChild); nodes.Add(node); TreeNode temp = AddNodes(node.Nodes, hvoChild, flidSub, flidSub, hvoTarget, tagName); if (hvoChild == hvoTarget) { result = node; } else if (temp != null) { result = temp; } } return(result); }
public void UpdateWritingSystemListField_RemovesMergedCodeBeforeMergeWith() { Cache.LangProject.AnalysisWss = "fr-NO en fr"; WritingSystemServices.UpdateWritingSystemListField(Cache, Cache.LangProject, LangProjectTags.kflidAnalysisWss, "fr-NO", "fr"); Assert.That(Cache.LangProject.AnalysisWss, Is.EqualTo("en fr")); }
/// <summary> /// Create the ordered vector of writing sytems to try for displaying names. /// </summary> protected void EstablishWritingSystemsToTry(string sDisplayWs) { if (m_writingSystemIds != null || m_cache == null || m_obj == null) { return; } if (string.IsNullOrEmpty(sDisplayWs)) { sDisplayWs = "analysis vernacular"; // very general default. } int flid = 0; if (!string.IsNullOrEmpty(m_displayNameProperty)) { #if WANTPORT // (FWR-2786 to investigate this)(FLEx) Needs replacement for virtual property handler CmObject obj = m_cache.GetObject(Hvo); string className = m_cache.MetaDataCache.GetClassName(obj.ClassID); IVwVirtualHandler vh = m_cache.VwCacheDaAccessor.GetVirtualHandlerName(className, m_displayNameProperty); if (vh != null) { flid = vh.Tag; } #endif } m_writingSystemIds = WritingSystemServices.GetWritingSystemIdsFromLabel(m_cache, sDisplayWs, m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem, m_obj.Hvo, flid, null); }
private void AddEditCell(IVwEnv vwenv, IVwCacheDa cda, int i) { XmlNode node = m_columns[i - 1]; // Make a cell and embed an editable virtual string for the column. var editable = XmlUtils.GetOptionalBooleanAttributeValue(node, "editable", true); if (!editable) { vwenv.set_IntProperty((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, NoEditBackgroundColor); } vwenv.OpenTableCell(1, 1); int flid = XMLViewsDataCache.ktagEditColumnBase + i; int ws = WritingSystemServices.GetWritingSystem(m_cache, node, null, m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle).Handle; // Paragraph directionality must be set before the paragraph is opened. bool fRTL = IsWsRTL(ws); vwenv.set_IntProperty((int)FwTextPropType.ktptRightToLeft, (int)FwTextPropVar.ktpvEnum, fRTL ? -1 : 0); vwenv.set_IntProperty((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, fRTL ? (int)FwTextAlign.ktalRight : (int)FwTextAlign.ktalLeft); // Fill in the cell with the virtual property. vwenv.OpenParagraph(); vwenv.set_IntProperty((int)FwTextPropType.ktptEditable, (int)FwTextPropVar.ktpvEnum, editable ? (int)TptEditable.ktptIsEditable : (int)TptEditable.ktptNotEditable); vwenv.AddStringAltMember(flid, ws, this); vwenv.CloseParagraph(); vwenv.CloseTableCell(); }
private int GetRealWsFromSpec(InterlinLineSpec spec) { if (!spec.IsMagicWritingSystem) { return(spec.WritingSystem); } // special case, the only few we support so far (and only for a few fields). if (spec.WritingSystem == WritingSystemServices.kwsFirstAnal) { return(Cache.LangProject.DefaultAnalysisWritingSystem.Handle); } if (spec.WritingSystem == WritingSystemServices.kwsVernInParagraph) { return(Cache.LangProject.DefaultVernacularWritingSystem.Handle); } int ws = -50; try { ws = WritingSystemServices.InterpretWsLabel(Cache, spec.WsLabel(Cache).Text, null, 0, 0, null); } catch { Debug.Assert(ws != -50, "InterpretWsLabel was not able to interpret the Ws Label. The most likely cause for this is that a magic ws was passed in."); } return(ws); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Try GetAlternativeTss on the given 'wsPreferred', else return the BestAlternativeTss, giving /// preference to vernacular or analysis if 'wsPreferred' is vernacular or analysis. /// </summary> /// <param name="wsPreferred">The ws preferred.</param> /// <param name="wsActual">ws of the best found alternative</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ITsString GetAlternativeOrBestTss(int wsPreferred, out int wsActual) { ITsString tss; if (wsPreferred < 0) { // already magic, try for that. tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache, wsPreferred, m_object.Hvo, m_flid, true, out wsActual); if ((tss == null || tss.Length == 0) && wsPreferred != WritingSystemServices.kwsFirstAnalOrVern) { tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache, WritingSystemServices.kwsFirstAnalOrVern, m_object.Hvo, m_flid, true, out wsActual); } return(tss); } var pref = m_object.Services.WritingSystemManager.Get(wsPreferred); wsActual = pref.Handle; if (!TryGetValue(pref.Handle, out tss)) { tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache, WritingSystemServices.kwsFirstVernOrAnal, m_object.Hvo, m_flid, true, out wsActual); if (tss == null || tss.Length == 0) { tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache, WritingSystemServices.kwsFirstAnalOrVern, m_object.Hvo, m_flid, true, out wsActual); } } return(tss); }
public void ChangingLangProjDefaultVernWs_ChangesCacheDefaultVernWs() { using ( var cache = FdoCache.CreateCacheWithNewBlankLangProj(new TestProjectId(FDOBackendProviderType.kMemoryOnly, null), "en", "fr", "en", m_ui, FwDirectoryFinder.FdoDirectories, new FdoSettings())) { var wsFr = cache.DefaultVernWs; Assert.That(cache.LangProject.DefaultVernacularWritingSystem.Handle, Is.EqualTo(wsFr)); IWritingSystem wsObjGerman = null; UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { WritingSystemServices.FindOrCreateWritingSystem(cache, FwDirectoryFinder.TemplateDirectory, "de", false, true, out wsObjGerman); Assert.That(cache.DefaultVernWs, Is.EqualTo(wsFr)); cache.LangProject.DefaultVernacularWritingSystem = wsObjGerman; Assert.That(cache.DefaultVernWs, Is.EqualTo(wsObjGerman.Handle)); }); UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { cache.LangProject.CurVernWss = "fr"; Assert.That(cache.DefaultVernWs, Is.EqualTo(wsFr)); }); cache.ActionHandlerAccessor.Undo(); Assert.That(cache.DefaultVernWs, Is.EqualTo(wsObjGerman.Handle)); cache.ActionHandlerAccessor.Redo(); Assert.That(cache.DefaultVernWs, Is.EqualTo(wsFr)); } }
private ITsString GetBest(int ws) { var bestWs = WritingSystemServices.ActualWs(m_object.Cache, ws, m_object.Hvo, m_flid); return((bestWs == 0 ? null : get_String(bestWs)) ?? TsStringUtils.MakeString(Strings.ksStars, m_object.Cache.WritingSystemFactory.UserWs)); }
private int getWsFromId(string id) { // special case, the only few we support so far (and only for a few fields). if (id == "best analysis") { return(WritingSystemServices.kwsFirstAnal); //LangProject.kwsFirstAnal; } else if (id == "vern in para") { return(WritingSystemServices.kwsVernInParagraph); } Debug.Assert(!XmlViewsUtils.GetWsRequiresObject(id), "Writing system is magic. These should never be used in the Interlinear area."); int ws = -50; try { if (!XmlViewsUtils.GetWsRequiresObject(id)) { // Try to convert the ws parameter into an int. Sometimes the parameter // cannot be interpreted without an object, such as when the ws is a magic // string that will change the actual ws depending on the contents of the // object. In these cases, we give -50 as a known constant to check for. // This can possibly throw an exception, so we'll enclose it in a try block. ws = WritingSystemServices.InterpretWsLabel(m_cache, id, null, 0, 0, null); } } catch { Debug.Assert(ws != -50, "InterpretWsLabel was not able to interpret the Ws Label. The most likely cause for this is that a magic ws was passed in."); } return(ws); }
// Replace any updated writing systems in the attribute value. // Handles an input which may begin with $ws= and/or may have multiple WSs separated by comma. private bool FixWsAtttribute(XAttribute attr) { bool changedFile = false; var oldTag = attr.Value; var prefix = ""; if (oldTag.StartsWith("$ws=")) { prefix = "$ws="; oldTag = oldTag.Substring(prefix.Length); } string combinedTags = ""; foreach (string input in oldTag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { string convertedTag; string outputTag = input; if (WritingSystemServices.GetMagicWsIdFromName(oldTag) == 0 && TryGetNewTag(input, out convertedTag)) { changedFile = true; outputTag = convertedTag; } if (combinedTags != "") { combinedTags += ","; } combinedTags += outputTag; } if (changedFile) { attr.Value = prefix + combinedTags; } return(changedFile); }
public void FindOrCreateSomeWritingSystem_Converts_Fr_Tech_30Oct_To_qaa_x_Fr_Tech_30Oct() { IWritingSystem ws; Assert.That(WritingSystemServices.FindOrCreateSomeWritingSystem(Cache, null, "Fr-Tech 30Oct", true, false, out ws), Is.False); Assert.That(ws.Id, Is.EqualTo("qaa-x-Fr-Tech30Oc")); //8 characters is the maximum allowed for a part. }
public void UpdateWritingSystemListField_ReplacesNonDuplicateCode() { Cache.LangProject.AnalysisWss = "fr en qaa-x-kal"; WritingSystemServices.UpdateWritingSystemListField(Cache, Cache.LangProject, LangProjectTags.kflidAnalysisWss, "fr", "de-NO"); Assert.That(Cache.LangProject.AnalysisWss, Is.EqualTo("de-NO en qaa-x-kal")); }
public void FindOrCreateSomeWritingSystem_Converts_x_To_qaa_x_qaa() { IWritingSystem ws; Assert.That(WritingSystemServices.FindOrCreateSomeWritingSystem(Cache, null, "x", true, false, out ws), Is.False); Assert.That(ws.Id, Is.EqualTo("qaa-x-qaa")); }
/// <summary/> public void UpdateWritingSystemListField_RemovesWsCode() { int m_wsEn = Cache.WritingSystemFactory.GetWsFromStr("en"); int m_wsFr = Cache.WritingSystemFactory.GetWsFromStr("fr"); CoreWritingSystemDefinition enBlz; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "blz", false, false, out enBlz); var revIndex = Cache.ServiceLocator.GetInstance <IReversalIndexRepository>().FindOrCreateIndexForWs(m_wsEn); var entry1 = SenseOrEntryTests.CreateInterestingLexEntry(Cache); var msa1 = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create(); entry1.MorphoSyntaxAnalysesOC.Add(msa1); entry1.SensesOS.First().MorphoSyntaxAnalysisRA = msa1; var entry2 = SenseOrEntryTests.CreateInterestingLexEntry(Cache); var msa2 = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create(); entry2.MorphoSyntaxAnalysesOC.Add(msa2); entry2.SensesOS.First().MorphoSyntaxAnalysisRA = msa2; var testEntry = revIndex.FindOrCreateReversalEntry("first"); entry1.SensesOS.First().ReversalEntriesRC.Add(testEntry); entry2.SensesOS.First().ReversalEntriesRC.Add(testEntry); testEntry.ReversalIndex.WritingSystem = "fr"; testEntry.ReversalForm.set_String(m_wsFr, "fr"); WritingSystemServices.UpdateWritingSystemFields(Cache, "fr", "blz"); Assert.That(testEntry.ReversalIndex.WritingSystem, Is.EqualTo("blz")); Assert.That(testEntry.ReversalIndex.ShortName, Is.EqualTo("Balantak")); }
private bool AddNewText(Command command) { // Get the default writing system for the new text. See LT-6692. m_wsPrevText = Cache.DefaultVernWs; if (CurrentObject != null && Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Count > 1) { m_wsPrevText = WritingSystemServices.ActualWs(Cache, WritingSystemServices.kwsVernInParagraph, CurrentObject.Hvo, StTextTags.kflidParagraphs); } if (m_list.Filter != null) { // Tell the user we're turning off the filter, and then do it. MessageBox.Show(ITextStrings.ksTurningOffFilter, ITextStrings.ksNote, MessageBoxButtons.OK); m_mediator.SendMessage("RemoveFilters", this); m_activeMenuBarFilter = null; } SaveOnChangeRecord(); // commit any changes before we create a new text. RecordList.ICreateAndInsert <IStText> createAndInsertMethodObj; if (command != null) { createAndInsertMethodObj = new UndoableCreateAndInsertStText(Cache, command, this); } else { createAndInsertMethodObj = new NonUndoableCreateAndInsertStText(Cache, this); } var newText = m_list.DoCreateAndInsert(createAndInsertMethodObj); // Check to if a genre was assigned to this text // (when selected from the text list: ie a genre w/o a text was sellected) string property = GetCorrespondingPropertyName("DelayedGenreAssignment"); var genreList = m_mediator.PropertyTable.GetValue(property, null) as List <TreeNode>; var ownerText = newText.Owner as FDO.IText; if (genreList != null && genreList.Count > 0 && ownerText != null) { foreach (var node in genreList) { ownerText.GenresRC.Add((ICmPossibility)node.Tag); } m_mediator.PropertyTable.RemoveProperty(property); } if (CurrentObject == null || CurrentObject.Hvo == 0) { return(false); } if (!InDesiredTool("interlinearEdit")) { m_mediator.SendMessage("FollowLink", new FwLinkArgs("interlinearEdit", CurrentObject.Guid)); } // This is a workable alternative (where link is the one created above), but means this code has to know about the FwXApp class. //(FwXApp.App as FwXApp).OnIncomingLink(link); // This alternative does NOT work; it produces a deadlock...I think the remote code is waiting for the target app // to return to its message loop, but it never does, because it is the same app that is trying to send the link, so it is busy // waiting for 'Activate' to return! //link.Activate(); return(true); }
public void CollatorSort_DoesNotThrow() { Assert.DoesNotThrow(() => { CoreWritingSystemDefinition fromWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, true, out fromWs); Cache.LangProject.DefaultVernacularWritingSystem = fromWs; fromWs.DefaultCollation.Collator.GetSortKey("boom"); }); }
public InnerLabeledMultiStringControl(LcmCache cache, int wsMagic) { m_realCache = cache; m_sda = new TextBoxDataAccess { WritingSystemFactory = cache.WritingSystemFactory }; m_rgws = WritingSystemServices.GetWritingSystemList(cache, wsMagic, 0, false); AutoScroll = true; IsTextBox = true; // range selection not shown when not in focus }
private IMoMorphType GetMorphType() { IMoMorphType morphType = null; string sMorphTypeName = (m_fPrefix ? "prefix" : "suffix"); int iEnglishWs = WritingSystemServices.FallbackUserWs(m_cache); foreach (var type in m_cache.LanguageProject.LexDbOA.MorphTypesOA.ReallyReallyAllPossibilities) { if (sMorphTypeName == type.Name.get_String(iEnglishWs).Text) { morphType = type as IMoMorphType; break; } } return(morphType); }
private void CreateSearcher() { int control = 0; for (; m_curPossIndex < m_possibilities.Count; m_curPossIndex++) { // Every so often see whether the user has typed something that makes our search irrelevant. if (control++ % 50 == 0 && ShouldAbort()) { return; } ICmPossibility poss = m_possibilities[m_curPossIndex]; ITsString name = null; foreach (int ws in WritingSystemServices.GetWritingSystemIdsFromLabel(m_cache, m_displayWs, m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem, poss.Hvo, CmPossibilityTags.kflidName, null)) { ITsString tss = poss.Name.StringOrNull(ws); if (tss != null && tss.Length > 0) { name = tss; m_searcher.Add(poss, 0, tss); break; } } foreach (int ws in WritingSystemServices.GetWritingSystemIdsFromLabel(m_cache, m_displayWs, m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem, poss.Hvo, CmPossibilityTags.kflidAbbreviation, null)) { ITsString tss = poss.Abbreviation.StringOrNull(ws); if (tss != null && tss.Length > 0) { m_searcher.Add(poss, 0, tss); if (name != null) { var tisb = TsIncStrBldrClass.Create(); tisb.AppendTsString(tss); tisb.AppendTsString(m_cache.TsStrFactory.MakeString(" - ", m_cache.DefaultUserWs)); tisb.AppendTsString(name); m_searcher.Add(poss, 0, tisb.GetString()); } break; } } } }
public void ChangingLangProjDefaultPronunciationWs_ChangesCacheDefaultPronunciationWs() { using (var threadHelper = new ThreadHelper()) using ( var cache = FdoCache.CreateCacheWithNewBlankLangProj(new TestProjectId(FDOBackendProviderType.kMemoryOnly, null), "en", "fr", "en", threadHelper)) { var wsFr = cache.DefaultPronunciationWs; Assert.That(cache.LangProject.DefaultPronunciationWritingSystem.Handle, Is.EqualTo(wsFr)); IWritingSystem wsObjGerman = null; IWritingSystem wsObjSpanish = null; UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { WritingSystemServices.FindOrCreateWritingSystem(cache, "de", false, true, out wsObjGerman); Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsFr)); cache.LangProject.DefaultVernacularWritingSystem = wsObjGerman; cache.LangProject.CurrentPronunciationWritingSystems.Clear(); // Now it re-evaluates to the new default vernacular. Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle)); // This no longer works..._IPA does not make a valid WS ID. //IWritingSystem wsObjGermanIpa; //WritingSystemServices.FindOrCreateWritingSystem(cache, "de__IPA", false, true, out wsObjGermanIpa); //cache.LangProject.CurrentPronunciationWritingSystems.Clear(); //// Once there is an IPA one, we should prefer that //Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGermanIpa.Handle)); // Unless we clear the list it does not regenerate. WritingSystemServices.FindOrCreateWritingSystem(cache, "es", false, true, out wsObjSpanish); // Once we've found a real pronunciation WS, changing the default vernacular should not change it. Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle)); }); UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { cache.LangProject.CurPronunWss = "es"; Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjSpanish.Handle)); }); cache.ActionHandlerAccessor.Undo(); Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle)); cache.ActionHandlerAccessor.Redo(); Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjSpanish.Handle)); } }
public PhonologicalFeatureEditor(XmlNode configurationNode) : this() { string displayWs = XmlUtils.GetOptionalAttributeValue(configurationNode, "displayWs", "best analorvern"); m_displayWs = WritingSystemServices.GetMagicWsIdFromName(displayWs); string layout = XmlUtils.GetAttributeValue(configurationNode, "layout"); if (!String.IsNullOrEmpty(layout)) { const string layoutName = "CustomMultiStringForFeatureDefn_"; int i = layout.IndexOf(layoutName); if (i >= 0) { m_featDefnAbbr = layout.Substring(i + layoutName.Length); } } }
private ITsString NameOfWs(int ws) { m_wsLabel = ws; var sWs = m_cache.WritingSystemFactory.GetStrFromWs(ws); IWritingSystem wsys; WritingSystemServices.FindOrCreateWritingSystem(m_cache, FwDirectoryFinder.TemplateDirectory, sWs, false, false, out wsys); var result = wsys.Abbreviation; if (string.IsNullOrEmpty(result)) { result = "??"; } ITsStrBldr tsb = TsStrBldrClass.Create(); tsb.Replace(0, 0, result, WritingSystemServices.AbbreviationTextProperties); tsb.SetIntPropValues(0, tsb.Length, (int)FwTextPropType.ktptWs, 0, m_wsEn); return(tsb.GetString()); }
public void GetMagicStringAlt_TestFirstAnaly() { CoreWritingSystemDefinition frWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "fr", false, false, out frWs); var frId = frWs.Handle; CoreWritingSystemDefinition enWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en", false, false, out enWs); var enId = enWs.Handle; CoreWritingSystemDefinition ptWs; WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "pt", false, false, out ptWs); var ptId = ptWs.Handle; Cache.LangProject.CurrentAnalysisWritingSystems.Clear(); Cache.LangProject.AddToCurrentAnalysisWritingSystems(frWs); Cache.LangProject.AddToCurrentAnalysisWritingSystems(enWs); Cache.LangProject.AnalysisWritingSystems.Add(ptWs); var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); var sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense); sense.Definition.set_String(frId, TsStringUtils.MakeString("fr", frId)); sense.Definition.set_String(enId, TsStringUtils.MakeString("en", enId)); sense.Definition.set_String(ptId, TsStringUtils.MakeString("pt", ptId)); int wsId; //SUT magic gets first analysis when there is one. WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor, WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId); Assert.AreEqual(wsId, frId, "Did not pull first analysis language first."); //SUT magic gets second analysis when the first is empty sense.Definition.set_String(frId, TsStringUtils.EmptyString(frId)); //wipe french WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor, WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId); Assert.AreEqual(wsId, enId, "Did not pull second analysis language when first was empty."); //SUT magic gets non current analysis when all current analysis languages are empty sense.Definition.set_String(enId, TsStringUtils.EmptyString(enId)); //wipe english WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor, WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId); Assert.AreEqual(wsId, ptId, "Did not pull from non current analysis language when all current languages were empty."); }