예제 #1
0
        void Command_Region_Select_Regions_Region(bool shiftDown, int?useRegion = null)
        {
            var sels = shiftDown ? Selections.ToList() : new List <Range>();

            sels.AddRange(Regions.Where(pair => pair.Key == (useRegion ?? pair.Key)).SelectMany(pair => pair.Value));
            SetSelections(sels);
        }
        void Command_Database_ExecuteQuery()
        {
            ValidateConnection();
            var selections = Selections.ToList();

            if ((Selections.Count == 1) && (!Selections[0].HasSelection))
            {
                selections = new List <Range> {
                    FullRange
                }
            }
            ;
            var strs = GetSelectionStrings();
            // Not in parallel because prior selections may affect later ones
            var results = selections.Select((range, index) => RunDBSelect(strs[index])).ToList();

            for (var ctr = 0; ctr < strs.Count; ++ctr)
            {
                var exception = results[ctr].Select(result => result.Exception).NonNull().FirstOrDefault();
                strs[ctr] += $": {(exception == null ? "Success" : $"{exception.Message}")}";

                foreach (var table in results[ctr].Where(table => table.Table != null))
                {
                    OpenTable(table.Table, table.TableName);
                }
            }

            ReplaceSelections(strs);
        }
예제 #3
0
        void Command_Edit_Sort(EditSortDialog.Result result)
        {
            var regions  = GetSortSource(result.SortScope, result.UseRegion);
            var ordering = GetOrdering(result.SortType, result.CaseSensitive, result.Ascending);

            if (regions.Count != ordering.Count)
            {
                throw new Exception("Ordering misaligned");
            }

            var newSelections     = Selections.ToList();
            var orderedRegions    = ordering.Select(index => regions[index]).ToList();
            var orderedRegionText = orderedRegions.Select(range => GetString(range)).ToList();

            Replace(regions, orderedRegionText);

            var newRegions = regions.ToList();
            var add        = 0;

            for (var ctr = 0; ctr < newSelections.Count; ++ctr)
            {
                var orderCtr = ordering[ctr];
                newSelections[orderCtr] = new Range(newSelections[orderCtr].Cursor - regions[orderCtr].Start + regions[ctr].Start + add, newSelections[orderCtr].Anchor - regions[orderCtr].Start + regions[ctr].Start + add);
                newRegions[orderCtr]    = new Range(newRegions[orderCtr].Cursor - regions[orderCtr].Start + regions[ctr].Start + add, newRegions[orderCtr].Anchor - regions[orderCtr].Start + regions[ctr].Start + add);
                add += orderedRegionText[ctr].Length - regions[ctr].Length;
            }
            newSelections = ordering.Select(num => newSelections[num]).ToList();

            SetSelections(newSelections);
            if (result.SortScope == SortScope.Regions)
            {
                SetRegions(result.UseRegion, newRegions);
            }
        }
예제 #4
0
        void Command_Edit_Find_Replace(EditFindReplaceDialog.Result result)
        {
            var text    = result.Text;
            var replace = result.Replace;

            if (!result.IsRegex)
            {
                text    = Regex.Escape(text);
                replace = replace.Replace("$", "$$");
            }
            if (result.WholeWords)
            {
                text = $"\\b{text}\\b";
            }
            if (result.EntireSelection)
            {
                text = $"\\A{text}\\Z";
            }
            var options = RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.Multiline;

            if (!result.MatchCase)
            {
                options |= RegexOptions.IgnoreCase;
            }
            var regex = new Regex(text, options);

            var regions = result.SelectionOnly ? Selections.ToList() : new List <Range> {
                FullRange
            };
            var sels = regions.AsParallel().AsOrdered().SelectMany(region => Data.RegexMatches(regex, region.Start, region.Length, result.MultiLine, false, false)).Select(tuple => Range.FromIndex(tuple.Item1, tuple.Item2)).ToList();

            SetSelections(sels);
            ReplaceSelections(Selections.AsParallel().AsOrdered().Select(range => regex.Replace(GetString(range), result.Replace)).ToList());
        }
예제 #5
0
        internal void AddCaretBelow()
        {
            foreach (var selection in Selections.ToList())
            {
                view.Caret.MoveTo(selection.GetVirtualPoint(Snapshot));
                EditorOperations.MoveLineDown(false);
                AddCaretMoveToSelections(selection);
            }

            view.Caret.MoveTo(Selections.Last().GetVirtualPoint(Snapshot));
        }
예제 #6
0
 /// <summary>
 /// Deletes the current selection from the frame drawing.
 /// </summary>
 public void DeleteSelection()
 {
     foreach (Selection s in Selections.ToList())
     {
         UpdateSelection(s, false);
         ICanvasDrawableObject o = (ICanvasDrawableObject)s.Drawable;
         drawing.Drawables.Remove((Drawable)o.IDrawableObject);
         RemoveObject(o);
     }
     UpdateCounters();
     widget?.ReDraw();
 }
