예제 #1
0
        private void GotoLine()
        {
            frmFind i_Goto = new frmFind(TotalLines, new FindParam(), null);
            if (i_Goto.ShowDialog() != DialogResult.OK)
                return;

            int s32_Pos = GetLineIndex(i_Goto.LineNumber);
            if (s32_Pos < 0)
                return;

            SetSelection(s32_Pos, 0);
        }
예제 #2
0
        /// <summary>
        /// b_OpenForm  = true  --> Open the search window (frmFind)
        /// b_Reverse   = true  --> search reverse
        /// b_Increment = false --> search from the current cursor position
        /// b_Increment = true  --> search from the current cursor position + 1
        /// returns the text to be displayed in the status bar
        /// </summary>
        private string FindReplace(bool b_OpenForm, bool b_Reverse, bool b_Increment)
        {
            if (b_OpenForm)
            {
                if (SelectedText.Length > 0) mi_FindParam.s_Find = SelectedText;
                mi_FindParam.b_Replace = !this.ReadOnly; // disable Replace

                frmFind i_Find = new frmFind(0, mi_FindParam, new FindCallback(OnFindCallback));

                i_Find.ShowDialog(this.TopLevelControl);
                return "";
            }

            bool b_Replaced = false;
            int  s32_Start  = SelectionStart;

            if (b_Increment)
            {
                if (b_Reverse) s32_Start --;
                else           s32_Start ++;
            }

            for (int s32_Loops=0; s32_Loops<=2; s32_Loops++)
            {
                s32_Start = Functions.Find(Text, mi_FindParam.s_Find, s32_Start, b_Reverse, mi_FindParam.b_WholeWord);

                if (s32_Start < 0) // not found
                {
                    // loop back to the begin / end of the text
                    if (b_Reverse) s32_Start = Text.Length-1;
                    else           s32_Start = 0;
                    continue;
                }

                int s32_SelBefore = SelectionStart;
                int s32_LenBefore = SelectionLength;

                SetSelection(s32_Start, mi_FindParam.s_Find.Length); // found

                if (!mi_FindParam.b_Replace)
                    return ""; // Find

                if (b_Replaced)
                    return ""; // replace only once

                if (s32_Start != s32_SelBefore || mi_FindParam.s_Find.Length != s32_LenBefore)
                    return ""; // replace only if text to be replaced was already selected

                SelectedText = mi_FindParam.s_Replace;
                b_Replaced   = true;
                s32_Loops    = 0;
                s32_Start += mi_FindParam.s_Replace.Length;
                // don't return here -> search the next text match
            }

            SelectionLength = 0;

            WriteStatus("Not found !");
            return "Not found !";
        }