Пример #1
0
        public void Insert(int position, FragmentSelection fragments)
        {
            var command = new InsertSelectionCommand(this, position, fragments);

            command.Execute();
            var undoCommand = new CutSelectionCommand(this, fragments);

            AddRedoUndo(undoCommand, command);
        }
Пример #2
0
 public void CutSelection(FragmentSelection fragments)
 {
     Contract.Requires(GeProfile.IsSelectable(fragments.Start, fragments.End, false));
     Contract.Ensures(GeProfile.IsInputable(fragments.Start));
     SaveState();
     NewProfile = GeProfile.ProfileText.Substring(0, fragments.Start) + GeProfile.ProfileText.Substring(fragments.End);
     ChangeProfile();
     RestoreState();
 }
Пример #3
0
        public void Cut(FragmentSelection fragments)
        {
            var command = new CutSelectionCommand(this, fragments);

            command.Execute();
            var undoCommand = new InsertSelectionCommand(this, fragments.Start, fragments);

            AddRedoUndo(undoCommand, command);
        }
Пример #4
0
 public void InsertSelection(int position, FragmentSelection fragments)
 {
     Contract.Requires(GeProfile.IsInputable(position));
     Contract.Ensures(GeProfile.IsSelectable(position, position + fragments.ProfileText.Length, false));
     SaveState();
     NewProfile = GeProfile.ProfileText.Insert(NodeFragmentPosition.Position.Offset + position,
                                               fragments.ProfileText);
     ChangeProfile();
     RestoreState();
 }
Пример #5
0
        public void Insert(int position, string text)
        {
            Contract.Requires(IsInputable(position));
            Contract.Ensures(IsSelectable(position, position + text.Length, false));
            var fragments = new FragmentSelection(position, position + text.Length)
            {
                ProfileText = text
            };

            Insert(position, fragments);
        }
Пример #6
0
        public FragmentSelection GetSelection(int start, int end)
        {
            Contract.Requires(IsSelectable(start, end, false));
            var      fragmentSelection = new FragmentSelection(start, end);
            Fragment beforeStart, afterStart, beforeEnd, afterEnd;

            GetFragmentsAt(out beforeStart, out afterStart, start);
            GetFragmentsAt(out beforeEnd, out afterEnd, end);
            if (beforeStart != afterStart && beforeEnd != afterEnd)
            {
                if (afterStart == beforeEnd)
                {
                    fragmentSelection.Fragments.Add(afterStart);
                }
                else if (afterStart.ParentFragment == beforeEnd.ParentFragment)
                {
                    var fragments = ((FragmentBody)afterStart.Parent).FragmentList;
                    CopySelectionFragments(fragments, fragmentSelection.Fragments, fragments.IndexOf(afterStart),
                                           fragments.IndexOf(beforeEnd));
                }
                else
                {
                    var prefixText = afterStart.ParentFragment is TextBlock;
                    var suffixText = beforeEnd.ParentFragment is TextBlock;
                    var fragments  = prefixText
                        ? ((FragmentBody)afterStart.ParentFragment.Parent).FragmentList
                        : ((FragmentBody)afterStart.Parent).FragmentList;
                    int i;
                    if (prefixText)
                    {
                        i = fragments.IndexOf(afterStart.ParentFragment) + 1;
                        var textFragments = ((FragmentBody)afterStart.Parent).FragmentList;
                        CopySelectionFragments(textFragments, fragmentSelection.Fragments,
                                               textFragments.IndexOf(afterStart), textFragments.Count - 1);
                    }
                    else
                    {
                        i = fragments.IndexOf(afterStart);
                    }
                    var j = suffixText ? fragments.IndexOf(beforeEnd.ParentFragment) - 1 : fragments.IndexOf(beforeEnd);
                    CopySelectionFragments(fragments, fragmentSelection.Fragments, i, j);
                    if (suffixText)
                    {
                        var textFragments = ((FragmentBody)beforeEnd.Parent).FragmentList;
                        CopySelectionFragments(textFragments, fragmentSelection.Fragments, 0,
                                               textFragments.IndexOf(beforeEnd));
                    }
                }
            }
            else if (beforeStart == afterStart && beforeEnd != afterEnd)
            {
                Contract.Assert(beforeStart is Text);
                var pos = ProfileTextPostionList.GetFragmentPosition(afterStart);
                fragmentSelection.SetPrefix((Text)afterStart, start - pos.Position.Offset);
                if (afterStart != beforeEnd)
                {
                    var fragments = ((FragmentBody)afterStart.Parent).FragmentList;
                    var n         = fragments.Count;
                    var i         = fragments.IndexOf(afterStart);
                    CopySelectionFragments(fragments, fragmentSelection.Fragments, i + 1, n - 1);
                    fragmentSelection.Fragments.Add(beforeEnd);
                }
            }
            else if (beforeStart != afterStart && beforeEnd == afterEnd)
            {
                Contract.Assert(afterEnd is Text);
                var pos = ProfileTextPostionList.GetFragmentPosition(beforeEnd);
                fragmentSelection.SetSuffix((Text)beforeEnd, end - pos.Position.Offset);
                if (beforeEnd != afterStart)
                {
                    fragmentSelection.Fragments.Add(afterStart);
                }
            }
            else if (beforeStart == afterStart && beforeEnd == afterEnd)
            {
                Contract.Assert(afterEnd is Text);
                var pos = ProfileTextPostionList.GetFragmentPosition(beforeEnd);
                fragmentSelection.SetInfix((Text)beforeEnd, start - pos.Position.Offset, end - pos.Position.Offset);
            }

            fragmentSelection.ProfileText = ProfileText.Substring(start, end - start);
            return(fragmentSelection);
        }
Пример #7
0
 public InsertSelectionCommand(GeProfile geProfile, int position, FragmentSelection fragments)
     : base(geProfile)
 {
     Position  = position;
     Fragments = fragments;
 }
Пример #8
0
 public CutSelectionCommand(GeProfile geProfile, FragmentSelection fragments)
     : base(geProfile)
 {
     Fragments = fragments;
 }