예제 #7
0
        void Command_Edit_Find_Binary(EditFindBinaryDialog.Result result)
        {
            var findStrs = result.CodePages
                           .Select(codePage => Tuple.Create(Coder.TryStringToBytes(result.Text, codePage), (!Coder.IsStr(codePage)) || (result.MatchCase) || (Coder.AlwaysCaseSensitive(codePage))))
                           .NonNull(tuple => tuple.Item1)
                           .Select(tuple => Tuple.Create(Coder.TryBytesToString(tuple.Item1, CodePage), tuple.Item2))
                           .NonNullOrEmpty(tuple => tuple.Item1)
                           .GroupBy(tuple => $"{tuple.Item1}-{tuple.Item2}")
                           .Select(group => group.First())
                           .ToList();
            var searcher   = new Searcher(findStrs);
            var selections = result.SelectionOnly ? Selections.ToList() : new List <Range> {
                FullRange
            };
            var ranges = selections.AsParallel().AsOrdered().SelectMany(selection => Data.StringMatches(searcher, selection.Start, selection.Length)).Select(tuple => Range.FromIndex(tuple.Item1, tuple.Item2)).ToList();

            ViewValuesFindValue = result.Text;
            SetSelections(ranges);
        }
예제 #8
0
        void Command_Edit_Find_MassFind(EditFindMassFindDialog.Result result)
        {
            var texts = GetVariableExpressionResults <string>(result.Text);

            if ((result.KeepMatching) || (result.RemoveMatching))
            {
                var set = new HashSet <string>(texts, result.MatchCase ? (IEqualityComparer <string>)EqualityComparer <string> .Default : StringComparer.OrdinalIgnoreCase);
                SetSelections(Selections.AsParallel().AsOrdered().Where(range => set.Contains(GetString(range)) == result.KeepMatching).ToList());
                return;
            }

            var searcher   = new Searcher(texts, result.MatchCase);
            var selections = result.SelectionOnly ? Selections.ToList() : new List <Range> {
                FullRange
            };
            var ranges = selections.AsParallel().AsOrdered().SelectMany(selection => Data.StringMatches(searcher, selection.Start, selection.Length)).Select(tuple => Range.FromIndex(tuple.Item1, tuple.Item2)).ToList();

            SetSelections(ranges);
        }
예제 #9
0
        List <Range> GetSortSource(SortScope scope, int useRegion)
        {
            List <Range> sortSource = null;

            switch (scope)
            {
            case SortScope.Selections: sortSource = Selections.ToList(); break;

            case SortScope.Lines: sortSource = GetSortLines(); break;

            case SortScope.Regions: sortSource = GetEnclosingRegions(useRegion, true); break;

            default: throw new Exception("Invalid sort type");
            }

            if (Selections.Count != sortSource.Count)
            {
                throw new Exception("Selections and regions counts must match");
            }

            var orderedRegions = sortSource.OrderBy(range => range.Start).ToList();
            var pos            = 0;

            foreach (var range in orderedRegions)
            {
                if (range.Start < pos)
                {
                    throw new Exception("Regions cannot overlap");
                }
                pos = range.End;
            }

            for (var ctr = 0; ctr < Selections.Count; ++ctr)
            {
                if ((Selections[ctr].Start < sortSource[ctr].Start) || (Selections[ctr].End > sortSource[ctr].End))
                {
                    throw new Exception("All selections must be a region");
                }
            }

            return(sortSource);
        }
예제 #10
0
 public void Paste()
 {
     if (copiedItems != null && copiedItems.Count > 0)
     {
         var selectionsCopy = Selections.ToList();
         ClearSelection();
         foreach (Selection sel in selectionsCopy)
         {
             ICanvasDrawableObject selectionDrawable = sel.Drawable as ICanvasDrawableObject;
             if (selectionDrawable == null)
             {
                 continue;
             }
             var copy = (Drawable)(selectionDrawable.IDrawableObject).Clone();
             copy.Move(SelectionPosition.All, new Point(copy.Area.TopLeft.X + 20, copy.Area.TopLeft.Y + 20),
                       new Point(copy.Area.TopLeft.X, copy.Area.TopLeft.Y));
             drawing.Drawables.Add(copy);
             ICanvasSelectableObject copyView = Add(copy);
             UpdateSelection(new Selection(copyView, sel.Position, sel.Accuracy), false);
         }
         SelectionChanged(Selections);
         widget?.ReDraw();
     }
 }
