internal void AddCaretMoveToSelections(Selection selection)
        {
            var caretPosition = view.Caret.Position.BufferPosition;
            var newSelection  = new Selection
            {
                Start          = null,
                End            = null,
                Caret          = Snapshot.CreateTrackingPoint(caretPosition),
                ColumnPosition = selection.ColumnPosition,
                VirtualSpaces  = view.Caret.Position.VirtualSpaces
            };

            var newPosition = newSelection.GetCaretColumnPosition(
                caretPosition,
                Snapshot,
                view.FormattedLineSource.TabSize);

            newSelection.Caret = Snapshot.CreateTrackingPoint(newPosition);

            if (Selections.Any(s => s.Caret.GetPoint(Snapshot) == newPosition))
            {
                return;
            }

            Selections.Add(newSelection);
        }
        void Command_Diff_SelectedFiles()
        {
            if (!Selections.Any())
            {
                return;
            }

            if (Selections.Count % 2 != 0)
            {
                throw new Exception("Must have even number of selections.");
            }

            var files = GetSelectionStrings();

            if (files.Any(file => !File.Exists(file)))
            {
                throw new Exception("Selections must be files.");
            }

            var tabs    = new Tabs();
            var batches = files.Batch(2).ToList();

            foreach (var batch in batches)
            {
                tabs.AddDiff(fileName1: batch[0], fileName2: batch[1]);
            }
        }
示例#3
0
        private void ProcessFoundOccurrence(SnapshotSpan occurrence)
        {
            if (!Selections.Any(s => s.OverlapsWith(occurrence, Snapshot)))
            {
                var start = Snapshot.CreateTrackingPoint(occurrence.Start);
                var end   = Snapshot.CreateTrackingPoint(occurrence.End);
                var caret = Selections.Last().IsReversed(Snapshot)
                    ? start : end;

                Selections.Add(
                    new Selection
                {
                    Start          = start,
                    End            = end,
                    Caret          = caret,
                    ColumnPosition = Snapshot.GetLineColumnFromPosition(caret.GetPoint(Snapshot))
                }
                    );

                outliningManager.ExpandAll(occurrence, r => r.IsCollapsed);

                view.Caret.MoveTo(caret == start ? occurrence.Start : occurrence.End);

                view.ViewScroller.EnsureSpanVisible(
                    new SnapshotSpan(view.Caret.Position.BufferPosition, 0)
                    );
            }
        }
 void Command_Select_Selection_Single()
 {
     if (!Selections.Any())
     {
         return;
     }
     SetSelections(new List <Range> {
         Selections[CurrentSelection]
     });
     CurrentSelection = 0;
 }
示例#5
0
        void Command_Text_Select_MinMax_Length(bool max)
        {
            if (!Selections.Any())
            {
                throw new Exception("No selections");
            }

            var lengths = Selections.Select(range => range.Length).ToList();
            var find    = max ? lengths.OrderByDescending().First() : lengths.OrderBy().First();

            SetSelections(lengths.Indexes(length => length == find).Select(index => Selections[index]).ToList());
        }
        void Command_Numeric_Select_MinMax(bool max)
        {
            if (!Selections.Any())
            {
                throw new Exception("No selections");
            }

            var values = Selections.AsParallel().AsOrdered().Select(range => double.Parse(GetString(range))).ToList();
            var find   = max ? values.OrderByDescending().First() : values.OrderBy().First();

            SetSelections(values.Indexes(value => value == find).Select(index => Selections[index]).ToList());
        }
示例#7
0
        protected override void HandleDoubleClick(Point coords, ButtonModifier modif)
        {
            base.HandleDoubleClick(coords, modif);

            if (Selections.Any())
            {
                if (CenterPlayheadClicked != null)
                {
                    CenterPlayheadClicked(this, new EventArgs());
                }
            }
        }
        void Command_Edit_Navigate_WordLeftRight(bool next, bool selecting)
        {
            if ((!selecting) && (Selections.Any(range => range.HasSelection)))
            {
                SetSelections(Selections.AsParallel().AsOrdered().Select(range => new Range(next ? range.End : range.Start)).ToList());
                return;
            }

            var func = next ? (Func <int, int>)GetNextWord : GetPrevWord;

            SetSelections(Selections.AsParallel().AsOrdered().Select(range => MoveCursor(range, func(range.Cursor), selecting)).ToList());
        }
