/// <summary>
        /// Set Error marker on code for Java. returns True on success False otherwise.
        /// </summary>
        public static bool SetJavaCodeError(FastColoredTextBox code, Range message, bool focus = false)
        {
            try
            {
                //split data in parts separated by ':'
                string   data = message.Text;
                string[] part = data.Split(new char[] { ':' });

                //usually row and col is on first two parts
                int row = int.Parse(part[0]) - 1; // <-- throws exception on failure

                //check if rest of the data is not empty
                string rest = string.Join(" ", part, 1, part.Length - 1);
                if (rest.Trim().Length == 0)
                {
                    return(false);
                }

                //get line by row number
                string line = code.Lines[row].TrimEnd();
                //get last of the message
                Place stop = new Place(line.Length, row);
                //we need to move start point where first  non-space character found
                int col = 0; while (col < line.Length && line[col] == ' ')
                {
                    ++col;
                }
                Place start = new Place(col, row);
                //get range from start to stop
                Range range = code.GetRange(start, stop);

                //show zigzag lines under the errors
                range.SetStyle(HighlightSyntax.LineErrorStyle);

                //focus current and exit
                if (focus)
                {
                    code.ExpandBlock(row);
                    code.Selection = range;
                    code.DoRangeVisible(range, true);
                }

                // add hints
                if (Properties.Settings.Default.EditorShowHints)
                {
                    Hint hdat = code.AddHint(range, data, focus, true, true);
                    hdat.Tag         = message;
                    hdat.BorderColor = Color.LightBlue;
                    hdat.BackColor   = Color.AliceBlue;
                    hdat.BackColor2  = Color.PowderBlue;
                }

                return(true);
            }
            catch { return(false); }
        }
Exemple #2
0
 // When clicking on the error message, move the cursor to the line/column of the error.
 private void statusStripErrorMessage_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     if (displayedError != null && displayedError.Line > 0 && displayedError.Column > 0)
     {
         int lineIndex = GMath.Clamp(displayedError.Line - 1, 0, codeEditor.Lines.Count - 1);
         int charIndex = GMath.Clamp(displayedError.Column - 1, 0, codeEditor.Lines[lineIndex].Length);
         codeEditor.Selection.Start = new Place(charIndex, lineIndex);
         codeEditor.DoRangeVisible(codeEditor.Selection, true);
         codeEditor.Invalidate();
         codeEditor.Focus();
     }
 }
Exemple #3
0
        private void Scroll(Point point)
        {
            if (_target == null)
            {
                return;
            }
            var zoom = Scale * 100 / _target.Zoom;

            if (zoom <= float.Epsilon)
            {
                return;
            }
            var p0 = _target.PlaceToPoint(_startPlace);

            p0 = new Point(0, p0.Y + (int)(point.Y / zoom));
            var pp = _target.PointToPlace(p0);

            _target.DoRangeVisible(new Range(_target, pp, pp), true);
            BeginInvoke((MethodInvoker)OnScroll);
        }
        /// <summary>
        /// Set Error marker on code for C/C++. returns True on success False otherwise.
        /// </summary>
        public static bool SetCPPCodeError(FastColoredTextBox code, Range message, bool focus = false)
        {
            try
            {
                //split data in parts separated by ':'
                string   data = message.Text;
                string[] part = data.Split(new char[] { ':' });

                //usually row and col is on first two parts
                int row, col;
                row = int.Parse(part[0]) - 1; // <-- throws exception on failure
                col = int.Parse(part[1]) - 1; // <-- throws exception on failure

                //get the type of message : there can be one and only one of these types
                bool error = Regex.IsMatch(data, " error:.*");   //check for error data type
                bool warn  = Regex.IsMatch(data, " warning:.*"); //check for warning data type
                bool note  = Regex.IsMatch(data, " note:.*");    //check for note data type
                if (!(error || warn || note))
                {
                    return(false);                          //for c++ do not proceed if not valid type
                }
                //get line by row number
                string line = code.Lines[row];
                //get start the message
                Place start = new Place(col, row);
                //we need to cover the next word after start
                while (col < line.Length && char.IsLetterOrDigit(line[col]))
                {
                    ++col;
                }
                //if no word of number is selected select all non-space chars instead
                if (start.iChar == col)
                {
                    while (col < line.Length && ' ' != line[col])
                    {
                        ++col;
                    }
                }
                //now we found our stop position
                Place stop = new Place(col, row);
                //get range from start to stop
                Range range = code.GetRange(start, stop);

                //show zigzag lines under the errors
                if (error)
                {
                    range.SetStyle(HighlightSyntax.LineErrorStyle);
                }
                else if (warn)
                {
                    range.SetStyle(HighlightSyntax.LineWarningStyle);
                }
                else if (note)
                {
                    range.SetStyle(HighlightSyntax.LineNoteStyle);
                }

                //focus current and exit
                if (focus && error)
                {
                    code.ExpandBlock(row);
                    code.Selection = range;
                    code.DoRangeVisible(range, true);
                }

                // add hints
                if (Properties.Settings.Default.EditorShowHints && error)
                {
                    Hint hdat = code.AddHint(range, data, focus, true, true);
                    hdat.Tag        = message;
                    hdat.BackColor  = Color.AliceBlue;
                    hdat.BackColor2 = Color.LightSkyBlue;
                }

                return(true);
            }
            catch { return(false); }
        }