예제 #11
0
        void Command_Region_ModifyRegions(RegionModifyRegionsDialog.Result result)
        {
            switch (result.Action)
            {
            case RegionModifyRegionsDialog.Action.Select:
                SetSelections(result.Regions.SelectMany(useRegion => Regions[useRegion]).ToList());
                break;

            case RegionModifyRegionsDialog.Action.Set:
                foreach (var useRegion in result.Regions)
                {
                    SetRegions(useRegion, Selections.ToList());
                }
                break;

            case RegionModifyRegionsDialog.Action.Clear:
                foreach (var useRegion in result.Regions)
                {
                    SetRegions(useRegion, new List <Range>());
                }
                break;

            case RegionModifyRegionsDialog.Action.Remove:
                foreach (var useRegion in result.Regions)
                {
                    var newRegions  = new List <Range>();
                    var regionIndex = 0;
                    foreach (var selection in Selections)
                    {
                        while ((regionIndex < Regions[useRegion].Count) && (Regions[useRegion][regionIndex].End <= selection.Start) && (!Regions[useRegion][regionIndex].Equals(selection)))
                        {
                            newRegions.Add(Regions[useRegion][regionIndex++]);
                        }
                        while ((regionIndex < Regions[useRegion].Count) && ((Regions[useRegion][regionIndex].Equals(selection)) || ((Regions[useRegion][regionIndex].End > selection.Start) && (Regions[useRegion][regionIndex].Start < selection.End))))
                        {
                            ++regionIndex;
                        }
                    }
                    while (regionIndex < Regions[useRegion].Count)
                    {
                        newRegions.Add(Regions[useRegion][regionIndex++]);
                    }
                    SetRegions(useRegion, newRegions);
                }
                break;

            case RegionModifyRegionsDialog.Action.Replace:
                foreach (var useRegion in result.Regions)
                {
                    var newRegions  = new List <Range>();
                    var regionIndex = 0;
                    foreach (var selection in Selections)
                    {
                        while ((regionIndex < Regions[useRegion].Count) && (Regions[useRegion][regionIndex].End <= selection.Start) && (!Regions[useRegion][regionIndex].Equals(selection)))
                        {
                            newRegions.Add(Regions[useRegion][regionIndex++]);
                        }
                        while ((regionIndex < Regions[useRegion].Count) && ((Regions[useRegion][regionIndex].Equals(selection)) || ((Regions[useRegion][regionIndex].End > selection.Start) && (Regions[useRegion][regionIndex].Start < selection.End))))
                        {
                            ++regionIndex;
                        }
                        newRegions.Add(selection);
                    }
                    while (regionIndex < Regions[useRegion].Count)
                    {
                        newRegions.Add(Regions[useRegion][regionIndex++]);
                    }
                    SetRegions(useRegion, newRegions);
                }
                break;

            case RegionModifyRegionsDialog.Action.Unite:
                foreach (var useRegion in result.Regions)
                {
                    var   newRegions = new List <Range>();
                    int   regionIndex = 0, selectionIndex = 0;
                    Range region = null;
                    while (true)
                    {
                        if ((region == null) && (regionIndex < Regions[useRegion].Count))
                        {
                            region = Regions[useRegion][regionIndex++];
                        }

                        if (selectionIndex >= Selections.Count)
                        {
                            if (region == null)
                            {
                                break;
                            }
                            newRegions.Add(region);
                            region = null;
                        }
                        else if (region == null)
                        {
                            newRegions.Add(Selections[selectionIndex++]);
                        }
                        else if (region.Equals(Selections[selectionIndex]))
                        {
                            region = null;
                        }
                        else if (region.End <= Selections[selectionIndex].Start)
                        {
                            newRegions.Add(region);
                            region = null;
                        }
                        else if (Selections[selectionIndex].End <= region.Start)
                        {
                            newRegions.Add(Selections[selectionIndex++]);
                        }
                        else
                        {
                            if (region.Start < Selections[selectionIndex].Start)
                            {
                                newRegions.Add(new Range(region.Start, Selections[selectionIndex].Start));
                            }
                            if (region.End <= Selections[selectionIndex].End)
                            {
                                region = null;
                            }
                            else
                            {
                                region = new Range(Selections[selectionIndex].End, region.End);
                            }
                        }
                    }
                    SetRegions(useRegion, newRegions);
                }
                break;

            case RegionModifyRegionsDialog.Action.Intersect:
                foreach (var useRegion in result.Regions)
                {
                    var newRegions       = new List <Range>();
                    var startRegionIndex = 0;
                    foreach (var selection in Selections)
                    {
                        var regionIndex = startRegionIndex;
                        while ((regionIndex < Regions[useRegion].Count) && (Regions[useRegion][regionIndex].End < selection.Start))
                        {
                            ++regionIndex;
                        }
                        startRegionIndex = regionIndex;
                        while ((regionIndex < Regions[useRegion].Count) && (Regions[useRegion][regionIndex].Start <= selection.End))
                        {
                            if ((!Regions[useRegion][regionIndex].HasSelection) || (!selection.HasSelection) || ((Regions[useRegion][regionIndex].End != selection.Start) && (Regions[useRegion][regionIndex].Start != selection.End)))
                            {
                                var newRegion = new Range(Math.Max(Regions[useRegion][regionIndex].Start, selection.Start), Math.Min(Regions[useRegion][regionIndex].End, selection.End));
                                if ((newRegions.Count == 0) || (!newRegion.Equals(newRegions[newRegions.Count - 1])))
                                {
                                    newRegions.Add(newRegion);
                                }
                            }
                            ++regionIndex;
                        }
                    }
                    SetRegions(useRegion, newRegions);
                }
                break;

            case RegionModifyRegionsDialog.Action.Exclude:
                foreach (var useRegion in result.Regions)
                {
                    var regions        = Regions[useRegion].ToList();
                    var newRegions     = new List <Range>();
                    var regionIndex    = 0;
                    var selectionIndex = 0;
                    while (regionIndex < regions.Count)
                    {
                        if (selectionIndex >= Selections.Count)
                        {
                            newRegions.Add(regions[regionIndex++]);
                        }
                        else if (Selections[selectionIndex].Equals(regions[regionIndex]))
                        {
                            regionIndex++;
                        }
                        else if (regions[regionIndex].End < Selections[selectionIndex].Start)
                        {
                            newRegions.Add(regions[regionIndex++]);
                        }
                        else if (Selections[selectionIndex].End < regions[regionIndex].Start)
                        {
                            ++selectionIndex;
                        }
                        else
                        {
                            if (regions[regionIndex].Start < Selections[selectionIndex].Start)
                            {
                                newRegions.Add(new Range(regions[regionIndex].Start, Selections[selectionIndex].Start));
                            }
                            while ((regionIndex < regions.Count) && (regions[regionIndex].End <= Selections[selectionIndex].End))
                            {
                                regionIndex++;
                            }
                            if ((regionIndex < regions.Count) && (regions[regionIndex].Start < Selections[selectionIndex].End))
                            {
                                regions[regionIndex] = new Range(Selections[selectionIndex].End, regions[regionIndex].End);
                            }
                            ++selectionIndex;
                        }
                    }
                    SetRegions(useRegion, newRegions);
                }
                break;
            }
        }
