Example #1
0
        private void MoveCaretToDocumentEnd(TextEditorBase documentTextEditor)
        {
            documentTextEditor.SelectionStart  = 0;
            documentTextEditor.SelectionLength = 0;

            documentTextEditor.CaretOffset = documentTextEditor.Document.TextLength;
        }
Example #2
0
        private bool Find(FindingOrder order)
        {
            if (string.IsNullOrWhiteSpace(textBox_Find.Text))
            {
                ShowError("Invalid input.");
                return(false);
            }

            TextEditorBase currentTabTextEditor = GetTextEditorOfTab(_editorTabControl.SelectedTab);
            string         pattern = GetCurrentPattern();
            RegexOptions   options = GetCurrentRegexOptions();

            if (Regex.Matches(currentTabTextEditor.Text, pattern, options).Count == 0)             // If no matches were found in the current document
            {
                if (radioButton_Current.Checked)
                {
                    ShowError("No matches found in the current document.");                     // Search cancelled
                }
                else if (radioButton_AllTabs.Checked)
                {
                    FindMatchInAnotherTab(order, pattern, options);
                }
            }
            else             // Matches were found in the current document
            {
                return(FindMatch(order, currentTabTextEditor, pattern, options));
            }

            return(false);
        }
Example #3
0
        private DarkTreeNode GetNodeForAllTabMatches(TabPage tab, string pattern, RegexOptions options)
        {
            TextEditorBase  tabTextEditor           = GetTextEditorOfTab(tab);
            MatchCollection documentMatchCollection = Regex.Matches(tabTextEditor.Text, pattern, options);

            if (documentMatchCollection.Count == 0)
            {
                return(null);
            }

            DarkTreeNode fileNode = new DarkTreeNode(tab.Text + " (Matches: " + documentMatchCollection.Count + ")");

            foreach (Match match in documentMatchCollection)
            {
                DocumentLine line     = tabTextEditor.Document.GetLineByOffset(match.Index);
                string       lineText = tabTextEditor.Document.GetText(line.Offset, line.Length);

                fileNode.Nodes.Add(new DarkTreeNode
                {
                    Text = "(" + line.LineNumber + ") " + lineText,
                    Tag  = match
                });
            }

            fileNode.Expanded = true;

            return(fileNode);
        }
Example #4
0
        private void SelectMatch(FindingOrder order, TextEditorBase textEditor, MatchCollection sectionMatchCollection)
        {
            switch (order)
            {
            case FindingOrder.Prev:
            {
                // Get the last match of that section, since we're going upwards
                Match lastMatch = sectionMatchCollection[sectionMatchCollection.Count - 1];

                textEditor.Select(lastMatch.Index, lastMatch.Length);                         // Select the match
                break;
            }

            case FindingOrder.Next:
            {
                // Get the first match of that section, since we're going downwards
                Match firstMatch = sectionMatchCollection[0];

                int    selectionEnd       = textEditor.SelectionStart + textEditor.SelectionLength;
                string textAfterSelection = GetTextAfterSelection(textEditor.Text, selectionEnd);
                int    cutStringLength    = textEditor.Document.TextLength - textAfterSelection.Length;

                textEditor.Select(cutStringLength + firstMatch.Index, firstMatch.Length);                         // Select the match
                break;
            }
            }

            textEditor.ScrollTo(textEditor.TextArea.Caret.Position.Line, textEditor.TextArea.Caret.Position.Column);
        }
Example #5
0
        private bool FindMatch(FindingOrder order, TextEditorBase textEditor, string pattern, RegexOptions options)
        {
            MatchCollection sectionMatchCollection = GetMatchCollectionFromSection(order, textEditor, pattern, options);

            if (sectionMatchCollection.Count == 0)             // If no matches were found in that section of the document
            {
                if (radioButton_Current.Checked)
                {
                    EndSuccessfulSearch(order, textEditor);
                }
                else if (radioButton_AllTabs.Checked)
                {
                    FindMatchInAnotherTab(order, pattern, options);
                }
            }
            else             // Matches were found in that section of the document
            {
                SelectMatch(order, textEditor, sectionMatchCollection);

                UpdateStatusLabel(textEditor.Text, pattern, options);
                return(true);
            }

            return(false);
        }
Example #6
0
        private void EndSuccessfulSearch(FindingOrder order, TextEditorBase textEditor)
        {
            switch (order)
            {
            case FindingOrder.Prev:
                MoveCaretToDocumentStart(textEditor);
                ShowWarning("Reached the start of the document with no more matches found.");                         // Search ends here
                break;

            case FindingOrder.Next:
                MoveCaretToDocumentEnd(textEditor);
                ShowWarning("Reached the end of the document with no more matches found.");                         // Search ends here
                break;
            }
        }