Exemple #5
0
        /// <summary>
        /// Set Error marker on code for Java. returns True on success False otherwise.
        /// </summary>
        public static bool SetJavaCodeError(FastColoredTextBox code, Range message, bool focus = false)
        {
            try
            {
                //split data in parts separated by ':'
                string data = message.Text;
                string[] part = data.Split(new char[] { ':' });

                //usually row and col is on first two parts
                int row = int.Parse(part[0]) - 1; // <-- throws exception on failure

                //check if rest of the data is not empty
                string rest = string.Join(" ", part, 1, part.Length - 1);
                if (rest.Trim().Length == 0) return false;

                //get line by row number
                string line = code.Lines[row].TrimEnd();
                //get last of the message
                Place stop = new Place(line.Length, row);
                //we need to move start point where first  non-space character found
                int col = 0; while (col < line.Length && line[col] == ' ') ++col;
                Place start = new Place(col, row);
                //get range from start to stop
                Range range = code.GetRange(start, stop);

                //show zigzag lines under the errors
                range.SetStyle(HighlightSyntax.LineErrorStyle);

                //focus current and exit
                if (focus)
                {
                    code.ExpandBlock(row);
                    code.Selection = range;
                    code.DoRangeVisible(range, true);
                }

                // add hints
                if (Properties.Settings.Default.EditorShowHints)
                {
                    Hint hdat = code.AddHint(range, data, focus, true, true);
                    hdat.Tag = message;
                    hdat.BorderColor = Color.LightBlue;
                    hdat.BackColor = Color.AliceBlue;
                    hdat.BackColor2 = Color.PowderBlue;
                }

                return true;
            }
            catch { return false; }
        }
Exemple #6
0
        /// <summary>
        /// Set Error marker on code for C/C++. returns True on success False otherwise.
        /// </summary>
        public static bool SetCPPCodeError(FastColoredTextBox code, Range message, bool focus = false)
        {
            try
            {
                //split data in parts separated by ':'
                string data = message.Text;
                string[] part = data.Split(new char[] { ':' });

                //usually row and col is on first two parts
                int row, col;
                row = int.Parse(part[0]) - 1; // <-- throws exception on failure
                col = int.Parse(part[1]) - 1; // <-- throws exception on failure

                //get the type of message : there can be one and only one of these types
                bool error = Regex.IsMatch(data, " error:.*"); //check for error data type
                bool warn = Regex.IsMatch(data, " warning:.*"); //check for warning data type
                bool note = Regex.IsMatch(data, " note:.*"); //check for note data type
                if (!(error || warn || note)) return false; //for c++ do not proceed if not valid type

                //get line by row number
                string line = code.Lines[row];
                //get start the message
                Place start = new Place(col, row);
                //we need to cover the next word after start
                while (col < line.Length && char.IsLetterOrDigit(line[col])) ++col;
                //if no word of number is selected select all non-space chars instead
                if (start.iChar == col) { while (col < line.Length && ' ' != line[col]) ++col; }
                //now we found our stop position
                Place stop = new Place(col, row);
                //get range from start to stop
                Range range = code.GetRange(start, stop);

                //show zigzag lines under the errors
                if (error) range.SetStyle(HighlightSyntax.LineErrorStyle);
                else if (warn) range.SetStyle(HighlightSyntax.LineWarningStyle);
                else if (note) range.SetStyle(HighlightSyntax.LineNoteStyle);

                //focus current and exit
                if (focus && error)
                {
                    code.ExpandBlock(row);
                    code.Selection = range;
                    code.DoRangeVisible(range, true);
                }

                // add hints
                if (Properties.Settings.Default.EditorShowHints && error)
                {
                    Hint hdat = code.AddHint(range, data, focus, true, true);
                    hdat.Tag = message;
                    hdat.BackColor = Color.AliceBlue;
                    hdat.BackColor2 = Color.LightSkyBlue;
                }

                return true;
            }
            catch { return false; }
        }