/// ------------------------------------------------------------------------------------ /// <summary> /// Appends the given text as a hyperlink to the given URL. /// </summary> /// <param name="strBldr">The string builder.</param> /// <param name="ws">The HVO of the writing system to use for the added text.</param> /// <param name="sLinkText">The text which should appear as the hyperlink text</param> /// <param name="sUrl">The URL that is the target of the hyperlink.</param> /// <param name="stylesheet">The stylesheet.</param> /// <returns><c>true</c> if the hyperlink was successfully inserted; <c>false</c> /// otherwise (indicating that the hyperlink style could not be found in the given /// stylesheet). In either case, the link text will be appended to the string builder. /// </returns> /// ------------------------------------------------------------------------------------ public static bool AddHyperlink(ITsStrBldr strBldr, int ws, string sLinkText, string sUrl, LcmStyleSheet stylesheet) { var hyperlinkStyle = stylesheet.FindStyle(StyleServices.Hyperlink); if (hyperlinkStyle == null) { return(false); } if (stylesheet != null && stylesheet.Cache != null && stylesheet.Cache.ProjectId != null) { sUrl = FwLinkArgs.FixSilfwUrlForCurrentProject(sUrl, stylesheet.Cache.ProjectId.Name); } int ichStart = strBldr.Length; strBldr.Replace(ichStart, ichStart, sLinkText, StyleUtils.CharStyleTextProps(null, ws)); StringServices.MarkTextInBldrAsHyperlink(strBldr, ichStart, strBldr.Length, sUrl, hyperlinkStyle); return(true); }
private async Task <Card> CreateCardAsync(DbContextOptions <MemCheckDbContext> testDB, Guid versionCreatorId, DateTime versionDate, IEnumerable <Guid>?userWithViewIds = null) { //userWithViewIds null means public card using var dbContext = new MemCheckDbContext(testDB); var creator = await dbContext.Users.Where(u => u.Id == versionCreatorId).SingleAsync(); var result = new Card(); result.VersionCreator = creator; result.FrontSide = StringServices.RandomString(); result.BackSide = StringServices.RandomString(); result.AdditionalInfo = StringServices.RandomString(); result.VersionDescription = StringServices.RandomString(); result.VersionType = CardVersionType.Creation; result.InitialCreationUtcDate = versionDate; result.VersionUtcDate = versionDate; dbContext.Cards.Add(result); var usersWithView = new List <UserWithViewOnCard>(); if (userWithViewIds != null) { Assert.IsTrue(userWithViewIds.Any(id => id == versionCreatorId), "Version creator must be allowed to view"); foreach (var userWithViewId in userWithViewIds) { var userWithView = new UserWithViewOnCard(); userWithView.CardId = result.Id; userWithView.UserId = userWithViewId; dbContext.UsersWithViewOnCards.Add(userWithView); usersWithView.Add(userWithView); } } result.UsersWithView = usersWithView; await dbContext.SaveChangesAsync(); return(result); }
private async Task <CardPreviousVersion> CreatePreviousVersionPreviousVersionAsync(DbContextOptions <MemCheckDbContext> testDB, Guid versionCreatorId, CardPreviousVersion previousVersion, DateTime versionDate) { using var dbContext = new MemCheckDbContext(testDB); var creator = await dbContext.Users.Where(u => u.Id == versionCreatorId).SingleAsync(); var result = new CardPreviousVersion(); result.Card = previousVersion.Card; result.VersionCreator = creator; result.VersionUtcDate = versionDate; result.VersionType = CardPreviousVersionType.Creation; result.FrontSide = StringServices.RandomString(); result.BackSide = StringServices.RandomString(); result.AdditionalInfo = StringServices.RandomString(); result.VersionDescription = StringServices.RandomString(); dbContext.CardPreviousVersions.Add(result); previousVersion.PreviousVersion = result; previousVersion.VersionType = CardPreviousVersionType.Changes; await dbContext.SaveChangesAsync(); return(result); }
public void FixHyperlinkFolder_changeOfPlatform() { // When running on Windows, call "foreign"="Linux" and "current"="Windows". // When running on Linux, call "foreign"="Windows" and "current"="Linux". string origPathSetInDatabase = MiscUtils.IsUnix ? @"c:\origdir\file.txt" : "/origdir/file.txt"; string newPlatformStyleLookupPath = MiscUtils.IsUnix ? "/origdir" : @"C:\origdir"; string newPlatformStyleResultToVerify = MiscUtils.IsUnix ? "file.txt" : "file.txt"; string pathToRebaseFrom = MiscUtils.IsUnix ? "/origdir" : @"C:\origdir"; string pathToRebaseTo = MiscUtils.IsUnix ? "/newdir" : @"C:\newdir"; string rebasedPathToVerify = MiscUtils.IsUnix ? "/newdir/file.txt": @"C:\newdir\file.txt"; // Add an external link into database and look it up var output = GetHyperlinksInFolder_changeOfPlatform_helper(origPathSetInDatabase, newPlatformStyleLookupPath, newPlatformStyleResultToVerify); var hyperlinkInfo = output.Item1; var entry = output.Item2; // Update link paths using currentOS-style paths, even though they are presently stored // as foreign-style paths. StringServices.FixHyperlinkFolder(hyperlinkInfo, pathToRebaseFrom, pathToRebaseTo); VerifyHyperlinkInfo(hyperlinkInfo, entry, LexEntryTags.kflidLiteralMeaning, Cache.DefaultAnalWs, 5, 9, newPlatformStyleResultToVerify); VerifyObjData(entry.LiteralMeaning.AnalysisDefaultWritingSystem, 5, 9, rebasedPathToVerify); }
/// <summary> /// Method to insert the homograph number with settings into the Text /// </summary> private void InsertHomographNumber(IVwEnv vwenv, HomographConfiguration hc, int nHomograph, int defUserWs) { if (nHomograph <= 0) { return; } // Use a string builder to embed the properties in with the TsString. // this allows our TsStringCollectorEnv to properly encode the superscript. // ideally, TsStringCollectorEnv could be made smarter to handle SetIntPropValues // since AppendTss treats the given Tss as atomic. ITsIncStrBldr tsBldr = TsStringUtils.MakeIncStrBldr(); tsBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum, (int)FwSuperscriptVal.kssvSub); tsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); tsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, defUserWs); StringServices.InsertHomographNumber(tsBldr, nHomograph, hc, HomographConfiguration.HeadwordVariant.Main, m_cache); vwenv.AddString(tsBldr.GetString()); }
private void AddHeadwordWithHomograph(IVwEnv vwenv, int hvo) { ISilDataAccess sda = vwenv.DataAccess; int hvoLf = sda.get_ObjectProp(hvo, LexEntryTags.kflidLexemeForm); int hvoType = 0; if (hvoLf != 0) { hvoType = sda.get_ObjectProp(hvoLf, MoFormTags.kflidMorphType); } // If we have a type of morpheme, show the appropriate prefix that indicates it. // We want vernacular so it will match the point size of any aligned vernacular text. // (The danger is that the vernacular font doesn't have these characters...not sure what // we can do about that, but most do, and it looks awful in analysis if that is a // much different size from vernacular.) string sPrefix = null; if (hvoType != 0) { sPrefix = sda.get_UnicodeProp(hvoType, MoMorphTypeTags.kflidPrefix); } // LexEntry.ShortName1; basically tries for form of the lexeme form, then the citation form. bool fGotLabel = false; int wsActual = 0; if (hvoLf != 0) { // if we have a lexeme form and its label is non-empty, use it. if (TryMultiStringAlt(sda, hvoLf, MoFormTags.kflidForm, out wsActual)) { m_wsActual = wsActual; fGotLabel = true; if (sPrefix != null) { vwenv.AddString(TsStringUtils.MakeTss(sPrefix, wsActual)); } vwenv.AddObjProp(LexEntryTags.kflidLexemeForm, this, kfragFormForm); } } if (!fGotLabel) { // If we didn't get a useful form from the lexeme form try the citation form. if (TryMultiStringAlt(sda, hvo, LexEntryTags.kflidCitationForm, out wsActual)) { m_wsActual = wsActual; if (sPrefix != null) { vwenv.AddString(TsStringUtils.MakeTss(sPrefix, wsActual)); } vwenv.AddStringAltMember(LexEntryTags.kflidCitationForm, wsActual, this); fGotLabel = true; } } int defUserWs = m_cache.WritingSystemFactory.UserWs; if (!fGotLabel) { // If that fails just show two questions marks. if (sPrefix != null) { vwenv.AddString(TsStringUtils.MakeTss(sPrefix, wsActual)); } vwenv.AddString(m_cache.TsStrFactory.MakeString(FdoUiStrings.ksQuestions, defUserWs)); // was "??", not "???" } // If we have a lexeme form type show the appropriate postfix. if (hvoType != 0) { vwenv.AddString(TsStringUtils.MakeTss( sda.get_UnicodeProp(hvoType, MoMorphTypeTags.kflidPostfix), wsActual)); } // Show homograph number if non-zero. int nHomograph = sda.get_IntProp(hvo, LexEntryTags.kflidHomographNumber); vwenv.NoteDependency(new[] { hvo }, new[] { LexEntryTags.kflidHomographNumber }, 1); if (nHomograph > 0) { // Use a string builder to embed the properties in with the TsString. // this allows our TsStringCollectorEnv to properly encode the superscript. // ideally, TsStringCollectorEnv could be made smarter to handle SetIntPropValues // since AppendTss treats the given Tss as atomic. ITsIncStrBldr tsBldr = TsIncStrBldrClass.Create(); tsBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, (int)FwTextPropVar.ktpvEnum, (int)FwSuperscriptVal.kssvSub); tsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); tsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, defUserWs); var hc = m_cache.ServiceLocator.GetInstance <HomographConfiguration>(); StringServices.InsertHomographNumber(tsBldr, nHomograph, hc, HomographConfiguration.HeadwordVariant.Main, m_cache); vwenv.AddString(tsBldr.GetString()); } }