private void RegisterAllSubrecordIndexTSSChanged(ILcmOwningSequence <IRnGenericRec> subs, int flid, ITsString dummy) { foreach (IRnGenericRec rec in subs) { ((IServiceLocatorInternal)m_cache.ServiceLocator).UnitOfWorkService.RegisterVirtualAsModified( rec, flid, null, dummy); RegisterAllSubrecordIndexTSSChanged(rec.SubRecordsOS, flid, dummy); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the insert index where a new annotation is inserted when the annotation's /// reference is that specified. The index will be at the end of those for the /// specified reference. /// </summary> /// ------------------------------------------------------------------------------------ private int GetInsertIndexForRef(BCVRef startRef) { ILcmOwningSequence <IScrScriptureNote> notes = NotesOS; for (int i = notes.Count - 1; i >= 0; i--) { IScrScriptureNote note = notes[i]; if (note.BeginRef <= startRef) { return(i + 1); } } return(0); }
private void ProcessIndicesSimpleContext(ILcmOwningSequence <IPhSimpleContext> seq, ICmObject[] ctxts, bool preRemovalSideEffects, int idx) { if (ctxts == null || idx > ctxts.Length - 1 || idx < 0) { return; } var c = (IPhSimpleContext)ctxts[idx]; if (preRemovalSideEffects) { c.PreRemovalSideEffects(); } seq.Remove(c); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Tests that a footnote has been created in the DB with a single default run having /// the specified text and the given translation. /// </summary> /// <param name="iFootnoteIndex">zero-based footnote index</param> /// <param name="sFootnoteSegment">Expected footnote contents</param> /// <param name="sFootnoteTransSegment">Expected footnote translation contents</param> /// <param name="sMarker">One of: <c>"a"</c>, for automatic alpha sequence; <c>"*"</c>, /// for a literal marker (we always use "*" in these tests); or <c>string.Empty</c>, /// for no marker</param> /// <param name="sParaStyleName">Name of the paragraph style</param> /// ------------------------------------------------------------------------------------ public void VerifyFootnoteWithTranslation(int iFootnoteIndex, string sFootnoteSegment, string sFootnoteTransSegment, string sMarker, string sParaStyleName) { // Force reload of book IStFootnote footnote = m_importer.GetFootnote(iFootnoteIndex); if (sMarker == "a") { sMarker = new string((char)((int)'a' + (iFootnoteIndex % 26)), 1); } if (sMarker != null) { AssertEx.RunIsCorrect(footnote.FootnoteMarker, 0, sMarker, ScrStyleNames.FootnoteMarker, m_wsVern); } else { Assert.IsNull(footnote.FootnoteMarker.Text); } ILcmOwningSequence <IStPara> footnoteParas = footnote.ParagraphsOS; Assert.AreEqual(1, footnoteParas.Count); IStTxtPara para = (IStTxtPara)footnoteParas[0]; Assert.AreEqual(StyleUtils.ParaStyleTextProps(sParaStyleName), para.StyleRules); ITsString tss = para.Contents; Assert.AreEqual(1, tss.RunCount); AssertEx.RunIsCorrect(tss, 0, sFootnoteSegment, null, m_wsVern); // Check Translation if (sFootnoteTransSegment != null) { Assert.AreEqual(1, para.TranslationsOC.Count); ICmTranslation trans = para.GetBT(); tss = trans.Translation.AnalysisDefaultWritingSystem; Assert.AreEqual(1, tss.RunCount); AssertEx.RunIsCorrect(tss, 0, sFootnoteTransSegment, null, m_wsAnal); } else { Assert.AreEqual(1, para.TranslationsOC.Count); Assert.IsNull(para.GetBT().Translation.AnalysisDefaultWritingSystem.Text); } }
protected bool RemoveContextsFrom(bool forward, SelectionHelper sel, ILcmOwningSequence <IPhSimpleContext> seq, bool preRemovalSideEffects, out int index) { index = -1; bool reconstruct = true; ICmObject[] ctxts = seq.Cast <ICmObject>().ToArray(); // if the selection is a range remove all items in the selection if (sel.IsRange) { int[] indices = GetIndicesToRemove(ctxts, sel); // return index of the item before the removed items if (indices.Length > 0) { index = indices[0] - 1; } foreach (int idx in indices) { // Sometimes when deleting a range, DeleteUnderlyingObject() takes out // parts of the rule before this loop gets to it. [LT-9775] if (ctxts[idx].IsValidObject) { ProcessIndicesSimpleContext(seq, ctxts, preRemovalSideEffects, idx); } } } else { int idx = GetIndexToRemove(ctxts, sel, forward); if (idx > -1) { // return index of the item before the removed items index = idx - 1; ProcessIndicesSimpleContext(seq, ctxts, preRemovalSideEffects, idx); } else { // if the backspace button is pressed at the beginning of a cell or the delete // button is pressed at the end of a cell, don't do anything reconstruct = false; } } return(reconstruct); }
protected int InsertContextInto(IPhSimpleContext ctxt, SelectionHelper sel, ILcmOwningSequence <IPhSimpleContext> seq) { ICmObject[] ctxts = seq.Cast <ICmObject>().ToArray(); int index = GetInsertionIndex(ctxts, sel); // if the current selection is a range remove the items we are overwriting if (sel.IsRange) { var indices = GetIndicesToRemove(ctxts, sel); foreach (int idx in indices) { var c = (IPhSimpleContext)ctxts[idx]; c.PreRemovalSideEffects(); seq.Remove(c); } } seq.Insert(index, ctxt); return(index); }
/// <summary> /// Fills the in map of English name to CmPossibility object. /// </summary> /// <remarks> /// Allow access to tests. /// </remarks> internal void FillInMapForPossibilities(Dictionary <string, ICmPossibility> mapNameToItem, ILcmOwningSequence <ICmPossibility> possibilities) { if (possibilities == null) { return; } foreach (var item in possibilities) { var key = GetKeyForPossibility(item); if (String.IsNullOrEmpty(key)) { continue; } if (mapNameToItem.ContainsKey(key)) { continue; } mapNameToItem.Add(key, item); FillInMapForPossibilities(mapNameToItem, item.SubPossibilitiesOS); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determine where in the annotation list to insert a new annotation having the /// specified startRef, beginning object and beginning offset. /// </summary> /// <param name="startRef">The start ref.</param> /// <param name="beginObject">The begin object.</param> /// <param name="begOffset">The beg offset.</param> /// ------------------------------------------------------------------------------------ private int GetNewNotesInsertIndex(BCVRef startRef, ICmObject beginObject, int begOffset) { // Get the index within the book of the section containing the paragraph // containing the reference to which the new annotation corresponds. int iNewNoteSection; int iNewNotePara; GetLocationInfoForObj(beginObject, out iNewNoteSection, out iNewNotePara); ILcmOwningSequence <IScrScriptureNote> notes = NotesOS; int insertIndex = notes.Count; // Go backward through the list of existing annotations. for (int i = notes.Count - 1; i >= 0; i--) { IScrScriptureNote note = notes[i]; int iSect, iPara; GetLocationInfoForObj(note.BeginObjectRA, out iSect, out iPara); // If the annotation is for text that follows the text associated // with the new annotation we're adding, then decrement the index // of where to insert the new annotation. if (note.BeginRef > startRef || iSect > iNewNoteSection || (iSect == iNewNoteSection && iPara > iNewNotePara) || (iSect == iNewNoteSection && iPara == iNewNotePara && note.BeginOffset > begOffset)) { insertIndex--; } else { break; // found first spot for note } } return(insertIndex); }
/// <summary> /// Creates a TreeNode tree along genres populated by the texts that claim them. /// The list of textsWithNoGenre is also populated. /// Recursively descend the genre tree and duplicate parts that have corresponding texts. /// </summary> /// <param name="parent">The parent to attach the genres to. If null, nothing is done.</param> /// <param name="genreList">The owning sequence of genres - its a tree.</param> /// <param name="allTexts">The flat list of all texts in the project.</param> private static void LoadTextsFromGenres(TreeNode parent, ILcmOwningSequence <ICmPossibility> genreList, IEnumerable <LCModel.IText> allTexts) { if (parent == null) { return; } var sortedGenreList = new List <ICmPossibility>(genreList); var sorter = new CmPossibilitySorter(); sortedGenreList.Sort(sorter); foreach (var gen in sortedGenreList) { // This tree node is added to genreTreeNodes if there are texts or children var genItem = new TreeNode(gen.ChooserNameTS.Text); // LT-12179: Create a List for collecting selected tree nodes which we will later sort // before actually adding them to the tree: var sortedNodes = new List <TreeNode>(); var foundFirstText = false; foreach (var tex in allTexts) { // This tex may not have a genre or it may claim to be in more than one if (!Enumerable.Contains(tex.GenresRC, gen)) { continue; } var texItem = new TreeNode(tex.ChooserNameTS.Text) { Tag = tex.ContentsOA, Name = "Text" }; // LT-12179: Add the new TreeNode to the (not-yet-)sorted list: sortedNodes.Add(texItem); // LT-12179: If this is the first tex we've added, establish the collator's details // according to the writing system at the start of the tex: if (foundFirstText) { continue; } foundFirstText = true; } // Always use the system collation definition. Texts have different writing systems anyhow. var wsCollator = new SystemCollationDefinition(); // LT-12179: if (foundFirstText) { // Order the TreeNodes alphabetically: sortedNodes.Sort((x, y) => wsCollator.Collator.Compare(x.Text, y.Text)); // Add the TreeNodes to the tree: genItem.Nodes.AddRange(sortedNodes.ToArray()); } if (gen.SubPossibilitiesOS.Count > 0) { // Descend to the child genres regardless if there were texts assigned to this genre LoadTextsFromGenres(genItem, gen.SubPossibilitiesOS, allTexts); } //Add the node even if there are no texts that point to this genre. genItem.Tag = gen; // ICmPossibility genItem.Name = "Genre"; parent.Nodes.Add(genItem); } }