How to change segment pair attributes - IsLocked - and refresh the editor screen ??

Hi there,

I'm currently struggling with something which should be quite simple..

By clicking on a custom ribbon button I'd like to

1. loop over the segment pairs displayed in the editor
2. based on a predicate set their property to IsLocked = true
3. change the display filter to "view only locked"
4. refresh the editor grid.

My neurons are probably affected by the flu, because I couldn't make it work..

My main difficulties are:

1. I can't change and persist the IsLocked property as it switches automatically back to false
2. I can't call a refresh on the EditorController because of it's protection level applied to the AbstractViewController
3. I never found in the documentation how to change the display filter.

Any help would be much appreciated,

have a great day ...

Greg

Code :

        public class ApplyAction : AbstractViewControllerAction<EditorController>
        {
            protected override void Execute()
            {
                foreach (var s in Controller.ActiveDocument.SegmentPairs)
                    if (/*specific condition*/)
                        s.Properties.IsLocked = true;
                        // can be persited , it switches back to false immediately

                // Here I'd like to do 2 things
                
                // 1. change the editor display filter to "only locked segment"
                //    I've been looking in vain in the documentation, any hint ?       

                // 2. trigger a refresh of the editor
                //    Controller.Refresh is inaccessible due to its protection level.
            }
        }
Parents
  • Hi,

      I don't know if this is still an issue, but this worked for me. First I set up a generic filter:

       class GenericSegmentFilter : IDisplayFilter
        {
            private Func<ISegmentPair, bool> Evaluator;

            public GenericSegmentFilter()
            { }

            public GenericSegmentFilter(Func<ISegmentPair, bool> evaluator)
            {
                Evaluator += evaluator;
            }

            public bool EvaluateRow(DisplayFilterRowInfo rowInfo)
            {
                return (rowInfo.IsSegment && Evaluator(rowInfo.SegmentPair));
            }
        }

    and in your main code:

        EditorController ec = SdlTradosStudio.Application.GetController<EditorController>();
        Document activedoc = ec.ActiveDocument;

        // to lock your segments
        foreach (ISegmentPair isp in activedoc.SegmentPairs.Where(sp => MySpecificCondition(sp)))
        {
            ISegmentPairProperties spp = isp.Properties.Clone() as ISegmentPairProperties;
            spp.IsLocked = true;
            activedoc.UpdateSegmentPairProperties(isp, spp);
        }

        // to filter for locked segments - this will trigger a refresh as well
        activedoc.ApplyFilterOnSegments(new GenericSegmentFilter(s => s.Target.Properties.IsLocked));

    Hope this helps.

    Attila

Reply
  • Hi,

      I don't know if this is still an issue, but this worked for me. First I set up a generic filter:

       class GenericSegmentFilter : IDisplayFilter
        {
            private Func<ISegmentPair, bool> Evaluator;

            public GenericSegmentFilter()
            { }

            public GenericSegmentFilter(Func<ISegmentPair, bool> evaluator)
            {
                Evaluator += evaluator;
            }

            public bool EvaluateRow(DisplayFilterRowInfo rowInfo)
            {
                return (rowInfo.IsSegment && Evaluator(rowInfo.SegmentPair));
            }
        }

    and in your main code:

        EditorController ec = SdlTradosStudio.Application.GetController<EditorController>();
        Document activedoc = ec.ActiveDocument;

        // to lock your segments
        foreach (ISegmentPair isp in activedoc.SegmentPairs.Where(sp => MySpecificCondition(sp)))
        {
            ISegmentPairProperties spp = isp.Properties.Clone() as ISegmentPairProperties;
            spp.IsLocked = true;
            activedoc.UpdateSegmentPairProperties(isp, spp);
        }

        // to filter for locked segments - this will trigger a refresh as well
        activedoc.ApplyFilterOnSegments(new GenericSegmentFilter(s => s.Target.Properties.IsLocked));

    Hope this helps.

    Attila

Children