Exemplo n.º 1
0
        internal static void InsertTag(Form1 form, String tag, TagType type, TagExtension extension, String customTypeBegin = null, String customTypeEnd = null)
        {
            XtraTabControl    pagesTabControl = form.pagesTabControl;
            CustomRichTextBox pageTextBox     = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            switch (type)
            {
            case TagType.XHTML:
                customTypeBegin = "<";
                customTypeEnd   = ">";
                break;

            case TagType.Forum:
                customTypeBegin = "[";
                customTypeEnd   = "]";
                break;
            }

            if (String.IsNullOrEmpty(customTypeBegin) || String.IsNullOrEmpty(customTypeEnd))
            {
                throw new ParameterException(LanguageUtil.GetCurrentLanguageString("TagTypeEmpty", className));
            }

            String newSelection;
            int    selectionStart = pageTextBox.SelectionStart;
            int    insertionLength;

            switch (extension)
            {
            case TagExtension.Complete:
                newSelection    = customTypeBegin + tag + customTypeEnd + pageTextBox.SelectedText + customTypeBegin + "/" + tag + customTypeEnd;
                insertionLength = newSelection.Length;

                pageTextBox.SelectedText = newSelection;
                pageTextBox.Select(selectionStart, insertionLength);
                break;

            case TagExtension.Short:
                newSelection    = pageTextBox.SelectedText + customTypeBegin + tag + " /" + customTypeEnd;
                insertionLength = newSelection.Length;

                pageTextBox.SelectedText = newSelection;
                pageTextBox.Select(selectionStart, insertionLength);
                break;
            }

            TextManager.RefreshUndoRedoExternal(form);
        }
Exemplo n.º 2
0
        internal static void GoToLine(Form1 form, int row)
        {
            ToolStripStatusLabel rowToolStripStatusLabel1 = form.rowToolStripStatusLabel1;
            CustomRichTextBox    pageTextBox = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);

            pageTextBox.Select(TextManager.ReadRTBFirstCharIndexFromLine(form, row - 1), 0);
            rowToolStripStatusLabel1.Text = row.ToString();
        }
Exemplo n.º 3
0
        private static bool ReplaceAllInOneFile(Form1 form, bool searchInAllFiles)
        {
            CustomRichTextBox    textBox                       = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);
            TextBox              searchTextBox                 = form.searchPanel.searchTextBox;
            TextBox              replaceTextBox                = form.searchPanel.replaceTextBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CheckBox             caseCheckBox                  = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            FileListManager.SetNewSearchHistory(form, searchTextBox.Text);

            String textWhereToSearch;
            String textToSearch;

            GetTextCaseNormalization(form, out textWhereToSearch, out textToSearch);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(textWhereToSearch, textToSearch, SearchReplaceUtil.SearchType.First, useRegularExpressionsCheckBox.Checked, textBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int counter = SearchReplaceUtil.SearchCountOccurency(form, false, true);
                textBox.SelectAll();

                if (caseCheckBox.Checked)
                {
                    textBox.SelectedText = Replace(useRegularExpressionsCheckBox.Checked, textBox.Text, GetTextNewLineNormalization(searchTextBox.Text), GetTextNewLineNormalization(replaceTextBox.Text), StringComparison.Ordinal);
                }
                else
                {
                    textBox.SelectedText = Replace(useRegularExpressionsCheckBox.Checked, textBox.Text, GetTextNewLineNormalization(searchTextBox.Text), GetTextNewLineNormalization(replaceTextBox.Text), StringComparison.OrdinalIgnoreCase);
                }

                TextManager.RefreshUndoRedoExternal(form);
                textBox.Select(0, 0);

                toolStripStatusLabel.Text = String.Format("{0} {1}", counter, LanguageUtil.GetCurrentLanguageString("Replaced", className, counter));

                return(true);
            }
            if (!searchInAllFiles)
            {
                String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                WindowManager.ShowInfoBox(form, notFoundMessage);
                toolStripStatusLabel.Text = notFoundMessage;
            }

            return(false);
        }
Exemplo n.º 4
0
        private void InitializeFile()
        {
            if (Session.TextFiles.Count == 0)
            {
                var file = new TextFile("Sans Titre 1");

                MainTabControl.TabPages.Add(file.SafeFileName);

                var tabPage = MainTabControl.TabPages[0];
                var rtb     = new CustomRichTextBox();
                tabPage.Controls.Add(rtb);
                rtb.Select();

                Session.TextFiles.Add(file);

                CurrentFile = file;
                CurrentRtb  = rtb;
            }
        }
Exemplo n.º 5
0
        private static void SearchPreviousInAllFiles(Form1 form)
        {
            XtraTabControl       pagesTabControl      = form.pagesTabControl;
            ToolStripStatusLabel toolStripStatusLabel = form.toolStripStatusLabel;

            int initialSelectedIndex = pagesTabControl.SelectedTabPageIndex;

            for (int i = initialSelectedIndex; i >= 0; i--)
            {
                pagesTabControl.SelectedTabPage = pagesTabControl.TabPages[i];
                if (i != initialSelectedIndex)
                {
                    CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
                    pageTextBox.Select(pageTextBox.Text.Length - 1, 0);
                }

                if (SearchPrevious(form, false, true))
                {
                    return;
                }
            }

            for (int i = pagesTabControl.TabPages.Count - 1; i > initialSelectedIndex; i--)
            {
                pagesTabControl.SelectedTabPage = pagesTabControl.TabPages[i];
                CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
                pageTextBox.SelectionStart  = pageTextBox.Text.Length - 1;
                pageTextBox.SelectionLength = 0;

                if (SearchPrevious(form, false, true))
                {
                    return;
                }
            }

            String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);

            WindowManager.ShowInfoBox(form, notFoundMessage);
            toolStripStatusLabel.Text = notFoundMessage;
        }
