Ejemplo n.º 1
0
        EditFindReplaceDialog.Result Command_Edit_Find_Replace_Dialog()
        {
            string text          = null;
            var    selectionOnly = Selections.AsParallel().Any(range => range.HasSelection);

            if (Selections.Count == 1)
            {
                var sel = Selections.Single();
                if ((selectionOnly) && (Data.GetOffsetLine(sel.Cursor) == Data.GetOffsetLine(sel.Anchor)) && (sel.Length < 1000))
                {
                    selectionOnly = false;
                    text          = GetString(sel);
                }
            }

            return(EditFindReplaceDialog.Run(WindowParent, text, selectionOnly));
        }
Ejemplo n.º 2
0
        void Command_Text_ReverseRegEx(TextReverseRegExDialog.Result result)
        {
            if (Selections.Count != 1)
            {
                throw new Exception("Must have one selection.");
            }

            var data   = RevRegExVisitor.Parse(result.RegEx, result.InfiniteCount);
            var output = data.GetPossibilities().Select(str => str + Data.DefaultEnding).ToList();

            ReplaceSelections(string.Join("", output));

            var start = Selections.Single().Start;
            var sels  = new List <Range>();

            foreach (var str in output)
            {
                sels.Add(Range.FromIndex(start, str.Length - Data.DefaultEnding.Length));
                start += str.Length;
            }
            SetSelections(sels);
        }
        void Command_Numeric_CombinationsPermutations(NumericCombinationsPermutationsDialog.Result result)
        {
            if (Selections.Count != 1)
            {
                throw new Exception("Must have one selection.");
            }

            var output = new List <List <string> >();
            var nums   = new int[result.UseCount];
            var used   = new bool[result.ItemCount];

            nums[0] = -1;
            var onNum = 0;

            while (true)
            {
                ++nums[onNum];
                if (nums[onNum] >= result.ItemCount)
                {
                    --onNum;
                    if (onNum < 0)
                    {
                        break;
                    }
                    used[nums[onNum]] = false;
                    continue;
                }
                if ((!result.Repeat) && (used[nums[onNum]]))
                {
                    continue;
                }

                used[nums[onNum]] = true;
                ++onNum;
                if (onNum < result.UseCount)
                {
                    if (result.Type == NumericCombinationsPermutationsDialog.CombinationsPermutationsType.Combinations)
                    {
                        nums[onNum] = nums[onNum - 1] - 1;
                    }
                    else
                    {
                        nums[onNum] = -1;
                    }
                }
                else
                {
                    output.Add(nums.Select(num => (num + 1).ToString()).ToList());
                    --onNum;
                    used[nums[onNum]] = false;
                }
            }

            ReplaceSelections(string.Join("", output.Select(row => string.Join(" ", row) + Data.DefaultEnding)));

            var start = Selections.Single().Start;
            var sels  = new List <Range>();

            foreach (var row in output)
            {
                foreach (var str in row)
                {
                    sels.Add(Range.FromIndex(start, str.Length));
                    start += str.Length + 1;                     // +1 is for space
                }
                start += Data.DefaultEnding.Length - 1;          // -1 is for space added before
            }
            SetSelections(sels);
        }