public void UpdateAllFootnotesWhenValuesChangeInScripture() { CheckDisposed(); ScrBook james = (ScrBook)m_scr.ScriptureBooksOS[0]; m_scr.DisplayFootnoteReference = false; m_scr.FootnoteMarkerSymbol = "*"; m_scr.FootnoteMarkerType = FootnoteMarkerTypes.SymbolicFootnoteMarker; m_footnoteView.RefreshDisplay(); for (int i = james.FootnotesOS.Count - 2; i < james.FootnotesOS.Count; i++) { StFootnote fNote = (StFootnote)james.FootnotesOS[i]; // Assert.AreEqual(m_footnoteView.m_updatedDisplayMarker, // fNote.DisplayFootnoteMarker); // Assert.AreEqual(m_footnoteView.m_updatedDisplayReference, // fNote.DisplayFootnoteReference); Assert.AreEqual(m_footnoteView.m_updatedFootnoteMarker, fNote.FootnoteMarker.Text); } for (int i = 0; i <= 2; i++) { StFootnote fNote = (StFootnote)m_Jude.FootnotesOS[i]; // Assert.AreEqual(m_footnoteView.m_updatedDisplayMarker, // fNote.DisplayFootnoteMarker); // Assert.AreEqual(m_footnoteView.m_updatedDisplayReference, // fNote.DisplayFootnoteReference); Assert.AreEqual(m_footnoteView.m_updatedFootnoteMarker, fNote.FootnoteMarker.Text); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Insert a book /// </summary> /// <returns>The new book</returns> /// ------------------------------------------------------------------------------------ public IScrBook Do() { IScripture scr = m_cache.LangProject.TranslatedScriptureOA; int hvoTitle; IScrBook newBook = ScrBook.CreateNewScrBook(m_bookID, scr, out hvoTitle); m_bookHvo = newBook.Hvo; // Insert the new book title and set the book names newBook.InitTitlePara(); newBook.Name.CopyAlternatives(newBook.BookIdRA.BookName); newBook.Abbrev.CopyAlternatives(newBook.BookIdRA.BookAbbrev); // Now insert the first section for the new book. ITsTextProps textProps = StyleUtils.CharStyleTextProps(ScrStyleNames.ChapterNumber, m_cache.DefaultVernWs); ScrSection.CreateScrSection(newBook, 0, scr.ConvertToString(1), textProps, false); // Do synchronize stuff if (FwApp.App != null) { FwApp.App.Synchronize(new SyncInfo(SyncMsg.ksyncReloadScriptureControl, 0, 0), m_cache); } // Use Redo for rest of sync'ing and updating book filter Redo(false); return(newBook); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a book without issuing a PropChanged or checking for deleted books. /// </summary> /// <param name="bookHvo">The book hvo.</param> /// ------------------------------------------------------------------------------------ private void AddInternal(int bookHvo) { if (!m_cache.IsRealObject(bookHvo, ScrBook.kClassId)) { return; } int canonicalNum = new ScrBook(m_cache, bookHvo).CanonicalNum; // find the spot to insert the book int insertIndex = 0; for (; insertIndex < m_filteredBooks.Count; insertIndex++) { int checkCanonicalNum = new ScrBook(m_cache, m_filteredBooks[insertIndex]).CanonicalNum; // if the book already exists, overwrite it if (checkCanonicalNum == canonicalNum) { RemoveInternal(insertIndex); break; } // found the insert location if (checkCanonicalNum > canonicalNum) { break; } } // insert the book at the found location or the end Debug.Assert(!m_filteredBooks.Contains(bookHvo)); m_filteredBooks.Insert(insertIndex, bookHvo); }
/// ------------------------------------------------------------------------------------ /// <summary> /// If name of one book is not available in the first (primary) writing system, /// the info in the next available (secondary) writing system is substituted. /// If not available in any given writing system, the 3-letter SIL/UBS book code is /// returned. /// </summary> /// <param name="fAvailable">Normally, the output array only includes available books /// if fAvailable is true.</param> /// <returns>An array of BookNameInfo objects in the requested primary writing system, /// as far as possible.</returns> /// ------------------------------------------------------------------------------------ public override BookLabel[] GetBookNames(bool fAvailable) { // TODO: ToddJ (BryanW) Implement the description above // foreach (int nEnc in m_requestedEncodings) // Assert that knEncSilCodes is in the list if (m_scripture == null) { return(null); } BookLabel[] rgblBookNames = new BookLabel[m_scripture.ScriptureBooksOS.Count]; // for performance reasons, we assume that the books are fully cached. So // we temporary disable loading them from the database. FdoCache cache = m_scripture.Cache; bool fPrevPreloadData = cache.PreloadData; cache.PreloadData = false; for (int i = 0; i < m_scripture.ScriptureBooksOS.Count; i++) { ScrBook book = (ScrBook)m_scripture.ScriptureBooksOS[i]; string sBookName = book.BestUIName; rgblBookNames[i] = new BookLabel(sBookName, (book.CanonicalNum)); } cache.PreloadData = fPrevPreloadData; return(rgblBookNames); }
/// <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 (IsDisposed) { return; } if (disposing) { // Dispose managed resources here. } // Dispose unmanaged resources here, whether disposing is true or false. m_footnote = null;; m_book = null; if (m_strFact != null) { Marshal.ReleaseComObject(m_strFact); } m_strFact = null;; base.Dispose(disposing); }
public void InsertVerseNumber_Verse2NoVerse1() { CheckDisposed(); // Remove the formatting on the verse number so it doesn't interfere with the test. m_draftView.SelectRangeOfChars(1, 11, 0, 1, 2); m_draftView.EditingHelper.RemoveCharFormattingWithUndo(); // Set the IP in the middle of verse James 4:1 when there is no verse number 1 m_draftView.SetInsertionPoint(1, 11, 0, 8, true); // insert verse num 2 at the IP m_draftView.InsertVerseNumber(); ScrBook book = (ScrBook)m_cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[1]; StTxtPara para = (StTxtPara)((ScrSection)book.SectionsOS[11]).ContentOA.ParagraphsOS[0]; ITsString tss = para.Contents.UnderlyingTsString; AssertEx.RunIsCorrect(tss, 0, "4", "Chapter Number", m_cache.DefaultVernWs); Assert.AreEqual("1Where ", para.Contents.UnderlyingTsString.get_RunText(1).Substring(0, 7)); Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs), para.Contents.UnderlyingTsString.get_Properties(1)); AssertEx.RunIsCorrect(tss, 2, "2", "Verse Number", m_cache.DefaultVernWs); Assert.AreEqual("do all the fights", para.Contents.UnderlyingTsString.get_RunText(3).Substring(0, 17)); Assert.AreEqual(StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs), para.Contents.UnderlyingTsString.get_Properties(3)); }
public void UndoReinsertInsertFootnote() { CheckDisposed(); // Need to have an IP m_firstDraftView.RootBox.MakeSimpleSel(true, true, false, true); ScrBook book = (ScrBook)m_firstMainWnd.Cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[0]; int nFootnotes = book.FootnotesOS.Count; // When we start up we shouldn't be able to Undo Assert.IsFalse(m_firstMainWnd.Cache.CanUndo, "Undo possible after startup"); m_firstMainWnd.CallInsertFootnote(); Assert.IsTrue(m_firstMainWnd.Cache.CanUndo, "Undo not possible after inserting footnote"); Assert.AreEqual(nFootnotes + 1, book.FootnotesOS.Count); m_firstMainWnd.SimulateEditUndoClick(); Assert.IsFalse(m_firstMainWnd.Cache.CanUndo, "Inserting footnote not undone"); Assert.AreEqual(nFootnotes, book.FootnotesOS.Count); Application.DoEvents(); m_firstDraftView.RootBox.MakeSimpleSel(true, true, false, true); m_firstDraftView.Focus(); m_firstMainWnd.CallInsertFootnote(); Assert.IsTrue(m_firstMainWnd.Cache.CanUndo, "Undo not possible after second inserting footnote"); Assert.AreEqual(nFootnotes + 1, book.FootnotesOS.Count); }
public void DisableCompareBtn() { // Add Revelation, archive it and then remove it. int hvoTitle; Assert.IsNull(ScrBook.FindBookByID(m_cache, 66), "Revelation should not be in the database. Restore the clean version of TestLangProj."); IScrBook revelation = ScrBook.CreateNewScrBook(66, m_scr, out hvoTitle); ITsPropsFactory propFact = TsPropsFactoryClass.Create(); ITsTextProps ttp = propFact.MakeProps(ScrStyleNames.NormalParagraph, m_cache.DefaultVernWs, 0); ScrSection.CreateScrSection(revelation, 0, "Text for section", ttp, false); AddArchive("Revelation Archive", new List <int>(new int[] { revelation.Hvo })); m_scr.ScriptureBooksOS.Remove(m_scr.ScriptureBooksOS[3]); DummySavedVersionsDialog dlg = new DummySavedVersionsDialog(m_cache); TreeView tree = dlg.ArchiveTree; // Select the archive node that was just added. tree.SelectedNode = tree.Nodes[0]; dlg.SimulateSelectEvent(); // Check to make sure the Compare to Current Version button is disabled Assert.IsFalse(dlg.ComparetoCurrentVersionBtn.Enabled, "The Compare to Current Version button should be disabled"); // Select a book node. tree.SelectedNode = tree.Nodes[0].Nodes[0]; dlg.SimulateSelectEvent(); // Check to make sure the Diff button is still disabled if we select Philemon // after it is removed from the DB. Assert.IsFalse(dlg.ComparetoCurrentVersionBtn.Enabled, "The Compare to Current Version button should still"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="cache"></param> /// <param name="filter">book filter in place</param> /// <param name="bookID">ordinal ID of the book being removed</param> /// ------------------------------------------------------------------------------------ public UndoRemoveBookAction(FdoCache cache, FilteredScrBooks filter, int bookID) { m_cache = cache; m_bookFilter = filter; m_bookID = bookID; m_bookHvo = ScrBook.FindBookByID(m_cache, bookID).Hvo; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Go to the previous footnote in the footnote view /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ public override ScrFootnote GoToPreviousFootnote() { CheckDisposed(); // In case no footnote is selected - can happen when footnote pane is first opened. if (CurrentSelection == null) { return(null); } // Get the information needed from the current selection int iBook = CurrentSelection.GetLevelInfoForTag(BookFilter.Tag).ihvo; int iFootnote = CurrentSelection.GetLevelInfoForTag((int)ScrBook.ScrBookTags.kflidFootnotes).ihvo; ScrBook book = BookFilter.GetBook(iBook); // Get the previous footnote if it exists if (--iFootnote < 0) { return(null); } ScrFootnote footnote = new ScrFootnote(m_cache, book.FootnotesOS.HvoArray[iFootnote]); ScrollToFootnote(iBook, iFootnote, 0); return(footnote); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load data needed to display the specified objects using the specified fragment. /// This is called before attempting to Display an item that has been listed for lazy /// display using AddLazyItems. It may be used to load the necessary data into the /// DataAccess object. /// </summary> /// <param name="vwenv"></param> /// <param name="rghvo"></param> /// <param name="chvo"></param> /// <param name="hvoParent"></param> /// <param name="tag"></param> /// <param name="frag"></param> /// <param name="ihvoMin"></param> /// ------------------------------------------------------------------------------------ public override void LoadDataFor(IVwEnv vwenv, int[] rghvo, int chvo, int hvoParent, int tag, int frag, int ihvoMin) { CheckDisposed(); string text; try { switch ((FootnoteFrags)frag) { case FootnoteFrags.kfrBook: { ScrBook scrBook; // The range of hvo's are for scripture books. Loop through the list of // requested books (i.e. requested by the views framework). foreach (int hvo in rghvo) { try { scrBook = new ScrBook(m_cache, hvo); // Loop through all the footnotes in the book. foreach (StFootnote stFootnote in scrBook.FootnotesOS) { if (ContentType == ContentTypes.kctSegmentBT) { LoadDataForStText(stFootnote); } // This serves only to load the data from the database into the // cache. That's because referencing an fdo cache property forces // its data to be loaded if it hasn't been already. foreach (StTxtPara stPara in stFootnote.ParagraphsOS) { text = stPara.Contents.Text; } } } catch (Exception e) { Debug.WriteLine("Got exception while loading footnotes for book: " + e.Message); throw; } } break; } default: Debug.Assert(false); break; } } catch (Exception e) { Debug.WriteLine("Got exception in LoadDataFor: " + e.Message); throw; } }
int m_wsUr; // Urdu writing system (used for Foreign style) #endregion #region Test setup /// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_inMemoryCache.InitializeWritingSystemEncodings(); // create footnote m_footnote = new StFootnote(); m_book = (ScrBook)m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis"); m_book.FootnotesOS.Append(m_footnote); m_footnote.FootnoteMarker.Text = "o"; m_footnote.DisplayFootnoteMarker = true; m_footnote.DisplayFootnoteReference = false; // create one empty footnote para StTxtPara para = new StTxtPara(); m_footnote.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.NormalFootnoteParagraph); m_strFact = TsStrFactoryClass.Create(); m_vernWs = Cache.LangProject.DefaultVernacularWritingSystem; para.Contents.UnderlyingTsString = m_strFact.MakeString(string.Empty, m_vernWs); m_footnotePara = (StTxtPara)m_footnote.ParagraphsOS[0]; m_wsUr = InMemoryFdoCache.s_wsHvos.Ur; // used with 'foreign' character style m_wsDe = InMemoryFdoCache.s_wsHvos.De; // used for back translations m_wsEs = InMemoryFdoCache.s_wsHvos.Es; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Loads the footnotes. /// </summary> /// <param name="footnoteHvo">The footnote hvo.</param> /// ------------------------------------------------------------------------------------ private void LoadFootnotes(int footnoteHvo) { Debug.Assert(m_cache.GetClassOfObject(footnoteHvo) == StFootnote.kClassId); StFootnote foot = new StFootnote(m_cache, footnoteHvo); IScrBook book = new ScrBook(m_cache, foot.OwnerHVO); int footnoteCount = GetBookFootnoteCount(book.Hvo); FdoOwningSequence <IStFootnote> footnotes = book.FootnotesOS; // If the information we want is already in the cache, then do nothing if (footnotes.Count == footnoteCount && m_htFootnoteIndex.ContainsKey(footnoteHvo)) { return; } ScrFootnote footnote = null; int index = 0; for (int i = 0; i < footnotes.Count; i++) { footnote = new ScrFootnote(m_cache, footnotes.HvoArray[i]); if (footnote.FootnoteType == FootnoteMarkerTypes.AutoFootnoteMarker) { int oldIndex = GetFootnoteIndex(footnote.Hvo); if (oldIndex != index) { m_htFootnoteIndex[footnote.Hvo] = new FootnoteIndexCacheInfo(index, true); } index++; } } m_htBookFootnoteCount[book.Hvo] = footnotes.Count; }
public void PageElementsDontOverlap_TwoFootnotes() { IScripture scr = Cache.LangProject.TranslatedScriptureOA; ScrBook genesis = (ScrBook)scr.ScriptureBooksOS[0]; // Add a footnote in the first book, first section, first paragraph IScrSection section = (IScrSection)genesis.SectionsOS[0]; StFootnote footnote = m_scrInMemoryCache.AddFootnote(genesis, (StTxtPara)section.ContentOA.ParagraphsOS[0], 2); StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "Another footnote", 0); // Add a footnote in the first book, last section, 6th paragraph section = (IScrSection)genesis.SectionsOS[genesis.SectionsOS.Count - 1]; footnote = m_scrInMemoryCache.AddFootnote(genesis, (StTxtPara)section.ContentOA.ParagraphsOS[5], 10); para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "This is the footnote", 0); m_pub.CreatePages(); m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2); Page firstPage = m_pub.Pages[0]; int cFoonotesOnThisPage = (int)m_division.m_testPageFootnoteInfo[firstPage.Handle]; Assert.AreEqual(2, cFoonotesOnThisPage, "Should display two footnotes on first page"); // None of the page elements on the first page should intersect CheckThatPageElementsDontOverlap(firstPage); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get a string that describes the Scripture passage based on the selection. /// </summary> /// <param name="tag">The flid of the selected element</param> /// <param name="hvoSel">The hvo of the selected element, either a ScrSection (usually) /// or ScrBook (if in a title)</param> /// <param name="fSimpleFormat">Gets a simple, standardized reference (uses SIL 3-letter /// codes and no verse bridges)</param> /// <returns> /// String that describes the Scripture passage or null if the selection /// can't be interpreted as a book and/or section reference. /// </returns> /// ------------------------------------------------------------------------------------ public override string GetPassageAsString(int tag, int hvoSel, bool fSimpleFormat) { CheckDisposed(); if (m_cache == null) { return(null); } string sEditRef = null; // Title/reference/etc of text being edited in the draft pane switch (tag) { case (int)ScrBook.ScrBookTags.kflidFootnotes: { ScrBook book = new ScrBook(m_cache, hvoSel, false, false); sEditRef = (fSimpleFormat ? (book.BookId + " 0:0") : book.BestUIName); break; } default: return(base.GetPassageAsString(tag, hvoSel, fSimpleFormat)); } // Add the back translation writing system info to the output string, if needed if (IsBackTranslation) { LgWritingSystem ws = new LgWritingSystem(m_cache, ViewConstructorWS); sEditRef = string.Format( TeResourceHelper.GetResourceString("kstidCaptionInBackTrans"), sEditRef, ws.Name.UserDefaultWritingSystem); } return(string.IsNullOrEmpty(sEditRef) ? null : sEditRef); }
/// ------------------------------------------------------------------------------------ /// <summary> /// When a footnote is deleted and there are no more in the book, find the book index /// and footnote index of the nearest footnote. /// </summary> /// <param name="iBook">The book index in the filter.</param> /// <param name="iFootnote">The footnote index.</param> /// ------------------------------------------------------------------------------------ protected void FindNearestFootnote(ref int iBook, ref int iFootnote) { // first, try to move to the first footnote in a following book for (int iFindBook = iBook + 1; iFindBook < m_bookFilter.BookCount; iFindBook++) { ScrBook book = m_bookFilter.GetBook(iFindBook); if (book.FootnotesOS.Count > 0) { iBook = iFindBook; iFootnote = 0; return; } } // we did not find a footnote in any following books, so look at the previous books for (int iFindBook = iBook; iFindBook >= 0; iFindBook--) { ScrBook book = m_bookFilter.GetBook(iFindBook); if (book.FootnotesOS.Count > 0) { iBook = iFindBook; iFootnote = book.FootnotesOS.Count - 1; return; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determine the start and end reference for the section this paragraph belongs to. /// </summary> /// <param name="sectRefStart">Section start reference</param> /// <param name="sectRefEnd">Section end reference</param> /// ------------------------------------------------------------------------------------ protected void GetSectionStartAndEndRefs(out BCVRef sectRefStart, out BCVRef sectRefEnd) { // Processing depends on "type" of paragraph (content, heading, title...) switch (m_cache.GetOwningFlidOfObject(OwnerHVO)) { case (int)ScrSection.ScrSectionTags.kflidContent: case (int)ScrSection.ScrSectionTags.kflidHeading: { int hvoScrSection = m_cache.GetOwnerOfObject(OwnerHVO); int nSectRefMin = m_cache.GetIntProperty(hvoScrSection, (int)ScrSection.ScrSectionTags.kflidVerseRefMin); int nSectRefMax = m_cache.GetIntProperty(hvoScrSection, (int)ScrSection.ScrSectionTags.kflidVerseRefMax); sectRefStart = new BCVRef(nSectRefMin); sectRefEnd = new BCVRef(nSectRefMax); break; } case (int)ScrBook.ScrBookTags.kflidTitle: { IScrBook scrBook = new ScrBook(m_cache, m_cache.GetOwnerOfObject(OwnerHVO)); sectRefStart = new BCVRef(scrBook.CanonicalNum, 1, 0); sectRefEnd = new BCVRef(scrBook.CanonicalNum, 1, 0); break; } default: Debug.Assert(false); // Unexpected owning field for StText sectRefStart = 0; sectRefEnd = 0; break; } }
public void DeleteFootnoteSelection() { m_ScrPubCtrl.PageHeight = 432000; // 6 inches m_ScrPubCtrl.PageWidth = 288000; // 4 inches m_division.TopMargin = 18000; // Half inch m_division.BottomMargin = 18000; m_division.InsideMargin = 18000; m_division.OutsideMargin = 18000; m_ScrPubCtrl.Width = 4 * 96; // represents a window that is 4" wide at 96 DPI m_ScrPubCtrl.CreatePages(); List <Page> pagesToBeDrawn = m_ScrPubCtrl.PrepareToDrawPages(0, 2000); IVwLayoutStream layoutStream = m_division.MainLayoutStream; IVwRootBox rootbox = layoutStream as IVwRootBox; // Get number of footnotes in book. IScripture scr = m_fdoCache.LangProject.TranslatedScriptureOA; Assert.AreEqual(3, scr.ScriptureBooksOS.Count); ScrBook james = (ScrBook)m_fdoCache.LangProject.TranslatedScriptureOA.ScriptureBooksOS[1]; int numFootnotes = james.FootnotesOS.Count; // Select the first footnote in James. SelectionHelper selHelper = SelectRangeOfChars(rootbox, 2, 2, 3); // Delete the footnote marker selection. //m_footnoteView.OnKeyDown(new KeyEventArgs(Keys.Delete)); m_ScrPubCtrl.PressKey(new KeyEventArgs(Keys.Delete)); // Confirm that there is one less footnote in the book. Assert.AreEqual(numFootnotes - 1, james.FootnotesOS.Count); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="para"></param> /// <param name="iPara"></param> /// <param name="section"></param> /// <param name="iSec"></param> /// <param name="book"></param> /// <param name="iBook"></param> /// <param name="setupForHeading"></param> /// ------------------------------------------------------------------------------------ public void SetupSelectionInPara(StTxtPara para, int iPara, ScrSection section, int iSec, ScrBook book, int iBook, int ich, bool setupForHeading) { CheckDisposed(); SetupRangeSelection(book, iBook, section, iSec, para, iPara, ich, setupForHeading, book, iBook, section, iSec, para, iPara, ich, setupForHeading); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clear the footnote cache before refreshing the display. /// </summary> /// ------------------------------------------------------------------------------------ public override void RefreshDisplay() { CheckDisposed(); DoSpellCheck = (EditingHelper as TeEditingHelper).ShowSpellingErrors; ScrBook.ClearAllFootnoteCaches(m_fdoCache); base.RefreshDisplay(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="ScrCheckingTokenizer"/> class. /// </summary> /// <param name="book">The book being parsed.</param> /// <param name="chapterNum">The 1-basede canonical chapter number being parse, or 0 to /// parse the whole book</param> /// ------------------------------------------------------------------------------------ public ScrCheckingTokenizer(ScrBook book, int chapterNum) { m_book = book; m_scr = (Scripture)book.Owner; m_chapterNum = chapterNum; m_writingSystemLocales = new Dictionary <int, string>(); Reset(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> /// ------------------------------------------------------------------------------------ public void Dispose() { m_book = null; m_currentSection = null; m_internalToken = null; m_outerText = null; m_currentScrText = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructs ParaNode map using the paragraph. /// </summary> /// <param name="para">The given paragraph.</param> /// ------------------------------------------------------------------------------------ private void ConstructFromPara(StTxtPara para) { // Get the iPara first m_location[kParaIndex] = para.IndexInOwner; // Prepare to get the others StText text = new StText(para.Cache, para.OwnerHVO); int hvoOwner = para.Cache.GetOwnerOfObject(text.Hvo); int ownerClass = para.Cache.GetClassOfObject(hvoOwner); // If the ownerClass is a book, we know that sections are not relevant // to this paragraph and can process accordingly if (ownerClass == ScrBook.kClassId) { // If we've got a title, we can set the rest in short order // (we know that there are no sections) Debug.Assert(text.OwningFlid == (int)ScrBook.ScrBookTags.kflidTitle); m_location[kSectionFlidIndex] = 0; m_location[kSectionIndex] = 0; m_location[kBookFlidIndex] = kTitle; ScrBook book = new ScrBook(para.Cache, text.OwnerHVO); m_location[kBookIndex] = book.IndexInOwner; } // Otherwise, we'll need to use the section data else if (ownerClass == ScrSection.kClassId) { // Since we have sections, get the flid and set others based upon it int sectionFlid = text.OwningFlid; if (sectionFlid == (int)ScrSection.ScrSectionTags.kflidHeading) { m_location[kSectionFlidIndex] = kHeading; } else if (sectionFlid == (int)ScrSection.ScrSectionTags.kflidContent) { m_location[kSectionFlidIndex] = kContent; } // If it was not one of these types, something is wrong, it's an invalid // flid else { Debug.Assert(false); } ScrSection section = new ScrSection(para.Cache, text.OwnerHVO); m_location[kSectionIndex] = section.IndexInOwner; m_location[kBookFlidIndex] = kSections; m_location[kBookIndex] = section.OwningBook.IndexInOwner; } else { Debug.Assert(false); } // default char offset m_location[kCharIndex] = 0; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Read the text for the specified book number. /// ENHANCE: For our initial implementation, we'll see how it performs if we don't /// do the parsing ahead of time. We'll just set up the enumerators...Parse into Tokens. /// The tokens are accessed via the TextTokens() method. /// We split this operation into two parts since we often want to create /// the tokens list once and then present them to several different checks. /// </summary> /// <param name="bookNum">Canonical number of book, as returned in list from call to /// BooksPresent.</param> /// <param name="chapterNum">0=read whole book, else specified chapter number</param> /// <returns><c>true</c></returns> /// ------------------------------------------------------------------------------------ public bool GetText(int bookNum, int chapterNum) { m_bookBeingChecked = (ScrBook)m_scr.FindBook(bookNum); SetParameterValue("Book ID", m_bookBeingChecked.BookId); SetParameterValue("Chapter Number", chapterNum.ToString()); return(m_bookBeingChecked.GetTextToCheck(chapterNum)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes a footnote /// </summary> /// <param name="args"></param> /// <returns><c>true</c> if we handle this</returns> /// ------------------------------------------------------------------------------------ protected bool OnDeleteFootnote(object args) { if (DataUpdateMonitor.IsUpdateInProgress(DataAccess)) { return(true); //discard this event } if (!ValidFootnoteSelection) { return(true); } string undo; string redo; TeResourceHelper.MakeUndoRedoLabels("kstidUndoDelFootnote", out undo, out redo); using (new UndoTaskHelper(this, undo, redo, false)) using (new DataUpdateMonitor(this, RootBox.DataAccess, this, "DeleteFootnote")) { SelectionHelper helper = SelectionHelper.Create(this); int fnLevel = helper.GetLevelForTag((int)ScrBook.ScrBookTags.kflidFootnotes); if (helper.Selection.IsRange) { DeleteFootnoteRange(helper); } else { // There's no range selection, so delete only one footnote ScrFootnote footnote = new ScrFootnote(m_fdoCache, helper.LevelInfo[fnLevel].hvo); ScrFootnote.DeleteFootnoteAndMarker(footnote); } if (RootBox.Height <= 0) { DraftView.Focus(); } else { int iBook = helper.LevelInfo[fnLevel + 1].ihvo; ScrBook book = m_bookFilter.GetBook(iBook); int iFootnote = helper.LevelInfo[fnLevel].ihvo; // If the last footnote in the book was deleted find a footnote to move to if (iFootnote >= book.FootnotesOS.Count) { FindNearestFootnote(ref iBook, ref iFootnote); } FootnoteEditingHelper.ScrollToFootnote(iBook, iFootnote, 0); } } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the View Differences button. Display the Review Differences window to /// view/merge differences between the current scripture and selected book in the tree. /// </summary> /// ------------------------------------------------------------------------------------ private void m_btnDiff_Click(object sender, System.EventArgs e) { // If the selected item is not a book, then don't do a diff. TreeNode node = m_treeArchives.SelectedNode; if (node == null) { return; } ScrBook bookRev = node.Tag as ScrBook; if (bookRev == null) { return; } //ScrDraft archive = node.Parent.Tag as ScrDraft; using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, bookRev)) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this)) { progress.Title = DlgResources.ResourceString("kstidCompareCaption"); progress.Message = string.Format( DlgResources.ResourceString("kstidMergeProgress"), bookRev.BestUIName); progress.RunTask(true, new BackgroundTaskInvoker(merger.DetectDifferences)); } // always hide diffs that could cause deletion of current sections, if reverted merger.UseFilteredDiffList(); // If there were differences detected then show the diff dialog if (merger.NumberOfDifferences != 0) { using (DiffDialog dlg = new DiffDialog(merger, m_cache, m_styleSheet, m_zoomDraft, m_zoomFootnote)) { // We have to pass the owner (this), so that the dialog shows when the // user clicks on the TE icon in the taskbar. Otherwise only the Archive // dialog would pop up and beeps; diff dialog could only be regained by Alt-Tab. dlg.ShowDialog(this); } } else { // Tell users that no differences were found in the merge MessageBox.Show(this, string.Format(DlgResources.ResourceString("kstidNoDifferencesDetected"), bookRev.BestUIName), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Moves one or more paragraphs from the content of one section to the beginning of /// the heading of the following section. The paragraphs from the given index to the /// last content paragraph are moved. /// </summary> /// <param name="cache">the fdocache</param> /// <param name="book">the current book</param> /// <param name="iSection">index of the section we move paragraphs from</param> /// <param name="indexFirstPara">index of the first content paragraph to be moved</param> /// ------------------------------------------------------------------------------------ public static void MoveContentParasToNextSectionHeading(FdoCache cache, ScrBook book, int iSection, int indexFirstPara) { Debug.Assert(iSection < book.SectionsOS.Count - 1); IScrSection origSection = book.SectionsOS[iSection]; IScrSection nextSection = book.SectionsOS[iSection + 1]; // Copy the paragraphs from the section content to the next section heading StText.MoveTextParagraphs(origSection.ContentOA, nextSection.HeadingOA, indexFirstPara, false); }
public void PagesWithFootnotes() { CheckDisposed(); // Need VC with footnotes for this test, so we recreate one ConfigurePublication(true); // Add a footnote in the last book, last section, last paragraph IScripture scr = Cache.LangProject.TranslatedScriptureOA; ScrBook deut = (ScrBook)scr.ScriptureBooksOS[scr.ScriptureBooksOS.Count - 1]; IScrSection section = (IScrSection)deut.SectionsOS[deut.SectionsOS.Count - 1]; StFootnote footnote = m_scrInMemoryCache.AddFootnote(deut, (StTxtPara)section.ContentOA.ParagraphsOS[section.ContentOA.ParagraphsOS.Count - 1], 10); StTxtPara para = m_scrInMemoryCache.AddParaToMockedText(footnote.Hvo, ScrStyleNames.NormalFootnoteParagraph); m_scrInMemoryCache.AddRunToMockedPara(para, "This is the footnote", 0); // Set up the publication m_pub.PageHeight = 72000 * 11; // 11 inches m_pub.PageWidth = (int)(72000 * 8.5); // 8.5 inches m_division.TopMargin = 36000; // Half inch m_division.BottomMargin = 18000; // Quarter inch m_division.InsideMargin = 9000; // 1/8 inch m_division.OutsideMargin = 4500; // 1/16 inch DummyMainLazyViewVc vc = m_division.MainVc as DummyMainLazyViewVc; vc.m_estBookHeight = 2000; vc.m_estSectionHeight = 2000; m_pub.Width = 3 * 96; // represents a window that is 3" wide at 96 DPI m_pub.CreatePages(); Assert.AreEqual(14, m_pub.Pages.Count, "Our estimate of book should try to fit all of Scripture on 14 pages."); // expand the last page m_pub.ScrollPosition = new Point(-m_pub.ScrollPosition.X, m_pub.AutoScrollMinSize.Height - 10); m_pub.PrepareToDrawPages(0, 100); // now expand all of the pages m_pub.ScrollPosition = new Point(0, 0); m_pub.PrepareToDrawPages(0, m_pub.AutoScrollMinSize.Height * 2); Page lastPage = (Page)m_pub.Pages[m_pub.Pages.Count - 1]; PageElement peMain = lastPage.GetFirstElementForStream(m_division.MainLayoutStream); Assert.IsTrue(m_division.m_testPageFootnoteInfo.ContainsKey(lastPage.Handle)); Assert.AreEqual(2, lastPage.PageElements.Count, "Main and footnote streams should be laid out on page " + lastPage.PageNumber); int cFoonotesOnThisPage = (int)m_division.m_testPageFootnoteInfo[lastPage.Handle]; Assert.Greater(cFoonotesOnThisPage, 0, "Should display at least one footnote on last page"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Moves the requested number of paragraphs from the heading of one section to the end /// of the content of the previous section. /// </summary> /// <param name="cache">the fdocache</param> /// <param name="book">the current book</param> /// <param name="iSection">index of the section we move paragraphs from</param> /// <param name="indexLastPara">index of the last heading paragraph to be moved</param> /// <returns>number of paragraphs in previous section before move (use as index /// of first moved paragraph)</returns> /// ------------------------------------------------------------------------------------ public static int MoveHeadingToPreviousSectionContent(FdoCache cache, ScrBook book, int iSection, int indexLastPara) { IScrSection prevSection = book.SectionsOS[iSection - 1]; IScrSection origSection = book.SectionsOS[iSection]; //this************* int cInitParaCount = prevSection.ContentOA.ParagraphsOS.Count; // Copy the paragraphs from the section heading to the previous section content StText.MoveTextParagraphs(origSection.HeadingOA, prevSection.ContentOA, indexLastPara, true); return(cInitParaCount); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets book from list of filtered books by book ordinal. /// </summary> /// <param name="canonicalNum">Ordinal of book - <code>ScrBook.CanonicalNum</code></param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public ScrBook GetBookByOrd(int canonicalNum) { CheckFilteredBooks(); for (int i = 0; i < m_filteredBooks.Count; i++) { ScrBook book = new ScrBook(m_cache, m_filteredBooks[i]); if (book.CanonicalNum == canonicalNum) { return(book); } } return(null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="IScrBook"/> class and adds it to /// the given sequence. /// </summary> /// <param name="booksOS">Owning sequence of books to add the new book to</param> /// <param name="bookNumber">Canonical book number to be inserted</param> /// <returns>A ScrBook object representing the newly inserted book</returns> /// <exception cref="InvalidOperationException">If this method is called with a /// canonical book number which is already represented in the given sequence</exception> /// ------------------------------------------------------------------------------------ public IScrBook Create(IFdoOwningSequence<IScrBook> booksOS, int bookNumber) { int iBook = 0; foreach (var existingBook in booksOS) { if (existingBook.CanonicalNum == bookNumber) throw new InvalidOperationException("Attempting to create a Scripture book that already exists."); if (existingBook.CanonicalNum > bookNumber) break; iBook++; } IScrBook book = new ScrBook(); booksOS.Insert(iBook, book); book.CanonicalNum = bookNumber; book.BookIdRA = m_cache.ServiceLocator.GetInstance<IScrRefSystemRepository>().Singleton.BooksOS[bookNumber - 1]; book.Name.CopyAlternatives(book.BookIdRA.BookName); book.Abbrev.CopyAlternatives(book.BookIdRA.BookAbbrev); return book; }