/// ----------------------------------------------------------------------------------- /// <summary> /// Replace the user prompt with the text the user typed. This method is called from /// the views code when the user prompt is edited. /// </summary> /// <param name="vwsel">Current selection in rootbox where this prop was updated</param> /// <param name="hvo">Hvo of the paragraph/string/segment whose contents are being /// changed</param> /// <param name="tag">Tag (must be SimpleRootSite.kTagUserPrompt)</param> /// <param name="frag">Owning flid of the text/object that owns the paragraph/string/ /// segment whose user prompt is being replaced with typed text</param> /// <param name="tssVal">Text the user just typed</param> /// <returns>possibly modified ITsString.</returns> /// <remarks>The return value is currently ignored in production code, but we use it /// in our tests.</remarks> /// ----------------------------------------------------------------------------------- public override ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag, ITsString tssVal) { Debug.Assert(tag == SimpleRootSite.kTagUserPrompt, "Got an unexpected tag"); Debug.Assert(vwsel != null, "Got a null selection!"); Debug.Assert(vwsel.IsValid, "Got an invalid selection!"); IVwRootBox rootbox = vwsel.RootBox; // If a (typically Chinese) character composition is in progress, replacing the prompt will // destroy the selection and end the composition, causing weird typing problems (TE-8267). // Ending the composition does another Commit, which ensures that this will eventually be // called when there is NOT a composition in progress. if (rootbox.IsCompositionInProgress) { return(tssVal); } // Remove the UserPrompt pseudo-property from the text the user typed. // when appropriate also ensure the correct writing system. // The correct WS is m_wsDefault in the view constructor ITsStrBldr bldr = tssVal.GetBldr(); if (frag != SegmentTags.kflidFreeTranslation) { bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_wsDefault); } // Delete the user prompt property from the string (TE-3994) bldr.SetIntPropValues(0, bldr.Length, SimpleRootSite.ktptUserPrompt, -1, -1); tssVal = bldr.GetString(); // Get information about current selection int cvsli = vwsel.CLevels(false); cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. int ihvoRoot; int tagTextProp_Ignore; int cpropPrevious; int ichAnchor; int ichEnd; int ihvoEnd; // Prior to the Commit in selection changed which causes this UpdateProp to be called, // earlier selection changed code has expanded the selection (because it is in a user prompt) // to the whole prompt. It is therefore a range selection, and the value of fAssocPrev we got // is useless. bool fAssocPrev_Ignore; int ws; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwsel, cvsli, out ihvoRoot, out tagTextProp_Ignore, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev_Ignore, out ihvoEnd, out ttp); int tagTextProp; ITsTextProps props = null; if (frag == SegmentTags.kflidFreeTranslation) { // If the length is zero...we need to suppress replacing the comment with a prompt. if (tssVal.Length == 0) { m_hvoOfSegmentWhoseBtPromptIsToBeSupressed = hvo; } ISegment seg = Cache.ServiceLocator.GetInstance <ISegmentRepository>().GetObject(hvo); if (seg.FreeTranslation.get_String(BackTranslationWS).Length == 0) { // Undo needs to unset suppressing the comment prompt. Cache.ActionHandlerAccessor.AddAction(new UndoSuppressBtPrompt(this, seg)); } ws = BackTranslationWS; tagTextProp = frag; seg.FreeTranslation.set_String(ws, tssVal); rootbox.PropChanged(seg.Paragraph.Owner.Hvo, StTextTags.kflidParagraphs, seg.Paragraph.IndexInOwner, 1, 1); } else { ReplacePromptUndoAction undoAction = new ReplacePromptUndoAction(hvo, rootbox, m_updatedPrompts); if (m_cache.ActionHandlerAccessor != null) { m_cache.ActionHandlerAccessor.AddAction(new UndoSelectionAction(rootbox.Site, true, vwsel)); m_cache.ActionHandlerAccessor.AddAction(undoAction); } // Mark the user prompt as having been updated - will not show prompt again. // Note: ReplacePromptUndoAction:Undo removes items from the Set. m_updatedPrompts.Add(hvo); // Replace the ITsString in the paragraph or translation props = StyleUtils.CharStyleTextProps(null, m_wsDefault); if (frag == CmTranslationTags.kflidTranslation) { ICmTranslation trans = Cache.ServiceLocator.GetInstance <ICmTranslationRepository>().GetObject(hvo); trans.Translation.set_String(m_wsDefault, tssVal); undoAction.ParaHvo = trans.Owner.Hvo; ws = BackTranslationWS; tagTextProp = frag; } else { IStTxtPara para = Cache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(hvo); para.Contents = tssVal; undoAction.ParaHvo = hvo; ws = 0; tagTextProp = StTxtParaTags.kflidContents; } // Do a fake propchange to update the prompt rootbox.PropChanged(undoAction.ParaHvo, StParaTags.kflidStyleRules, 0, 1, 1); } // Now request a selection at the end of the text that was just put in. rootbox.Site.RequestSelectionAtEndOfUow(rootbox, ihvoRoot, cvsli, rgvsli, tagTextProp, cpropPrevious, ichEnd, ws, true, props); return(tssVal); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Replace the user prompt with the text the user typed. This method is called from /// the views code when the user prompt is edited. /// </summary> /// <param name="vwsel">Current selection in rootbox where this prop was updated</param> /// <param name="hvo">Hvo of the paragraph/string/segment whose contents are being /// changed</param> /// <param name="tag">Tag (must be SimpleRootSite.kTagUserPrompt)</param> /// <param name="frag">Owning flid of the text/object that owns the paragraph/string/ /// segment whose user prompt is being replaced with typed text</param> /// <param name="tssVal">Text the user just typed</param> /// <returns>possibly modified ITsString.</returns> /// <remarks>The return value is currently ignored in production code, but we use it /// in our tests.</remarks> /// ----------------------------------------------------------------------------------- public override ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag, ITsString tssVal) { Debug.Assert(tag == SimpleRootSite.kTagUserPrompt, "Got an unexpected tag"); Debug.Assert(vwsel != null, "Got a null selection!"); Debug.Assert(vwsel.IsValid, "Got an invalid selection!"); IVwRootBox rootbox = vwsel.RootBox; // If a (typically Chinese) character composition is in progress, replacing the prompt will // destroy the selection and end the composition, causing weird typing problems (TE-8267). // Ending the composition does another Commit, which ensures that this will eventually be // called when there is NOT a composition in progress. if (rootbox.IsCompositionInProgress) return tssVal; // Remove the UserPrompt pseudo-property from the text the user typed. // when appropriate also ensure the correct writing system. // The correct WS is m_wsDefault in the view constructor ITsStrBldr bldr = tssVal.GetBldr(); if (frag != SegmentTags.kflidFreeTranslation) { bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_wsDefault); } // Delete the user prompt property from the string (TE-3994) bldr.SetIntPropValues(0, bldr.Length, SimpleRootSite.ktptUserPrompt, -1, -1); tssVal = bldr.GetString(); // Get information about current selection int cvsli = vwsel.CLevels(false); cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. int ihvoRoot; int tagTextProp_Ignore; int cpropPrevious; int ichAnchor; int ichEnd; int ihvoEnd; // Prior to the Commit in selection changed which causes this UpdateProp to be called, // earlier selection changed code has expanded the selection (because it is in a user prompt) // to the whole prompt. It is therefore a range selection, and the value of fAssocPrev we got // is useless. bool fAssocPrev_Ignore; int ws; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwsel, cvsli, out ihvoRoot, out tagTextProp_Ignore, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev_Ignore, out ihvoEnd, out ttp); int tagTextProp; ITsTextProps props = null; if (frag == SegmentTags.kflidFreeTranslation) { // If the length is zero...we need to suppress replacing the comment with a prompt. if (tssVal.Length == 0) m_hvoOfSegmentWhoseBtPromptIsToBeSupressed = hvo; ISegment seg = Cache.ServiceLocator.GetInstance<ISegmentRepository>().GetObject(hvo); if (seg.FreeTranslation.get_String(BackTranslationWS).Length == 0) { // Undo needs to unset suppressing the comment prompt. Cache.ActionHandlerAccessor.AddAction(new UndoSuppressBtPrompt(this, seg)); } ws = BackTranslationWS; tagTextProp = frag; seg.FreeTranslation.set_String(ws, tssVal); rootbox.PropChanged(seg.Paragraph.Owner.Hvo, StTextTags.kflidParagraphs, seg.Paragraph.IndexInOwner, 1, 1); } else { ReplacePromptUndoAction undoAction = new ReplacePromptUndoAction(hvo, rootbox, m_updatedPrompts); if (m_cache.ActionHandlerAccessor != null) { m_cache.ActionHandlerAccessor.AddAction( new UndoSelectionAction(rootbox.Site, true, vwsel)); m_cache.ActionHandlerAccessor.AddAction(undoAction); } // Mark the user prompt as having been updated - will not show prompt again. // Note: ReplacePromptUndoAction:Undo removes items from the Set. m_updatedPrompts.Add(hvo); // Replace the ITsString in the paragraph or translation props = StyleUtils.CharStyleTextProps(null, m_wsDefault); if (frag == CmTranslationTags.kflidTranslation) { ICmTranslation trans = Cache.ServiceLocator.GetInstance<ICmTranslationRepository>().GetObject(hvo); trans.Translation.set_String(m_wsDefault, tssVal); undoAction.ParaHvo = trans.Owner.Hvo; ws = BackTranslationWS; tagTextProp = frag; } else { IStTxtPara para = Cache.ServiceLocator.GetInstance<IStTxtParaRepository>().GetObject(hvo); para.Contents = tssVal; undoAction.ParaHvo = hvo; ws = 0; tagTextProp = StTxtParaTags.kflidContents; } // Do a fake propchange to update the prompt rootbox.PropChanged(undoAction.ParaHvo, StParaTags.kflidStyleRules, 0, 1, 1); } // Now request a selection at the end of the text that was just put in. rootbox.Site.RequestSelectionAtEndOfUow(rootbox, ihvoRoot, cvsli, rgvsli, tagTextProp, cpropPrevious, ichEnd, ws, true, props); return tssVal; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Replace the user prompt with the text the user typed. This method is called from /// the views code when the user prompt is edited. /// </summary> /// <param name="vwsel">Current selection in rootbox where this prop was updated</param> /// <param name="hvo">Hvo of the paragraph</param> /// <param name="tag">Tag</param> /// <param name="frag">Fragment</param> /// <param name="tssVal">Text the user just typed</param> /// <returns>possibly modified ITsString.</returns> /// <remarks>The return value is currently ignored in production code, but we use it /// in our tests.</remarks> /// ----------------------------------------------------------------------------------- public override ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag, ITsString tssVal) { CheckDisposed(); Debug.Assert(tag == SimpleRootSite.kTagUserPrompt, "Got an unexpected tag"); Debug.Assert(vwsel != null, "Got a null selection!"); Debug.Assert(vwsel.IsValid, "Got an invalid selection!"); IVwRootBox rootbox = vwsel.RootBox; // If a (typically Chinese) character composition is in progress, replacing the prompt will // destroy the selection and end the composition, causing weird typing problems (TE-8267). // Ending the composition does another Commit, which ensures that this will eventually be // called when there is NOT a composition in progress. if (rootbox.IsCompositionInProgress) return tssVal; // Remove the UserPrompt pseudo-property from the text the user typed. // when appropriate also ensure the correct writing system. // The correct WS is m_wsDefault in the view constructor ITsStrBldr bldr = (ITsStrBldr)tssVal.GetBldr(); if (frag != (int)CmAnnotation.CmAnnotationTags.kflidComment) { bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_wsDefault); } // Delete the user prompt property from the string (TE-3994) bldr.SetIntPropValues(0, bldr.Length, SimpleRootSite.ktptUserPrompt, -1, -1); tssVal = bldr.GetString(); // Get information about current selection int cvsli = vwsel.CLevels(false); cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it. int ihvoRoot; int tagTextProp; int cpropPrevious; int ichAnchor; int ichEnd; int ihvoEnd; bool fAssocPrev; int ws; ITsTextProps ttp; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwsel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttp); // Prior to the Commit in selection changed which causes this UpdateProp to be called, // earlier selection changed code has expanded the selection (because it is in a user prompt) // to the whole prompt. It is therefore a range selection, and the value of fAssocPrev we got // is useless. We want to make a selection associated with the previous character at the END of // the range. if (frag == (int)CmAnnotation.CmAnnotationTags.kflidComment) { // If the length is zero...we need to suppress replacing the comment with a prompt. if (tssVal.Length == 0) m_hvoSuppressCommentPrompt = hvo; CmIndirectAnnotation ann = new CmIndirectAnnotation(Cache, hvo); if (ann.Comment.GetAlternative(BackTranslationWS).Length == 0) { // Undo needs to unset suppressing the comment prompt. Cache.ActionHandlerAccessor.AddAction(new UndoSuppressCommentPrompt(this, ann)); } // Turn the prompt property off for future typing, too. ITsPropsBldr pb = ttp.GetBldr(); pb.SetIntPropValues(SimpleRootSite.ktptUserPrompt, -1, -1); ann.Comment.SetAlternative(tssVal, BackTranslationWS); rootbox.MakeTextSelection(ihvoRoot, cvsli, rgvsli, (int)CmAnnotation.CmAnnotationTags.kflidComment, cpropPrevious, ichEnd, ichEnd, BackTranslationWS, fAssocPrev, ihvoEnd, pb.GetTextProps(), true); return tssVal; } ReplacePromptUndoAction undoAction = new ReplacePromptUndoAction(hvo, m_cache, m_updatedPrompts); if (m_cache.ActionHandlerAccessor != null) m_cache.ActionHandlerAccessor.AddAction(undoAction); // Mark the user prompt as having been updated - will not show prompt again. // Note: ReplacePromptUndoAction:Undo removes items from the Set. m_updatedPrompts.Add(hvo); // Replace the ITsString in the paragraph or translation // - this destroys the selection because we replace the user prompt. StTxtPara para; CmTranslation trans; ITsTextProps props = StyleUtils.CharStyleTextProps(null, m_wsDefault); if (frag == (int)CmTranslation.CmTranslationTags.kflidTranslation) { trans = new CmTranslation(Cache, hvo); trans.Translation.GetAlternative(m_wsDefault).UnderlyingTsString = tssVal; undoAction.ParaHvo = trans.OwnerHVO; // now set the selection to the end of the text that was just put in. ichAnchor = ichEnd; rootbox.MakeTextSelection(ihvoRoot, cvsli, rgvsli, (int)CmTranslation.CmTranslationTags.kflidTranslation, cpropPrevious, ichAnchor, ichEnd, m_wsDefault, true, ihvoEnd, props, true); } else { para = new StTxtPara(Cache, hvo); para.Contents.UnderlyingTsString = tssVal; undoAction.ParaHvo = hvo; // now set the selection to the end of the text that was just put in. ichAnchor = ichEnd; rootbox.MakeTextSelection(ihvoRoot, cvsli, rgvsli, (int)StTxtPara.StTxtParaTags.kflidContents, cpropPrevious, ichAnchor, ichEnd, m_wsDefault, true, ihvoEnd, props, true); } return tssVal; }