示例#9
0
        void Command_Text_Select_MinMax_Text(bool max)
        {
            if (!Selections.Any())
            {
                throw new Exception("No selections");
            }

            var strings = GetSelectionStrings();
            var find    = max ? strings.OrderByDescending().First() : strings.OrderBy().First();

            SetSelections(strings.Indexes(str => str == find).Select(index => Selections[index]).ToList());
        }
        void Command_Table_RegionSelectionsToTable_Region(int useRegion)
        {
            if (!Selections.Any())
            {
                return;
            }

            var sels    = GetSelectionStrings();
            var regions = GetEnclosingRegions(useRegion);
            var rows    = Enumerable.Range(0, Selections.Count).GroupBy(index => regions[index]).Select(group => group.Select(index => sels[index]).ToList()).ToList();

            OpenTable(new Table(rows, false));
        }
示例#11
0
        private void SelectPerson(Person person)
        {
            if (!AllowMultiple && Selections.Any())
            {
                Selections.Clear();
                Selections.Add(person);
            }
            else
            {
                Selections.Add(person);
            }

            RaiseSelectionChanged();
            SearchPattern = string.Empty;
        }
示例#12
0
        internal void AddMouseCaretToSelections()
        {
            var caretPosition = view.Caret.Position.BufferPosition;

            if (!Selections.Any(s => s.Caret.GetPosition(Snapshot) == caretPosition))
            {
                Selections.Add(
                    new Selection
                {
                    Start          = null,
                    End            = null,
                    Caret          = Snapshot.CreateTrackingPoint(caretPosition),
                    ColumnPosition = Snapshot.GetLineColumnFromPosition(caretPosition)
                }
                    );
            }
        }
示例#13
0
        internal void ApplyStashedCaretPosition()
        {
            var stashedCaretPosition = StashedCaret.GetPosition(Snapshot);

            if (!Selections.Any(s => s.Caret.GetPoint(Snapshot) == stashedCaretPosition))
            {
                Selections.Add(
                    new Selection
                {
                    Start          = null,
                    End            = null,
                    Caret          = StashedCaret,
                    ColumnPosition = Snapshot.GetLineColumnFromPosition(stashedCaretPosition)
                }
                    );
            }

            StashedCaret = null;
        }
        void Command_Table_LineSelectionsToTable()
        {
            if (!Selections.Any())
            {
                return;
            }

            var lineSets = Selections.AsParallel().AsOrdered().Select(range => new { start = Data.GetOffsetLine(range.Start), end = Data.GetOffsetLine(range.End) }).ToList();

            if (lineSets.Any(range => range.start != range.end))
            {
                throw new Exception("Cannot have multi-line selections");
            }

            var sels  = GetSelectionStrings();
            var lines = lineSets.Select(range => range.start).ToList();
            var rows  = Enumerable.Range(0, Selections.Count).GroupBy(index => lines[index]).Select(group => group.Select(index => sels[index]).ToList()).ToList();

            OpenTable(new Table(rows, false));
        }
