Esempio n. 1
0
 public bool Replace(bool exec_goto_action = true)
 {
     UpdateLastWordsList(this.tbTextToReplace);
     if (!findSuccess)
     {
         FindNext(exec_goto_action);
     }
     if (findSuccess)
     {
         /*Form1.CurrentSyntaxEditor.TextEditor.Document.Remove(resOffset, resLength);
          * Form1.CurrentSyntaxEditor.TextEditor.Document.Insert(resOffset, tbTextToReplace.Text);*/
         Form1.CurrentSyntaxEditor.TextEditor.Document.Replace(resOffset, resLength, tbTextToReplace.Text);
         resLength = tbTextToReplace.Text.Length;
         //Point p = Form1.CurrentSyntaxEditor.TextEditor.Document.OffsetToPosition(resOffset);
         if (exec_goto_action)
         {
             ICSharpCode.TextEditor.TextLocation p = Form1.CurrentSyntaxEditor.TextEditor.Document.OffsetToPosition(resOffset);
             Form1.ExecuteSourceLocationAction(new PascalABCCompiler.SourceLocation(null, p.Y + 1, p.X + 1, p.Y + 1, p.X + resLength), VisualPascalABCPlugins.SourceLocationAction.SelectAndGotoEnd);
         }
         else
         {
             startOffset = resOffset + resLength;
         }
         resOffset   = -1;
         findSuccess = false;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 2
0
        private void btOk_Click(object sender, EventArgs e)
        {
            int line;

            if (int.TryParse(tbLineNumber.Text, out line))
            {
                if (line <= MainForm.CurrentSyntaxEditor.LinesCount)
                {
                    Close();
                    MainForm.ExecuteSourceLocationAction(new PascalABCCompiler.SourceLocation(MainForm.CurrentSourceFileName, line, 1, line, 1), VisualPascalABCPlugins.SourceLocationAction.GotoBeg);
                    return;
                }
            }
            this.ActiveControl = tbLineNumber;
        }
Esempio n. 3
0
        public bool FindNext(bool exec_goto_action = true)
        {
            Form1 = (Form1)this.Owner;
            UpdateLastWordsList(this.tbTextToFind);
            if (exec_goto_action)
            {
                startOffset = Form1.CurrentSyntaxEditor.TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
            }
            if (cbSearchUp.Checked && resLength >= 0)
            {
                startOffset -= resLength;
            }
            resOffset = -1;
            //resLength = -1;
            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.None;
            if (!cbMathCase.Checked)
            {
                options = options | System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            }
            if (cbSearchUp.Checked)
            {
                options = options | System.Text.RegularExpressions.RegexOptions.RightToLeft;
            }
            string pattern = this.tbTextToFind.Text;

            if (pattern == "")
            {
                findSuccess = false;
                return(findSuccess);
            }
            if (!cbUseRegex.Checked)
            {
                pattern = System.Text.RegularExpressions.Regex.Escape(pattern);
            }
            if (cbMathWord.Checked)
            {
                pattern = @"\b" + pattern + @"\b";
            }
            System.Text.RegularExpressions.Regex Regex;
            try
            {
                Regex = new System.Text.RegularExpressions.Regex(pattern, options);
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format(PascalABCCompiler.StringResources.Get("VP_REPLACEFORM_REGEXPERR{0}"), e.Message), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                findSuccess = false;
                return(findSuccess);
            }
            if (cbSearchUp.Checked)
            {
                Match = Regex.Match(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, 0, startOffset);
            }
            else
            {
                Match = Regex.Match(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, startOffset);
            }

            if (findSuccess = Match.Success)
            {
                resOffset = Match.Index;
                resLength = Match.Length;
                //Point p = Form1.CurrentSyntaxEditor.TextEditor.Document.OffsetToPosition(resOffset);
                if (exec_goto_action)
                {
                    ICSharpCode.TextEditor.TextLocation p = Form1.CurrentSyntaxEditor.TextEditor.Document.OffsetToPosition(resOffset);
                    Form1.ExecuteSourceLocationAction(new PascalABCCompiler.SourceLocation(null, p.Y + 1, p.X + 1, p.Y + 1, p.X + resLength), VisualPascalABCPlugins.SourceLocationAction.FindSelection);
                }
                else
                {
                    startOffset = resOffset + resLength;
                }
            }
            return(findSuccess);
        }
Esempio n. 4
0
 public bool FindNext(bool exec_goto_action=true)
 {
     Form1 = (Form1)this.Owner;
     UpdateLastWordsList(this.tbTextToFind);
     if (exec_goto_action)
         startOffset = Form1.CurrentSyntaxEditor.TextEditor.ActiveTextAreaControl.TextArea.Caret.Offset;
     if (cbSearchUp.Checked && resLength >= 0)
         startOffset -= resLength;
     resOffset = -1;
     //resLength = -1;
     System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.None;
     if (!cbMathCase.Checked)
         options = options | System.Text.RegularExpressions.RegexOptions.IgnoreCase;
     if (cbSearchUp.Checked)
         options = options | System.Text.RegularExpressions.RegexOptions.RightToLeft;
     string pattern = this.tbTextToFind.Text;
     if (pattern == "")
     {
         findSuccess = false;
         return findSuccess;
     }
     if (!cbUseRegex.Checked)
         pattern = System.Text.RegularExpressions.Regex.Escape(pattern);
     if (cbMathWord.Checked)
         pattern = @"\b" + pattern + @"\b";
     System.Text.RegularExpressions.Regex Regex;
     try
     {
         Regex = new System.Text.RegularExpressions.Regex(pattern, options);
     }
     catch (Exception e)
     {
         MessageBox.Show(string.Format(PascalABCCompiler.StringResources.Get("VP_REPLACEFORM_REGEXPERR{0}"),e.Message), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
         findSuccess = false;
         return findSuccess;
     }
     if (cbSearchUp.Checked)
         Match = Regex.Match(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, 0, startOffset);
     else
         Match = Regex.Match(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, startOffset);
     
     if (findSuccess = Match.Success)
     {
         resOffset = Match.Index;
         resLength = Match.Length;
         //Point p = Form1.CurrentSyntaxEditor.TextEditor.Document.OffsetToPosition(resOffset);
         if (exec_goto_action)
         {
             ICSharpCode.TextEditor.TextLocation p = Form1.CurrentSyntaxEditor.TextEditor.Document.OffsetToPosition(resOffset);
             Form1.ExecuteSourceLocationAction(new PascalABCCompiler.SourceLocation(null, p.Y + 1, p.X + 1, p.Y + 1, p.X + resLength), VisualPascalABCPlugins.SourceLocationAction.FindSelection);
         }
         else
             startOffset = resOffset + resLength;
     }
     return findSuccess;
 }