private void FillStylesCombo(string sStyle) { m_cbStyle.Enabled = true; m_cbStyle.Items.Clear(); m_cbStyle.Sorted = true; IStStyle stySel = null; for (int i = 0; i < m_stylesheet.CStyles; ++i) { int hvo = m_stylesheet.get_NthStyle(i); IStStyle sty = m_cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(hvo); if (sty.Type == StyleType.kstCharacter) { m_cbStyle.Items.Add(sty); if (sty.Name == sStyle) { stySel = sty; } } } if (stySel == null) { // TODO: Should we create a style here to match the name??? } else { m_cbStyle.SelectedItem = stySel; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the paragraph style list of the combo box /// </summary> /// <param name="style">the current paragraph style where the IP is</param> /// <param name="view">The currently active view</param> /// ------------------------------------------------------------------------------------ public void RefreshParaStyleComboBoxList(IStStyle style, IRootSite view) { if (m_callbacks.PopulateParaStyleListOverride()) { return; } if (ParaStyleListHelper.ActiveView == view && style != null && m_prevParaStyleContext == style.Context) { return; } ParaStyleListHelper.IncludeStylesWithContext.Clear(); FwEditingHelper editingHelper = view.EditingHelper as FwEditingHelper; if (editingHelper != null && editingHelper.ApplicableStyleContexts != null) { ParaStyleListHelper.IncludeStylesWithContext.AddRange(editingHelper.ApplicableStyleContexts); } else { if (style != null) { ParaStyleListHelper.IncludeStylesWithContext.Add((ContextValues)style.Context); } ParaStyleListHelper.IncludeStylesWithContext.Add(ContextValues.General); } ParaStyleListHelper.Refresh(); ParaStyleListHelper.ActiveView = view as Control; }
public override void Initialize() { CheckDisposed(); base.Initialize(); m_fdoCache = Cache; // Setup the stylesheet. IStStyle captionStyle = AddTestStyle("Caption", ContextValues.Internal, StructureValues.Body, FunctionValues.Prose, false, Cache.LangProject.StylesOC); m_styleSheet = new FwStyleSheet(); ((FwStyleSheet)m_styleSheet).Init(m_fdoCache, m_lp.Hvo, (int)LangProject.LangProjectTags.kflidStyles); Debug.Assert(m_stylesComboBox == null, "m_stylesComboBox is not null."); //if (m_stylesComboBox != null) // m_stylesComboBox.Dispose(); m_stylesComboBox = new ComboBox(); m_styleListHelper = new StyleComboListHelper(m_stylesComboBox); // Set the options to display all of the styles m_styleListHelper.MaxStyleLevel = int.MaxValue; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Fills the style table and populates the list based on it. /// </summary> /// ------------------------------------------------------------------------------------ private void FillStyleList() { m_styleTable.Clear(); for (int i = 0; i < m_styleSheet.CStyles; i++) { IStStyle style = m_styleSheet.get_NthStyleObject(i); if (m_applicableStyleContexts == null || m_applicableStyleContexts.Contains(style.Context)) { m_styleTable.Add(style.Name, new StyleInfo(style)); } } if (m_fCanApplyCharacterStyle && !m_fCanApplyParagraphStyle) { m_styleListHelper.ShowOnlyStylesOfType = StyleType.kstCharacter; } else if (m_fCanApplyParagraphStyle && !m_fCanApplyCharacterStyle) { m_styleListHelper.ShowOnlyStylesOfType = StyleType.kstParagraph; } else if (!m_fCanApplyCharacterStyle && !m_fCanApplyParagraphStyle) { throw new InvalidOperationException("Can't show the Apply Style dialog box if neither character nor paragraph styles can be applied."); } else { m_styleListHelper.ShowOnlyStylesOfType = StyleType.kstLim; } m_styleListHelper.AddStyles(m_styleTable, null); m_styleListHelper.Refresh(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a new real style in the stylesheet for this proxy, if needed. /// </summary> /// ------------------------------------------------------------------------------------ private void AddStyleToStylesheet() { if (m_style != null || m_Context == ContextValues.EndMarker || m_sStyleName == null) { return; } // If m_ttpFormattingProps has not been set up, initialize it now if (m_ttpFormattingProps == null) { ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); m_ttpFormattingProps = tsPropsBldr.GetTextProps(); // default properties } // Get an hvo for the new style int hvoStyle = m_FwStyleSheet.MakeNewStyle(); m_style = m_FwStyleSheet.Cache.ServiceLocator.GetInstance <IStStyleRepository>().GetObject(hvoStyle); // PutStyle() adds the style to the stylesheet. we'll give it the properties we // are aware of. m_FwStyleSheet.PutStyle(m_sStyleName, string.Empty, hvoStyle, 0, m_StyleType == StyleType.kstParagraph ? hvoStyle : 0, (int)m_StyleType, false, false, m_ttpFormattingProps); // base the new style on "Paragraph" if (m_StyleType == StyleType.kstParagraph) { m_style.BasedOnRA = m_FwStyleSheet.FindStyle(ScrStyleNames.NormalParagraph); m_style.Context = m_style.BasedOnRA.Context; m_style.Structure = m_style.BasedOnRA.Structure; m_style.Function = m_style.BasedOnRA.Function; } }
/// ------------------------------------------------------------------------------------- /// <summary> /// Update the style context and do any special processing needed to deal with existing /// data that may be marked with the given style. (Since it was previously not an /// internal style, it is possible the user has used it in ways that would be /// incompatible with its intended use.) Any time a factory style is changed to an /// internal context, specific code must be written here to deal with it. Some possible /// options for dealing with this scenario are: /// * Delete any data previously marked with the style (and possibly set some other /// object properties) /// * Add to the m_styleReplacements dictionary so existing data will be marked with a /// different style (note that this will only work if no existing data should be /// preserved with the style). /// </summary> /// <param name="style">The style being updated</param> /// <param name="context">The context (either internal or internal mappable) that the /// style is to be given</param> /// ------------------------------------------------------------------------------------- protected override void ChangeFactoryStyleToInternal(IStStyle style, ContextValues context) { if (!CompatibleContext(style.Context, context)) { if (style.Name == ScrStyleNames.FootnoteTargetRef) { foreach (var book in m_scr.ScriptureBooksOS) { RemoveDirectUsesOfFootnoteTargetRef(book); } foreach (var draft in m_scr.ArchivedDraftsOC) { foreach (var book in draft.BooksOS) { RemoveDirectUsesOfFootnoteTargetRef(book); } } } else if (style.InUse) { // This is where we should handle any future upgrade issues } } style.Context = context; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Mega constructor with style /// </summary> /// ------------------------------------------------------------------------------------ public ImportMappingInfo(string beginMarker, string endMarker, bool isExcluded, MappingTargetType mappingTarget, MarkerDomain domain, IStStyle style, string wsId, ICmAnnotationDefn noteType) : this(beginMarker, endMarker, isExcluded, mappingTarget, domain, style == null ? null : style.Name, wsId, noteType) { m_style = style; }
/// ------------------------------------------------------------------------------------- /// <summary> /// If the proposed context for a style is internal or internalMappable, make sure the /// program actually expects and supports this context for this style. /// </summary> /// <param name="style">The style being updated</param> /// <param name="proposedContext">The proposed context for the style</param> /// <returns><c>true</c>if the proposed context is internal or internal mappable and /// the program recognizes it as a valid</returns> /// ------------------------------------------------------------------------------------- public override bool IsValidInternalStyleContext(IStStyle style, ContextValues proposedContext) { return((proposedContext == ContextValues.Internal && ScrStyleNames.InternalStyles.Contains(style.Name)) || (proposedContext == ContextValues.InternalMappable && ScrStyleNames.InternalMappableStyles.Contains(style.Name))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Install the control. /// </summary> /// <param name="dockHost">The control that hosts the browser</param> /// <param name="cache">The cache (needed in case we have to create the English LDS file /// on the fly)</param> /// <param name="normalStyle">The normal style (needed in case we have to create the /// English LDS file on the fly)</param> /// <returns> /// <c>true</c> if the browser was installed successfully; <c>false</c> /// otherwise. /// </returns> /// ------------------------------------------------------------------------------------ public bool Install(Control dockHost, FdoCache cache, IStStyle normalStyle) { while (true) { try { RegistrationInfo.AllowP6RegistrationCode = true; RegistrationInfo.AllowAccessToResources(); string paratextProjectDir = ScrImportP6Project.ProjectDir; if (!String.IsNullOrEmpty(paratextProjectDir)) { string englishLdsPathname = Path.Combine(paratextProjectDir, "English.lds"); if (!File.Exists(englishLdsPathname)) { ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(cache); UsfmStyEntry normalUsfmStyle = new UsfmStyEntry(); StyleInfoTable styleTable = new StyleInfoTable(normalStyle.Name, cache.LanguageWritingSystemFactoryAccessor); normalUsfmStyle.SetPropertiesBasedOnStyle(normalStyle); styleTable.Add(normalStyle.Name, normalUsfmStyle); styleTable.ConnectStyles(); ldsAccessor.WriteParatextLdsFile(englishLdsPathname, cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"), normalUsfmStyle); } } ScrTextCollection.Initialize(); break; } catch (Exception e) { try { ReflectionHelper.SetField(typeof(ScrTextCollection), "initialized", false); } catch (Exception reflectionHelperException) { throw new ContinuableErrorException("Paratext resource browser failed to initialize." + Environment.NewLine + reflectionHelperException.Message, e); } if (MessageBox.Show(dockHost.FindForm(), String.Format( Properties.Resources.kstidCannotDisplayResourcePane, Application.ProductName, e.Message), Application.ProductName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) != DialogResult.Retry) { return false; } } } m_toolStrip.Text = "USFM Resource Browser"; m_extender = new DockExtender(dockHost); dockHost.Controls.Add(this); m_floaty = m_extender.Attach(this, m_toolStrip, true); this.SendToBack(); return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Install the control. /// </summary> /// <param name="dockHost">The control that hosts the browser</param> /// <param name="cache">The cache (needed in case we have to create the English LDS file /// on the fly)</param> /// <param name="normalStyle">The normal style (needed in case we have to create the /// English LDS file on the fly)</param> /// <returns> /// <c>true</c> if the browser was installed successfully; <c>false</c> /// otherwise. /// </returns> /// ------------------------------------------------------------------------------------ public bool Install(Control dockHost, FdoCache cache, IStStyle normalStyle) { while (true) { try { RegistrationInfo.AllowP6RegistrationCode = true; RegistrationInfo.AllowAccessToResources(); string paratextProjectDir = ScrImportP6Project.ProjectDir; if (!String.IsNullOrEmpty(paratextProjectDir)) { string englishLdsPathname = Path.Combine(paratextProjectDir, "English.lds"); if (!File.Exists(englishLdsPathname)) { ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(cache); UsfmStyEntry normalUsfmStyle = new UsfmStyEntry(); StyleInfoTable styleTable = new StyleInfoTable(normalStyle.Name, cache.LanguageWritingSystemFactoryAccessor); normalUsfmStyle.SetPropertiesBasedOnStyle(normalStyle); styleTable.Add(normalStyle.Name, normalUsfmStyle); styleTable.ConnectStyles(); ldsAccessor.WriteParatextLdsFile(englishLdsPathname, cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"), normalUsfmStyle); } } ScrTextCollection.Initialize(); break; } catch (Exception e) { try { ReflectionHelper.SetField(typeof(ScrTextCollection), "initialized", false); } catch (Exception reflectionHelperException) { throw new ContinuableErrorException("Paratext resource browser failed to initialize." + Environment.NewLine + reflectionHelperException.Message, e); } if (MessageBox.Show(dockHost.FindForm(), String.Format( Properties.Resources.kstidCannotDisplayResourcePane, Application.ProductName, e.Message), Application.ProductName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) != DialogResult.Retry) { return(false); } } } m_toolStrip.Text = "USFM Resource Browser"; m_extender = new DockExtender(dockHost); dockHost.Controls.Add(this); m_floaty = m_extender.Attach(this, m_toolStrip, true); this.SendToBack(); return(true); }
public void ConstructBasedOnStyleAndEffects() { IStStyle mainTitleStyle = AddTestStyle("Title Main", ContextValues.Title, StructureValues.Body, FunctionValues.Prose, false, Cache.LangProject.StylesOC); var props = TsStringUtils.MakeProps("rubbish", Cache.DefaultAnalWs); var sut = new BaseStyleInfo(mainTitleStyle, props); Assert.That(sut.Cache, Is.EqualTo(Cache)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set a font face name for a style. /// </summary> /// <param name="styleName"></param> /// <param name="fontName"></param> /// ------------------------------------------------------------------------------------ public void SetStyleFont(string styleName, string fontName) { IStStyle style = FindStyle(styleName); ITsPropsBldr ttpBldr = style.Rules.GetBldr(); ttpBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, fontName); style.Rules = ttpBldr.GetTextProps(); ComputeDerivedStyles(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Marks the indicated text in the given string builder as a hyperlink. /// </summary> /// <param name="strBldr">The string builder.</param> /// <param name="ichStart">The index of the first character in the string builder which /// should be marked as hyperlink text.</param> /// <param name="ichLim">The "limit" index in the string builder indicating the end of /// the hyperlink text.</param> /// <param name="url">The URL that is the target of the hyperlink.</param> /// <param name="linkStyle">The style to use to mark the hyperlink.</param> /// ------------------------------------------------------------------------------------ public static void MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart, int ichLim, string url, IStStyle linkStyle) { var propVal = Convert.ToChar((int)FwObjDataTypes.kodtExternalPathName) + url; if (!linkStyle.InUse && linkStyle is StStyle) ((StStyle)linkStyle).InUse = true; strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptNamedStyle, linkStyle.Name); strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptObjData, propVal); }
public void ConstructBasedOnStyle() { CheckDisposed(); ITsPropsBldr props; IStStyle mainTitleStyle = AddTestStyle("Title Main", ContextValues.Title, StructureValues.Body, FunctionValues.Prose, false, Cache.LangProject.StylesOC); props = mainTitleStyle.Rules.GetBldr(); props.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvDefault, 1); props.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvDefault, (int)FwTextAlign.ktalCenter); props.SetIntPropValues((int)FwTextPropType.ktptFontSize, (int)FwTextPropVar.ktpvMilliPoint, 20000); props.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "Arial"); mainTitleStyle.Rules = props.GetTextProps(); DummyStyleInfo entry = new DummyStyleInfo(mainTitleStyle); Assert.AreEqual("Title Main", entry.Name); // Was: Assert.AreEqual(mainTitleStyle.Usage.UserDefaultWritingSystem, entry.Usage); // Since nothing in our test has initialized mainTitleStyle.Usage, it used to be null, like // entry.Usage. A change to the implementation of UserDefaultWritingSystem causes it to always // return something. Assert.AreEqual(mainTitleStyle.Usage.RawUserDefaultWritingSystem, entry.Usage); Assert.IsTrue(entry.IsParagraphStyle); Assert.AreEqual(FwTextAlign.ktalCenter, entry.Alignment); FontInfo fontInfo = entry.FontInfoForWs(-1); Assert.IsNotNull(fontInfo); Assert.IsTrue(fontInfo.m_bold.Value); Assert.AreEqual(20000, fontInfo.m_fontSize.Value); Assert.AreEqual("Arial", (string)fontInfo.m_fontName.Value); Assert.AreEqual(ContextValues.Title, entry.Context); Assert.AreEqual(StructureValues.Body, entry.Structure); Assert.AreEqual(FunctionValues.Prose, entry.Function); // Check that everything else is inherited Assert.IsTrue(fontInfo.m_backColor.IsInherited); Assert.IsTrue(fontInfo.m_fontColor.IsInherited); Assert.IsTrue(fontInfo.m_italic.IsInherited); Assert.IsTrue(fontInfo.m_superSub.IsInherited); Assert.IsTrue(fontInfo.m_underline.IsInherited); Assert.IsTrue(fontInfo.m_underlineColor.IsInherited); Assert.IsTrue(fontInfo.m_features.IsInherited); Assert.IsTrue(entry.InheritableLineSpacing.IsInherited); Assert.IsTrue(entry.InheritableSpaceBefore.IsInherited); Assert.IsTrue(entry.InheritableFirstLineIndent.IsInherited); Assert.IsTrue(entry.InheritableLeadingIndent.IsInherited); Assert.IsTrue(entry.InheritableTrailingIndent.IsInherited); Assert.IsTrue(entry.InheritableBorder.IsInherited); Assert.IsTrue(entry.InheritableBorderColor.IsInherited); }
private IStStyle GenerateEmptyParagraphStyle(string name, IStStyle basedOnStyle) { var styleFactory = Cache.ServiceLocator.GetInstance <IStStyleFactory>(); var newStyle = styleFactory.Create(); Cache.LangProject.TranslatedScriptureOA.StylesOC.Add(newStyle); newStyle.Name = name; newStyle.BasedOnRA = basedOnStyle; return(newStyle); }
public void EnterKey_InBtSectionHead() { CheckDisposed(); IScrBook book = m_scrInMemoryCache.AddBookToMockedScripture(2, "Exodus"); m_scrInMemoryCache.AddTitleToMockedBook(book.Hvo, "Exodus"); m_btDraftView.BookFilter.Insert(0, book.Hvo); IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(book.Hvo); StTxtPara headPara = m_scrInMemoryCache.AddSectionHeadParaToSection( section.Hvo, "The first section", ScrStyleNames.SectionHead); // Construct a parent paragraph StTxtPara parentPara = m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, ScrStyleNames.NormalParagraph); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.ChapterNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "1", ScrStyleNames.VerseNumber); m_scrInMemoryCache.AddRunToMockedPara(parentPara, "uno ", null); section.AdjustReferences(); // Construct the initial back translation. int wsBt = m_inMemoryCache.Cache.DefaultAnalWs; ICmTranslation headingTrans = m_inMemoryCache.AddBtToMockedParagraph(headPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(headingTrans, wsBt, "BT heading", ScrStyleNames.Header); ICmTranslation paraTrans = m_inMemoryCache.AddBtToMockedParagraph(parentPara, wsBt); m_inMemoryCache.AddRunToMockedTrans(paraTrans, wsBt, "one", null); // Set the following style for section head. IStStyle styleHead = m_scr.FindStyle(ScrStyleNames.SectionHead); IStStyle stylePara = m_scr.FindStyle(ScrStyleNames.NormalParagraph); styleHead.NextRA = stylePara; // Set IP at the end of the section head. int sectionHeadLength = headingTrans.Translation.GetAlternativeTss(wsBt).Length; m_btDraftView.TeEditingHelper.SetInsertionPoint( (int)ScrSection.ScrSectionTags.kflidHeading, 0, 0, 0, sectionHeadLength, false); m_btDraftView.OnKeyPress(new KeyPressEventArgs('\r')); // Verify that the selection has moved to the start of the BT of the section Content. IVwSelection vwsel = m_btDraftView.RootBox.Selection; int ich, hvo, textTag, enc; bool fAssocPrev; ITsString tss; vwsel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out textTag, out enc); Assert.AreEqual((int)CmTranslation.CmTranslationTags.kflidTranslation, textTag); Assert.AreEqual(paraTrans.Hvo, hvo, "Current paragraph should be content following section head."); Assert.AreEqual(0, ich); // selection is at start of paragraph }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the given style is (possibly) in use. /// </summary> /// <remarks>This method is virtual to allow for applications (such as FLEx) that may /// not have made good use of the InUse property of styles.</remarks> /// <param name="style">The style.</param> /// <returns><c>true</c> if there is any reasonable chance the given style is in use /// somewhere in the project data; <c>false</c> if the style has never been used and /// there is no real possibility it could be in the data.</returns> /// ------------------------------------------------------------------------------------ protected override bool StyleIsInUse(IStStyle style) { if ((style.Context == ContextValues.Internal && !ScrStyleNames.InternalStyles.Contains(style.Name)) || (style.Context == ContextValues.InternalMappable && !ScrStyleNames.InternalMappableStyles.Contains(style.Name))) { return(false); } return(style.InUse); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Marks the indicated text in the given string builder as a hyperlink. /// </summary> /// <param name="strBldr">The string builder.</param> /// <param name="ichStart">The index of the first character in the string builder which /// should be marked as hyperlink text.</param> /// <param name="ichLim">The "limit" index in the string builder indicating the end of /// the hyperlink text.</param> /// <param name="url">The URL that is the target of the hyperlink.</param> /// <param name="linkStyle">The style to use to mark the hyperlink.</param> /// ------------------------------------------------------------------------------------ public static void MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart, int ichLim, string url, IStStyle linkStyle) { var propVal = Convert.ToChar((int)FwObjDataTypes.kodtExternalPathName) + url; if (!linkStyle.InUse && linkStyle is StStyle) { ((StStyle)linkStyle).InUse = true; } strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptNamedStyle, linkStyle.Name); strBldr.SetStrPropValue(ichStart, ichLim, (int)FwTextPropType.ktptObjData, propVal); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Copy constructor /// </summary> /// <param name="copy"></param> /// ------------------------------------------------------------------------------------ public ImportMappingInfo(ImportMappingInfo copy) { m_beginMarker = copy.m_beginMarker; m_endMarker = copy.m_endMarker; m_isExcluded = copy.m_isExcluded; m_mappingTarget = copy.m_mappingTarget; m_domain = copy.m_domain; m_styleName = copy.m_styleName; m_style = copy.m_style; m_wsId = copy.m_wsId; m_noteType = copy.m_noteType; }
public void SectionHead_UserDefined() { CheckDisposed(); IStStyle sectionHead = m_scr.FindStyle("Section Head"); int hvoNewStyle = m_stylesheet.MakeNewStyle(); m_stylesheet.PutStyle("Major Massive Huge Section Head", "Use for little tiny sections", hvoNewStyle, sectionHead.Hvo, hvoNewStyle, (int)StyleType.kstParagraph, false, false, sectionHead.Rules); // Create section head with this "user-defined" style. IScrSection section = m_scrInMemoryCache.AddSectionToMockedBook(m_book.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(section.Hvo, "This is a user-defined section head", "Major Massive Huge Section Head"); m_scrInMemoryCache.AddParaToMockedSectionContent(section.Hvo, "Paragraph"); // Export. m_exporter.Run(); // Validate. string errors = OxesIO.Validator.GetAnyValidationErrors(m_fileName); Assert.IsNull(errors); // Read file and compare to expected results. The first node inside sectionHead should // be trGroup. XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(m_fileName); XmlNode nodeOxes = xmlDoc.ChildNodes[1]; Assert.AreEqual("oxes", nodeOxes.Name); XmlNode nodeOxesText = nodeOxes.FirstChild; Assert.AreEqual("oxesText", nodeOxesText.Name); XmlNode nodeCanon = FindChildNode(nodeOxesText, "canon"); Assert.IsNotNull(nodeCanon); XmlNode nodeBook = nodeCanon.FirstChild; Assert.AreEqual("book", nodeBook.Name); Assert.AreEqual("GEN", nodeBook.Attributes[0].Value); XmlNode nodeSection = FindChildNode(nodeBook, "section"); XmlNode nodeSectionHead = nodeSection.FirstChild; Assert.AreEqual("sectionHead", nodeSectionHead.Name); XmlNode nodeTrGroup = nodeSectionHead.FirstChild; Assert.AreEqual("trGroup", nodeTrGroup.Name); Assert.AreEqual("This is a user-defined section head", nodeTrGroup.FirstChild.InnerText); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sanity check to ensure the scripture texts are valid. /// </summary> /// ------------------------------------------------------------------------------------ protected void EnsureScriptureTextsValid() { foreach (ScrBook book in m_scr.ScriptureBooksOS) { int[] sectionHvos = book.SectionsOS.HvoArray; // Don't crash if we don't have any sections (TE-5380) if (sectionHvos.Length == 0) { continue; } ContextValues sectionContext; foreach (ScrSection section in book.SectionsOS) { // Check the heading paragraphs. if (section.HeadingOA == null) { m_cache.CreateObject(StText.kClassId, section.Hvo, (int)ScrSection.ScrSectionTags.kflidHeading, 0); } if (section.HeadingOA.ParagraphsOS.Count == 0) { StTxtPara para = new StTxtPara(); section.HeadingOA.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead); sectionContext = ContextValues.Text; } else { IStStyle style = m_scr.FindStyle(section.HeadingOA.ParagraphsOS[0].StyleRules); // style could be null. set default context if possible sectionContext = style == null ? ContextValues.Text : style.Context; } // Check the content paragraphs. if (section.ContentOA == null) { m_cache.CreateObject(StText.kClassId, section.Hvo, (int)ScrSection.ScrSectionTags.kflidContent, 0); } if (section.ContentOA.ParagraphsOS.Count == 0) { StTxtPara para = new StTxtPara(); section.ContentOA.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps( TeEditingHelper.GetDefaultStyleForContext(sectionContext, false)); section.AdjustReferences(); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Marks the indicated text in the given string builder as a hyperlink. /// </summary> /// <param name="strBldr">The string builder.</param> /// <param name="ichStart">The index of the first character in the string builder which /// should be marked as hyperlink text.</param> /// <param name="ichLim">The "limit" index in the string builder indicating the end of /// the hyperlink text.</param> /// <param name="url">The URL that is the target of the hyperlink.</param> /// <param name="linkStyle">The style to use to mark the hyperlink.</param> /// <param name="linkedFilesRootDir">The project's LinkedFilesRootDir</param> /// <returns>The value returned is used to create a CmFile if it represents a file path.</returns> /// ------------------------------------------------------------------------------------ public static string MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart, int ichLim, string url, IStStyle linkStyle, string linkedFilesRootDir) { var relativeUrl = LinkedFilesRelativePathHelper.GetRelativeLinkedFilesPath(url, linkedFilesRootDir); if (string.IsNullOrEmpty(relativeUrl)) { MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, url, linkStyle); return url; } else { MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, relativeUrl, linkStyle); return relativeUrl; } }
public override void FixtureSetup() { base.FixtureSetup(); FileUtils.Manager.SetFileAdapter(_mockFilesystem); FileUtils.EnsureDirectoryExists(_defaultConfigPath); NonUndoableUnitOfWorkHelper.DoSomehow(Cache.ActionHandlerAccessor, () => { var styleFactory = Cache.ServiceLocator.GetInstance <IStStyleFactory>(); _characterTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "TestStyle", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false); _characterTestStyle.Usage.set_String(Cache.DefaultAnalWs, "Test Style"); var propsBldr = TsStringUtils.MakePropsBldr(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Red)); propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderline, (int)FwTextPropVar.ktpvDefault, (int)FwUnderlineType.kuntDouble); propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Blue)); propsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); propsBldr.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn); propsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "times"); _characterTestStyle.Rules = propsBldr.GetTextProps(); _paraTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "ParaTestStyle", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false); propsBldr.Clear(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Lime)); propsBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter); propsBldr.SetIntPropValues((int)FwTextPropType.ktptLineHeight, (int)FwTextPropVar.ktpvMilliPoint, -3000); propsBldr.SetIntPropValues((int)FwTextPropType.ktptTrailingIndent, (int)FwTextPropVar.ktpvDefault, 4000); propsBldr.SetIntPropValues((int)FwTextPropType.ktptFirstIndent, (int)FwTextPropVar.ktpvDefault, -5000); propsBldr.SetIntPropValues((int)FwTextPropType.ktptLeadingIndent, (int)FwTextPropVar.ktpvDefault, 6000); propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvDefault, 7000); propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceAfter, (int)FwTextPropVar.ktpvDefault, 8000); _paraTestStyle.Rules = propsBldr.GetTextProps(); _paraChildTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "ParaChildTesttStyle", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 3, false); propsBldr.Clear(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalJustify); _paraChildTestStyle.Rules = propsBldr.GetTextProps(); _paraChildTestStyle.BasedOnRA = _paraTestStyle; _bulletedTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "Bulleted List", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false); _numberedTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "Numbered List", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false); _homographTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "Homograph-Number", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false); var characterStyleBasedOnSomething = styleFactory.Create(Cache.LangProject.StylesOC, "CharacterStyleBasedOnSomething", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false); characterStyleBasedOnSomething.BasedOnRA = _characterTestStyle; }); }
public void WithBorderOnBottomOfTitle() { IStStyle titleMain = m_scr.FindStyle(ScrStyleNames.MainBookTitle); Assert.IsNotNull(titleMain); ITsPropsBldr propBldr = titleMain.Rules.GetBldr(); propBldr.SetIntPropValues((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 20); titleMain.Rules = propBldr.GetTextProps(); m_draftForm.StyleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); m_group.RefreshDisplay(); m_draftView.PerformLayout(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Marks the indicated text in the given string builder as a hyperlink. /// </summary> /// <param name="strBldr">The string builder.</param> /// <param name="ichStart">The index of the first character in the string builder which /// should be marked as hyperlink text.</param> /// <param name="ichLim">The "limit" index in the string builder indicating the end of /// the hyperlink text.</param> /// <param name="url">The URL that is the target of the hyperlink.</param> /// <param name="linkStyle">The style to use to mark the hyperlink.</param> /// <param name="linkedFilesRootDir">The project's LinkedFilesRootDir</param> /// <returns>The value returned is used to create a CmFile if it represents a file path.</returns> /// ------------------------------------------------------------------------------------ public static string MarkTextInBldrAsHyperlink(ITsStrBldr strBldr, int ichStart, int ichLim, string url, IStStyle linkStyle, string linkedFilesRootDir) { var relativeUrl = DirectoryFinderRelativePaths.GetRelativeLinkedFilesPath(url, linkedFilesRootDir); if (string.IsNullOrEmpty(relativeUrl)) { MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, url, linkStyle); return(url); } else { MarkTextInBldrAsHyperlink(strBldr, ichStart, ichLim, relativeUrl, linkStyle); return(relativeUrl); } }
public void CopyObject() { CheckDisposed(); IStStyle styleToCopy = AddTestStyle("MyStyle", ContextValues.General, StructureValues.Undefined, FunctionValues.Prose, false, Cache.LangProject.StylesOC); int originalNumberOfStyles = Cache.LangProject.LexDbOA.StylesOC.Count; int hvoCopiedStyle = Cache.CopyObject(styleToCopy.Hvo, Cache.LangProject.LexDbOA.Hvo, (int)LexDb.LexDbTags.kflidStyles); IStStyle copiedStyle = CmObject.CreateFromDBObject(Cache, hvoCopiedStyle) as IStStyle; Assert.AreEqual(originalNumberOfStyles + 1, Cache.LangProject.LexDbOA.StylesOC.Count); Assert.AreNotEqual(styleToCopy.Hvo, hvoCopiedStyle); Assert.AreEqual(styleToCopy.Name, copiedStyle.Name); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sanity check to ensure the scripture texts are valid. /// </summary> /// ------------------------------------------------------------------------------------ protected void EnsureScriptureTextsValid() { foreach (IScrBook book in m_scr.ScriptureBooksOS) { if (book.SectionsOS.Count == 0) { continue; } ContextValues sectionContext; foreach (IScrSection section in book.SectionsOS) { // Check the heading paragraphs. if (section.HeadingOA == null) { section.HeadingOA = m_cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); } if (section.HeadingOA.ParagraphsOS.Count == 0) { IStTxtPara para = m_cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( section.HeadingOA, ScrStyleNames.SectionHead); sectionContext = ContextValues.Text; } else { IStStyle style = m_scr.FindStyle(section.HeadingOA.ParagraphsOS[0].StyleRules); // style could be null. set default context if possible sectionContext = style == null ? ContextValues.Text : style.Context; } // Check the content paragraphs. if (section.ContentOA == null) { section.ContentOA = m_cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); } if (section.ContentOA.ParagraphsOS.Count == 0) { IStTxtPara para = m_cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle( section.ContentOA, TeStylesXmlAccessor.GetDefaultStyleForContext(sectionContext, false)); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor with ContextValues and MarkerDomain as a parameters. /// </summary> /// <param name="sStyleName">Name of the style.</param> /// <param name="styleType">kstCharacter or kstParagraph</param> /// <param name="ws">character or paragraph writing system</param> /// <param name="context">Context that will be used if this is a new style (otherwise existing /// context in DB will be used), see ContextValues for possible types</param> /// <param name="domain">The marker domain to use</param> /// <param name="styleSheet">The style sheet</param> /// ------------------------------------------------------------------------------------ public ImportStyleProxy(string sStyleName, StyleType styleType, int ws, ContextValues context, MarkerDomain domain, FwStyleSheet styleSheet) { m_FwStyleSheet = styleSheet; m_domain = domain; Debug.Assert(m_FwStyleSheet != null); m_ttpFormattingProps = null; m_fIsScriptureStyle = true; //default m_sEndMarker = null; //default if (context == ContextValues.EndMarker) { // this proxy represents an end marker - not a style; set bogus info sStyleName = "End"; //name does not matter styleType = StyleType.kstCharacter; } else if (sStyleName != null) { // Determine whether style exists in the StyleSheet Debug.Assert(ws != 0); m_style = m_FwStyleSheet.FindStyle(sStyleName); if (m_style != null) { // If this is an existing style, the actual type, context, structure, and // function always override the requested values. styleType = m_style.Type; context = (ContextValues)m_style.Context; m_structure = (StructureValues)m_style.Structure; m_function = (FunctionValues)m_style.Function; } } m_sStyleName = sStyleName; m_StyleType = styleType; m_ws = ws; m_Context = context; // //force StartOfFootnote marker to be processed as a para style proxy having para props // if (context == StyleRole.StartOfFootnote) // m_StyleType = StyleType.kstParagraph; //set the text property vars for this proxy SetTextProps(); }
public void AddHyperlink() { ITsStrBldr strBldr = TsStringUtils.MakeStrBldr(); LcmStyleSheet mockStylesheet = MockRepository.GenerateStub <LcmStyleSheet>(); IStStyle mockHyperlinkStyle = MockRepository.GenerateStub <IStStyle>(); mockHyperlinkStyle.Name = StyleServices.Hyperlink; mockHyperlinkStyle.Stub(x => x.InUse).Return(true); mockStylesheet.Stub(x => x.FindStyle(StyleServices.Hyperlink)).Return(mockHyperlinkStyle); Assert.IsTrue(FwEditingHelper.AddHyperlink(strBldr, Cache.DefaultAnalWs, "Click Here", "www.google.com", mockStylesheet)); Assert.AreEqual(1, strBldr.RunCount); Assert.AreEqual("Click Here", strBldr.get_RunText(0)); ITsTextProps props = strBldr.get_Properties(0); LcmTestHelper.VerifyHyperlinkPropsAreCorrect(props, Cache.DefaultAnalWs, "www.google.com"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Mega constructor with style name /// </summary> /// ------------------------------------------------------------------------------------ public ImportMappingInfo(string beginMarker, string endMarker, bool isExcluded, MappingTargetType mappingTarget, MarkerDomain domain, string styleName, string icuLocale, ICmAnnotationDefn noteType, bool isInUse, ImportDomain importDomain) { m_beginMarker = beginMarker; m_endMarker = endMarker; m_isExcluded = isExcluded; m_mappingTarget = mappingTarget; m_domain = domain; m_styleName = styleName; m_style = null; m_icuLocale = icuLocale; m_noteType = noteType; if (isInUse) { m_inUse[ScrImportSet.CreateImportSourceKey(importDomain, icuLocale, noteType == null ? 0 : noteType.Hvo)] = isInUse; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new style on the specified style list. /// </summary> /// <param name="styleList">The style list to add the style to</param> /// <param name="name">style name</param> /// <param name="context">style context</param> /// <param name="structure">style structure</param> /// <param name="function">style function</param> /// <param name="isCharStyle">true if character style, otherwise false</param> /// <param name="userLevel">User level</param> /// <param name="isBuiltIn">true if style is a bult-in style</param> /// ------------------------------------------------------------------------------------ public IStStyle AddStyle(IFdoOwningCollection <IStStyle> styleList, string name, ContextValues context, StructureValues structure, FunctionValues function, bool isCharStyle, int userLevel, bool isBuiltIn) { IStStyle style = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create(); styleList.Add(style); style.Name = name; style.Context = context; style.Structure = structure; style.Function = function; style.Type = (isCharStyle ? StyleType.kstCharacter : StyleType.kstParagraph); style.UserLevel = userLevel; ITsPropsBldr bldr = TsPropsBldrClass.Create(); style.Rules = bldr.GetTextProps(); style.IsBuiltIn = isBuiltIn; return(style); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Mega constructor with style name /// </summary> /// ------------------------------------------------------------------------------------ public ImportMappingInfo(string beginMarker, string endMarker, bool isExcluded, MappingTargetType mappingTarget, MarkerDomain domain, string styleName, string wsId, ICmAnnotationDefn noteType, bool isInUse, ImportDomain importDomain) { m_beginMarker = beginMarker; m_endMarker = endMarker; m_isExcluded = isExcluded; m_mappingTarget = mappingTarget; m_domain = domain; m_styleName = styleName; m_style = null; m_wsId = wsId; m_noteType = noteType; if (isInUse) { m_inUse[ScriptureServices.CreateImportSourceKey(importDomain, wsId, noteType)] = isInUse; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Test converting the digits to a specific digit set /// </summary> /// <param name="zeroChar">zero character in the desired language</param> /// <param name="nineChar">nine character in the desired language</param> /// <param name="dlg">scripture properties dialog</param> /// ------------------------------------------------------------------------------------ private void ScriptDigitConversionTest(char zeroChar, char nineChar, ScriptureProperties dlg) { m_scr.ScriptDigitZero = zeroChar; m_scr.UseScriptDigits = (zeroChar != '0'); ReflectionHelper.CallMethod(dlg, "ConvertChapterVerseNumbers", null); int[] expectedNumbers = new int[] { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int expectedIndex = 0; ITsString tss = ((IStTxtPara)((IScrSection)m_exodus.SectionsOS[0]).ContentOA.ParagraphsOS[0]).Contents.UnderlyingTsString; for (int i = 0; i < tss.RunCount; i++) { TsRunInfo tri; ITsTextProps ttp = tss.FetchRunInfo(i, out tri); IStStyle style = m_scr.FindStyle(ttp); if (style != null && (style.Function == FunctionValues.Verse || style.Function == FunctionValues.Chapter)) { int expectedNumber = expectedNumbers[expectedIndex++]; string runChars = tss.GetChars(tri.ichMin, tri.ichLim); // make sure the expected digits were found Assert.AreEqual(expectedNumber, ScrReference.ChapterToInt(runChars)); // make sure that all of the digits are in the desired language foreach (char c in runChars) { if (Char.IsDigit(c)) { Assert.IsTrue(c >= zeroChar && c <= nineChar, "Found incorrect digit"); } } } } // Make sure we saw all the expected numbers in the data Assert.AreEqual(expectedNumbers.Length, expectedIndex); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the given style is (possibly) in use. /// </summary> /// <remarks>This method is virtual to allow for applications (such as FLEx) that may /// not have made good use of the InUse property of styles.</remarks> /// <param name="style">The style.</param> /// <returns><c>true</c> if there is any reasonable chance the given style is in use /// somewhere in the project data; <c>false</c> if the style has never been used and /// there is no real possibility it could be in the data.</returns> /// ------------------------------------------------------------------------------------ protected override bool StyleIsInUse(IStStyle style) { if ((style.Context == ContextValues.Internal && !ScrStyleNames.InternalStyles.Contains(style.Name)) || (style.Context == ContextValues.InternalMappable && !ScrStyleNames.InternalMappableStyles.Contains(style.Name))) { return false; } return style.InUse; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes changes in text structure when the context of the new paragraph style does not /// match the context of the current paragraph style. /// </summary> /// <remarks>This method properly adjusts the text structure for newStyle; the style is /// not applied here - the caller should do that.</remarks> /// <param name="selHelper">the selection to which the new style is being applied</param> /// <param name="curStyle">current style at the selection anchor</param> /// <param name="newStyle">new style to be applied (has a new style context)</param> /// <returns>Returns true if the style change can now be applied.</returns> /// ------------------------------------------------------------------------------------ protected virtual bool AdjustTextStructure(SelectionHelper selHelper, IStStyle curStyle, IStStyle newStyle) { SelLevInfo[] top = selHelper.GetLevelInfo(SelectionHelper.SelLimitType.Top); SelLevInfo[] bottom = selHelper.GetLevelInfo(SelectionHelper.SelLimitType.Bottom); ILocationTracker tracker = ((ITeView)Control).LocationTracker; int scrLevelCount = tracker.GetLevelCount((int)ScrSection.ScrSectionTags.kflidContent); // Adjustments will only be done in section level selections. if (top.Length != scrLevelCount || bottom.Length != scrLevelCount) return true; // CASE 1: Change a section head to a content paragraph // If style of paragraphs of the section heading are changed to something // that is not a section head style, restructure heading paragraphs if (top[1].tag == (int)ScrSection.ScrSectionTags.kflidHeading && newStyle.Structure == StructureValues.Body) { // these will be adjusted to the new indices after the structure is changed int iSection = tracker.GetSectionIndexInBook(selHelper, SelectionHelper.SelLimitType.Top); int iPara; bool firstSectionInContext = (iSection == 0); int iBook = tracker.GetBookIndex(selHelper, SelectionHelper.SelLimitType.Top); ScrBook book = BookFilter.GetBook(iBook); ScrSection section = (ScrSection)book.SectionsOS[iSection]; // for an interior section, need to check context of next section if (!firstSectionInContext) { IScrSection prevSection = book.SectionsOS[iSection - 1]; firstSectionInContext = !SectionsHaveSameContext(section, prevSection); } // If all paragraphs of heading are selected, merge selected section // with previous section if (AreAllParagraphsSelected(top, bottom, section.HeadingOA)) { if (!firstSectionInContext) { iPara = ScrSection.MergeIntoPreviousSectionContent(m_cache, book, iSection); iSection--; } else { // Just need to move all heading paragraphs to the content. The move // method will create a new empty heading paragraph. iPara = 0; section.MoveHeadingParasToContent(0); } } // If selection starts at first paragraph of the heading, move heading paragraphs to // content of previous section. else if (top[0].ihvo == 0) { if (!firstSectionInContext) { iPara = ScrSection.MoveHeadingToPreviousSectionContent(m_cache, book, iSection, bottom[0].ihvo); iSection--; } else { // In this case, we want the selected paragraphs to become the content // of a new section, and the preceding paragraph(s) to become the // heading of the new section. section.ChangeParagraphToSectionContent(top[0].ihvo, bottom[0].ihvo - top[0].ihvo + 1); // update insertion point to first paragraph(s) of new section content iPara = 0; } } else { // If selection bottoms at the last paragraph of the heading, move heading // paragraphs to content of this section if (section.HeadingOA.ParagraphsOS.Count - 1 == bottom[0].ihvo) { section.MoveHeadingParasToContent(top[0].ihvo); iPara = 0; } else // The selection must be only inner paragraphs in the section head, // not including the first or last paragraphs. // In this case, we want the selected paragraph(s) to become content for // the heading paragraph(s) above it, and the following section head // paragraph(s) become the heading of a new section object. { int iParaStart = top[0].ihvo; int iParabottom = bottom[0].ihvo; section.SplitSectionHeading(iSection, iParaStart, iParabottom); iPara = 0; } } // Select all paragraphs in content that were part of section heading (and have // now been moved to iSection, iPara) SetInsertionPoint(iBook, iSection, iPara, 0, false); // Get bottom point of selection and update it to point to beginning of // last paragraph of old heading. Use offsets of current selection. SelectionHelper newHelper = SelectionHelper.Create(Callbacks.EditedRootBox.Site); SelLevInfo[] levInfo = newHelper.GetLevelInfo(SelectionHelper.SelLimitType.End); levInfo[0].ihvo += bottom[0].ihvo - top[0].ihvo; newHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, levInfo); newHelper.IchAnchor = selHelper.GetIch(SelectionHelper.SelLimitType.Top); newHelper.IchEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom); newHelper.SetSelection(true); } //bottom of CASE 1 "Change a section head to a scripture paragraph" // CASE 2: Change scripture paragraph to a section head // - only if the new style has "section head" structure, the selection is in // one paragraph, and that paragraph is part of the section content else if (top[1].tag == (int)ScrSection.ScrSectionTags.kflidContent && newStyle.Structure == StructureValues.Heading) { // Check selected paragraphs for chapter or verse numbers - style will not be // changed if any are found. ScrSection section = new ScrSection(m_cache, tracker.GetSectionHvo(selHelper, SelectionHelper.SelLimitType.Top)); for (int i = top[0].ihvo; i <= bottom[0].ihvo; i++) { ScrTxtPara para = new ScrTxtPara(m_cache, section.ContentOA.ParagraphsOS.HvoArray[i]); if (para.HasChapterOrVerseNumbers()) { // Cancel the request if chapter or verse numbers are present. // display message box if not running in a test if (!InTestMode) { MessageBox.Show(Control, TeResourceHelper.GetResourceString("kstidParaHasNumbers"), TeResourceHelper.GetResourceString("kstidApplicationName"), MessageBoxButtons.OK); } return false; } } int iBook = tracker.GetBookIndex(selHelper, SelectionHelper.SelLimitType.Top); int iSection = tracker.GetSectionIndexInBook(selHelper, SelectionHelper.SelLimitType.Top); int iPara; ScrBook book = section.OwningBook; // End of book is end of context type bool lastSectionInContext = (iSection == book.SectionsOS.Count - 1); // for an interior section, need to check context of next section if (!lastSectionInContext) { IScrSection nextSection = book.SectionsOS[iSection + 1]; lastSectionInContext = !SectionsHaveSameContext(section, nextSection); } if (AreAllParagraphsSelected(top, bottom, section.ContentOA)) { if (!lastSectionInContext) { // Need to combine this section with the following section. // Heading of combined section will be section1.Heading + // section1.Content + section2.Heading iPara = section.HeadingOA.ParagraphsOS.Count; IScrSection nextSection = book.SectionsOS[iSection + 1]; StText.MoveTextContents(section.ContentOA, nextSection.HeadingOA, false); StText.MoveTextContents(section.HeadingOA, nextSection.HeadingOA, false); nextSection.AdjustReferences(); book.SectionsOS.RemoveAt(iSection); } else { // Just need to move all content paragraphs to the heading. The move // method will create a new empty content paragraph. iPara = section.HeadingOA.ParagraphsOS.Count; section.MoveContentParasToHeading(section.ContentOA.ParagraphsOS.Count - 1); } } else if (top[0].ihvo == 0) { // Move the first content paragraphs to become the last para of the // section head section.MoveContentParasToHeading(bottom[0].ihvo); iPara = section.HeadingOA.ParagraphsOS.Count - (bottom[0].ihvo - top[0].ihvo + 1); } else if (bottom[0].ihvo == section.ContentOA.ParagraphsOS.Count - 1 && !lastSectionInContext) { // Move the last content paragraphs to become the first para of the next // section in the book. ScrSection.MoveContentParasToNextSectionHeading(m_cache, book, iSection, top[0].ihvo); // update insertion point to first paragraph(s) of next section head iSection++; iPara = 0; } else { // In this case, we want the selected paragraph to become the heading // of a new section, and the following paragraph(s) to become the // content of the new section object. section.ChangeParagraphToSectionHead(top[0].ihvo, bottom[0].ihvo - top[0].ihvo + 1); // update insertion point to first paragraph(s) of next section head iSection++; iPara = 0; } // Select all paragraphs in content that were part of section heading (and have // now been moved to iSection, iPara) SetInsertionPoint((int)ScrSection.ScrSectionTags.kflidHeading, iBook, iSection, iPara); // Get bottom point of selection and update it to point to beginning of // last paragraph of old heading. Use offsets of current selection. SelectionHelper newHelper = SelectionHelper.Create(Callbacks.EditedRootBox.Site); SelLevInfo[] levInfo = newHelper.GetLevelInfo(SelectionHelper.SelLimitType.End); levInfo[0].ihvo += bottom[0].ihvo - top[0].ihvo; newHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, levInfo); newHelper.IchAnchor = selHelper.GetIch(SelectionHelper.SelLimitType.Top); newHelper.IchEnd = selHelper.GetIch(SelectionHelper.SelLimitType.Bottom); newHelper.SetSelection(true); } return true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// If a style has been modified by the user, this method will be called to determine /// whether the factory settings or the modified properties should be used. /// </summary> /// <param name="style">The style.</param> /// <param name="styleTag">The style tag.</param> /// <returns>OverwriteOptions.Skip to indicate that the caller should not alter the /// user-modified style; /// OverwriteOptions.FunctionalPropertiesOnly to indicate that the caller should update /// the functional properties of the style but leave the user-modified properties that /// affect only the appearance; /// OverwriteOptions.All to indicate that the caller should proceed with the style /// definition update, based on the information in the XML node.</returns> /// ------------------------------------------------------------------------------------ protected override OverwriteOptions OverwriteUserModifications(IStStyle style, XmlNode styleTag) { return OverwriteOptions.FunctionalPropertiesOnly; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Move the entire Heading or Content paragraphs from srcSection to the Heading or Contents /// in another ScrSection. /// </summary> /// ------------------------------------------------------------------------------------ internal static void MoveAllParas(IScrSection srcSection, int srcField, IScrSection destSection, int destField, bool fAtEnd, IStStyle newStyle) { IStText destText = (destField == ScrSectionTags.kflidContent) ? destSection.ContentOA : destSection.HeadingOA; int iLastParaSrc = (srcField == ScrSectionTags.kflidContent) ? srcSection.ContentOA.ParagraphsOS.Count - 1 : srcSection.HeadingOA.ParagraphsOS.Count - 1; int insertIndex = (fAtEnd) ? destText.ParagraphsOS.Count : 0; MoveWholeParas(srcSection, srcField, 0, iLastParaSrc, destSection, destField, insertIndex, newStyle); }
/// ------------------------------------------------------------------------------------- /// <summary> /// Update the style context and do any special processing needed to deal with existing /// data that may be marked with the given style. (Since it was previously not an /// internal style, it is possible the user has used it in ways that would be /// incompatible with its intended use.) Any time a factory style is changed to an /// internal context, specific code must be written here to deal with it. Some possible /// options for dealing with this scenario are: /// * Delete any data previously marked with the style (and possibly set some other /// object properties) /// * Add to the m_deletedStyles or m_replacedStyles arrays so existing data will be /// marked with a different style (note that this will only work if no existing data /// should be preserved with the style). /// </summary> /// <param name="style">The style being updated</param> /// <param name="context">The context (either internal or internal mappable) that the /// style is to be given</param> /// ------------------------------------------------------------------------------------- protected override void ChangeFactoryStyleToInternal(IStStyle style, ContextValues context) { if (!CompatibleContext((ContextValues)style.Context, context)) { if (style.Name == ScrStyleNames.FootnoteTargetRef) { foreach (IScrBook book in m_scr.ScriptureBooksOS) RemoveDirectUsesOfFootnoteTargetRef(book); foreach (IScrDraft draft in m_scr.ArchivedDraftsOC) { foreach (IScrBook book in draft.BooksOS) RemoveDirectUsesOfFootnoteTargetRef(book); } } else if (style.InUse) { // This is where we should handle any future upgrade issues } } style.Context = context; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find a paragraph with the specified style id, containing the specified verse number, /// if specified, and having the correct sequence number. Sets all appropriate state /// variables before returning. /// </summary> /// <param name="style">style of paragraph to find. If the style is null, then /// disregard the style of the paragraph. Just get first paragraph with the given /// reference.</param> /// <param name="targetRef">Reference to seek</param> /// <param name="fAppend">Indicates to caller that the found paragraph already has /// been used previously, so new (BT) text should be appended to the existing back /// translation (with a hard line break separating the two parts). This is needed to /// support special logic we do in section headers when two paragraphs with the same /// style are imported in succession.</param> /// <returns>The corrersponding StTxtPara, or null if no matching para is found</returns> /// ------------------------------------------------------------------------------------ protected IStTxtPara FindCorrespondingVernParaForSegment(IStStyle style, BCVRef targetRef, out bool fAppend) { fAppend = false; int iCurrSectionTemp = m_iCurrSection; m_lastPara = (m_scrBook as ScrBook).FindCorrespondingVernParaForSegment(style, targetRef, m_iNextBtPara, ref m_iCurrSection); if (m_lastPara == null && style.Structure == StructureValues.Heading && m_iNextBtPara > 0) { m_iCurrSection = iCurrSectionTemp; m_lastPara = (m_scrBook as ScrBook).FindCorrespondingVernParaForSegment(style, targetRef, --m_iNextBtPara, ref m_iCurrSection); fAppend = (m_lastPara != null); } if (m_lastPara != null) { m_CurrParaFootnotes = (m_lastPara as StTxtPara).GetFootnotes(); m_CurrParaPictures = m_lastPara.GetPictures(); } m_currSection = null; m_fCurrentSectionIsIntro = false; m_fInBookTitle = false; m_fInSectionHeading = false; m_fInVerseTextParagraph = false; m_hvoSectionContent = 0; m_hvoSectionHeading = 0; m_hvoTitle = CurrentBook.TitleOAHvo; Debug.Assert(m_ParaBldr.Length == 0); return m_lastPara; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find a paragraph with the specified style id, containing the specified verse number, /// if specified, and having the correct sequence number. /// </summary> /// <param name="targetStyle">style of paragraph to find</param> /// <param name="targetRef">Reference to seek</param> /// <param name="iPara">0-based index of paragraph</param> /// <param name="iVernSection">0-based index of the section the corresponding /// vernacular paragraph is in. This will be 0 if no corresponding paragraph can be /// found.</param> /// <returns>The corresponding StTxtPara, or null if no matching para is found</returns> /// ------------------------------------------------------------------------------------ public IScrTxtPara FindPara(IStStyle targetStyle, BCVRef targetRef, int iPara, ref int iVernSection) { // REVIEW: In production code, iPara is always passed as 0. Can we eliminate this parameter? // Do tests really need to be able to pass 1? Why are we testing something that can never happen in real life? Debug.Assert(targetRef.BookIsValid, "Invalid book number"); IScrBook book = FindBook(targetRef.Book); if (book == null) return null; return book.FindPara(targetStyle, targetRef, iPara, ref iVernSection); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set the style for the mapping. This is internal because we want all external /// processes to set the style name instead but ScrImportSet needs to be able to /// set the style when saving the mapping info to a ScrMarkerMapping object. /// </summary> /// <param name="style"></param> /// ------------------------------------------------------------------------------------ internal void SetStyle(IStStyle style) { Debug.Assert(style == null || m_styleName == style.Name); m_style = style; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method is needed when an inner paragraph in the content of this section /// has its style changed to a heading. /// This method creates a new following section using the specified content paragraphs as the new heading /// and the remaining paragraphs of this section as its content. /// The specified paragraphs must not include the first or last paragraphs. Also, the /// caller must make the necessary style changes before calling this method, i.e. the /// specified paragraphs must have a section heading style applied.</summary> /// /// <param name="iPara">Index of first content paragraph to be changed to section head. /// It must not be the first paragraph.</param> /// <param name="cParagraphs">Number of paragraphs to be changed to section head. /// The last paragraph in the section content must NOT be included.</param> /// <returns>the new following section</returns> /// <param name="newStyle">The new style for the content paragraphs that will become /// heading.</param> /// /// <exception cref="ArgumentOutOfRangeException">Occurs when iPara is the first paragraph, /// or out of range. Also when the count includes the last paragraph.</exception> /// <exception cref="InvalidStructureException">Occurs when the style of the specified paragraphs /// is not already section heading structure.</exception> /// ------------------------------------------------------------------------------------ public IScrSection SplitSectionContent_ExistingParaBecomesHeading(int iPara, int cParagraphs, IStStyle newStyle) { VerifyParasForHeadingHaveNoReferences(ContentOA, iPara, iPara + cParagraphs - 1, newStyle); // Creates a new following section // and moves paragraphs after the specified paragraphs to the new section content IScrSection newSection = SplitSection(ScrSectionTags.kflidContent, iPara + cParagraphs, 0); // move specified paragraphs to new section head MoveWholeParas(this, ScrSectionTags.kflidContent, iPara, ContentOA.ParagraphsOS.Count - 1, newSection, ScrSectionTags.kflidHeading, 0, newStyle); VerifyThatParaStylesHaveCorrectStructure(newSection, ScrSectionTags.kflidHeading); VerifyThatParaStylesHaveCorrectStructure(newSection, ScrSectionTags.kflidContent); return newSection; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Moves paragraphs from the heading of a section to the beginning of its content. /// All paragraphs from the given index to the end of the heading are moved. /// </summary> /// <param name="indexFirstPara">index of the first heading paragraph to be moved</param> /// <param name="newStyle">The new style for the moved paragraphs.</param> /// <exception cref="ArgumentOutOfRangeException">Occurs when paragraph index is invalid. /// </exception> /// ------------------------------------------------------------------------------------ public void MoveHeadingParasToContent(int indexFirstPara, IStStyle newStyle) { // Get paragraph props for first heading para in case we need to create a new one. ITsTextProps paraPropsSave = HeadingOA.ParagraphsOS[indexFirstPara].StyleRules; MoveWholeParas(this, ScrSectionTags.kflidHeading, indexFirstPara, HeadingOA.ParagraphsOS.Count - 1, this, ScrSectionTags.kflidContent, 0, newStyle); // Verify that paragraph styles are consistent with the structure changes. VerifyThatParaStylesHaveCorrectStructure(this, ScrSectionTags.kflidContent); // If heading is now empty, create a new empty paragraph. if (HeadingOA.ParagraphsOS.Count == 0) { string styleName = paraPropsSave.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); StTxtParaBldr.CreateEmptyPara(m_cache, HeadingOA, styleName, m_cache.DefaultVernWs); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Moves paragraphs from the content of a section to the end of its heading. /// All paragraphs from the beginning of the content to the given index are moved. /// </summary> /// <param name="indexLastPara">index of the last content paragraph to be moved</param> /// <param name="newStyle">The new style for the moved paragraphs.</param> /// <exception cref="InvalidStructureException">Occurs when a content paragraph that we /// are attempting to move to a heading paragraph contains chapter/verse numbers. /// </exception> /// ------------------------------------------------------------------------------------ public void MoveContentParasToHeading(int indexLastPara, IStStyle newStyle) { // Get paragraph props for last content para in case we need to create a new one. ITsTextProps paraPropsSave = ContentOA.ParagraphsOS[indexLastPara].StyleRules; VerifyParasForHeadingHaveNoReferences(ContentOA, 0, indexLastPara, newStyle); MoveWholeParas(this, ScrSectionTags.kflidContent, 0, indexLastPara, this, ScrSectionTags.kflidHeading, HeadingOA.ParagraphsOS.Count, newStyle); // Verify that paragraph styles are consistent with the structure changes. VerifyThatParaStylesHaveCorrectStructure(this, ScrSectionTags.kflidHeading); // If content is now empty, create a new empty paragraph. if (ContentOA.ParagraphsOS.Count == 0) { string styleName = paraPropsSave.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); StTxtParaBldr.CreateEmptyPara(m_cache, ContentOA, styleName, m_cache.DefaultVernWs); } }
/// ------------------------------------------------------------------------------------- /// <summary> /// If the proposed context for a style is internal or internalMappable, make sure the /// program actually expects and supports this context for this style. /// </summary> /// <param name="style">The style being updated</param> /// <param name="proposedContext">The proposed context for the style</param> /// <returns><c>true</c>if the proposed context is internal or internal mappable and /// the program recognizes it as a valid</returns> /// ------------------------------------------------------------------------------------- public override bool IsValidInternalStyleContext(IStStyle style, ContextValues proposedContext) { return ((proposedContext == ContextValues.Internal && ScrStyleNames.InternalStyles.Contains(style.Name)) || (proposedContext == ContextValues.InternalMappable && ScrStyleNames.InternalMappableStyles.Contains(style.Name))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find a paragraph with the specified style id, containing the specified verse number, /// if specified, and having the correct sequence number. Sets all appropriate state /// variables before returning. /// </summary> /// <param name="style">style of paragraph to find</param> /// <param name="targetRef">Reference to seek</param> /// <param name="iPara">0-based index of paragraph</param> /// <returns>The corrersponding IStTxtPara, or null if no matching para is found</returns> /// ------------------------------------------------------------------------------------ public IStTxtPara FindCorrespondingVernParaForSegment(IStStyle style, BCVRef targetRef, int iPara) { CheckDisposed(); m_iNextBtPara = iPara; bool fDummy; return base.FindCorrespondingVernParaForSegment(style, targetRef, out fDummy); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the properties of this entry based on the given FW style. /// </summary> /// ------------------------------------------------------------------------------------ public override void SetPropertiesBasedOnStyle(IStStyle style, IWritingSystem forceStyleInfo) { base.SetPropertiesBasedOnStyle(style, forceStyleInfo); m_textPropertiesFromStyFile = null; }
public override void FixtureTeardown() { m_styleOrig = null; m_styleReplace = null; base.FixtureTeardown(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies the content paragraphs that to move to heading paragraphs have no /// Scripture references. /// </summary> /// <param name="contents">The contents of the ScrSection.</param> /// <param name="startPara">The index of the first content para.</param> /// <param name="endPara">The index of the last content para.</param> /// <param name="newStyle">The new style for the moved paragraphs.</param> /// <exception cref="InvalidStructureException">Occurs when a content paragraph that we /// are attempting to move to a heading paragraph contains chapter/verse numbers. /// </exception> /// ------------------------------------------------------------------------------------ internal static void VerifyParasForHeadingHaveNoReferences(IStText contents, int startPara, int endPara, IStStyle newStyle) { for (int iPara = startPara; iPara <= endPara; iPara++) { if (((IScrTxtPara)contents.ParagraphsOS[iPara]).HasChapterOrVerseNumbers()) throw new InvalidStructureException(newStyle.Name, StructureValues.Body); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Divides the current section into two sections with section index iSection and /// iSection + 1. Moves the selected paragraphs from the heading of /// the current section into the content of the current section. /// </summary> /// <param name="iParaStart">index of the first heading paragraph to be moved into /// content</param> /// <param name="iParaEnd">index of the last heading paragraph to be moved into /// content</param> /// <param name="newStyle">The new style for the heading paragraphs that will become /// content.</param> /// ------------------------------------------------------------------------------------ public void SplitSectionHeading_ExistingParaBecomesContent(int iParaStart, int iParaEnd, IStStyle newStyle) { int iSection = IndexInOwner; // Create empty section after the current section IScrSection newSection = m_cache.ServiceLocator.GetInstance<IScrSectionFactory>().CreateEmptySection((IScrBook)Owner, iSection + 1); // Move remainder of Heading and all the Content to new following section: MoveWholeParas(this, ScrSectionTags.kflidHeading, iParaEnd + 1, HeadingOA.ParagraphsOS.Count - 1, newSection, ScrSectionTags.kflidHeading, 0, null); MoveAllParas(this, ScrSectionTags.kflidContent, newSection, ScrSectionTags.kflidContent, false, null); // Move current selection in heading to content // note: because we already moved the "heading paras after selection" // we will now move all paras from start of selection MoveHeadingParasToContent(iParaStart, newStyle); VerifyThatParaStylesHaveCorrectStructure(this, ScrSectionTags.kflidContent); VerifyThatParaStylesHaveCorrectStructure(newSection, ScrSectionTags.kflidHeading); VerifyThatParaStylesHaveCorrectStructure(newSection, ScrSectionTags.kflidContent); // We shouldn't need to do a PropChanged in the new FDO //Cache.PropChanged(Owner.Hvo, ScrBookTags.kflidSections, iSection + 1, 1, 0); }
/// -------------------------------------------------------------------------------- /// <summary> /// Use this method to transfer whole paragraphs from one StText to another. /// </summary> /// <param name="srcSection">ScrSection from which the paragraphs are moved</param> /// <param name="srcField">The field (contents or heading) from which we will move paras</param> /// <param name="iMinSrc">Index of first paragraph to be moved</param> /// <param name="iLastSrc">Index of last paragraph to be moved</param> /// <param name="destSection">ScrSection to which the paragraphs are moved</param> /// <param name="destField">The destination field (contents or heading).</param> /// <param name="destIndex">Index of paragraph before which paragraphs are to be /// inserted</param> /// <param name="destStyle">The paragraph style to apply to the moved paragraphs.</param> /// -------------------------------------------------------------------------------- internal static void MoveWholeParas(IScrSection srcSection, int srcField, int iMinSrc, int iLastSrc, IScrSection destSection, int destField, int destIndex, IStStyle destStyle) { IStText srcText = (srcField == ScrSectionTags.kflidContent) ? srcSection.ContentOA : srcSection.HeadingOA; IStText destnText = (destField == ScrSectionTags.kflidContent) ? destSection.ContentOA : destSection.HeadingOA; bool fStructureChange = (srcField != destField); Debug.Assert((fStructureChange && destStyle != null) || (!fStructureChange && destStyle == null), "Unexpected style specification: " + (fStructureChange ? " changing structure but no style specified." : " not changing structure but style is specified.")); for (int i = iMinSrc; i <= iLastSrc; i++) { IStTxtPara paraToMove = (IStTxtPara)srcText.ParagraphsOS[iMinSrc]; // Insert method will remove the para from its prior StText destnText.ParagraphsOS.Insert(destIndex, paraToMove); destIndex++; // Make sure the style is set after moving the paragraph to its new owner // so that the generated PropChanges happen in the correct order. // (Caused by a NoteDependency on the style rules for the paragraph) // (TE-9233) if (destStyle != null) paraToMove.StyleName = destStyle.Name; Debug.Assert(!srcText.ParagraphsOS.Contains(paraToMove), "Paragraph not removed from current ScrSection."); Debug.Assert(destnText.ParagraphsOS.Contains(paraToMove), "Paragraph not added to destination ScrSection."); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:DummyStyleInfo"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public DummyStyleInfo(IStStyle style) : base(style) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines whether the given style is (possibly) in use. /// </summary> /// <remarks>This override is needed because previously hotlinks in FLEx were /// not have made good use of the InUse property of styles.</remarks> /// <param name="style">The style.</param> /// <returns><c>true</c> if there is any reasonable chance the given style is in use /// somewhere in the project data; <c>false</c> if the style has never been used and /// there is no real possibility it could be in the data.</returns> /// ------------------------------------------------------------------------------------ protected override bool StyleIsInUse(IStStyle style) { return (style.Name == "External Link" || base.StyleIsInUse(style)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a new real style in the stylesheet for this proxy, if needed. /// </summary> /// ------------------------------------------------------------------------------------ private void AddStyleToStylesheet() { if (m_style != null || m_Context == ContextValues.EndMarker || m_sStyleName == null) return; // If m_ttpFormattingProps has not been set up, initialize it now if (m_ttpFormattingProps == null) { ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); m_ttpFormattingProps = tsPropsBldr.GetTextProps(); // default properties } // Get an hvo for the new style int hvoStyle = m_FwStyleSheet.MakeNewStyle(); m_style = m_FwStyleSheet.Cache.ServiceLocator.GetInstance<IStStyleRepository>().GetObject(hvoStyle); // PutStyle() adds the style to the stylesheet. we'll give it the properties we // are aware of. m_FwStyleSheet.PutStyle(m_sStyleName, string.Empty, hvoStyle, 0, m_StyleType == StyleType.kstParagraph ? hvoStyle : 0, (int)m_StyleType, false, false, m_ttpFormattingProps); // base the new style on "Paragraph" if (m_StyleType == StyleType.kstParagraph) { m_style.BasedOnRA = m_FwStyleSheet.FindStyle(ScrStyleNames.NormalParagraph); m_style.Context = m_style.BasedOnRA.Context; m_style.Structure = m_style.BasedOnRA.Structure; m_style.Function = m_style.BasedOnRA.Function; } }
/// <summary> /// /// </summary> public override void FixtureSetup() { base.FixtureSetup(); NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () => { m_styleOrig = Cache.ServiceLocator.GetInstance<IStStyleFactory>().Create(); m_scr.StylesOC.Add(m_styleOrig); m_styleOrig.Name = "Cool style"; m_styleOrig.Context = ContextValues.Intro; m_styleOrig.IsBuiltIn = true; m_styleReplace = Cache.ServiceLocator.GetInstance<IStStyleFactory>().Create(); m_scr.StylesOC.Add(m_styleReplace); m_styleReplace.Name = "Cooler style"; m_styleReplace.IsBuiltIn = true; }); }