示例#15
0
        internal SnapshotPoint ApplyStashedCaretPosition()
        {
            var stashedCaretPosition = StashedCaret.GetPosition(Snapshot);

            var position = view.Caret.Position.BufferPosition;

            view.Caret.MoveTo(StashedCaret.GetPoint(Snapshot));

            if (!Selections.Any(s => s.Caret.GetPoint(Snapshot) == stashedCaretPosition))
            {
                Selections.Add(
                    new Selection
                {
                    Caret          = StashedCaret,
                    ColumnPosition = GetColumnPosition()
                }
                    );
            }
            StashedCaret = null;
            return(position);
        }
        void Command_Numeric_Add_Sum()
        {
            if (!Selections.Any())
            {
                return;
            }

            var result = Selections.Where(range => !range.HasSelection).FirstOrDefault();

            if (result == null)
            {
                result = Selections[Math.Max(0, Math.Min(CurrentSelection, Selections.Count - 1))];
            }

            var sum = Selections.AsParallel().Where(range => range.HasSelection).Select(range => double.Parse(GetString(range))).Sum();

            SetSelections(new List <Range> {
                result
            });
            ReplaceSelections(sum.ToString());
        }
        void Command_Edit_Navigate_AllRight(bool selecting)
        {
            if (!Selections.Any())
            {
                return;
            }

            var offsets = Selections.Select(range => range.Cursor).ToList();
            var lines   = offsets.AsParallel().AsOrdered().Select(offset => Data.GetOffsetLine(offset)).ToList();

            var index    = offsets.Zip(lines, (offset, line) => Data.GetOffsetIndex(offset, line)).Min();
            var endIndex = lines.Select(line => Data.GetLineLength(line)).Min();

            var currentIsSpace = default(bool?);

            while (true)
            {
                if (index > endIndex)
                {
                    offsets = lines.Select(line => Data.GetOffset(line, Data.GetLineLength(line))).ToList();
                    break;
                }

                var isSpace = lines.All(line => GetWordSkipType(line, index) == WordSkipType.Space);

                if (!currentIsSpace.HasValue)
                {
                    currentIsSpace = isSpace;
                }
                else if (isSpace != currentIsSpace)
                {
                    offsets = lines.Select(line => Data.GetOffset(line, index)).ToList();
                    break;
                }

                ++index;
            }

            SetSelections(Selections.Zip(offsets, (range, offset) => MoveCursor(range, offset, selecting)).ToList());
        }
示例#18
0
        internal void AddCurrentCaretToSelections()
        {
            var caretPosition = view.Caret.Position.BufferPosition;

            if (!Selections.Any(s => s.Caret.GetPosition(Snapshot) == caretPosition))
            {
                var newSelection = new Selection
                {
                    Caret          = Snapshot.CreateTrackingPoint(caretPosition),
                    ColumnPosition = GetColumnPosition() + view.Caret.Position.VirtualSpaces,
                    VirtualSpaces  = view.Caret.Position.VirtualSpaces
                };

                if (!view.Selection.IsEmpty)
                {
                    newSelection.Start = Snapshot.CreateTrackingPoint(view.Selection.Start.Position);
                    newSelection.End   = Snapshot.CreateTrackingPoint(view.Selection.End.Position);
                }

                Selections.Add(newSelection);
            }
        }
示例#19
0
        private void OnAutoCompletionListChanged()
        {
            Dispatcher.Invoke(() =>
            {
                TextBoxAutoComplete.IsEnabled = true;
                TextBoxAutoComplete.Focus();

                if (_autoCompletionList != null)
                {
                    ComboAutoComplete.Items.Clear();

                    foreach (var entry in _autoCompletionList)
                    {
                        if (Selections.Any((sel => sel.Id == entry.Id)))
                        {
                            continue;
                        }

                        ComboAutoComplete.Items.Add(entry);
                    }
                }

                if (ComboAutoComplete.HasItems)
                {
                    ComboAutoComplete.Visibility = Visibility.Visible;
                }
                else
                {
                    ComboAutoComplete.Visibility = Visibility.Hidden;
                }

                ComboAutoComplete.IsDropDownOpen = ComboAutoComplete.HasItems;

                if (ImgLoader != null)
                {
                    ImgLoader.Visibility = Visibility.Hidden;
                }
            }, DispatcherPriority.Normal);
        }
示例#20
0
        private void SearchResultListBox_OnSelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)
        {
#pragma warning disable SA1119 // Statement must not use unnecessary parenthesis
            if (!((sender as ListBox)?.SelectedItem is Person person))
#pragma warning restore SA1119 // Statement must not use unnecessary parenthesis
            {
                return;
            }

            if (!AllowMultiple && Selections.Any())
            {
                Selections.Clear();
                Selections.Add(person);
            }
            else
            {
                Selections.Add(person);
            }

            RaiseSelectionChanged();

            _searchBox.Text = string.Empty;
        }
 EditFindMassFindDialog.Result Command_Edit_Find_MassFind_Dialog() => EditFindMassFindDialog.Run(WindowParent, Selections.Any(range => range.HasSelection), GetVariables());
