public CircularConfiguration(float tolerance, float resolution, SelectionFlag selectionType)
        {
            if (tolerance < 0 || tolerance > 1) 
                throw new ArgumentOutOfRangeException("Should be a percentage");

            if (resolution < 0 || resolution > 1) 
                throw new ArgumentOutOfRangeException("Should be a percentage");

            this.Tolerance = tolerance;
            this.Resolution = resolution;
            this.SelectionType = selectionType;

            this.Steps = (int)Math.Round(1 / this.Resolution + 1, 0);
            this.MaxSurface = this.Steps * this.Steps;
            this.MinSurface = this.Tolerance * this.MaxSurface;
        }
        /// <summary>
        /// Define CircularConfiguration with automatic resolution based on tolerance
        /// </summary>
        /// <param name="tolerance">Tolerance percentage for selectionType</param>
        /// <param name="selectionType"></param>
        public CircularConfiguration(float tolerance, SelectionFlag selectionType)
        {
            if (tolerance < 0 || tolerance > 1)
                throw new ArgumentOutOfRangeException("Should be a percentage");

            this.Tolerance = tolerance;
            this.Resolution = 1f;
            this.SelectionType = selectionType;

            // Automatic resolution
            float factor = tolerance;
            while (Math.Floor(factor) != factor)
            {
                this.Resolution = this.Resolution / 10f;
                factor = factor * 10f;
            }

            // Members
            this.Steps = (int)Math.Round(1 / this.Resolution + 1, 0);
            this.MaxSurface = this.Steps * this.Steps;
            this.MinSurface = this.Tolerance * this.MaxSurface;
        }
Пример #3
0
        void SetSelection(int displayIndex, SelectionFlag flag = SelectionFlag.None, int?textCharIndex = null)
        {
            var dmsg = screenBuffer.Messages[displayIndex];
            var msg  = dmsg.Message;
            var line = GetTextToDisplay(msg).GetNthTextLine(dmsg.TextLineIndex);
            int newLineCharIndex;

            if ((flag & SelectionFlag.SelectBeginningOfLine) != 0)
            {
                newLineCharIndex = 0;
            }
            else if ((flag & SelectionFlag.SelectEndOfLine) != 0)
            {
                newLineCharIndex = line.Length;
            }
            else
            {
                newLineCharIndex = RangeUtils.PutInRange(0, line.Length,
                                                         textCharIndex.GetValueOrDefault(selection.First.LineCharIndex));
                if ((flag & SelectionFlag.SelectBeginningOfNextWord) != 0)
                {
                    newLineCharIndex = StringUtils.FindNextWordInString(line, newLineCharIndex);
                }
                else if ((flag & SelectionFlag.SelectBeginningOfPrevWord) != 0)
                {
                    newLineCharIndex = StringUtils.FindPrevWordInString(line, newLineCharIndex);
                }
            }

            tracer.Info("Selecting line {0}. Display position = {1}", msg.GetHashCode(), displayIndex);

            bool resetEnd = (flag & SelectionFlag.PreserveSelectionEnd) == 0;

            Action doScrolling = () =>
            {
                if (displayIndex == 0 && screenBuffer.TopLineScrollValue > 1e3)
                {
                    screenBuffer.TopLineScrollValue = 0;
                    view.Invalidate();
                }
                if ((flag & SelectionFlag.NoHScrollToSelection) == 0)
                {
                    view.HScrollToSelectedText(selection);
                }
                view.RestartCursorBlinking();
            };

            if (selection.First.Message != msg ||
                selection.First.DisplayIndex != displayIndex ||
                selection.First.LineCharIndex != newLineCharIndex ||
                resetEnd != selection.IsEmpty)
            {
                var oldSelection = selection;

                InvalidateTextLineUnderCursor();

                var tmp = new CursorPosition()
                {
                    Message       = msg,
                    Source        = dmsg.Source,
                    DisplayIndex  = displayIndex,
                    TextLineIndex = dmsg.TextLineIndex,
                    LineCharIndex = newLineCharIndex
                };

                SetSelection(tmp, resetEnd ? tmp : new CursorPosition?());

                OnSelectionChanged();

                foreach (var displayIndexToInvalidate in oldSelection.GetDisplayIndexesRange().SymmetricDifference(selection.GetDisplayIndexesRange())
                         .Where(idx => idx < screenBuffer.Messages.Count && idx >= 0))
                {
                    view.InvalidateLine(screenBuffer.Messages[displayIndexToInvalidate].ToViewLine());
                }

                InvalidateTextLineUnderCursor();

                doScrolling();

                UpdateSelectionInplaceHighlightingFields();

                if (selection.First.Message != oldSelection.First.Message)
                {
                    tracer.Info("focused message changed");
                    OnFocusedMessageChanged();
                    OnFocusedMessageBookmarkChanged();
                }
                else if (selection.First.TextLineIndex != oldSelection.First.TextLineIndex)
                {
                    tracer.Info("focused message's line changed");
                    OnFocusedMessageBookmarkChanged();
                }
            }
            else if ((flag & SelectionFlag.ScrollToViewEventIfSelectionDidNotChange) != 0)
            {
                doScrolling();
            }
        }
Пример #4
0
 void ISelectionManager.SetSelection(int displayIndex, SelectionFlag flag, int?textCharIndex)
 {
     SetSelection(displayIndex, flag, textCharIndex);
 }