Exemplo n.º 6
0
        private static bool ReplacePrevious(Form1 form, bool loopAtEOF, bool searchInAllFiles)
        {
            XtraTabControl       pagesTabControl               = form.pagesTabControl;
            TextBox              searchTextBox                 = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox                  = form.searchPanel.caseCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            TextBox              replaceTextBox                = form.searchPanel.replaceTextBox;
            CustomRichTextBox    pageTextBox                   = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            String subString = textWhereToSearch.Substring(0, pageTextBox.SelectionStart);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(subString, textToSearch, SearchReplaceUtil.SearchType.Previous, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                toolStripStatusLabel.Text = String.Format("1 {0}", LanguageUtil.GetCurrentLanguageString("Replaced", className, 1));
                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.SelectedText = replaceTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);
                TextManager.RefreshUndoRedoExternal(form);

                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                if (SearchReplaceUtil.GetNoMatchesInFile(textWhereToSearch, textToSearch, useRegularExpressionsCheckBox.Checked))
                {
                    String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                    WindowManager.ShowInfoBox(form, notFoundMessage);
                    toolStripStatusLabel.Text = notFoundMessage;
                }
                else
                {
                    if (loopAtEOF)
                    {
                        pageTextBox.SelectionStart = pageTextBox.Text.Length - 1;
                        return(ReplacePrevious(form, false, false));
                    }

                    if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SOF", className)) == DialogResult.Yes)
                    {
                        pageTextBox.SelectionStart = pageTextBox.Text.Length - 1;
                        return(ReplacePrevious(form, false, false));
                    }
                }
            }

            return(valueFounded);
        }
Exemplo n.º 7
0
        private static bool SearchPrevious(Form1 form, bool loopAtEOF, bool searchInAllFiles)
        {
            XtraTabControl       pagesTabControl = form.pagesTabControl;
            TextBox              searchTextBox   = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox    = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CustomRichTextBox    pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            //int selectionLength = -1;
            //int positionSearchedText = -1;
            //if (useRegularExpressionsCheckBox.Checked == false)
            //{
            //    selectionLength = textToSearch.Length;
            //    positionSearchedText = subString.LastIndexOf(textToSearch);
            //}
            //else
            //{
            //    Match regexMatch = Regex.Match(subString, textToSearch, RegexOptions.RightToLeft);
            //    if (regexMatch.Success)
            //    {
            //        positionSearchedText = regexMatch.Index;
            //        selectionLength = regexMatch.Value.Length;
            //    }
            //}
            String subString = textWhereToSearch.Substring(0, pageTextBox.SelectionStart);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(subString, textToSearch, SearchReplaceUtil.SearchType.Previous, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int occurences = SearchReplaceUtil.SearchCountOccurency(form, searchInAllFiles);
                toolStripStatusLabel.Text = String.Format("{0} {1}", occurences, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurences));

                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                if (SearchReplaceUtil.GetNoMatchesInFile(textWhereToSearch, textToSearch, useRegularExpressionsCheckBox.Checked))
                {
                    String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                    WindowManager.ShowInfoBox(form, notFoundMessage);
                    toolStripStatusLabel.Text = notFoundMessage;
                }
                else
                {
                    if (loopAtEOF)
                    {
                        return(SearchLast(form, false));
                    }

                    if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SOF", className)) == DialogResult.Yes)
                    {
                        return(SearchLast(form, false));
                    }
                }
            }

            return(valueFounded);
        }
Exemplo n.º 8
0
        private static bool SearchFirst(Form1 form, bool searchInAllFiles, String specificTextToSearch = null)
        {
            XtraTabControl       pagesTabControl = form.pagesTabControl;
            TextBox              searchTextBox   = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox    = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CustomRichTextBox    pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text) && String.IsNullOrEmpty(specificTextToSearch))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = !String.IsNullOrEmpty(specificTextToSearch) ? specificTextToSearch : searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            //int positionSearchedText = -1;
            //int selectionLength = -1;
            //if (useRegularExpressionsCheckBox.Checked == false)
            //{
            //    positionSearchedText = textWhereToSearch.IndexOf(textToSearch);
            //    selectionLength = textToSearch.Length;
            //}
            //else
            //{
            //    Regex regex = new Regex(textToSearch);
            //    Match regexMatch = regex.Match(textWhereToSearch, 0);
            //    if (regexMatch.Success)
            //    {
            //        positionSearchedText = regexMatch.Index;
            //        selectionLength = regexMatch.Value.Length;
            //    }
            //}
            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(textWhereToSearch, textToSearch, SearchReplaceUtil.SearchType.First, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int occurences = SearchReplaceUtil.SearchCountOccurency(form, searchInAllFiles, false, specificTextToSearch);
                toolStripStatusLabel.Text = String.Format("{0} {1}", occurences, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurences));

                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                WindowManager.ShowInfoBox(form, notFoundMessage);
                toolStripStatusLabel.Text = notFoundMessage;
            }

            return(valueFounded);
        }