/// ------------------------------------------------------------------------------------ /// <summary> /// Provides access to the "MakeLabelFromText" method. /// </summary> /// <param name="labelText">text to put in the label</param> /// <param name="styleName">style name to use for the character style on the text</param> /// <param name="ann">The annotation.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ITsString CallMakeLabelFromText(string labelText, string styleName, ScrScriptureNote ann) { CheckDisposed(); return(base.MakeLabelFromText(labelText, styleName, ann)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Checks the given object agains the filter criteria /// </summary> /// <param name="hvoObj">ID of object to check against the filter criteria</param> /// <returns> /// <c>true</c> if the object passes the filter criteria; otherwise /// <c>false</c> /// </returns> /// <remarks>currently only handles basic filters (single cell)</remarks> /// ------------------------------------------------------------------------------------ public bool MatchesCriteria(int hvoObj) { int classId = m_cache.GetClassOfObject(hvoObj); if (classId != ScrScriptureNote.kClassId) { return(false); // Not an annotation or not one we will care about } ScrScriptureNote note = new ScrScriptureNote(m_cache, hvoObj); if (note.AnnotationType != NoteType.CheckingError) { return(true); // Annotation is a Translator or Consultant note } if (note.ResolutionOA != null) { foreach (StTxtPara para in note.ResolutionOA.ParagraphsOS) { if (para.Contents.Length > 0) { return(true); } } } return(false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Attempts to scroll to an annotation whose BeginObjectRAHvo is the same as the hvo /// of the paragraph where the anchor is in the specified editing helper's selection. /// </summary> /// <param name="editingHelper">The TE editing helper with information about the /// selection in the Scripture pane.</param> /// <param name="selectedText">The selected text or the word containing the IP if the /// selection is not a range.</param> /// <param name="fExactMatchOnly">if set to <c>true</c> then only scroll to a found /// note if the cited text is an exact match.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ private bool ScrollToAnnotationByPara(TeEditingHelper editingHelper, string selectedText, bool fExactMatchOnly) { if (editingHelper == null || editingHelper.CurrentSelection == null) { return(false); } ScrReference scrRef = editingHelper.CurrentStartRef; SelLevInfo[] info = editingHelper.CurrentSelection.GetLevelInfo( SelectionHelper.SelLimitType.Anchor); if (info.Length == 0) { return(false); } int bookHvo = m_scr.BookAnnotationsOS[scrRef.Book - 1].Hvo; int[] annHvos = m_fdoCache.GetVectorProperty(bookHvo, m_vc.NotesSequenceHandler.Tag, false); if (annHvos.Length == 0) { return(false); } int ich = editingHelper.CurrentSelection.IchAnchor; // Go through the annotations for the book and find the one whose // begin object is in the same as the selection's paragraph. for (int i = 0; i < annHvos.Length; i++) { ScrScriptureNote ann = new ScrScriptureNote(m_fdoCache, annHvos[i]); if (ann.BeginObjectRAHvo == info[0].hvo) { // When matching on the cited text, allow for the possibility that the // begin offset is off by a little bit since leading spaces and/or ORCs // may have been trimmed and subsequent editing may have messed up the // offsets a little. int adjustedBeginOffset = ann.BeginOffset - (string.IsNullOrEmpty(ann.CitedText) ? 1 : ann.CitedText.Length); if ((!fExactMatchOnly && ich >= ann.BeginOffset && ich <= ann.EndOffset) || (ich >= adjustedBeginOffset && selectedText == ann.CitedText)) { m_vc.SelectedNoteHvo = ann.Hvo; NotesEditingHelper.MakeSelectionInNote(m_vc, scrRef.Book - 1, i, this, m_vc.IsExpanded(ann.Hvo)); return(true); } } } return(false); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the Scripture reference of the specified annotation as string. /// </summary> /// <param name="ann">The specified annotation.</param> /// ------------------------------------------------------------------------------------ private string GetRefAsString(ScrScriptureNote ann) { BCVRef startRef = new BCVRef(ann.BeginRef); IScrBook book = m_scr.FindBook(startRef.Book); string titleText = ResourceHelper.GetResourceString("kstidScriptureTitle"); string introText = ResourceHelper.GetResourceString("kstidScriptureIntro"); return(ScrReference.MakeReferenceString(book.BestUIName, startRef, new BCVRef(ann.EndRef), m_scr.ChapterVerseSepr, m_scr.Bridge, titleText, introText)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Looks for any annotations in the curtrently filtered set whose reference range /// covers the given Scripture reference. Any such annotations are expanded and the /// first on is scrolled to near the top of the view. /// </summary> /// ------------------------------------------------------------------------------------ internal void ScrollRefIntoView(ScrReference reference, string quotedText) { CheckDisposed(); if (reference.Book <= 0) { return; } bool fSaveSendSyncScrollMsg = m_fSendSyncScrollMsg; try { m_fSendSyncScrollMsg = false; int bookHvo = m_scr.BookAnnotationsOS[reference.Book - 1].Hvo; int[] annHvos = m_fdoCache.GetVectorProperty(bookHvo, m_vc.NotesSequenceHandler.Tag, false); int exactMatchingAnnotation = -1; int firstMatchingAnnotation = -1; for (int i = 0; i < annHvos.Length; i++) { ScrScriptureNote ann = new ScrScriptureNote(m_fdoCache, annHvos[i]); if (ann.BeginRef <= reference && ann.EndRef >= reference) { if (firstMatchingAnnotation < 0) { firstMatchingAnnotation = i; } string qtext = ((StTxtPara)ann.QuoteOA.ParagraphsOS[0]).Contents.Text; if (!string.IsNullOrEmpty(qtext) && !string.IsNullOrEmpty(quotedText) && qtext == quotedText && exactMatchingAnnotation < 0) { exactMatchingAnnotation = i; } } else if (firstMatchingAnnotation >= 0) { break; } } int idx = Math.Max(exactMatchingAnnotation, firstMatchingAnnotation); if (idx >= 0) { NotesEditingHelper.MakeSelectionInNote(m_vc, reference.Book - 1, idx, this, m_vc.IsExpanded(annHvos[idx])); } } finally { m_fSendSyncScrollMsg = fSaveSendSyncScrollMsg; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Connects the notes to new categories using a map created before the new categories /// were loaded. If the note category does not already exist, it will create the /// category. /// </summary> /// <param name="map">The map (for each writing system) from the note id to the /// full string path of the category name.</param> /// <remarks>Limitation: If any category is renamed, any notes that used the previous /// name will continue to use the old category. To fix this problem, we would need to /// specify in the category file (for each category with a changed name) how the old /// category maps to its renamed/relocated category).</remarks> /// ------------------------------------------------------------------------------------ private void ConnectNotesToNewCategories(Dictionary <int, List <string> > map) { foreach (int noteHvo in map.Keys) { ScrScriptureNote note = new ScrScriptureNote(m_scr.Cache, noteHvo); note.CategoriesRS.RemoveAll(); // Just in case List <string> strCategories = map[noteHvo]; foreach (string strCategory in strCategories) { note.CategoriesRS.Append(m_scr.NoteCategoriesOA.FindOrCreatePossibility( strCategory, m_scr.Cache.DefaultAnalWs)); } } }
public void MakeLabelFromText_AnnotationOnScripturePara() { CheckDisposed(); ScrScriptureNote note = new ScrScriptureNote(); m_scr.BookAnnotationsOS[0].NotesOS.Append(note); note.BeginRef = 01001011; note.EndRef = 01001011; note.BeginObjectRA = m_gen.SectionsOS[1].ContentOA.ParagraphsOS[0]; ITsString tss = m_vc.CallMakeLabelFromText("GEN 1:11", "WhoCares", note); Assert.AreEqual(2, tss.RunCount); Assert.AreEqual("GEN 1:11", tss.get_RunText(0)); Assert.AreEqual("WhoCares", tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); CheckFinalSpaceInReferenceLabel(tss); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Attempts to scroll to the first annotation whose beginning reference's book is /// the same as the specified book. /// </summary> /// ------------------------------------------------------------------------------------ private bool ScrollToNonScrAnnotationByBook(int book, string selectedText) { int bookHvo = m_scr.BookAnnotationsOS[book - 1].Hvo; int[] annHvos = m_fdoCache.GetVectorProperty(bookHvo, m_vc.NotesSequenceHandler.Tag, false); if (annHvos.Length == 0) { return(false); } int ihvo = 0; ScrScriptureNote ann; BCVRef bcvRef; // Go through the annotations for the book and find the one whose // cited text is the same as the specified selected text. for (int i = 0; i < annHvos.Length; i++) { ann = new ScrScriptureNote(m_fdoCache, annHvos[i]); bcvRef = new BCVRef(ann.BeginRef); if (ann.CitedText == selectedText && bcvRef.Chapter == 0) { ihvo = i; break; } } ann = new ScrScriptureNote(m_fdoCache, annHvos[ihvo]); bcvRef = new BCVRef(ann.BeginRef); if (bcvRef.Chapter > 0) { return(false); } NotesEditingHelper.MakeSelectionInNote(m_vc, book - 1, ihvo, this, m_vc.IsExpanded(ann.Hvo)); return(true); }
public void CreateScrNoteCategories() { CheckDisposed(); XmlDocument doc = CreateCategoryXmlDoc(); // Create the annotation categories. DummyTeScrNoteCategoriesInit.CallCreateScrNoteCategories(m_scr, doc); ScrScriptureNote note = new ScrScriptureNote(); m_scr.BookAnnotationsOS[0].NotesOS.Append(note); // Set the note's category to Discourse-Chiasmus note.CategoriesRS.Append(m_scr.NoteCategoriesOA.PossibilitiesOS[0].SubPossibilitiesOS[0]); // Reload the annotation categories. DummyTeScrNoteCategoriesInit.CallCreateScrNoteCategories(m_scr, doc); // Confirm that the note's category is retained. Assert.AreEqual(m_scr.NoteCategoriesOA.PossibilitiesOS[0].SubPossibilitiesOS[0], note.CategoriesRS[0]); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the category chooser dialog to let the user set the category for the /// specified annotation. /// </summary> /// ------------------------------------------------------------------------------------ private void SetAnnotationCategory(ScrScriptureNote ann) { if (ann == null) { return; // Not much we can do } m_rootb.DestroySelection(); string sUndo, sRedo; TeResourceHelper.MakeUndoRedoLabels("kstidSetAnnotationCategory", out sUndo, out sRedo); using (new UndoTaskHelper(this, sUndo, sRedo, true)) using (new WaitCursor(this)) using (CategoryChooserDlg dlg = new CategoryChooserDlg(m_scr.NoteCategoriesOA, ann.CategoriesRS.HvoArray)) { if (dlg.ShowDialog(ParentForm) == DialogResult.OK && !dlg.GetPossibilities(ann.CategoriesRS)) { ann.DateModified = DateTime.Now; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the updateTime on the specified note. This method deletes the mark in the /// undo stack. If fStartNewMark is true then a new mark is created. /// </summary> /// <param name="noteHvo">The hvo of the note to be updated, or 0 to ignore</param> /// ------------------------------------------------------------------------------------ public void SetNoteUpdateTime(int noteHvo) { CheckDisposed(); IActionHandler handler = m_fdoCache.ActionHandlerAccessor; if (m_fIgnoreTmStmpUpdate || handler == null || handler.CurrentDepth > 0 || handler.TopMarkHandle == 0) { return; } if (!handler.get_TasksSinceMark(true)) { handler.DiscardToMark(0); } else { // Can happen... just continue on if (noteHvo != 0 && m_fdoCache.IsValidObject(noteHvo)) { ScrScriptureNote ann = new ScrScriptureNote(m_fdoCache, noteHvo); ann.DateModified = DateTime.Now; m_fdoCache.PropChanged(null, PropChangeType.kpctNotifyAll, noteHvo, (int)CmAnnotation.CmAnnotationTags.kflidDateModified, 0, 1, 1); } string sUndo; string sRedo; TeResourceHelper.MakeUndoRedoLabels("kstidDiffDlgUndoRedoEditNote", out sUndo, out sRedo); handler.CollapseToMark(0, sUndo, sRedo); // If no tasks since the mark actually change the data, they should all get // deleted when we collapse. } }
public void MakeLabelFromText_AnnotationOnFootnote() { CheckDisposed(); ScrScriptureNote note = new ScrScriptureNote(); m_scr.BookAnnotationsOS[0].NotesOS.Append(note); note.BeginRef = 01001011; note.EndRef = 01001011; StFootnote footnote = m_scrInMemoryCache.AddFootnote(m_gen, (IStTxtPara)m_gen.SectionsOS[1].ContentOA.ParagraphsOS[0], 0); note.BeginObjectRA = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, "Whatever"); ITsString tss = m_vc.CallMakeLabelFromText("GEN 1:11", "WhoCares", note); Assert.AreEqual(3, tss.RunCount); Assert.AreEqual("\u0032", tss.get_RunText(0)); Assert.AreEqual("GEN 1:11", tss.get_RunText(1)); Assert.AreEqual("Marlett", tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptFontFamily)); Assert.AreEqual("WhoCares", tss.get_Properties(1).GetStrPropValue((int)FwTextPropType.ktptNamedStyle)); CheckFinalSpaceInReferenceLabel(tss); }
public void ExportBookSection_BTIntroWithNotes() { int wsAnal = Cache.DefaultAnalWs; IScrSection introSection = m_scrInMemoryCache.AddIntroSectionToMockedBook(m_book.Hvo); m_scrInMemoryCache.AddSectionHeadParaToSection(introSection.Hvo, "Introduccion", ScrStyleNames.IntroSectionHead); StTxtPara introPara = AddPara(introSection, ScrStyleNames.NormalParagraph); AddVerse(introPara, 0, 0, "Texto de introduccion"); CmTranslation trans = (CmTranslation)m_scrInMemoryCache.AddTransToMockedParagraph(introPara, LangProject.kguidTranBackTranslation, wsAnal); trans.Translation.SetAlternative("Introduction text", wsAnal); ScrScriptureNote note = (ScrScriptureNote)m_scrInMemoryCache.AddAnnotation(trans, 01001000, NoteType.Consultant, "This is a basic note about the BT of an intro."); note.ResolutionStatus = NoteStatus.Open; note.BeginOffset = 0; note.EndOffset = 5; note.WsSelector = wsAnal; DateTime now = DateTime.Now; string strNow = now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss.ff"); note.DateCreated = now; note.DateModified = now; StringWriter stream = new StringWriter(); XmlTextWriter writer = new XmlTextWriter(stream); writer.Formatting = Formatting.None; m_exporter = new ExportXml(null, Cache, null, ExportWhat.AllBooks, 0, 0, 0, "ExportBookSection_IntroWithNotes"); // Initialize writing systems for export (required to export back translations), but // called from ExportTE. ReflectionHelper.CallMethod(m_exporter, "InitializeExportWs", null); ReflectionHelper.SetField(m_exporter, "m_writer", writer); string sCanon = "ot"; ReflectionHelper.CallMethod(m_exporter, "ExportBook", sCanon, m_book, null); XmlDocument actual = new XmlDocument(); actual.Load(new StringReader(stream.ToString())); string strExpected = "<book ID=\"GEN\"><titleGroup short=\"Genesis\"><title type=\"main\">" + "<trGroup><tr>Genesis</tr></trGroup></title></titleGroup>" + "<introduction><section><sectionHead><trGroup><tr>Introduction</tr></trGroup></sectionHead>" + "<p><annotation type=\"consultantNote\" status=\"0\" oxesRef=\"GEN.1.0\" beginOffset=\"0\" " + "endOffset=\"5\" languageInFocus=\"en\">" + "<created>" + strNow + "</created><modified>" + strNow + "</modified>" + "<resolved /><notationDiscussion><para xml:lang=\"en\">" + "<run>This is a basic note about the BT of an intro.</run></para></notationDiscussion></annotation>" + "<trGroup><tr><userCS type=\"Paragraph\">Some intro text</userCS></tr>" + "<bt xml:lang=\"en\">Texto de introduccion</bt></trGroup>" + "<chapterEnd ID=\"GEN.0\"/></p></section></introduction></book>"; XmlDocument expected = new XmlDocument(); expected.Load(new StringReader(strExpected)); string strDifference; if (!XmlHelper.CompareXmlNodes(expected.ChildNodes, actual.ChildNodes, out strDifference)) { Assert.Fail(strDifference); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// We override this method to make a selection in all of the views that are in a /// snynced group. This fixes problems where the user changes the selection in one of /// the slaves, but the master is not updated. Thus the view is not scrolled as the /// groups scroll position only scrolls the master's selection into view. (TE-3380) /// </summary> /// <param name="prootb"></param> /// <param name="vwselNew"></param> /// ------------------------------------------------------------------------------------ public override void SelectionChanged(IVwRootBox prootb, IVwSelection vwselNew) { CheckDisposed(); if (s_fInSelectionChanged) { return; } base.SelectionChanged(prootb, vwselNew); if (m_ignoreSelChanged || EditingHelper.CurrentSelection == null) { return; } SelLevInfo noteInfo = EditingHelper.CurrentSelection.GetLevelInfoForTag(m_currentNotesTag); if (noteInfo.hvo == m_prevNoteHvo) { return; } ScrScriptureNote ann = new ScrScriptureNote(m_fdoCache, noteInfo.hvo); s_fInSelectionChanged = true; try { // Remove highlighting on previously selected annotation, and add highlighting to selected annotation. SelectionHelper sel = EditingHelper.CurrentSelection; m_vc.SelectedNoteHvo = noteInfo.hvo; if (m_prevNoteHvo != 0) { // Make sure we use the index in the virtual property and not // the index in the list of notes. int ownerHvo = m_fdoCache.GetOwnerOfObject(m_prevNoteHvo); int ihvo = m_fdoCache.GetObjIndex(ownerHvo, m_currentNotesTag, m_prevNoteHvo); if (ihvo >= 0) // Could be -1 if not in the filter anymore (TE-8891) { m_fdoCache.PropChanged(null, PropChangeType.kpctNotifyAll, ownerHvo, m_currentNotesTag, ihvo, 1, 1); } } m_fdoCache.PropChanged(null, PropChangeType.kpctNotifyAll, ann.OwnerHVO, m_currentNotesTag, noteInfo.ihvo, 1, 1); sel.SetSelection(false); // restore selection taken from PropChange } finally { s_fInSelectionChanged = false; } // Set text of caption to indicate which annotation is selected m_notesMainWnd.InformationBarText = BaseInfoBarCaption + " - " + GetRefAsString(ann) + " " + GetQuotedText(ann.QuoteOA, 30); SetNoteUpdateTime(m_prevNoteHvo); m_prevNoteHvo = noteInfo.hvo; if (!m_fSendSyncScrollMsg) { return; } NotesMainWnd notesMainWnd = TheMainWnd as NotesMainWnd; if (notesMainWnd != null && notesMainWnd.SyncHandler != null) { Trace.WriteLine("Calling SyncToAnnotation from NotesDataEntryView: " + ann.CitedText); notesMainWnd.SyncHandler.SyncToAnnotation(this, ann, m_scr); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Call MouseUp on the rootbox /// </summary> /// ----------------------------------------------------------------------------------- protected override void CallMouseUp(Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot) { IVwSelection sel = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false); ScrScriptureNote ann = CurrentAnnotation; ScrScriptureNote.ScrScriptureNoteTags noteTagToSelect = ScrScriptureNote.ScrScriptureNoteTags.kflidDiscussion; bool fMakeSelInFirstResponse = false; if (sel != null && sel.SelType == VwSelType.kstPicture) { SelectionHelper selHelper = SelectionHelper.Create(sel, this); SelLevInfo[] info = selHelper.LevelInfo; if (info.Length >= 1 && info[0].tag == (int)ScrScriptureNote.ScrScriptureNoteTags.kflidDiscussion || info[0].tag == (int)ScrScriptureNote.ScrScriptureNoteTags.kflidRecommendation || m_fdoCache.GetClassOfObject(info[0].hvo) == StJournalText.kClassId) { bool fExpanding = m_vc.ToggleItemExpansion(info[0].hvo, m_rootb); if (fExpanding) { // If the tag is not a valid tag, the assumption // is we're expanding the responses. fMakeSelInFirstResponse = (info[0].tag < 0); noteTagToSelect = (ScrScriptureNote.ScrScriptureNoteTags)info[0].tag; } } else if (selHelper.GetTextPropId(SelectionHelper.SelLimitType.Anchor) == -(int)NotesFrags.kfrConnotCategory) // This is not a real flid, just a unique number to match on. { SetAnnotationCategory(ann); } else if (info.Length >= 2 && info[1].tag == m_currentNotesTag) { m_ignoreSelChanged = !m_vc.ToggleItemExpansion(info[1].hvo, m_rootb); } } base.CallMouseUp(pt, rcSrcRoot, rcDstRoot); m_ignoreSelChanged = false; if (!m_pictureSelected) { return; } m_pictureSelected = false; if (ann == null || m_vc.NotesSequenceHandler == null) { return; } // Make a selection in the proper place in the annotation. int book = BCVRef.GetBookFromBcv(ann.BeginRef) - 1; ScrBookAnnotations annotations = (ScrBookAnnotations)m_scr.BookAnnotationsOS[book]; int index = m_vc.NotesSequenceHandler.GetVirtualIndex(annotations.Hvo, ann.IndexInOwner); if (fMakeSelInFirstResponse) { NotesEditingHelper.MakeSelectionInNote(book, index, 0, ScrScriptureNote.ScrScriptureNoteTags.kflidResponses); } else if (m_vc.IsExpanded(ann.Hvo) && m_vc.IsExpanded(Cache.GetObjProperty(ann.Hvo, (int)noteTagToSelect))) { NotesEditingHelper.MakeSelectionInNote(m_vc, false, book, index, 0, noteTagToSelect, this, true); } else { NotesEditingHelper.MakeSelectionInNoteRef(m_vc, book, index, this); } }