Exemplo n.º 1
0
        private int MatchNext(string matchText)
        {
            if (String.IsNullOrEmpty(matchText))
            {
                return(-1);
            }

            int indexOf = -1;

            try
            {
                ActiveTextArea.BeginUpdate();
                int    lineNo          = ActiveTextArea.Caret.Line;
                int    colNo           = ActiveTextArea.Caret.Column;
                int    totalNumOfLines = ActiveDocument.TotalNumberOfLines;
                string LineText        = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);
                LineText = ActiveDocument.GetText(ActiveTextArea.Caret.Offset, LineText.Length - colNo);

                indexOf = LineText.IndexOf(matchText, StringComparison.InvariantCultureIgnoreCase);
                int offset = colNo;

                if (indexOf < 0)
                {
                    offset = 0;
                    do
                    {
                        int tmpLineNo = ActiveDocument.GetNextVisibleLineAbove(lineNo, 1);
                        if (tmpLineNo == lineNo)
                        {
                            break;
                        }
                        lineNo   = tmpLineNo;
                        LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);
                        indexOf  = LineText.IndexOf(matchText, StringComparison.InvariantCultureIgnoreCase);
                    }while (indexOf < 0 && lineNo < totalNumOfLines);
                }

                if (indexOf >= 0)
                {
                    ActiveTextArea.Caret.Column = 0;
                    ActiveTextArea.Caret.Line   = lineNo;

                    Point startPoint = ActiveTextArea.Caret.Position;
                    startPoint.X = indexOf + offset;
                    Point endPoint = startPoint;
                    endPoint.X = endPoint.X + matchText.Length;
                    ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);
                    ActiveTextArea.Caret.Column = endPoint.X;
                }
                else if (lineNo == totalNumOfLines - 1)
                {
                    MessageBox.Show("Reached end of document", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            finally
            {
                ActiveTextArea.EndUpdate();
            }
            return(indexOf);
        }
Exemplo n.º 2
0
        private int MatchPrev(string matchText)
        {
            if (String.IsNullOrEmpty(matchText))
            {
                return(-1);
            }

            int indexOf = -1;

            try
            {
                ActiveTextArea.BeginUpdate();
                int lineNo = ActiveTextArea.Caret.Line;
                int colNo  = ActiveTextArea.Caret.Column;

                string LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);
                LineText = LineText.Substring(0, ActiveTextArea.Caret.Column);

                indexOf = LineText.LastIndexOf(matchText, StringComparison.InvariantCultureIgnoreCase);
                if (indexOf < 0)
                {
                    do
                    {
                        int tmpLineNo = ActiveDocument.GetNextVisibleLineBelow(lineNo, 1);
                        if (tmpLineNo == lineNo)
                        {
                            break;
                        }
                        lineNo   = tmpLineNo;
                        LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);

                        indexOf = LineText.LastIndexOf(matchText, StringComparison.InvariantCultureIgnoreCase);
                    }while (indexOf < 0 && lineNo >= 0);
                }

                if (indexOf > 0)
                {
                    ActiveTextArea.Caret.Column = 0;
                    ActiveTextArea.Caret.Line   = lineNo;

                    Point startPoint = ActiveTextArea.Caret.Position;
                    startPoint.X = indexOf;
                    Point endPoint = startPoint;
                    endPoint.X = endPoint.X + matchText.Length;
                    ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);
                    ActiveTextArea.Caret.Column = startPoint.X;
                }
                else if (lineNo == 0)
                {
                    MessageBox.Show("Reached start of document", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            finally
            {
                ActiveTextArea.EndUpdate();
            }
            return(indexOf);
        }
Exemplo n.º 3
0
        public int DeleteWordBeforeCaret()
        {
            int start = SharpDevelopTextEditorUtilities.FindPrevWordStart(ActiveDocument, ActiveTextArea.Caret.Offset);

            string partToRemove = ActiveDocument.GetText(start, ActiveTextArea.Caret.Offset - start);

            if (partToRemove != "." && partToRemove != "..")
            {
                ActiveDocument.Remove(start, partToRemove.Length);// ActiveTextArea.Caret.Offset - start);
                Point p = ActiveDocument.OffsetToPosition(start);
                ActiveTextArea.Caret.Column = p.X;
            }
            return(start);
        }
Exemplo n.º 4
0
        private void PerformSearch(Regex regularExpression)
        {
            if (regularExpression == null)
            {
                return;
            }

            int    lineNo          = ActiveTextArea.Caret.Line;
            int    colNo           = ActiveTextArea.Caret.Column;
            int    totalNumOfLines = ActiveDocument.TotalNumberOfLines;
            string LineText        = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);

            LineText = ActiveDocument.GetText(ActiveTextArea.Caret.Offset, LineText.Length - colNo);

            Match m      = regularExpression.Match(LineText);
            int   offset = colNo;

            if (!m.Success)
            {
                offset = 0;
                do
                {
                    int tmpLineNo = ActiveDocument.GetNextVisibleLineAbove(lineNo, 1);
                    if (tmpLineNo == lineNo)
                    {
                        break;
                    }
                    lineNo   = tmpLineNo;
                    LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);
                    m        = regularExpression.Match(LineText);
                }while (!m.Success && lineNo < totalNumOfLines);
            }

            if (m.Success)
            {
                ActiveTextArea.Caret.Column = 0;
                ActiveTextArea.Caret.Line   = lineNo;

                Point startPoint = ActiveTextArea.Caret.Position;
                startPoint.X = m.Index + offset;
                Point endPoint = startPoint;
                endPoint.X = endPoint.X + m.Length;
                ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);
                ActiveTextArea.Caret.Column = endPoint.X;
            }
            else if (lineNo == totalNumOfLines - 1)
            {
                MessageBox.Show("Reached end of document", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 5
0
 private void MoveCaretToEOL()
 {
     ActiveTextArea.Caret.Column = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, ActiveTextArea.Caret.Line).Length;
 }
Exemplo n.º 6
0
        private void PerformReplace(Regex regularExpression, string replaceText, bool replaceAll)
        {
            if (regularExpression == null)
            {
                return;
            }

            bool replaceAllConfirmed = false;
            bool matchExist          = false;

            int replaceCnt = 0;

            int lineNo     = ActiveTextArea.Caret.Line;
            int colNo      = ActiveTextArea.Caret.Column;
            int matchIndex = 1;

            string LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);

            LineText = ActiveDocument.GetText(ActiveTextArea.Caret.Offset, LineText.Length - colNo);

            int   offset = colNo;
            Match m      = null;

            do
            {
                m          = regularExpression.Match(LineText);
                matchIndex = m.Index;

                if (m.Success)
                {
                    if (!replaceAll)
                    {
                        ActiveTextArea.Caret.Column = 0;
                        ActiveTextArea.Caret.Line   = lineNo;

                        lineNo = ActiveTextArea.Caret.Line;

                        Point startPoint = ActiveTextArea.Caret.Position;
                        startPoint.X = m.Index + offset;
                        Point endPoint = startPoint;

                        endPoint.X = startPoint.X + m.Length;
                        ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);

                        DialogResult dlgRes = MessageBox.Show("Replace selected text?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dlgRes == DialogResult.Yes)
                        {
                            ActiveTextArea.Caret.Line   = lineNo;
                            ActiveTextArea.Caret.Column = startPoint.X;

                            ActiveDocument.Replace(ActiveTextArea.Caret.Offset, m.Length, replaceText);
                            endPoint.X = startPoint.X + replaceText.Length;
                            ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);

                            ActiveTextArea.Caret.Line   = lineNo;
                            ActiveTextArea.Caret.Column = endPoint.X;
                        }

                        ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);
                        ActiveTextArea.Caret.Column = endPoint.X;
                        matchExist = true;

                        break;
                    }
                    else
                    {
                        ActiveTextArea.Caret.Column = 0;
                        ActiveTextArea.Caret.Line   = lineNo;

                        do
                        {
                            Point startPoint = ActiveTextArea.Caret.Position;
                            startPoint.X = matchIndex + offset;
                            Point endPoint = startPoint;

                            endPoint.X = startPoint.X + m.Length;
                            ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);

                            if (!replaceAllConfirmed)
                            {
                                DialogResult dlgRes = MessageBox.Show("Replace all occurances ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (dlgRes == DialogResult.No)
                                {
                                    return;
                                }
                                replaceAllConfirmed = true;
                                matchExist          = true;
                            }
                            ActiveTextArea.Caret.Line   = lineNo;
                            ActiveTextArea.Caret.Column = startPoint.X;

                            ActiveDocument.Replace(ActiveTextArea.Caret.Offset, m.Length, replaceText);

                            endPoint.X = startPoint.X + replaceText.Length;
                            ActiveTextArea.SelectionManager.SetSelection(startPoint, endPoint);

                            ActiveTextArea.Caret.Line   = lineNo;
                            ActiveTextArea.Caret.Column = endPoint.X;

                            LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);
                            LineText = ActiveDocument.GetText(ActiveTextArea.Caret.Offset, LineText.Length - endPoint.X);

                            replaceCnt++;

                            m          = regularExpression.Match(LineText);
                            matchIndex = m.Index + endPoint.X;

                            LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);
                        }while (m.Success);
                    }
                }


                int tmpLineNo = ActiveDocument.GetNextVisibleLineAbove(lineNo, 1);
                if (tmpLineNo == lineNo)
                {
                    break;
                }
                lineNo   = tmpLineNo;
                LineText = SharpDevelopTextEditorUtilities.GetLineAsString(ActiveDocument, lineNo);
                offset   = 0;
            }while (lineNo < ActiveDocument.TotalNumberOfLines);

            if (replaceCnt > 0)
            {
                MessageBox.Show(replaceCnt.ToString() + " ocurrence(s) replaced.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (!matchExist)
            {
                MessageBox.Show("Nothing found to be replaced.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }