How to execute a "Copy Source to Target" command

A couple of questions

I have a plugin that is running and I am exploring the ability to do the following:

  1. I would like to execute the same functionality as found in the Editor View > right click on source segment > Copy Source to Target.  Where is that found in the API?
  2. After doing so, how can I lock the ISegmentPair so that it cannot be edited?  If that is possible?

  • Below, I have different variations of doing the same thing.  However, with each approach, after I update the text, I don't see the update occur within the actual Target segment object itself:

    ISegmentPair activeSegmentPair = document.ActiveSegmentPair;

    IAbstractMarkupData markupData = activeSegmentPair.Target.Find(IsIText); // IsItext is a function: bool IsItext(IAbstractMarkupData x) { return x is IText; }
    IText targetText = markupData as IText;
    if (targetText != null)
    {
         targetText.Properties.Text = activeSourceText.ToString();
    }

    ------------

    ISegmentPair activeSegmentPair = document.ActiveSegmentPair;

    document.ProcessSegmentPairs(
    "Copy Source to Target",
    (sp, args) =>
    {
    if (sp.Properties.Id.Id == activeSegmentPair.Properties.Id.Id)
    {
         foreach (IAbstractMarkupData targetMarkupData in sp.Target)
         {
              var targetText = targetMarkupData as IText;
              if (targetText != null)
              {
                   targetText.Properties.Text = activeSourceText.ToString();
              }
         }

    }
    );

  • Someone asked a similar question here: https://community.sdl.com/developers/language-developers/f/57/p/2315/14849#14849