Пример #1
0
        private void OnStepChanged(CachedStep cachedStep)
        {
            var step = cachedStep.Step;

            if (step.Type != ParseStepType.Error)
            {
                using (this.LockWindowUpdate())
                {
                    txtPattern.TextChanged -= TxtPatternOnTextChanged;
                    txtInput.TextChanged -= TxtInputOnTextChanged;

                    lblMessage.Text =
                        step.Type == ParseStepType.Pass || step.Type == ParseStepType.Fail || step.Type == ParseStepType.Match
                        ? step.Message
                        : string.Format("{0} - {1} /{2}/", step.Message, step.NodeType, step.Pattern);

                    txtPattern.ClearHighlights();
                    txtInput.ClearHighlights();

                    ClearTreeNodeSelections();
                    var foundNode = FindNodeById(tvRegex.Nodes, step.Node.Id.ToString(CultureInfo.InvariantCulture));
                    if (foundNode != null)
                    {
                        SetNodeBackColor(foundNode, Color.Yellow);
                    }

                    txtPattern.SetHighlight(step.Node.Index, step.Node.Pattern.Length, Color.Yellow);

                    lvMessages.SelectedIndexChanged -= LvMessagesOnSelectedIndexChanged;
                    foreach (ListViewItem item in lvMessages.Items)
                    {
                        var itemCachedStep = (CachedStep)item.Tag;
                        if (itemCachedStep.StepIndex == cachedStep.StepIndex)
                        {
                            item.Selected = true;
                            lvMessages.Select();
                            item.EnsureVisible();
                        }
                    }
                    lvMessages.SelectedIndexChanged += LvMessagesOnSelectedIndexChanged;

                    var regex = step.Node as Regex;
                    if (regex != null && step.Type == ParseStepType.Match)
                    {
                        txtInput.SetHighlight(step.InitialState.Index, step.MatchedText.Length, Color.LawnGreen);
                    }
                    else
                    {
                        if (step.Type == ParseStepType.Pass || step.Type == ParseStepType.Capture)
                        {
                            txtInput.SetHighlight(step.InitialState.Index, step.MatchedText.Length, Color.LightSkyBlue);
                        }
                        else if (step.Type == ParseStepType.Fail)
                        {
                            txtInput.SetHighlight(step.InitialState.Index, (step.CurrentState.Index - step.InitialState.Index) + 1, Color.PeachPuff);
                        }
                    }

                    _regexIndexPosition = txtInput.GetPositionFromCharIndex(cachedStep.StepIndex == 0 ? 0 : cachedStep.RegexIndex);
                    _currentIndexPosition = txtInput.GetPositionFromCharIndex(cachedStep.StepIndex == 0 ? 0 : cachedStep.CurrentIndex);

                    if (cachedStep.CurrentLookaroundIndex == -1)
                    {
                        _lookAroundIndexPosition = Point.Empty;
                    }
                    else
                    {
                        _lookAroundIndexPosition = txtInput.GetPositionFromCharIndex(cachedStep.StepIndex == 0 ? 0 : cachedStep.CurrentLookaroundIndex);
                    }

                    _savedStatesIndexPositions = cachedStep.SavedStatesIndexes.Select(index => txtInput.GetPositionFromCharIndex(index)).ToArray();
                    txtInput.Invalidate();

                    txtPattern.TextChanged += TxtPatternOnTextChanged;
                    txtInput.TextChanged += TxtInputOnTextChanged;
                }
            }
            else
            {
                MessageBox.Show(step.Exception.ToString());
            }
        }
Пример #2
0
        private void OnStepChanged(CachedStep cachedStep)
        {
            var step = cachedStep.Step;

            if (step.Type != ParseStepType.Error)
            {
                using (this.LockWindowUpdate())
                {
                    txtPattern.TextChanged -= TxtPatternOnTextChanged;
                    txtInput.TextChanged   -= TxtInputOnTextChanged;

                    lblMessage.Text =
                        step.Type == ParseStepType.Pass || step.Type == ParseStepType.Fail || step.Type == ParseStepType.Match
                        ? step.Message
                        : string.Format("{0} - {1} /{2}/", step.Message, step.NodeType, step.Pattern);

                    txtPattern.ClearHighlights();
                    txtInput.ClearHighlights();

                    ClearTreeNodeSelections();
                    var foundNode = FindNodeById(tvRegex.Nodes, step.Node.Id.ToString(CultureInfo.InvariantCulture));
                    if (foundNode != null)
                    {
                        SetNodeBackColor(foundNode, Color.Yellow);
                    }

                    txtPattern.SetHighlight(step.Node.Index, step.Node.Pattern.Length, Color.Yellow);

                    lvMessages.SelectedIndexChanged -= LvMessagesOnSelectedIndexChanged;
                    foreach (ListViewItem item in lvMessages.Items)
                    {
                        var itemCachedStep = (CachedStep)item.Tag;
                        if (itemCachedStep.StepIndex == cachedStep.StepIndex)
                        {
                            item.Selected = true;
                            lvMessages.Select();
                            item.EnsureVisible();
                        }
                    }
                    lvMessages.SelectedIndexChanged += LvMessagesOnSelectedIndexChanged;

                    var regex = step.Node as Regex;
                    if (regex != null && step.Type == ParseStepType.Match)
                    {
                        txtInput.SetHighlight(step.InitialState.Index, step.MatchedText.Length, Color.LawnGreen);
                    }
                    else
                    {
                        if (step.Type == ParseStepType.Pass || step.Type == ParseStepType.Capture)
                        {
                            txtInput.SetHighlight(step.InitialState.Index, step.MatchedText.Length, Color.LightSkyBlue);
                        }
                        else if (step.Type == ParseStepType.Fail)
                        {
                            txtInput.SetHighlight(step.InitialState.Index, (step.CurrentState.Index - step.InitialState.Index) + 1, Color.PeachPuff);
                        }
                    }

                    _regexIndexPosition   = txtInput.GetPositionFromCharIndex(cachedStep.StepIndex == 0 ? 0 : cachedStep.RegexIndex);
                    _currentIndexPosition = txtInput.GetPositionFromCharIndex(cachedStep.StepIndex == 0 ? 0 : cachedStep.CurrentIndex);

                    if (cachedStep.CurrentLookaroundIndex == -1)
                    {
                        _lookAroundIndexPosition = Point.Empty;
                    }
                    else
                    {
                        _lookAroundIndexPosition = txtInput.GetPositionFromCharIndex(cachedStep.StepIndex == 0 ? 0 : cachedStep.CurrentLookaroundIndex);
                    }

                    _savedStatesIndexPositions = cachedStep.SavedStatesIndexes.Select(index => txtInput.GetPositionFromCharIndex(index)).ToArray();
                    txtInput.Invalidate();

                    txtPattern.TextChanged += TxtPatternOnTextChanged;
                    txtInput.TextChanged   += TxtInputOnTextChanged;
                }
            }
            else
            {
                MessageBox.Show(step.Exception.ToString());
            }
        }