private void SetStyleSheet(int hvo) { var text = hvo == 0 ? null : (IStText)Cache.ServiceLocator.GetObject(hvo); IVwStylesheet wantedStylesheet = m_styleSheet; if (text != null && ScriptureServices.ScriptureIsResponsibleFor(text)) { // Use the Scripture stylesheet if (m_teStylesheet == null) { m_flexStylesheet = m_styleSheet; // remember the default. var stylesheet = new FwStyleSheet(); stylesheet.Init(Cache, Cache.LangProject.TranslatedScriptureOA.Hvo, ScriptureTags.kflidStyles); m_teStylesheet = stylesheet; } wantedStylesheet = m_teStylesheet; } else if (m_flexStylesheet != null) { wantedStylesheet = m_flexStylesheet; } if (wantedStylesheet != m_styleSheet) { m_styleSheet = wantedStylesheet; // Todo: set up the comobo; set the main window one. } }
public void SetRoot(int hvo) { CheckDisposed(); if (hvo != 0) { IStText stText = Cache.ServiceLocator.GetInstance <IStTextRepository>().GetObject(hvo); if (ScriptureServices.ScriptureIsResponsibleFor(stText)) { m_hvoRoot = hvo; // StText (i.e. Scripture) } else { m_hvoRoot = stText.Owner.Hvo; // Text (i.e. non-scripture). Editable. } SetupVc(); } else { m_hvoRoot = 0; ReadOnlyView = true; if (m_vc != null) { m_vc.IsScripture = false; m_vc.Editable = false; } } ChangeOrMakeRoot(m_hvoRoot, m_vc, TitleContentsVc.kfragRoot, m_styleSheet); }
private void SetupVc() { if (m_vc == null || m_hvoRoot == 0) { return; } int wsFirstPara = -1; wsFirstPara = GetWsOfFirstWordOfFirstTextPara(); if (wsFirstPara == -1) { // The paragraph's first character has no valid writing system...this seems to be possible // when it consists entirely of a picture. Rather than crashing, presume the default. wsFirstPara = Cache.DefaultVernWs; } m_vc.SetupVernWsForText(wsFirstPara); IStText stText = Cache.ServiceLocator.GetInstance <IStTextRepository>().GetObject(m_hvoRoot); if (m_configurationParameters != null) { m_vc.Editable = SIL.Utils.XmlUtils.GetOptionalBooleanAttributeValue( m_configurationParameters, "editable", true); m_vc.Editable &= !ScriptureServices.ScriptureIsResponsibleFor(stText); } }
public void TwoSegsPerVerse() { string pc1 = "Das Buch ist rot. "; string pc2 = "Das Maedchen ist schoen."; string verse1 = "9"; string pc3 = "Der Herr ist gross."; string pc4 = "Ich spreche nicht viel Deutsch."; string verse2 = "10"; string pc5 = "Was ist das?"; string pc6 = "Wie gehts?"; ITsStrBldr bldr = m_tsf.MakeString(pc1 + pc2 + verse1 + pc3 + pc4 + verse2 + pc5 + pc6, m_wsVern).GetBldr(); bldr.SetStrPropValue(pc1.Length + pc2.Length, pc1.Length + pc2.Length + verse1.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); int ichEndV1 = pc1.Length + pc2.Length + verse1.Length + pc3.Length + pc4.Length; bldr.SetStrPropValue(ichEndV1, ichEndV1 + verse2.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); m_para.Contents = bldr.GetString(); using (ParagraphParser pp = new ParagraphParser(m_para)) { List <int> eosIndexes; var segments = pp.CollectSegments(m_para.Contents, out eosIndexes); Assert.AreEqual(8, segments.Count); Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 0)); Assert.AreEqual("b", ScriptureServices.VerseSegLabel(m_para, 1)); Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 3)); Assert.AreEqual("b", ScriptureServices.VerseSegLabel(m_para, 4)); Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 6)); Assert.AreEqual("b", ScriptureServices.VerseSegLabel(m_para, 7)); } }
public void OneSegPerVerse() { string pc1 = "Das Buch ist rot. "; string verse1 = "9"; string pc2 = "Der Herr ist gross."; string verse2 = "10"; string pc3 = "Ich spreche nicht viel Deutsch."; ITsStrBldr bldr = m_tsf.MakeString(pc1 + verse1 + pc2 + verse2 + pc3, m_wsVern).GetBldr(); bldr.SetStrPropValue(pc1.Length, pc1.Length + verse1.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); int ichV2 = pc1.Length + verse1.Length + pc2.Length; bldr.SetStrPropValue(ichV2, ichV2 + verse2.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); m_para.Contents = bldr.GetString(); using (ParagraphParser pp = new ParagraphParser(m_para)) { List <int> eosIndexes; var segments = pp.CollectSegments(m_para.Contents, out eosIndexes); Assert.AreEqual(5, segments.Count); Assert.AreEqual("", ScriptureServices.VerseSegLabel(m_para, 0)); Assert.AreEqual("", ScriptureServices.VerseSegLabel(m_para, 2)); Assert.AreEqual("", ScriptureServices.VerseSegLabel(m_para, 4)); } }
void SetupVc() { if (m_vc == null || m_hvoRoot == 0) { return; } Debug.Assert(m_hvoRoot != 0, "m_hvoRoot should be set before using SetupVc()."); ICmObject co = Cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(m_hvoRoot); m_vc.IsScripture = ScriptureServices.ScriptureIsResponsibleFor(co as IStText); // don't allow editing scripture titles. m_vc.Editable = !m_vc.IsScripture; this.ReadOnlyView = !m_vc.Editable; }
private ITsString TitleForWs(int ws) { ITsString tssTitle = null; if (ScriptureServices.ScriptureIsResponsibleFor(this)) { Scripture scripture = Cache.LangProject.TranslatedScriptureOA as Scripture; if (scripture != null) { tssTitle = scripture.BookChapterVerseBridgeAsTss(this, ws); if (OwningFlid == ScrSectionTags.kflidHeading) { string sFmt = Strings.ksSectionHeading; int iMin = sFmt.IndexOf("{0}"); if (iMin < 0) { tssTitle = m_cache.MakeUserTss(sFmt); } else { ITsIncStrBldr tisb = TsIncStrBldrClass.Create(); if (iMin > 0) { tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(0, iMin))); } tisb.AppendTsString(tssTitle); if (iMin + 3 < sFmt.Length) { tisb.AppendTsString(m_cache.MakeUserTss(sFmt.Substring(iMin + 3))); } tssTitle = tisb.GetString(); } } } } else if (Owner is IText) { IText text = Owner as IText; tssTitle = text.Name.get_String(ws); } else { // throw? } if (tssTitle == null) { tssTitle = TsStrFactoryClass.Create().EmptyString(Cache.DefaultAnalWs); } return(tssTitle); }
/// ------------------------------------------------------------------------------------ /// <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> /// In SE Fieldworks we can't depend upon ScrControls.dll We need some decoupling to /// prevent the linker from trying to load ScrControls.dll and crashing. /// This seems to work. (Although I wonder if we could get away with just calling this method /// if IsTEInstalled?) /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void LaunchFilterTextsDialog(object sender, EventArgs args) { IFilterTextsDialog <IStText> dlg = null; try { var interestingTextsList = InterestingTextsDecorator.GetInterestingTextList(m_mediator, m_cache.ServiceLocator); var textsToChooseFrom = new List <IStText>(interestingTextsList.InterestingTexts); if (!FwUtils.IsTEInstalled) { // TE is not installed, so remove scripture from the list textsToChooseFrom = textsToChooseFrom.Where(text => !ScriptureServices.ScriptureIsResponsibleFor(text)).ToList(); } var interestingTexts = textsToChooseFrom.ToArray(); if (FwUtils.IsTEInstalled) { dlg = (IFilterTextsDialog <IStText>)DynamicLoader.CreateObject( "ScrControls.dll", "SIL.FieldWorks.Common.Controls.FilterTextsDialogTE", m_cache, interestingTexts, m_mediator.HelpTopicProvider, m_bookImporter); } else { dlg = new FilterTextsDialog(m_cache, interestingTexts, m_mediator.HelpTopicProvider); } // LT-12181: Was 'PruneToSelectedTexts(text) and most others were deleted. // We want 'PruneToInterestingTextsAndSelect(interestingTexts, selectedText)' dlg.PruneToInterestingTextsAndSelect(interestingTexts, (IStText)m_objRoot); // LT-12140 Dialog name shouldn't change from Choose Texts //dlg.Text = ITextStrings.ksExportInterlinearizedTexts; dlg.TreeViewLabel = ITextStrings.ksSelectSectionsExported; if (dlg.ShowDialog(this) == DialogResult.OK) { m_objs.AddRange(dlg.GetListOfIncludedTexts()); } } finally { if (dlg != null) { ((IDisposable)dlg).Dispose(); } } }
private void LaunchFilterTextsDialog(object sender, EventArgs args) { IFilterTextsDialog <IStText> dlg = null; try { var interestingTextsList = InterestingTextsDecorator.GetInterestingTextList(m_mediator, m_cache.ServiceLocator); var textsToChooseFrom = new List <IStText>(interestingTextsList.InterestingTexts); if (!FwUtils.IsOkToDisplayScriptureIfPresent) { // Mustn't show any Scripture, so remove scripture from the list textsToChooseFrom = textsToChooseFrom.Where(text => !ScriptureServices.ScriptureIsResponsibleFor(text)).ToList(); } var interestingTexts = textsToChooseFrom.ToArray(); if (FwUtils.IsOkToDisplayScriptureIfPresent) { dlg = new FilterTextsDialogTE(m_cache, interestingTexts, m_mediator.HelpTopicProvider, m_bookImporter); } else { dlg = new FilterTextsDialog(m_cache, interestingTexts, m_mediator.HelpTopicProvider); } // LT-12181: Was 'PruneToSelectedTexts(text) and most others were deleted. // We want 'PruneToInterestingTextsAndSelect(interestingTexts, selectedText)' dlg.PruneToInterestingTextsAndSelect(interestingTexts, (IStText)m_objRoot); dlg.TreeViewLabel = ITextStrings.ksSelectSectionsExported; if (dlg.ShowDialog(this) == DialogResult.OK) { m_objs.AddRange(dlg.GetListOfIncludedTexts()); } } finally { if (dlg != null) { ((IDisposable)dlg).Dispose(); } } }
/// <summary> /// Allow the user to export more than one to a single file (LT-11483) /// </summary> /// <returns>true iff export can proceed to choosing an output file</returns> protected override bool PrepareForExport() { m_objs.Clear(); var interestingTextsList = InterestingTextsDecorator.GetInterestingTextList(m_mediator, m_propertyTable, m_cache.ServiceLocator); var textsToShow = interestingTextsList.InterestingTexts; var isOkToDisplayScripture = m_cache.ServiceLocator.GetInstance <IScrBookRepository>().AllInstances().Any(); if (!isOkToDisplayScripture) { // Mustn't show any Scripture, so remove scripture from the list textsToShow = textsToShow.Where(text => !ScriptureServices.ScriptureIsResponsibleFor(text)); } var selectedTexts = new[] { (IStText)m_objRoot }; using (var dlg = new FilterTextsDialog(m_propertyTable.GetValue <IApp>("App"), m_cache, selectedTexts, m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider"))) { dlg.TextsToShow = textsToShow.ToList(); dlg.TreeViewLabel = ITextStrings.ksSelectSectionsExported; if (dlg.ShowDialog(this) == DialogResult.OK) { m_objs.AddRange(dlg.GetListOfIncludedTexts()); } } return(m_objs.Count > 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets flag to indicate whether this mapping's begin marker is in use in the given /// import source -- Use this version only for non-Paratext 6. /// </summary> /// <param name="importDomain">Import domain of the source</param> /// <param name="icuLocale">ICU locale of the import source</param> /// <param name="noteType">The default note type for the import source</param> /// <param name="value"><c>true</c> if the marker is in use</param> /// ------------------------------------------------------------------------------------ public void SetIsInUse(ImportDomain importDomain, string icuLocale, ICmAnnotationDefn noteType, bool value) { m_inUse[ScriptureServices.CreateImportSourceKey(importDomain, icuLocale, noteType)] = value; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determine the default mapping for the given marker /// </summary> /// <param name="marker">The begin marker</param> /// <param name="styleName">The stylename, or null (output)</param> /// <param name="excluded">Flag indicating whether data marked up with this marker /// should be excluded (output)</param> /// <param name="target">Target type (output)</param> /// <param name="markerDomain"></param> /// <returns><c>true</c> if a default mapping was found for the given marker; /// <c>false</c> otherwise.</returns> /// ------------------------------------------------------------------------------------ private bool GetDefaultMapping(string marker, out string styleName, out bool excluded, out MappingTargetType target, ref MarkerDomain markerDomain) { styleName = null; excluded = false; target = MappingTargetType.TEStyle; if (s_defaultMappings.ContainsKey(marker)) { styleName = s_defaultMappings[marker]; markerDomain = ScriptureServices.GetDefaultDomainForStyle(m_stylesheet, styleName); return(true); } if (s_defaultExclusions.ContainsKey(marker)) { excluded = true; return(true); } if (s_defaultProperties.ContainsKey(marker)) { switch (s_defaultProperties[marker]) { case "Figure": target = MappingTargetType.Figure; return(true); case "FigureCaption": target = MappingTargetType.FigureCaption; return(true); case "FigureCopyright": target = MappingTargetType.FigureCopyright; return(true); case "FigureDescription": target = MappingTargetType.FigureDescription; return(true); case "FigureFilename": target = MappingTargetType.FigureFilename; return(true); case "FigureLayoutPosition": target = MappingTargetType.FigureLayoutPosition; return(true); case "FigureRefRange": target = MappingTargetType.FigureRefRange; return(true); case "FigureScale": target = MappingTargetType.FigureScale; return(true); case "ChapterLabel": target = MappingTargetType.ChapterLabel; return(true); case "TitleShort": target = MappingTargetType.TitleShort; return(true); case "DefaultParagraphCharacters": target = MappingTargetType.TEStyle; styleName = ResourceHelper.DefaultParaCharsStyleName; return(true); case "DefaultFootnoteCharacters": target = MappingTargetType.TEStyle; styleName = ResourceHelper.DefaultParaCharsStyleName; markerDomain = MarkerDomain.Footnote; return(true); } } return(false); }
public void MultipleParas() { var paraFactory = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>(); IScrTxtPara paraPrev = paraFactory.CreateWithStyle(m_stText, 0, ScrStyleNames.NormalParagraph); IScrTxtPara paraFirst = paraFactory.CreateWithStyle(m_stText, 0, ScrStyleNames.NormalParagraph); IScrTxtPara paraNext = paraFactory.CreateWithStyle(m_stText, ScrStyleNames.NormalParagraph); IScrTxtPara paraLast = paraFactory.CreateWithStyle(m_stText, ScrStyleNames.NormalParagraph); string pc1 = "Das buch ist rot. "; string pc2 = "Das Madchen ist shon."; string verse1 = "9"; string pc3 = "Der Herr ist gross."; string pc4 = "Ich spreche nicht viel Deutsch."; string verse2 = "10"; string pc5 = "Was is das?"; string pc6 = "Wie gehts?"; ITsStrBldr bldr = m_tsf.MakeString(pc1 + pc2 + verse1 + pc3 + pc4 + verse2 + pc5, m_wsVern).GetBldr(); bldr.SetStrPropValue(pc1.Length + pc2.Length, pc1.Length + pc2.Length + verse1.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); int ichEndV1 = pc1.Length + pc2.Length + verse1.Length + pc3.Length + pc4.Length; bldr.SetStrPropValue(ichEndV1, ichEndV1 + verse2.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); var segments = GetSegments(bldr, m_para); string verse8 = "8"; bldr = m_tsf.MakeString(verse8 + pc3 + pc4, m_wsVern).GetBldr(); bldr.SetStrPropValue(0, verse8.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); GetSegments(bldr, paraFirst); bldr = m_tsf.MakeString(pc1 + pc2, m_wsVern).GetBldr(); GetSegments(bldr, paraPrev); string verse11 = "11"; bldr = m_tsf.MakeString(pc3 + verse11 + pc4, m_wsVern).GetBldr(); bldr.SetStrPropValue(pc3.Length, pc3.Length + verse11.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); GetSegments(bldr, paraNext); string verse12 = "12"; bldr = m_tsf.MakeString(verse12 + pc5 + pc6, m_wsVern).GetBldr(); bldr.SetStrPropValue(0, verse12.Length, (int)FwTextPropType.ktptNamedStyle, ScrStyleNames.VerseNumber); GetSegments(bldr, paraLast); Assert.AreEqual(7, segments.Count); Assert.AreEqual("a", ScriptureServices.VerseSegLabel(paraFirst, 1)); Assert.AreEqual("b", ScriptureServices.VerseSegLabel(paraFirst, 2)); Assert.AreEqual("c", ScriptureServices.VerseSegLabel(paraPrev, 0)); Assert.AreEqual("d", ScriptureServices.VerseSegLabel(paraPrev, 1)); Assert.AreEqual("e", ScriptureServices.VerseSegLabel(m_para, 0)); Assert.AreEqual("f", ScriptureServices.VerseSegLabel(m_para, 1)); Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 3)); Assert.AreEqual("b", ScriptureServices.VerseSegLabel(m_para, 4)); Assert.AreEqual("a", ScriptureServices.VerseSegLabel(m_para, 6), "should have label because seg in following para"); Assert.AreEqual("b", ScriptureServices.VerseSegLabel(paraNext, 0), "should have label due to previous para"); Assert.AreEqual("", ScriptureServices.VerseSegLabel(paraNext, 2), "should have no label because next para starts with verse"); }