/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a ScrImportFileInfo from a CmFile. This is used when populating the /// file list from the database. /// </summary> /// <param name="file">The CmFile</param> /// <param name="mappingList">List of mappings to which newly found mappings /// should (and will) be added</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="wsId">The ICU locale of the source to which this file belongs /// (null for Scripture source)</param> /// <param name="noteType">The CmAnnotationDefn of the source to which /// this file belongs (only used for Note sources)</param> /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers /// must start on a new line, but Paratext considers all backslashes in the data to be /// SF markers.)</param> /// ------------------------------------------------------------------------------------ internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain, string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) : this(file.AbsoluteInternalPath, mappingList, domain, wsId, noteType, scanInlineBackslashMarkers) { m_file = file; }
/// ------------------------------------------------------------------------------------ /// <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) : this(beginMarker, endMarker, isExcluded, mappingTarget, domain, styleName, wsId, noteType, false, ImportDomain.Main /*This will be ignored*/) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create and Check an Annotation /// </summary> /// <param name="hvoParaStart">The hvo para start.</param> /// <param name="hvoParaEnd">The hvo para end.</param> /// <param name="startRef">The start ref.</param> /// <param name="endRef">The end ref.</param> /// <param name="startOffset">The start offset.</param> /// <param name="endOffset">The end offset.</param> /// <param name="tssQuote">The text in the quote.</param> /// <param name="sel">selection in main window</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IScrScriptureNote CreateAndCheckAnnotation(ICmObject topObj, ICmObject bottomObj, int startRef, int endRef, int startOffset, int endOffset, string strQuote) { ILangProject lp = Cache.LangProject; ICmAnnotationDefn transNoteAnnDefn = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().TranslatorAnnotationDefn; // Get information from the selection about the location of the annotation. ITsStrBldr tssBldrQuote = TsStrBldrClass.Create(); tssBldrQuote.Replace(0, 0, strQuote, StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs)); IScrScriptureNote ann = m_notesEditingHelper.InsertNote(transNoteAnnDefn, startRef, endRef, topObj, bottomObj, startOffset, endOffset, tssBldrQuote.GetString()); Assert.IsNotNull(ann); Assert.AreEqual(transNoteAnnDefn, ann.AnnotationTypeRA, "Wrong type of note created"); Assert.AreEqual(topObj, ann.BeginObjectRA, "Wrong paragraph annotated"); Assert.AreEqual(bottomObj, ann.EndObjectRA, "Wrong paragraph annotated"); Assert.AreEqual(startRef, ann.BeginRef, "Should have the correct start para reference"); Assert.AreEqual(endRef, ann.EndRef, "Should have the correct end para reference"); Assert.AreEqual(startOffset, ann.BeginOffset, "Should have the correct starting char offset"); Assert.AreEqual(endOffset, ann.EndOffset, "Should have the correct ending char offset"); Assert.AreEqual(lp.DefaultUserAgent, ann.SourceRA, "Wrong agent"); VerifyInitializedText(ann.DiscussionOA, "Discussion"); Assert.AreEqual(tssBldrQuote.Text, ((IStTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text); VerifyInitializedText(ann.RecommendationOA, "Recommendation"); VerifyInitializedText(ann.ResolutionOA, "Resolution"); return(ann); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a <see cref="ScrImportFileInfo"/> based on a file. This is used to build an /// in-memory list of files. /// </summary> /// <param name="fileName">Name of the file whose info this represents</param> /// <param name="mappingList">Sorted list of mappings to which newly found mappings /// should (and will) be added</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="wsId">The writing system identifier of the source to which this file /// belongs (null for Scripture source)</param> /// <param name="noteType">The CmAnnotationDefn of the source to which /// this file belongs (only used for Note sources)</param> /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers /// must start on a new line, but Paratext considers all backslashes in the data to be /// SF markers.)</param> /// ------------------------------------------------------------------------------------ public virtual IScrImportFileInfo Create(string fileName, ScrMappingList mappingList, ImportDomain domain, string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) { return(new ScrImportFileInfo(fileName, mappingList, domain, wsId, noteType, scanInlineBackslashMarkers)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the m_btnOk control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> /// ------------------------------------------------------------------------------------ private void btnOk_Click(object sender, EventArgs e) { using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(m_cache.ActionHandlerAccessor)) { ICmCell cell; string fmtClassFlid = ScrScriptureNoteTags.kClassId + ",{0}|"; StringBuilder bldr = new StringBuilder(); m_filter.RowsOS[0].CellsOS.Clear(); if (chkStatus.Checked) { bldr.AppendFormat(fmtClassFlid, ScrScriptureNoteTags.kflidResolutionStatus); cell = m_cellFactory.Create(); m_filter.RowsOS[0].CellsOS.Add(cell); int value = (rbResolved.Checked ? 1 : 0); cell.SetIntegerMatchCriteria(ComparisonTypes.kEquals, value); } if (chkType.Checked) { bldr.AppendFormat(fmtClassFlid, CmAnnotationTags.kflidAnnotationType); cell = m_cellFactory.Create(); m_filter.RowsOS[0].CellsOS.Add(cell); ICmAnnotationDefn type = m_cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().GetObject( rbConsultant.Checked ? CmAnnotationDefnTags.kguidAnnConsultantNote : CmAnnotationDefnTags.kguidAnnTranslatorNote); cell.SetObjectMatchCriteria(type, false, false); } if (chkScrRange.Checked) { bldr.AppendFormat(fmtClassFlid, CmBaseAnnotationTags.kflidBeginRef); bldr.AppendFormat(fmtClassFlid, CmBaseAnnotationTags.kflidBeginRef); ScrReference startRef = (scrBookFrom.ScReference.Chapter == 1 && scrBookFrom.ScReference.Verse == 1) ? new ScrReference(scrBookFrom.ScReference.Book, 0, 0, m_scr.Versification) : scrBookFrom.ScReference; cell = m_cellFactory.Create(); m_filter.RowsOS[0].CellsOS.Add(cell); cell.SetIntegerMatchCriteria(ComparisonTypes.kGreaterThanEqual, startRef); cell = m_cellFactory.Create(); m_filter.RowsOS[0].CellsOS.Add(cell); cell.SetIntegerMatchCriteria(ComparisonTypes.kLessThanEqual, scrBookTo.ScReference); } m_filter.ColumnInfo = bldr.ToString().TrimEnd('|'); if (chkCategory.Checked) { tvCatagories.UpdateFilter(m_filter); } undoHelper.RollBack = false; } }
public void AddFilesToNotesList_User() { m_builder.SelectTab(2); TempSFFileMaker fileMaker = new TempSFFileMaker(); string file1 = fileMaker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1" }); string file2 = fileMaker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1" }); string file3 = fileMaker.CreateFile("EXO", new string[] { @"\c 1", @"\v 1" }); m_builder.m_filenamesToAdd = new string[] { file1 }; m_builder.SelectNotesWritingSystem("German"); m_builder.SelectNoteType("Translator"); m_builder.ClickAddButton(); m_builder.m_filenamesToAdd = new string[] { file2, file3 }; m_builder.SelectNotesWritingSystem("German"); m_builder.SelectNoteType("Consultant"); m_builder.ClickAddButton(); // Make sure two files were added to the German Consultant Notes list Assert.AreEqual(2, m_builder.NotesFiles.Count); Assert.AreEqual(2, m_builder.NotesListView.Items.Count); m_builder.SelectNoteType("Translator"); // Make sure one file was added to the German Translator Notes list Assert.AreEqual(1, m_builder.NotesFiles.Count); Assert.AreEqual(1, m_builder.NotesListView.Items.Count); // Make sure all three annotation files were added properly to the import project ImportFileSource files = m_settings.GetImportFiles(ImportDomain.Annotations); Assert.AreEqual(3, files.Count); ICmAnnotationDefn translatorNoteDef = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().TranslatorAnnotationDefn; ICmAnnotationDefn consultantNoteDef = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().ConsultantAnnotationDefn; foreach (ScrImportFileInfo info in m_settings.GetImportFiles(ImportDomain.Annotations)) { Assert.AreEqual("de", info.WsId); if (info.FileName == file1) { Assert.AreEqual(new ScrReference(1, 1, 1, m_scr.Versification), info.StartRef); Assert.AreEqual(translatorNoteDef, info.NoteType); } else if (info.FileName == file2) { Assert.AreEqual(new ScrReference(1, 1, 1, m_scr.Versification), info.StartRef); Assert.AreEqual(consultantNoteDef, info.NoteType); } else if (info.FileName == file3) { Assert.AreEqual(new ScrReference(2, 1, 1, m_scr.Versification), info.StartRef); Assert.AreEqual(consultantNoteDef, info.NoteType); } else { Assert.Fail("Unexpected file in annotations import project: " + info.FileName); } } }
public void CreateFromGuid() { CheckDisposed(); ICmAnnotationDefn cad = CmAnnotationDefn.TextSegment(Cache); Assert.AreEqual("Text Segment", cad.Name.UserDefaultWritingSystem); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the exceeded error message when a check has more identical errors than /// specified for the check. /// </summary> /// <param name="checkId">The GUID which uniquely identifies the Scripture check.</param> /// <returns>error message</returns> /// ------------------------------------------------------------------------------------ private string GetExceededErrorMsg(Guid checkId) { ICmAnnotationDefn checkDef = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().GetObject(checkId); return(string.Format(StringUtils.GetUiString(ScrFdoResources.ResourceManager, "kstidExceededMaxNumberIdenticalChecks"), checkDef != null ? checkDef.Name.UserDefaultWritingSystem.Text : string.Empty)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a DummyScrImportFileInfo. /// </summary> /// <param name="fileName">Name of the file whose info this represents</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="icuLocale">The ICU locale of the source to which this file belongs /// (null for Scripture source)</param> /// <param name="noteType">The CmAnnotationDefn of the source to which this file belongs /// (only used for Note sources)</param> /// <param name="booksInFile">A list of integers representing 1-based canonical book /// numbers that are in this file</param> /// <param name="fileEncoding">The file encoding</param> /// <param name="startRef">The first reference encountered in the file</param> /// ------------------------------------------------------------------------------------ public DummyScrImportFileInfo(string fileName, ImportDomain domain, string icuLocale, ICmAnnotationDefn noteType, List<int> booksInFile, Encoding fileEncoding, ScrReference startRef) : base(fileName, null, domain, icuLocale, noteType, false) { m_booksInFile = booksInFile; m_fileEncoding = fileEncoding; m_startRef = startRef; }
/// ------------------------------------------------------------------------------------ /// <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> /// Construct a DummyScrImportFileInfo. /// </summary> /// <param name="fileName">Name of the file whose info this represents</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="icuLocale">The ICU locale of the source to which this file belongs /// (null for Scripture source)</param> /// <param name="noteType">The CmAnnotationDefn of the source to which this file belongs /// (only used for Note sources)</param> /// <param name="booksInFile">A list of integers representing 1-based canonical book /// numbers that are in this file</param> /// <param name="fileEncoding">The file encoding</param> /// <param name="startRef">The first reference encountered in the file</param> /// ------------------------------------------------------------------------------------ public DummyScrImportFileInfo(string fileName, ImportDomain domain, string icuLocale, ICmAnnotationDefn noteType, List <int> booksInFile, Encoding fileEncoding, ScrReference startRef) : base(fileName, null, domain, icuLocale, noteType, false) { m_booksInFile = booksInFile; m_fileEncoding = fileEncoding; m_startRef = startRef; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Resets the in use flags to false for all mappings in the list. /// Use this for non-Paratext 6. /// </summary> /// <param name="importDomain">Import domain</param> /// <param name="icuLocale">ICU locale of the import source</param> /// <param name="noteType">The default note type for the import source</param> /// ------------------------------------------------------------------------------------ internal void ResetInUseFlags(ImportDomain importDomain, string icuLocale, ICmAnnotationDefn noteType) { foreach (ImportMappingInfo mapping in m_list.Values) { mapping.SetIsInUse(importDomain, icuLocale, noteType, false); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor with ContextValues and MarkerDomain as a parameters. /// </summary> /// <param name="mapping">The Scr marker mapping.</param> /// <param name="ws">character or paragraph writing system</param> /// <param name="styleSheet">The style sheet</param> /// ------------------------------------------------------------------------------------ public ImportStyleProxy(ImportMappingInfo mapping, int ws, FwStyleSheet styleSheet) : this(mapping.StyleName, mapping.IsInline ? StyleType.kstCharacter : StyleType.kstParagraph, ws, ContextValues.General, mapping.Domain, styleSheet) { Excluded = mapping.IsExcluded; MappingTarget = mapping.MappingTarget; m_annotationType = mapping.NoteType; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates the scripture checks and updates the annotation definitions by checking /// that for each check we have a corresponding annotation definition in the database. /// </summary> /// <param name="dataSource">The data source.</param> /// ------------------------------------------------------------------------------------ private static SortedList <ScrCheckKey, IScriptureCheck> InstantiateChecks( ScrChecksDataSource dataSource) { FdoCache cache = dataSource.Cache; Dictionary <Guid, ICmAnnotationDefn> errorTypes = new Dictionary <Guid, ICmAnnotationDefn>(); ICmAnnotationDefn annDefnChkError = cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().GetObject(CmAnnotationDefnTags.kguidAnnCheckingError); foreach (ICmAnnotationDefn errorType in annDefnChkError.SubPossibilitiesOS) { errorTypes[errorType.Guid] = errorType; } SortedList <ScrCheckKey, IScriptureCheck> scriptureChecks = new SortedList <ScrCheckKey, IScriptureCheck>(); foreach (Type type in s_scrCheckList) { IScriptureCheck scrCheck = (IScriptureCheck)Activator.CreateInstance(type, dataSource); if (scrCheck == null) { continue; } // Get the localized version of the check name string scrCheckName = GetCheckProperty(ScrFdoResources.ResourceManager, scrCheck.CheckId, "Name", scrCheck.CheckName); scriptureChecks.Add(new ScrCheckKey(scrCheck.RelativeOrder, scrCheckName), scrCheck); ICmAnnotationDefn chkType; if (!errorTypes.TryGetValue(scrCheck.CheckId, out chkType)) { chkType = cache.ServiceLocator.GetInstance <ICmAnnotationDefnFactory>().Create(scrCheck.CheckId, annDefnChkError); annDefnChkError.SubPossibilitiesOS.Add(chkType); chkType.IsProtected = true; chkType.Name.UserDefaultWritingSystem = TsStringUtils.MakeTss(scrCheckName, cache.DefaultUserWs); chkType.Description.UserDefaultWritingSystem = TsStringUtils.MakeTss(scrCheck.Description, cache.DefaultUserWs); chkType.HelpId = scrCheck.CheckName.Replace(' ', '_'); InheritAttributes(annDefnChkError, chkType); } else if (chkType.Name.UserDefaultWritingSystem.Text != scrCheckName) { // Store the localized version of the check name as the current UI name. chkType.Name.UserDefaultWritingSystem = TsStringUtils.MakeTss(scrCheckName, cache.DefaultUserWs); } } return(scriptureChecks); }
/// ------------------------------------------------------------------------------------ /// <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; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a ScrImportFileInfo based on a filename. This is used to build an /// in-memory list of files. /// </summary> /// <param name="fileName">Name of the file whose info this represents</param> /// <param name="mappingList">Sorted list of mappings to which newly found mappings /// should (and will) be added</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="wsId">The writing system identifier of the source to which this file /// belongs (null for Scripture source)</param> /// <param name="noteType">The CmAnnotationDefn of the source to which /// this file belongs (only used for Note sources)</param> /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers /// must start on a new line, but Paratext considers all backslashes in the data to be /// SF markers.)</param> /// ------------------------------------------------------------------------------------ public ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain, string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) { m_fileName = fileName; m_mappingList = mappingList; m_domain = domain; m_wsId = wsId; m_noteType = noteType; m_doStrictFileChecking = false; ScanInlineBackslashMarkers = scanInlineBackslashMarkers; Initialize(); }
public void MatchesCriteria_AtomicObjectMatch_NotEmptyNoSubitems() { ICmAnnotationDefnRepository annDefnRepo = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>(); ICmAnnotationDefn consultantNoteDefn = annDefnRepo.ConsultantAnnotationDefn; ICmAnnotationDefn translatorNoteDefn = annDefnRepo.TranslatorAnnotationDefn; m_cell.SetObjectMatchCriteria(consultantNoteDefn, false, false); Assert.IsTrue(m_cell.MatchesCriteria(consultantNoteDefn.Hvo)); Assert.IsFalse(m_cell.MatchesCriteria(translatorNoteDefn.Hvo)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Copy "inheritable" attributes from the high-level error annotation definition to /// the given subpossibility. /// </summary> /// <param name="copyFrom">The ann defn to copy attributes from.</param> /// <param name="copyTo">The ann defn to copy attributes to.</param> /// ------------------------------------------------------------------------------------ private static void InheritAttributes(ICmAnnotationDefn copyFrom, ICmAnnotationDefn copyTo) { copyTo.AllowsComment = copyFrom.AllowsComment; copyTo.AllowsFeatureStructure = copyFrom.AllowsFeatureStructure; copyTo.AllowsInstanceOf = copyFrom.AllowsInstanceOf; copyTo.CanCreateOrphan = copyFrom.CanCreateOrphan; copyTo.CopyCutPastable = copyFrom.CopyCutPastable; copyTo.Hidden = copyFrom.Hidden; copyTo.Multi = copyFrom.Multi; copyTo.PromptUser = copyFrom.PromptUser; copyTo.Severity = copyFrom.Severity; copyTo.UserCanCreate = copyFrom.UserCanCreate; copyTo.ZeroWidth = copyFrom.ZeroWidth; }
// Make some sort of wfics for the text of the specified paragraph. Assumes no double spaces! // Caches results and does not repeat on same para internal int[] MakeAnnotations(StTxtPara para) { int[] previous; if (m_annotations.TryGetValue(para.Hvo, out previous)) { return(previous); } string contents = para.Contents.Text; string[] words = contents.Split(new char[] { ' ', '.' }); int ich = 0; List <int> results = new List <int>(); ICmAnnotationDefn WficType = CmAnnotationDefn.Twfic(Cache); foreach (string word in words) { if (word == "") { ich++; continue; } WfiWordform wordform = new WfiWordform(); Cache.LangProject.WordformInventoryOA.WordformsOC.Add(wordform); wordform.Form.SetAlternative(word, Cache.DefaultVernWs); // JohnT: This should ideally use CmBaseAnnotation.CreateUnownedCba. But most or all uses of this // method are memory-only tests, and that method requires a database. CmBaseAnnotation cba = new CmBaseAnnotation(); Cache.LangProject.AnnotationsOC.Add(cba); cba.BeginOffset = ich; ich += word.Length; cba.EndOffset = ich; ich++; // past space or dot cba.BeginObjectRA = para; cba.AnnotationTypeRA = WficType; //cba.AnnotationTypeRA = ?? can we get CmAnnotationDefn.Twfic(Cache) with a non-database cache? WfiAnalysis analysis = new WfiAnalysis(); wordform.AnalysesOC.Add(analysis); WfiGloss gloss = new WfiGloss(); analysis.MeaningsOC.Add(gloss); gloss.Form.SetAlternative(word + "Gloss" + ich, Cache.DefaultAnalWs); cba.InstanceOfRA = gloss; results.Add(cba.Hvo); } int[] result = results.ToArray(); m_annotations[para.Hvo] = result; return(result); }
/// ------------------------------------------------------------------------------------ /// <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> /// Get the annotation type from the Guid. /// </summary> /// <param name="defn">The defn.</param> /// <returns> /// The annotation type for <paramref name="defn"/>. /// </returns> /// ------------------------------------------------------------------------------------ public static NoteType GetAnnotationType(ICmAnnotationDefn defn) { Guid guid = defn.Guid; if (guid == CmAnnotationDefnTags.kguidAnnConsultantNote) { return(NoteType.Consultant); } else if (guid == CmAnnotationDefnTags.kguidAnnTranslatorNote) { return(NoteType.Translator); } else //if (guid == LangProject.kguidAnnCheckingError) -- There are multiple sub-types of checking errors { return(NoteType.CheckingError); } //return NoteType.Unknown; }
/// ------------------------------------------------------------------------------------ /// <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> /// Add the annotation types with their guids to the propery possibility or list. /// TODO: these lists have other properties that need to be set at some point. Hopefully we'll /// just load that from NewLangProj or some other xml file. /// </summary> /// <param name="lp"></param> private static void SetupAnnotationDefns(ILangProject lp) { ICmPossibilityList posList = lp.AnnotationDefsOA; // Text Annotations ICmAnnotationDefn txtAnnDef = AddAnnotationDefn(posList, CmAnnotationDefnTags.kguidAnnText); // Notes ICmAnnotationDefn noteAnnDef = AddAnnotationDefn(posList, CmAnnotationDefnTags.kguidAnnNote); ICmAnnotationDefn noteSubDef = AddAnnotationDefn(noteAnnDef, CmAnnotationDefnTags.kguidAnnConsultantNote); noteSubDef.UserCanCreate = true; noteSubDef.Name.UserDefaultWritingSystem = TsStringUtils.MakeTss("Consultant", lp.Cache.DefaultUserWs); noteSubDef = AddAnnotationDefn(noteAnnDef, CmAnnotationDefnTags.kguidAnnTranslatorNote); noteSubDef.UserCanCreate = true; noteSubDef.Name.UserDefaultWritingSystem = TsStringUtils.MakeTss("Translator", lp.Cache.DefaultUserWs); // Others AddAnnotationDefn(posList, CmAnnotationDefnTags.kguidAnnComment); AddAnnotationDefn(posList, CmAnnotationDefnTags.kguidAnnCheckingError); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts a note referencing the currently selected paragraph. /// </summary> /// <param name="noteType">Type of note</param> /// <param name="startRef">reference at beginning of selection</param> /// <param name="endRef">reference at end of selection</param> /// <param name="topObj">The object where quoted text begins.</param> /// <param name="bottomObj">The object where quoted text ends.</param> /// <param name="startOffset">The starting character offset.</param> /// <param name="endOffset">The ending character offset.</param> /// <param name="tssQuote">The text of the quote.</param> /// <returns>The inserted note</returns> /// ------------------------------------------------------------------------------------ public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef, BCVRef endRef, ICmObject topObj, ICmObject bottomObj, int startOffset, int endOffset, ITsString tssQuote) { CheckDisposed(); int iPos; IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[startRef.Book - 1]; StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache); quoteParaBldr.ParaStyleName = ScrStyleNames.Remark; quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote); IScrScriptureNote annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj, noteType.Guid, startOffset, endOffset, quoteParaBldr, null, null, null, out iPos); RegisterScrollCallBack(startRef.Book, iPos); // REVIEW: Do we need to create a synch record? return(annotation); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the type (and possibly subtype) of the given Scripture annotation. /// </summary> /// ------------------------------------------------------------------------------------ private void SetNoteType(IScrScriptureNote ann) { Debug.Assert(ann.AnnotationTypeRA != null, "The annotation type is not set!"); if (ann.AnnotationTypeRA == null) { return; } if (m_guidType == CmAnnotationDefnTags.kguidAnnTranslatorNote) { AnnotationType = XmlNoteType.Translator; } else if (m_guidType == CmAnnotationDefnTags.kguidAnnConsultantNote) { AnnotationType = XmlNoteType.Consultant; } else if (ann.ResolutionStatus == NoteStatus.Closed) // ignored checking error { ICmAnnotationDefn defn = ann.AnnotationTypeRA; SubType = GetCheckingErrorSubType(defn.Guid); AnnotationType = XmlNoteType.PreTypesettingCheck; } }
/// ------------------------------------------------------------------------------------ /// <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> /// Add a file to the project, and determine the file encoding and mappings. /// </summary> /// <param name="fileName">file name to add</param> /// <param name="domain">The domain to add the file to</param> /// <param name="wsId">The writing system identifier for the source (ignored for /// scripture domain)</param> /// <param name="noteType">The CmAnnotationDefn for the note type /// (ignored for back trans and scripture domains)</param> /// <param name="fileRemovedHandler">Handler for FileRemoved event (can be null if /// caller doesn't need to know if a file is removed as a result of a overlapping /// conflict</param> /// <returns>The IScrImportFileInfo representing the added file</returns> /// ------------------------------------------------------------------------------------ public IScrImportFileInfo AddFile(string fileName, ImportDomain domain, string wsId, ICmAnnotationDefn noteType, ScrImportFileEventHandler fileRemovedHandler) { lock (SyncRoot) { if (ImportTypeEnum == TypeOfImport.Paratext6) throw new InvalidOperationException("Cannot add files to Paratext 6 import Projects"); // first check to see if the file is already in the project, // if so - then remove the file. RemoveFile(fileName, domain, wsId, noteType); // Make a new file info entry for the added file IScrImportFileInfo info = m_scrImpFinfoFact.Create(fileName, GetMappingListForDomain(domain), domain, wsId, noteType, (ImportTypeEnum == TypeOfImport.Paratext5)); ScrSfFileList fileList = GetFileList(domain, wsId, noteType, true); if (fileRemovedHandler != null) fileList.FileRemoved += fileRemovedHandler; int index; try { index = fileList.Add(info); } finally { if (fileRemovedHandler != null) fileList.FileRemoved -= fileRemovedHandler; } return (index == -1) ? null : info; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor (used for testing) for mapping a non-inline marker to a style. /// </summary> /// ------------------------------------------------------------------------------------ public ImportMappingInfo(string beginMarker, MarkerDomain domain, string styleName, string icuLocale, ICmAnnotationDefn noteType) : this(beginMarker, null, false, MappingTargetType.TEStyle, domain, styleName, icuLocale, noteType) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts a note referencing the currently selected paragraph. /// </summary> /// <param name="noteType">Type of note</param> /// <param name="startRef">reference at beginning of selection</param> /// <param name="endRef">reference at end of selection</param> /// <param name="topObj">The object where quoted text begins.</param> /// <param name="bottomObj">The object where quoted text ends.</param> /// <param name="wsSelector">The writing system selector.</param> /// <param name="startOffset">The starting character offset.</param> /// <param name="endOffset">The ending character offset.</param> /// <param name="tssQuote">The text of the quote.</param> /// <returns>The inserted note</returns> /// ------------------------------------------------------------------------------------ public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef, BCVRef endRef, CmObject topObj, CmObject bottomObj, int wsSelector, int startOffset, int endOffset, ITsString tssQuote) { CheckDisposed(); TeNotesVc notesVc = CurrentNotesVc; IScrScriptureNote annotation; string sUndo, sRedo; int iPos; ScrBookAnnotations annotations = (ScrBookAnnotations)m_scr.BookAnnotationsOS[startRef.Book - 1]; TeResourceHelper.MakeUndoRedoLabels("kstidInsertAnnotation", out sUndo, out sRedo); string sType = noteType.Name.UserDefaultWritingSystem; sUndo = string.Format(sUndo, sType); sRedo = string.Format(sRedo, sType); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.MainCacheAccessor, Control as IVwRootSite, sUndo, sRedo, false)) { try { StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache); quoteParaBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark); quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote); annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj, noteType.Guid, wsSelector, startOffset, endOffset, quoteParaBldr, null, null, null, out iPos); if (notesVc != null) { // tell the VC that the newly inserted item should be expanded. That will cause // the view to be updated to show the new note. notesVc.ExpandItem(annotation.Hvo); notesVc.ExpandItem(annotation.DiscussionOAHvo); } } catch { undoTaskHelper.EndUndoTask = false; FwApp.App.RefreshAllViews(m_cache); throw; } } if (Control != null) Control.Focus(); // Make a selection in the discussion so the user can start to type if (notesVc != null && notesVc.NotesSequenceHandler != null) { // Get the corresponding index in the virtual property. iPos = notesVc.NotesSequenceHandler.GetVirtualIndex(annotations.Hvo, iPos); } IVwRootSite rootSite = Control as IVwRootSite; MakeSelectionInNote(notesVc, startRef.Book - 1, iPos, rootSite, true); // REVIEW: Do we need to create a synch record? return annotation; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize the scripture importer /// </summary> /// ------------------------------------------------------------------------------------ protected void Initialize() { m_wsAnal = m_cache.DefaultAnalWs; m_wsVern = m_cache.DefaultVernWs; m_wsPara = m_cache.DefaultVernWs; m_scr = m_cache.LangProject.TranslatedScriptureOA; InitInterpretFootnoteSettings(); ScrImportSet importSettings = (m_settings as ScrImportSet); // ENHANCE (TomB): Might want to make it possible to end importing in the middle // of a book someday. ScrReference endRef = new ScrReference(importSettings.EndRef, m_scr.Versification); ScrReference startRef = new ScrReference(importSettings.StartRef, m_scr.Versification); m_nBookNumber = importSettings.StartRef.Book; importSettings.EndRef = endRef = endRef.LastReferenceForBook; // Initialize scripture object InitScriptureObject(); // Load the scripture text project & enum LoadScriptureProject(); // Display progress if one was supplied if (m_importCallbacks.IsDisplayingUi) { int cChapters = ScrReference.GetNumberOfChaptersInRange(SOWrapper.BooksPresent, startRef, endRef); int nMax = m_settings.ImportTranslation ? cChapters : 0; if (SOWrapper.HasNonInterleavedBT && m_settings.ImportBackTranslation) nMax += cChapters; if (SOWrapper.HasNonInterleavedNotes && m_settings.ImportAnnotations) nMax += cChapters; m_importCallbacks.Maximum = nMax; } // Init our set of style proxies LoadImportMappingProxies(); // Init member vars special paragraph style proxies, used as fallbacks in case // import data lacks a paragraph style. // For now we always use the default vernacular writing system. This may change // when we are able to import paratext project proxies with multiple // domains (vern, back transl, notes) m_BookTitleParaProxy = new ImportStyleProxy(ScrStyleNames.MainBookTitle, StyleType.kstParagraph, m_wsVern, ContextValues.Title, m_styleSheet); Debug.Assert(m_BookTitleParaProxy.Context == ContextValues.Title); m_ScrSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.SectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroSectionHeadParaProxy = new ImportStyleProxy(ScrStyleNames.IntroSectionHead, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); m_DefaultScrParaProxy = new ImportStyleProxy(ScrStyleNames.NormalParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Text, m_styleSheet); m_DefaultIntroParaProxy = new ImportStyleProxy(ScrStyleNames.IntroParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Intro, m_styleSheet); m_DefaultFootnoteParaProxy = new ImportStyleProxy(ScrStyleNames.NormalFootnoteParagraph, StyleType.kstParagraph, m_wsVern, ContextValues.Note, m_styleSheet); m_DefaultAnnotationStyleProxy = new ImportStyleProxy(ScrStyleNames.Remark, StyleType.kstParagraph, m_wsAnal, ContextValues.Annotation, m_styleSheet); // Make a paragraph builder. We will keep re-using this every time we build a paragraph. m_ParaBldr = new StTxtParaBldr(m_cache); // Handle the case where the very first marker (after the \id line) is a // character style. m_ParaBldr.ParaStylePropsProxy = m_DefaultIntroParaProxy; // Build generic character props for use with different runs of text and analysis // character properties ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); // analysis character properties tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsAnal); m_analTextProps = tsPropsBldr.GetTextProps(); // vernacular character properties tsPropsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, m_wsVern); m_vernTextProps = tsPropsBldr.GetTextProps(); // Get a reference to the annotation definition of translator notes (to use as default note type) m_scrTranslatorAnnotationDef = new CmAnnotationDefn(m_cache, LangProject.kguidAnnTranslatorNote); }
private ICmBaseAnnotation Create(ICmAnnotationDefn annType, ICmObject instanceOf, IStTxtPara beginObject, int beginOffset, int endOffset) { ICmBaseAnnotation cba = Create(); // for now we're treating annotations as ownerless, even though that's not what the // model says. eventually they'll be owned by things like paragraphs or other annotations. if (cba.Cache == null) ((ICmObjectInternal) cba).InitializeNewOwnerlessCmObject(m_cache); else Debug.Fail("TODO(EricP): get rid of the code for InitializeNewOwnerlessCmObject"); cba.AnnotationTypeRA = annType; SegmentServices.SetCbaFields(cba, beginObject, beginOffset, endOffset, instanceOf); return cba; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor (used for testing) for mapping an inline marker to a style. /// </summary> /// ------------------------------------------------------------------------------------ public ImportMappingInfo(string beginMarker, string endMarker, MarkerDomain domain, string styleName, string wsId, ICmAnnotationDefn noteType) : this(beginMarker, endMarker, false, MappingTargetType.TEStyle, domain, styleName, wsId, noteType) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts a note referencing the currently selected paragraph. /// </summary> /// <param name="noteType">Type of note</param> /// <param name="startRef">reference at beginning of selection</param> /// <param name="endRef">reference at end of selection</param> /// <param name="topObj">The object where quoted text begins.</param> /// <param name="bottomObj">The object where quoted text ends.</param> /// <param name="startOffset">The starting character offset.</param> /// <param name="endOffset">The ending character offset.</param> /// <param name="tssQuote">The text of the quote.</param> /// <returns>The inserted note</returns> /// ------------------------------------------------------------------------------------ public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef, BCVRef endRef, ICmObject topObj, ICmObject bottomObj, int startOffset, int endOffset, ITsString tssQuote) { CheckDisposed(); int iPos; IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[startRef.Book - 1]; StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache); quoteParaBldr.ParaStyleName = ScrStyleNames.Remark; quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote); IScrScriptureNote annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj, noteType.Guid, startOffset, endOffset, quoteParaBldr, null, null, null, out iPos); RegisterScrollCallBack(startRef.Book, iPos); // REVIEW: Do we need to create a synch record? return annotation; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a ScrImportFileInfo based on a Toolbox (i.e., non-Paratext 5) filename. /// This is used only in tests. /// </summary> /// <param name="fileName">Name of the file whose info this represents</param> /// <param name="mappingList">Sorted list of mappings to which newly found mappings /// should (and will) be added</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="wsId">The writing system identifier of the source to which this file /// belongs (null for Scripture source)</param> /// <param name="noteType">The CmAnnotationDefn of the source to which /// this file belongs (only used for Note sources)</param> /// ------------------------------------------------------------------------------------ internal ScrImportFileInfo(string fileName, ScrMappingList mappingList, ImportDomain domain, string wsId, ICmAnnotationDefn noteType) : this(fileName, mappingList, domain, wsId, noteType, false) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a mocked <see cref="IScrImportFileInfo"/>. This is used to build an /// in-memory list of files. /// </summary> /// <param name="fileName">Name of the file whose info this represents</param> /// <param name="mappingList">Sorted list of mappings to which newly found mappings /// should (and will) be added</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="wsId">The writing system identifier of the source to which this file /// belongs (null for Scripture source)</param> /// <param name="noteType">The CmAnnotationDefn of the source to which /// this file belongs (only used for Note sources)</param> /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers /// must start on a new line, but Paratext considers all backslashes in the data to be /// SF markers.)</param> /// ------------------------------------------------------------------------------------ public override IScrImportFileInfo Create(string fileName, ScrMappingList mappingList, ImportDomain domain, string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) { IScrImportFileInfo info = MockRepository.GenerateStub<IScrImportFileInfo>(); m_mockedScrImportFinfos[fileName] = info; info.Stub(x => x.FileName).Return(fileName); info.Stub(x => x.WsId).Return(wsId); info.Stub(x => x.NoteType).Return(noteType); return info; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new indirect annotation /// </summary> /// <param name="annType">The type of indirect annotation</param> /// <param name="annotationsToWhichThisApplies">Zero or more annotations to which this /// annotation applies (typically a single segment)</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ICmIndirectAnnotation Create(ICmAnnotationDefn annType, params ICmAnnotation[] annotationsToWhichThisApplies) { var ann = Create(); // REVIEW(FWR-209): Indirect annotations, for now, should be treated ownerless. if (ann.Cache == null) ((ICmObjectInternal)ann).InitializeNewOwnerlessCmObject(m_cache); else Debug.Fail("TODO(EricP): get rid of the code for InitializeNewOwnerlessCmObject"); foreach (ICmAnnotation annot in annotationsToWhichThisApplies) { Debug.Assert(annot != null); ann.AppliesToRS.Add(annot); } // REVIEW(FWR-209): Should we check to ensure that the type is not null? ann.AnnotationTypeRA = annType; return ann; }
ICmIndirectAnnotation MakeIndirectAnnotation(int[] wfics, ICmAnnotationDefn type) { using (new UndoRedoTaskHelper(Cache, "ConstituentChartDatabaseTests - MakeIndirectAnnotation()", "ConstituentChartDatabaseTests - MakeIndirectAnnotation()")) { ICmIndirectAnnotation result = (ICmIndirectAnnotation)Cache.LangProject.AnnotationsOC.Add(new CmIndirectAnnotation()); result.AnnotationTypeRA = type; foreach (int hvo in wfics) result.AppliesToRS.Append(hvo); return result; } }
ICmBaseAnnotation MakeAnnotation(StTxtPara para, ICmBaseAnnotation previous, ICmAnnotationDefn type) { using (new UndoRedoTaskHelper(Cache, "ConstituentChartDatabaseTests - MakeAnnotation()", "ConstituentChartDatabaseTests - MakeAnnotation()")) { ICmBaseAnnotation result = (ICmBaseAnnotation)Cache.LangProject.AnnotationsOC.Add(new CmBaseAnnotation()); result.BeginObjectRA = para; int prevOffset = 0; if (previous != null) prevOffset = previous.EndOffset; result.BeginOffset = prevOffset + 1; result.EndOffset = prevOffset + 2; result.AnnotationTypeRA = type; return result; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Test setup stuff /// </summary> /// ------------------------------------------------------------------------------------ public override void TestSetup() { base.TestSetup(); m_importSettings = Cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create(); m_scr.ImportSettingsOC.Add(m_importSettings); m_translatorNoteDefn = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().TranslatorAnnotationDefn; m_consultantNoteDefn = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().ConsultantAnnotationDefn; m_fileOs = new MockFileOS(); FileUtils.Manager.SetFileAdapter(m_fileOs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:DisplayAnnotationDefn"/> class. /// </summary> /// <param name="source">source CmAnnotationDefn object to construct from</param> /// ------------------------------------------------------------------------------------ public DisplayAnnotationDefn(ICmAnnotationDefn source) { m_displayName = source.Name.UserDefaultWritingSystem; m_hvo = source.Hvo; }
public void AddingFilesToDifferentLists() { TempSFFileMaker maker = new TempSFFileMaker(); string scrFileName = maker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1" }); m_settings.AddFile(scrFileName, ImportDomain.Main, null, null); string enBtFileName = maker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1" }); string esBtFileName = maker.CreateFile("MAT", new string[] { @"\c 1", @"\v 1", @"\id MRK", @"\c 1", @"\v 1" }); m_settings.AddFile(enBtFileName, ImportDomain.BackTrans, "en", null); m_settings.AddFile(esBtFileName, ImportDomain.BackTrans, "es", null); string esTransNoteFileName = maker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1 No digan asi." }); string enTransNoteFileName = maker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1 Try to find a better word." }); string enConsNoteFileName1 = maker.CreateFile("GEN", new string[] { @"\c 1", @"\v 1 Check the meaning of floobywump." }); string enConsNoteFileName2 = maker.CreateFile("MAT", new string[] { @"\c 1", @"\v 1", @"\id MRK", @"\c 1", @"\v 1" }); ICmAnnotationDefn translatorNoteDef = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().TranslatorAnnotationDefn; ICmAnnotationDefn consultantNoteDef = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>().ConsultantAnnotationDefn; m_settings.AddFile(esTransNoteFileName, ImportDomain.Annotations, "es", translatorNoteDef); m_settings.AddFile(enTransNoteFileName, ImportDomain.Annotations, "en", translatorNoteDef); m_settings.AddFile(enConsNoteFileName1, ImportDomain.Annotations, "en", consultantNoteDef); m_settings.AddFile(enConsNoteFileName2, ImportDomain.Annotations, "en", consultantNoteDef); m_builder.CallPopulateFileListsFromSettings(); // Verify the Scripture file m_builder.SelectTab(0); Assert.AreEqual(1, m_builder.ScrListView.Items.Count); Assert.AreEqual(scrFileName, m_builder.ScrListView.Items[0].Text); // Verify the English BT file m_builder.SelectTab(1); m_builder.SelectBtWritingSystem("English"); Assert.AreEqual(1, m_builder.BtListView.Items.Count); Assert.AreEqual(enBtFileName, m_builder.BtListView.Items[0].Text); Assert.AreEqual("GEN", m_builder.BtListView.Items[0].SubItems[1].Text); // Assert.AreEqual("English", m_builder.BtListView.Items[0].SubItems[2].Text); Assert.AreEqual("US-ASCII", m_builder.BtListView.Items[0].SubItems[2].Text); // Verify the Spanish BT file m_builder.SelectBtWritingSystem("Spanish"); Assert.AreEqual(1, m_builder.BtListView.Items.Count); Assert.AreEqual(esBtFileName, m_builder.BtListView.Items[0].Text); Assert.AreEqual("MAT, MRK", m_builder.BtListView.Items[0].SubItems[1].Text); // Assert.AreEqual("Spanish", m_builder.BtListView.Items[0].SubItems[2].Text); Assert.AreEqual("US-ASCII", m_builder.BtListView.Items[0].SubItems[2].Text); // verify the Spanish Translator Notes file m_builder.SelectTab(2); m_builder.SelectNoteType("Translator"); m_builder.SelectNotesWritingSystem("Spanish"); Assert.AreEqual(1, m_builder.NotesListView.Items.Count); Assert.AreEqual(esTransNoteFileName, m_builder.NotesListView.Items[0].Text); Assert.AreEqual("GEN", m_builder.NotesListView.Items[0].SubItems[1].Text); // Assert.AreEqual("Spanish", m_builder.NotesListView.Items[0].SubItems[2].Text); Assert.AreEqual("US-ASCII", m_builder.NotesListView.Items[0].SubItems[2].Text); // verify the English Translator Notes file m_builder.SelectNotesWritingSystem("English"); Assert.AreEqual(1, m_builder.NotesListView.Items.Count); Assert.AreEqual(enTransNoteFileName, m_builder.NotesListView.Items[0].Text); Assert.AreEqual("GEN", m_builder.NotesListView.Items[0].SubItems[1].Text); // Assert.AreEqual("Spanish", m_builder.NotesListView.Items[0].SubItems[2].Text); Assert.AreEqual("US-ASCII", m_builder.NotesListView.Items[0].SubItems[2].Text); // verify the English Consultant Notes files m_builder.SelectNoteType("Consultant"); Assert.AreEqual(2, m_builder.NotesListView.Items.Count); Assert.AreEqual(enConsNoteFileName1, m_builder.NotesListView.Items[0].Text); Assert.AreEqual("GEN", m_builder.NotesListView.Items[0].SubItems[1].Text); // Assert.AreEqual("Spanish", m_builder.NotesListView.Items[0].SubItems[2].Text); Assert.AreEqual("US-ASCII", m_builder.NotesListView.Items[0].SubItems[2].Text); Assert.AreEqual(enConsNoteFileName2, m_builder.NotesListView.Items[1].Text); Assert.AreEqual("MAT, MRK", m_builder.NotesListView.Items[1].SubItems[1].Text); // Assert.AreEqual("Spanish", m_builder.NotesListView.Items[1].SubItems[2].Text); Assert.AreEqual("US-ASCII", m_builder.NotesListView.Items[1].SubItems[2].Text); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts a note referencing the currently selected paragraph. /// </summary> /// <param name="noteType">Type of note</param> /// <param name="startRef">reference at beginning of selection</param> /// <param name="endRef">reference at end of selection</param> /// <param name="topObj">The object where quoted text begins.</param> /// <param name="bottomObj">The object where quoted text ends.</param> /// <param name="wsSelector">The writing system selector.</param> /// <param name="startOffset">The starting character offset.</param> /// <param name="endOffset">The ending character offset.</param> /// <param name="tssQuote">The text of the quote.</param> /// <returns>The inserted note</returns> /// ------------------------------------------------------------------------------------ public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef, BCVRef endRef, CmObject topObj, CmObject bottomObj, int wsSelector, int startOffset, int endOffset, ITsString tssQuote) { CheckDisposed(); TeNotesVc notesVc = CurrentNotesVc; IScrScriptureNote annotation; string sUndo, sRedo; int iPos; ScrBookAnnotations annotations = (ScrBookAnnotations)m_scr.BookAnnotationsOS[startRef.Book - 1]; TeResourceHelper.MakeUndoRedoLabels("kstidInsertAnnotation", out sUndo, out sRedo); string sType = noteType.Name.UserDefaultWritingSystem; sUndo = string.Format(sUndo, sType); sRedo = string.Format(sRedo, sType); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.MainCacheAccessor, Control as IVwRootSite, sUndo, sRedo, false)) { try { StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache); quoteParaBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark); quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote); annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj, noteType.Guid, wsSelector, startOffset, endOffset, quoteParaBldr, null, null, null, out iPos); if (notesVc != null) { // tell the VC that the newly inserted item should be expanded. That will cause // the view to be updated to show the new note. notesVc.ExpandItem(annotation.Hvo); notesVc.ExpandItem(annotation.DiscussionOAHvo); } } catch { undoTaskHelper.EndUndoTask = false; FwApp.App.RefreshAllViews(m_cache); throw; } } if (Control != null) { Control.Focus(); } // Make a selection in the discussion so the user can start to type if (notesVc != null && notesVc.NotesSequenceHandler != null) { // Get the corresponding index in the virtual property. iPos = notesVc.NotesSequenceHandler.GetVirtualIndex(annotations.Hvo, iPos); } IVwRootSite rootSite = Control as IVwRootSite; MakeSelectionInNote(notesVc, startRef.Book - 1, iPos, rootSite, true); // REVIEW: Do we need to create a synch record? return(annotation); }
ICmAnnotationDefn ICmAnnotationDefnFactory.Create(Guid guid, ICmAnnotationDefn owner) { if (owner == null) throw new ArgumentNullException("owner"); int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo(); var retval = new CmAnnotationDefn(m_cache, hvo, guid); owner.SubPossibilitiesOS.Add(retval); return retval; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Returns the ScrImportSource for the notes import domain with the specified writing /// system identifier and having the specified note type. /// </summary> /// <param name="wsId"></param> /// <param name="noteType">The CmAnnotationDefn for the type of note to /// get the source for. Use <c>null</c> to get notes of any type that matches the given /// writing system identifier.</param> /// <param name="createSourceIfNeeded">True to create the source if it does not already /// exist for the given writing system identifier and note type</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private IScrImportSource GetSourceForNotes(string wsId, ICmAnnotationDefn noteType, bool createSourceIfNeeded) { int classId = (ImportTypeEnum == TypeOfImport.Paratext6) ? ScrImportP6ProjectTags.kClassId : ScrImportSFFilesTags.kClassId; foreach (IScrImportSource noteSource in NoteSourcesOC) { if (noteSource.WritingSystem == wsId && noteSource.NoteTypeRA == noteType && noteSource.ClassID == classId) { return noteSource; } } if (!createSourceIfNeeded) return null; IScrImportSource source; switch (ImportTypeEnum) { case TypeOfImport.Other: case TypeOfImport.Paratext5: source = Services.GetInstance<IScrImportSFFilesFactory>().Create(); break; case TypeOfImport.Paratext6: source = Services.GetInstance<IScrImportP6ProjectFactory>().Create(); break; default: throw new InvalidOperationException("Unexpected import type"); } NoteSourcesOC.Add(source); source.WritingSystem = wsId; source.NoteTypeRA = noteType; return source; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the file list for the given domain, writing system identifier and note type. /// </summary> /// <param name="domain">The source domain</param> /// <param name="wsId">The writing system identifier for the source (ignored for /// scripture domain)</param> /// <param name="noteType">The CmAnnotationDefn for the note type (ignored for back /// trans and scripture domains)</param> /// <param name="createListIfNeeded">True to create the list if it does not already /// exist for a given writing system identifier and note type</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private ScrSfFileList GetFileList(ImportDomain domain, string wsId, ICmAnnotationDefn noteType, bool createListIfNeeded) { Debug.Assert(ImportTypeEnum == TypeOfImport.Other || ImportTypeEnum == TypeOfImport.Paratext5); if (wsId == null) wsId = string.Empty; switch (domain) { default: case ImportDomain.Main: return m_scrFileInfoList; case ImportDomain.BackTrans: { // Look for a back trans source with the given writing system identifier. ScrSfFileList btList = m_btFileInfoLists[wsId] as ScrSfFileList; if (btList == null && createListIfNeeded) { btList = new ScrSfFileList(m_resolver); m_btFileInfoLists[wsId] = btList; } return btList; } case ImportDomain.Annotations: { // Look for a annotations source with the given writing system identifier. string key = ScriptureServices.CreateImportSourceKey(wsId, noteType); ScrSfFileList noteList = m_notesFileInfoLists[key] as ScrSfFileList; if (noteList == null && createListIfNeeded) { noteList = new ScrSfFileList(m_resolver); m_notesFileInfoLists[key] = noteList; } return noteList; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Remove a file from the file list /// </summary> /// <param name="fileName"></param> /// <param name="domain">The domain to remove the file from</param> /// <param name="wsId">The writing system identifier for the source (ignored for /// scripture domain)</param> /// <param name="noteType">The CmAnnotationDefn for the note type (ignored for back /// trans and scripture domains)</param> /// ------------------------------------------------------------------------------------ public void RemoveFile(string fileName, ImportDomain domain, string wsId, ICmAnnotationDefn noteType) { lock (SyncRoot) { ScrSfFileList fileList = GetFileList(domain, wsId, noteType, false); if (fileList == null) return; foreach (IScrImportFileInfo info in fileList) { if (info.FileName.ToUpper() == fileName.ToUpper()) { fileList.Remove(info); if (fileList.Count == 0) { GetMappingListForDomain(domain).ResetInUseFlags(domain, wsId, noteType); } return; } } } }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. } // Dispose unmanaged resources here, whether disposing is true or false. if (m_cpe != null && Marshal.IsComObject(m_cpe)) Marshal.ReleaseComObject(m_cpe); m_cpe = null; m_settings = null; m_SOWrapper = null; m_sSegmentText = null; m_sMarker = null; m_styleProxy = null; m_vernParaStyleProxy = null; m_vernTextProps = null; m_analTextProps = null; m_styleProxies = null; m_notesStyleProxies = null; m_lastPara = null; m_BookTitleParaProxy = null; m_DefaultFootnoteParaProxy = null; m_TsStringFactory = null; m_BTFootnoteStrBldr = null; m_CurrParaPictures = null; m_CurrParaFootnotes = null; m_BTPendingPictures = null; m_CurrBTFootnote = null; m_sBtFootnoteParaStyle = null; m_BtFootnoteStrBldrs = null; m_PendingAnnotations = null; m_BTfootnoteIndex = null; m_sCharStyleEndMarker = null; m_sFootnoteEndMarker = null; m_sCharStyleBeginMarker = null; m_sFootnoteBeginMarker = null; m_scrTranslatorAnnotationDef = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Add a file to the project, and determine the file encoding and mappings. /// </summary> /// <param name="fileName">file name to add</param> /// <param name="domain">The domain to add the file to</param> /// <param name="wsId">The icu locale for the source (ignored for scripture domain) /// </param> /// <param name="noteType">The CmAnnotationDefn for the note type (ignored for back /// trans and scripture domains)</param> /// <returns>The IScrImportFileInfo representing the added file</returns> /// ------------------------------------------------------------------------------------ public IScrImportFileInfo AddFile(string fileName, ImportDomain domain, string wsId, ICmAnnotationDefn noteType) { return AddFile(fileName, domain, wsId, noteType, null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the annotation type from the Guid. /// </summary> /// <param name="defn">The defn.</param> /// <returns> /// The annotation type for <paramref name="defn"/>. /// </returns> /// ------------------------------------------------------------------------------------ public static NoteType GetAnnotationType(ICmAnnotationDefn defn) { Guid guid = defn.Guid; if (guid == LangProject.kguidAnnConsultantNote) return NoteType.Consultant; else if (guid == LangProject.kguidAnnTranslatorNote) return NoteType.Translator; else //if (guid == LangProject.kguidAnnCheckingError) -- There are multiple sub-types of checking errors return NoteType.CheckingError; //return NoteType.Unknown; }