/// <summary> /// Move the sandbox to the annotation hvoAnnotation, currently analyzed as hvoAnalysis /// (which may be a WfiWordform, WfiAnalysis, or WfiGloss). /// </summary> /// <param name="hvoAnnotation"></param> /// <param name="hvoAnalysis"></param> /// <param name="fSaveGuess">if true, saves guesses; if false, skips guesses but still saves edits.</param> /// <param name="fMakeDefaultSelection">true to make the default selection within the /// new sandbox.</param> public virtual void TriggerAnnotationSelected(int hvoAnnotation, int hvoAnalysis, bool fSaveGuess, bool fMakeDefaultSelection) { // This can happen, though it is rare...see LT-8193. if (hvoAnnotation == 0) return; StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, hvoAnnotation); if (!twficInfo.IsObjectValid()) { this.MessageBoxMasterRefresh(); return; } if (Cache.IsDummyObject(hvoAnnotation)) { // convert this to a real object. using (SuppressSubTasks supressActionHandler = new SuppressSubTasks(Cache, true)) { int hvoAnnDummy = hvoAnnotation; CmBaseAnnotation realAnn = CmObject.ConvertDummyToReal(Cache, hvoAnnotation) as CmBaseAnnotation; hvoAnnotation = realAnn.Hvo; // re-cache items important to this view, without which some things like guesses may not appear // until after a refresh. TryCacheRealWordForm(hvoAnnotation); TryCacheLowercasedForm(hvoAnnotation); } } //if (hvoAnnotation != m_hvoAnnotation) //{ TryHideFocusBox(); Sandbox sandbox = ChangeOrCreateSandbox(hvoAnnotation, ref hvoAnalysis, fSaveGuess); FocusBox.InterlinWordControl = sandbox; if (!Controls.Contains(FocusBox)) Controls.Add(FocusBox); // Makes it real and may give it a root box. SetSandboxSize(); int hvoOldAnnotation = m_hvoAnnotation; HvoAnnotation = hvoAnnotation; m_hvoAnalysis = hvoAnalysis; SimulateReplaceAnnotation(hvoOldAnnotation); SimulateReplaceAnnotation(m_hvoAnnotation); MoveFocusBoxIntoPlace(); // Now it is the right size and place we can show it. TryShowFocusBox(); sandbox.Focus(); CheckForFreeOrLitAnnotations(MakeSandboxSel()); if (m_fCanAddFreeTrans) { // add a free translation for this segment, // but don't change the selection from the sandbox. AddFreeTrans(false); } if (fMakeDefaultSelection) FocusBox.InterlinWordControl.MakeDefaultSelection(); //} if (AnnnotationSelected != null) AnnnotationSelected(this, new AnnotationSelectedArgs(hvoAnnotation, hvoAnalysis)); }
internal bool CurrentParaIsValid() { if (ForEditing == false) return true; // not tracking a current annotation. if (HvoAnnotation == 0) return false; StTxtPara.TwficInfo currentTwficInfo = new StTxtPara.TwficInfo(Cache, HvoAnnotation); if (!currentTwficInfo.IsObjectValid()) return false; // go through the current paragraph and validate its segments and twfics. StTxtPara para = currentTwficInfo.Object.BeginObjectRA as StTxtPara; IVwVirtualHandler vh; if (Cache.TryGetVirtualHandler(StTxtPara.SegmentsFlid(Cache), out vh)) { BaseVirtualHandler bvh = vh as BaseVirtualHandler; if (!bvh.IsPropInCache(Cache.MainCacheAccessor, para.Hvo, 0)) return false; } int twficType = CmAnnotationDefn.Twfic(Cache).Hvo; foreach (int hvoSegment in para.Segments) { if (!Cache.IsValidObject(hvoSegment)) return false; foreach (int hvoSegform in para.SegmentForms(hvoSegment)) { // kflidAnnotationType int hvoAnnType = Cache.GetObjProperty(hvoSegform, (int)CmBaseAnnotation.CmAnnotationTags.kflidAnnotationType); if (hvoAnnType == twficType) { // do extra checking on twfics. StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, hvoSegform); if (!twficInfo.IsObjectValid()) return false; } else if (!Cache.IsValidObject(hvoSegform)) { return false; } } } return true; }
internal bool CurrentAnnotationIsValid() { if (ForEditing == false) return true; // not tracking a current annotation. if (HvoAnnotation == 0) return false; StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, HvoAnnotation); return twficInfo.IsObjectValid(); }
public void LT7202_CrashInWordsAfterEditingBaselineText() { // Switch to Texts m_window.ActivateTool("interlinearEdit"); RecordClerk clerk = m_window.ActiveClerk; int hvoFirstSelectedText = clerk.CurrentObject.Hvo; // switch to baseline tab. m_window.InvokeCommand("CmdInsertText"); int hvoNewText = clerk.CurrentObject.Hvo; Assert.AreNotEqual(hvoFirstSelectedText, hvoNewText, "clerk current object should have changed after inserting new text."); // should be the text in the active clerk. StText stText = clerk.CurrentObject as StText; // Assert in new text. using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - LT7202", "ConcordanceControlTests - LT7202")) { // verify we are in a blank text. Assert.AreEqual(null, (stText.ParagraphsOS[0] as StTxtPara).Contents.Text, "new text should be empty"); // paste in a new paragraph ITsStrFactory tsf = TsStrFactoryClass.Create(); (stText.ParagraphsOS[0] as StTxtPara).Contents.UnderlyingTsString = tsf.MakeString("aVVV boyVVV", Cache.DefaultVernWs); } // switch to InterlinearTab. InterlinMaster interlinMaster = m_window.FindControl("InterlinMaster") as InterlinMaster; TabControl interlinTabs = interlinMaster.Controls.Find("m_tabCtrl", false)[0] as TabControl; interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.Interlinearizer; InterlinDocChild idc = interlinMaster.Controls.Find("m_idcPane", true)[0] as InterlinDocChild; Assert.IsTrue(idc.HvoAnnotation != 0, "Expected to have selected nonzero annotation"); StTxtPara.TwficInfo currentTwficInfo = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation); Assert.IsTrue(currentTwficInfo.IsObjectValid() && currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId, "Expected to have selected a wfiwordform annotation"); Assert.AreEqual("aVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem, "Expected to have selected annotation for 'aVVV'"); // switch to wordListConcordance m_window.ActivateTool("wordListConcordance"); // validate we haven't invalidated the "aVVV" wordform or its annotation (yet) Assert.IsTrue(currentTwficInfo.IsObjectValid() && currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId && currentTwficInfo.Object.IsValidObject(), "Expected to have a valid wfiwordform"); // jump to the "aVVV" wordform. clerk = m_window.ActiveClerk; clerk.JumpToRecord(currentTwficInfo.Object.InstanceOfRAHvo); m_window.ProcessPendingItems(); // validate we jumped to the right wordform. Assert.AreEqual("aVVV", (clerk.CurrentObject as WfiWordform).Form.VernacularDefaultWritingSystem, "Expected to have selected wordform 'aVVV'"); // verify our OccurrencesOfWordform clerk sync'd properly. RecordClerk occurrencesClerk = RecordClerk.FindClerk(Mediator, "OccurrencesOfSelectedWordform"); Assert.AreEqual(clerk.CurrentObject.Hvo, occurrencesClerk.OwningObject.Hvo, "OccurrencesOfSelectedWordform should be sync'd to the current object of the active clerk."); Assert.AreEqual(1, occurrencesClerk.ListSize); Assert.IsTrue(occurrencesClerk.CurrentObject != null); currentTwficInfo = new StTxtPara.TwficInfo(Cache, occurrencesClerk.CurrentObject.Hvo); Assert.IsTrue(currentTwficInfo.IsObjectValid() && currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId, "Expected to have selected a wfiwordform annotation"); Assert.AreEqual("aVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem, "Expected to have selected annotation for 'aVVV'"); interlinMaster = m_window.FindControl("InterlinMaster") as InterlinMaster; // switch to InterlinearTab interlinTabs = interlinMaster.Controls.Find("m_tabCtrl", false)[0] as TabControl; interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.Interlinearizer; idc = interlinMaster.Controls.Find("m_idcPane", true)[0] as InterlinDocChild; // Verify we've selected the annotation for 'aVVV' currentTwficInfo = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation); Assert.IsTrue(currentTwficInfo.IsObjectValid() && currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId, "Expected to have selected a wfiwordform annotation"); Assert.AreEqual("aVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem, "Expected to have selected annotation for 'aVVV'"); // switch back to interlinearEdit m_window.ActivateTool("interlinearEdit"); clerk = m_window.ActiveClerk; interlinMaster = m_window.FindControl("InterlinMaster") as InterlinMaster; interlinTabs = interlinMaster.Controls.Find("m_tabCtrl", false)[0] as TabControl; interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.RawText; using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - LT7202", "ConcordanceControlTests - LT7202")) { // remove the first word ITsStrFactory tsf = TsStrFactoryClass.Create(); (stText.ParagraphsOS[0] as StTxtPara).Contents.UnderlyingTsString = tsf.MakeString("boyVVV", Cache.DefaultVernWs); } // parse the text again interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.Interlinearizer; idc = interlinMaster.Controls.Find("m_idcPane", true)[0] as InterlinDocChild; currentTwficInfo = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation); Assert.IsTrue(currentTwficInfo.IsObjectValid() && currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId, "Expected to have selected a wfiwordform annotation"); Assert.AreEqual("boyVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem, "Expected to have selected annotation for 'boyVVV'"); // switch back to Word List Concordance // this is where it was crashing. m_window.ActivateTool("wordListConcordance"); // validate we're still on the 'aVVV' wordform. clerk = m_window.ActiveClerk; Assert.AreEqual("aVVV", (clerk.CurrentObject as WfiWordform).Form.VernacularDefaultWritingSystem, "Expected to have selected wordform 'aVVV'"); occurrencesClerk = RecordClerk.FindClerk(Mediator, "OccurrencesOfSelectedWordform"); Assert.AreEqual(clerk.CurrentObject.Hvo, occurrencesClerk.OwningObject.Hvo, "OccurrencesOfSelectedWordform should be sync'd to the current object of the active clerk."); // should have cleared our occurrences list for this wordform. Assert.AreEqual(0, occurrencesClerk.ListSize, "Should have cleared the OccurrencesOfSelectedWordform for 'aVVV'"); }