示例#22
0
        /// <summary>
        /// Handles finding occurrences, selecting and adding to current selections
        /// </summary>
        /// <param name="reverseDirection">Search document in reverse direction for an occurrence</param>
        /// <param name="exactMatch">Search document for an exact match, overrides find-dialog settings</param>
        internal void SelectNextOccurrence(bool reverseDirection = false, bool exactMatch = false)
        {
            // Caret placed on a word, but nothing selected
            if (!Selections.Any() && view.Selection.IsEmpty)
            {
                SelectCurrentWord(view.Caret.Position.BufferPosition);
                return;
            }

            // First selection is selected by user, future selections will be located and selected on command-invocation
            if (!Selections.Any() && !view.Selection.IsEmpty)
            {
                AddCurrentSelectionToSelections();
            }

            // Multiple selections
            if (Selections.Any())
            {
                // Select words at caret again, this is where we have abandoned selections and goes to carets
                if (Selections.Any(s => !s.IsSelection()))
                {
                    var oldSelections = Selections;
                    Selections = new List <Selection>();

                    foreach (var selection in oldSelections)
                    {
                        if (!selection.IsSelection())
                        {
                            view.Caret.MoveTo(selection.Caret.GetPoint(Snapshot));
                            SelectCurrentWord(selection.Caret.GetPoint(Snapshot));
                        }
                        else
                        {
                            Selections.Add(selection);
                        }
                    }
                }
                else
                {
                    var orderedSelections = HasWrappedDocument
                        ? Selections
                        : Selections.OrderBy(n => n.Caret.GetPosition(Snapshot)).ToList();

                    var startSelection = reverseDirection && !HasWrappedDocument
                        ? orderedSelections.First()
                        : orderedSelections.Last();

                    var startIndex = reverseDirection ?
                                     startSelection.Start?.GetPosition(Snapshot) ?? startSelection.Caret.GetPosition(Snapshot)
                        : startSelection.End?.GetPosition(Snapshot) ?? startSelection.Caret.GetPosition(Snapshot);

                    var occurrence = textSearchService.FindNext(
                        startIndex,
                        true,
                        GetFindData(reverseDirection, exactMatch)
                        );

                    if (occurrence.HasValue)
                    {
                        ProcessFoundOccurrence(occurrence.Value);

                        if (!reverseDirection && Selections.Last().Caret.GetPosition(Snapshot) <
                            Selections.First().Caret.GetPosition(Snapshot))
                        {
                            HasWrappedDocument = true;
                        }

                        if (reverseDirection && Selections.Last().Caret.GetPosition(Snapshot) >
                            Selections.First().Caret.GetPosition(Snapshot))
                        {
                            HasWrappedDocument = true;
                        }
                    }
                }

                view.Selection.Clear();
                view.Caret.MoveTo(Selections.Last().Caret.GetPoint(Snapshot));
            }
        }
示例#23
0
        /// <summary>
        /// Handles finding occurrences, selecting and adding to current selections
        /// </summary>
        /// <param name="reverseDirection">Search document in reverse direction for an occurrence</param>
        /// <param name="exactMatch">Search document for an exact match, overrides find-dialog settings</param>
        internal void SelectNextOccurrence(bool reverseDirection = false, bool exactMatch = false)
        {
            // Caret placed on a word, but nothing selected
            if (!Selections.Any() && view.Selection.IsEmpty)
            {
                SelectCurrentWord(view.Caret.Position.BufferPosition);
                return;
            }

            // First selection is selected by user, future selections will be located and selected on command-invocation
            if (!Selections.Any() && !view.Selection.IsEmpty)
            {
                AddCurrentSelectionToSelections();
            }

            // Multiple selections
            if (Selections.Any())
            {
                // Select words at caret again, this is where we have abandoned selections and goes to carets
                if (Selections.Any(s => !s.IsSelection()))
                {
                    var oldSelections = Selections;
                    Selections = new List <Selection>();

                    // Note: The list is in reverse order to fix a bug in EditorOperations.SelectCurrentWord()
                    foreach (var selection in oldSelections.OrderByDescending(n => n.Caret.GetPosition(Snapshot)))
                    {
                        if (!selection.IsSelection())
                        {
                            view.Caret.MoveTo(selection.Caret.GetPoint(Snapshot));
                            SelectCurrentWord(selection.Caret.GetPoint(Snapshot));
                        }
                        else
                        {
                            Selections.Add(selection);
                        }
                    }
                }
                else
                {
                    var orderedSelections = Selections.OrderBy(n => n.Caret.GetPosition(Snapshot)).ToList();
                    var startIndex        = ExtensionOptions.Instance.InwardSelection ^ reverseDirection ? 0 : orderedSelections.Count - 1;
                    var direction         = reverseDirection ? -1 : 1;

                    var index = startIndex;
                    do
                    {
                        var position = reverseDirection
                            ? orderedSelections[index].Start.GetPosition(Snapshot)
                            : orderedSelections[index].End.GetPosition(Snapshot);

                        index = (index + direction + orderedSelections.Count) % orderedSelections.Count;
                        if (textSearchService.FindNext(position, true, GetFindData(reverseDirection, exactMatch))
                            is SnapshotSpan occurrence &&
                            !orderedSelections[index].OverlapsWith(occurrence, Snapshot))
                        {
                            ProcessFoundOccurrence(occurrence);
                            break;
                        }
                    } while (startIndex != index);
                }

                view.Selection.Clear();
                view.Caret.MoveTo(Selections.Last().Caret.GetPoint(Snapshot));
            }
        }
