/// <summary> /// Handle fixing the writing system values inside pasted text. Eventually, we may /// want some form of UI to guide the process, but for now we just bash in the /// default vernacular ws wherever any other ws occurs. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnPasteFixWs(EditingHelper sender, FwPasteFixTssEventArgs args) { if (args.EventHandled) { return; // only one delegate gets to play! } bool fFixed = false; int wsVern = Cache.LangProject.ActualWs(LangProject.kwsVernInParagraph, m_hvoRoot, (int)StText.StTextTags.kflidParagraphs); ITsStrBldr tsb = args.TsString.GetBldr(); int crun = tsb.RunCount; for (int irun = 0; irun < crun; ++irun) { ITsTextProps ttp = tsb.get_Properties(irun); int var; int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var); if (ws != wsVern) { fFixed = true; int ichMin; int ichLim; tsb.GetBoundsOfRun(irun, out ichMin, out ichLim); tsb.SetIntPropValues(ichMin, ichLim, (int)FwTextPropType.ktptWs, var, wsVern); } } if (fFixed) { args.TsString = tsb.GetString(); } args.EventHandled = true; }
public void PasteIntoMultiStringFieldDoesNotFlattenWsStyle() { var args = new FwPasteFixTssEventArgs(m_tss, new TextSelInfo((IVwSelection)null)); // Veryify that we are testing with a field of the correct type (if this fails the model changed) Assert.AreEqual((int)CellarPropertyType.MultiString, Cache.MetaDataCacheAccessor.GetFieldType(LexSenseTags.kflidGeneralNote)); //SUT InnerLabeledMultiStringView.EliminateExtraStyleAndWsInfo(Cache.MetaDataCacheAccessor, args, LexSenseTags.kflidGeneralNote); string differences; Assert.True(TsStringHelper.TsStringsAreEqual(m_tss, args.TsString, out differences), differences); }
static internal void EliminateExtraStyleAndWsInfo(IFwMetaDataCache mdc, FwPasteFixTssEventArgs e, int flid) { var type = (CellarPropertyType)mdc.GetFieldType(flid); if (type == CellarPropertyType.MultiUnicode || type == CellarPropertyType.Unicode) { e.TsString = e.TsString.ToWsOnlyString(); } }
public void PasteIntoMultiUnicodeFieldFlattensWsStyle() { var args = new FwPasteFixTssEventArgs(m_tss, new TextSelInfo((IVwSelection)null)); // Veryify that we are testing with a field of the correct type (if this fails the model changed) Assert.AreEqual((int)CellarPropertyType.MultiUnicode, Cache.MetaDataCacheAccessor.GetFieldType(LexEntryTags.kflidCitationForm)); //SUT InnerLabeledMultiStringView.EliminateExtraStyleAndWsInfo(Cache.MetaDataCacheAccessor, args, LexEntryTags.kflidCitationForm); string differences; Assert.False(TsStringHelper.TsStringsAreEqual(m_tss, args.TsString, out differences), differences); Assert.That(differences, Is.StringContaining("TsStrings have different number of runs")); }
/// <summary> /// If the text for pasting is too long, truncate it and warn the user. /// </summary> void OnPasteFixTssEvent(EditingHelper sender, FwPasteFixTssEventArgs e) { TruncatePasteIfNecessary(e, m_flid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Removes the hard formatting from text that is pasted. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="T:SIL.FieldWorks.Common.RootSites.FwPasteFixTssEventArgs"/> /// instance containing the event data.</param> /// ------------------------------------------------------------------------------------ public void RemoveHardFormatting(EditingHelper sender, FwPasteFixTssEventArgs e) { ITsString tss = e.TsString; ITsStrBldr tssBldr = tss.GetBldr(); for (int i = 0; i < tss.RunCount; i++) { TsRunInfo runInfo; ITsTextProps props = tss.FetchRunInfo(i, out runInfo); ITsPropsBldr propsBuilder = TsPropsBldrClass.Create(); // Copy the style name from the run properties string style = props.GetStrPropValue((int)FwTextPropType.ktptNamedStyle); if (style != null) propsBuilder.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, style); // Copy the WS information from the run properties int var; int ws = props.GetIntPropValues((int)FwTextPropType.ktptWs, out var); if (ws > 0) propsBuilder.SetIntPropValues((int)FwTextPropType.ktptWs, var, ws); // Copy the ORC information from the run properties string orcData = props.GetStrPropValue((int)FwTextPropType.ktptObjData); if (orcData != null) propsBuilder.SetStrPropValue((int)FwTextPropType.ktptObjData, orcData); tssBldr.SetProperties(runInfo.ichMin, runInfo.ichLim, propsBuilder.GetTextProps()); } e.TsString = tssBldr.GetString(); }
public void RemoveHardFormatting() { CheckDisposed(); // build the original string ITsStrBldr tssBldr = TsStrBldrClass.Create(); ITsPropsBldr propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptBorderColor, 0, 0x00ff00cc); propsBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript, 0, 5); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, 711); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "My Style"); tssBldr.Replace(0, 0, "This", propsBldr.GetTextProps()); propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, 711); tssBldr.Replace(tssBldr.Length, tssBldr.Length, " is my ", propsBldr.GetTextProps()); propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, 711); propsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, 0, 1); tssBldr.Replace(tssBldr.Length, tssBldr.Length, "text.", propsBldr.GetTextProps()); FwPasteFixTssEventArgs args = new FwPasteFixTssEventArgs(tssBldr.GetString()); m_TeEditingHelper.RemoveHardFormatting(m_TeEditingHelper, args); // build what we expect it to return tssBldr = TsStrBldrClass.Create(); propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, 711); propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "My Style"); tssBldr.Replace(0, 0, "This", propsBldr.GetTextProps()); propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, 711); tssBldr.Replace(tssBldr.Length, tssBldr.Length, " is my ", propsBldr.GetTextProps()); propsBldr = TsPropsBldrClass.Create(); propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, 711); tssBldr.Replace(tssBldr.Length, tssBldr.Length, "text.", propsBldr.GetTextProps()); AssertEx.AreTsStringsEqual(tssBldr.GetString(), args.TsString); }
/// <summary> /// If the text for pasting is too long, truncate it and warn the user. /// </summary> void OnPasteFixTssEvent(EditingHelper sender, FwPasteFixTssEventArgs e) { if (!sender.Editable) return; TextSelInfo tsi = e.TextSelInfo; if (tsi == null) return; int flid = tsi.TagAnchor; if (flid == 0) return; }
/// <summary> /// If the text for pasting is too long, truncate it and warn the user. /// </summary> void OnPasteFixTssEvent(EditingHelper sender, FwPasteFixTssEventArgs e) { EliminateExtraStyleAndWsInfo(RootBox.DataAccess.MetaDataCache, e, m_flid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// If the text for pasting is too long, truncate it and warn the user. /// This is shared by subclasses of RootSite for implementing handlers for /// RootSiteEditingHelper.PasteFixTssEvent. /// </summary> /// ------------------------------------------------------------------------------------ protected void TruncatePasteIfNecessary(FwPasteFixTssEventArgs e, int flid) { int type = Cache.MetaDataCacheAccessor.GetFieldType((uint)flid); if (type == (int)CellarModuleDefns.kcptMultiString || type == (int)CellarModuleDefns.kcptMultiUnicode || type == (int)CellarModuleDefns.kcptString || type == (int)CellarModuleDefns.kcptUnicode) { ITsString tssCurrent = EditingHelper.CurrentSelection.GetTss(SelectionHelper.SelLimitType.End); int cchSel = 0; if (EditingHelper.CurrentSelection.IsRange) cchSel = Math.Abs(EditingHelper.CurrentSelection.IchAnchor - EditingHelper.CurrentSelection.IchEnd); int cchMax = Cache.MaxFieldLength(flid); int cchIncoming = e.TsString.Length; if (tssCurrent.Length + cchIncoming - cchSel > cchMax) { int cchPaste = cchMax - (tssCurrent.Length - cchSel); if (cchPaste < 0) cchPaste = 0; System.Windows.Forms.MessageBox.Show( String.Format(SIL.FieldWorks.Resources.ResourceHelper.GetResourceString("kstidTruncatingPaste"), cchIncoming, cchPaste, cchMax), SIL.FieldWorks.Resources.ResourceHelper.GetResourceString("kstidWarning"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); ITsStrBldr bldr = e.TsString.GetBldr(); bldr.ReplaceTsString(cchPaste, cchIncoming, null); e.TsString = bldr.GetString(); } } }
/// <summary> /// If the text for pasting is too long, truncate it and warn the user. /// </summary> void OnPasteFixTssEvent(EditingHelper sender, FwPasteFixTssEventArgs e) { if (!sender.Editable) return; TextSelInfo tsi = sender.TextSelInfoBeforeEdit; if (tsi == null) return; int flid = tsi.TagAnchor; if (flid == 0) return; TruncatePasteIfNecessary(e, flid); }
/// <summary> /// Handle fixing the writing system values inside pasted text. Eventually, we may /// want some form of UI to guide the process, but for now we just bash in the /// default vernacular ws wherever any other ws occurs. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnPasteFixWs(EditingHelper sender, FwPasteFixTssEventArgs args) { if (args.EventHandled) return; // only one delegate gets to play! bool fFixed = false; int wsVern = Cache.LangProject.ActualWs(LangProject.kwsVernInParagraph, m_hvoRoot, (int)StText.StTextTags.kflidParagraphs); ITsStrBldr tsb = args.TsString.GetBldr(); int crun = tsb.RunCount; for (int irun = 0; irun < crun; ++irun) { ITsTextProps ttp = tsb.get_Properties(irun); int var; int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var); if (ws != wsVern) { fFixed = true; int ichMin; int ichLim; tsb.GetBoundsOfRun(irun, out ichMin, out ichLim); tsb.SetIntPropValues(ichMin, ichLim, (int)FwTextPropType.ktptWs, var, wsVern); } } if (fFixed) args.TsString = tsb.GetString(); args.EventHandled = true; }