예제 #12
0
 void Command_Region_SetSelections_Region(int?useRegion = null) => Regions.Keys.ToList().Where(key => key == (useRegion ?? key)).ForEach(key => SetRegions(key, Selections.ToList()));
        private void Bitenumeration_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var selectedItems = Selections.ToList().Where(x => x.IsChecked).ToArray();

            StrCheckedItems = DisplayFormat(selectedItems);
        }
 public void ShowStockSelector()
 {
     originalSelections = Selections?.ToList();
     showStockSelector  = true;
 }
예제 #15
0
 public void Copy()
 {
     copiedItems = Selections.ToList();
 }
예제 #16
0
        void Command_Edit_Find_Find(bool selecting, EditFindFindDialog.Result result)
        {
            var text = result.Text;

            if (!result.IsRegex)
            {
                text = Regex.Escape(text);
            }
            text = $"(?:{text})";
            if (result.WholeWords)
            {
                text = $"\\b{text}\\b";
            }
            if (result.EntireSelection)
            {
                text = $"\\A{text}\\Z";
            }
            var options = RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.Multiline;

            if (!result.MatchCase)
            {
                options |= RegexOptions.IgnoreCase;
            }
            var regex = new Regex(text, options);

            if ((result.KeepMatching) || (result.RemoveMatching))
            {
                SetSelections(Selections.AsParallel().AsOrdered().Where(range => regex.IsMatch(GetString(range)) == result.KeepMatching).ToList());
                return;
            }

            var regions = result.SelectionOnly ? Selections.ToList() : new List <Range> {
                FullRange
            };
            var resultsByRegion = regions.AsParallel().AsOrdered().Select(region => Data.RegexMatches(regex, region.Start, region.Length, result.MultiLine, result.RegexGroups, false)).ToList();

            if (result.Type == EditFindFindDialog.ResultType.CopyCount)
            {
                SetClipboardStrings(resultsByRegion.Select(list => list.Count.ToString()));
                return;
            }

            var results = resultsByRegion.SelectMany().Select(tuple => Range.FromIndex(tuple.Item1, tuple.Item2)).ToList();

            if (result.AddMatches)
            {
                results.AddRange(Selections);
            }

            switch (result.Type)
            {
            case EditFindFindDialog.ResultType.FindFirst:
                SetSearches(results);
                FindNext(true, selecting);
                break;

            case EditFindFindDialog.ResultType.FindAll:
                SetSelections(results);
                break;
            }
        }