Example #7
0
        private void ReplaceMatch()
        {
            TextEditorBase currentTextEditor = GetTextEditorOfTab(_editorTabControl.SelectedTab);

            if (radioButton_Normal.Checked)
            {
                currentTextEditor.SelectedText = textBox_Replace.Text;
            }
            else if (radioButton_Regex.Checked)
            {
                string       pattern = GetCurrentPattern();
                RegexOptions options = GetCurrentRegexOptions();

                currentTextEditor.SelectedText = AdvancedRegexReplace(currentTextEditor.SelectedText, pattern, textBox_Replace.Text, options);
            }
        }
Example #8
0
        private MatchCollection GetMatchCollectionFromSection(FindingOrder order, TextEditorBase textEditor, string pattern, RegexOptions options)
        {
            switch (order)
            {
            case FindingOrder.Prev:
                string textBeforeSelection = GetTextBeforeSelection(textEditor.Text, textEditor.SelectionStart);
                return(Regex.Matches(textBeforeSelection, pattern, options));

            case FindingOrder.Next:
                int    selectionEnd       = textEditor.SelectionStart + textEditor.SelectionLength;
                string textAfterSelection = GetTextAfterSelection(textEditor.Text, selectionEnd);
                return(Regex.Matches(textAfterSelection, pattern, options));
            }

            return(null);
        }
Example #9
0
        private void FindNextInNextTab()
        {
            if (_editorTabControl.SelectedIndex == _editorTabControl.TabCount - 1)
            {
                MoveCaretToDocumentEnd(GetTextEditorOfTab(_editorTabControl.SelectedTab));
                ShowWarning("Reached the end of the last tab document with no more matches found.");                 // Search ends here
            }
            else
            {
                _editorTabControl.SelectedIndex++;

                TextEditorBase nextTarget = GetTextEditorOfTab(_editorTabControl.SelectedTab);                 // The tab has changed, therefore we can get the current tab's TextEditor
                MoveCaretToDocumentStart(nextTarget);

                Find(FindingOrder.Next);
            }
        }
Example #10
0
        private void FindPrevInPrevTab()
        {
            if (_editorTabControl.SelectedIndex == 0)
            {
                MoveCaretToDocumentStart(GetTextEditorOfTab(_editorTabControl.SelectedTab));
                ShowWarning("Reached the start of the first tab document with no more matches found.");                 // Search ends here
            }
            else
            {
                _editorTabControl.SelectedIndex--;

                TextEditorBase nextTarget = GetTextEditorOfTab(_editorTabControl.SelectedTab);                 // The tab has changed, therefore we can get the current tab's TextEditor
                MoveCaretToDocumentEnd(nextTarget);

                Find(FindingOrder.Prev);
            }
        }
Example #11
0
 protected override void OnInit(System.EventArgs e)
 {
     base.OnInit(e);
     _Editor = (TextEditorBase)ModuleController.LoadDefaultEditor(this.Page);
     this.phEditor.Controls.Add(_Editor);
 }
Example #12
0
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     _Editor = (TextEditorBase)HccPartController.LoadDefaultEditor(Page);
     phEditor.Controls.Add(_Editor);
 }
Example #13
0
        private void ReplaceAll()         // TODO: Refactor
        {
            if (string.IsNullOrWhiteSpace(textBox_Find.Text))
            {
                ShowError("Invalid input.");
                return;
            }

            string       pattern = GetCurrentPattern();
            RegexOptions options = GetCurrentRegexOptions();

            int matchCount = 0;

            if (radioButton_Current.Checked)
            {
                TextEditorBase currentTabTextEditor = GetTextEditorOfTab(_editorTabControl.SelectedTab);
                matchCount = Regex.Matches(currentTabTextEditor.Text, pattern, options).Count;

                if (matchCount > 0)
                {
                    currentTabTextEditor.SelectAll();
                    currentTabTextEditor.SelectedText = AdvancedRegexReplace(currentTabTextEditor.Text, pattern, textBox_Replace.Text, options);
                    MoveCaretToDocumentStart(currentTabTextEditor);
                }
            }
            else if (radioButton_AllTabs.Checked)
            {
                matchCount = GetAllTabsMatchCount(pattern, options);

                if (matchCount > 0)
                {
                    DialogResult result = DarkMessageBox.Show(this,
                                                              "Are you sure you want to replace all matching items across all tabs?", "Are you sure?",
                                                              MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        foreach (TabPage tab in _editorTabControl.TabPages)
                        {
                            TextEditorBase tabTextEditor = GetTextEditorOfTab(tab);

                            tabTextEditor.SelectAll();
                            tabTextEditor.SelectedText = AdvancedRegexReplace(tabTextEditor.Text, pattern, textBox_Replace.Text, options);
                            MoveCaretToDocumentStart(tabTextEditor);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (matchCount == 0)
            {
                ShowError("No matches found.");
            }
            else
            {
                ShowStatusInfo("Replaced " + matchCount + " matches.");
            }
        }
Example #14
0
 public ErrorRenderer(TextEditorBase e)
 {
     _editor = e;
 }
Example #15
0
 public BookmarkRenderer(TextEditorBase e)
 {
     _editor = e;
 }