示例#24
0
        private async Task SearchPeopleAsync(string searchPattern)
        {
            if (string.IsNullOrWhiteSpace(searchPattern))
            {
                ClearAndHideSearchResultListBox();
                return;
            }

            IsLoading = true;
            try
            {
                GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync();

                if (graphClient != null)
                {
                    int searchLimit = SearchResultLimit > 0 ? SearchResultLimit : DefaultSearchResultLimit;
                    int queryLimit  = searchLimit + Selections.Count;
                    IEnumerable <Person> rawResults;
                    if (string.IsNullOrWhiteSpace(GroupId))
                    {
                        var options = new List <QueryOption>
                        {
                            new QueryOption("$search", $"\"{searchPattern}\""),
                            new QueryOption("$filter", "personType/class eq 'Person' and personType/subclass eq 'OrganizationUser'"),
                            new QueryOption("$top", queryLimit.ToString())
                        };
                        rawResults = await graphClient.Me.People.Request(options).GetAsync();
                    }
                    else
                    {
                        IGroupMembersCollectionWithReferencesPage userRequest = await graphClient.Groups[GroupId].Members.Request().GetAsync();
                        List <Person> allPersons = new List <Person>();
                        while (true)
                        {
                            foreach (User user in userRequest)
                            {
                                if (string.IsNullOrEmpty(searchPattern) ||
                                    (!string.IsNullOrEmpty(user.DisplayName) && user.DisplayName.StartsWith(searchPattern, StringComparison.OrdinalIgnoreCase)) ||
                                    (!string.IsNullOrEmpty(user.Surname) && user.Surname.StartsWith(searchPattern, StringComparison.OrdinalIgnoreCase)))
                                {
                                    Person person = GetPersonFromUser(user);
                                    allPersons.Add(person);
                                }

                                if (allPersons.Count >= queryLimit)
                                {
                                    break;
                                }
                            }

                            if (allPersons.Count >= queryLimit ||
                                userRequest.NextPageRequest == null)
                            {
                                break;
                            }

                            userRequest = await userRequest.NextPageRequest.GetAsync();
                        }

                        rawResults = allPersons;
                    }

                    SearchResults.Clear();
                    var results = rawResults.Where(o => !Selections.Any(s => s.Id == o.Id))
                                  .Take(searchLimit);
                    foreach (var item in results)
                    {
                        SearchResults.Add(item);
                    }

                    if (SearchResults.Count > 0)
                    {
                        ShowSearchResults();
                    }
                    else
                    {
                        ClearAndHideSearchResultListBox();
                    }
                }
            }
            catch (Exception exception)
            {
                MessageDialog messageDialog = new MessageDialog(exception.Message);
                await messageDialog.ShowAsync();
            }
            finally
            {
                IsLoading = false;
            }
        }
示例#25
0
        TextWidthDialog.Result Command_Text_Width_Dialog()
        {
            var numeric = Selections.Any() ? Selections.AsParallel().All(range => GetString(range).IsNumeric()) : false;

            return(TextWidthDialog.Run(WindowParent, numeric, false, GetVariables()));
        }