/// <summary>
        /// Respond to user clicks in references display.
        /// </summary>
        private void webBrowser_BeforeNavigate(object s, onlyconnect.BeforeNavigateEventArgs e)
        {
            string link = e.Target;

            // Deny that missing reference rendering is a problem
            if (link.StartsWith("userclick:deny"))
            {
                DenyReference(link.Substring(15), true);
                e.Cancel = true;
            }

            // Remove denial that missing reference is a problem
            else if (link.StartsWith("userclick:undeny"))
            {
                DenyReference(link.Substring(17), false);
                e.Cancel = true;
            }

            // Scroll the editor to this reference.
            else if (link.StartsWith("userclick:scripref"))
            {
                string thisRef = link.Substring(19).Replace('_', ' ');
                string strStoryName, strAnchor;
                int    nLineNumber;
                BiblicalTermsHTMLBuilder.ParseReference(thisRef, out strStoryName, out nLineNumber, out strAnchor);
                _theSE.NavigateTo(strStoryName, nLineNumber, strAnchor);
                e.Cancel = true;
            }
        }
Пример #2
0
        public void DoFindNext()
        {
            string strToSearchFor = UpdateComboBox(comboBoxFindWhat);

            if (String.IsNullOrEmpty(strToSearchFor))
            {
                MessageBox.Show(Properties.Resources.IDS_NoSearchString, Properties.Resources.IDS_Caption);
                return;
            }

            if (FindProperties.UseRegex)
            {
                regex = GetRegex(strToSearchFor);
            }
            else
            {
                regex = null;
            }

            int nLastStoryIndex, nLastCtxBoxIndex, nLastCharIndex;

            InitSearchList(ref BoxesToSearch, out nLastStoryIndex, out nLastCtxBoxIndex, out nLastCharIndex);

            CtrlTextBox ctbStopWhereWeStarted = null;
            int         nStoryIndex           = nLastStoryIndex;
            int         nCtxBoxIndex          = nLastCtxBoxIndex;

            while (nStoryIndex < BoxesToSearch.Count)
            {
                StringTransferSearchIndex stsi = BoxesToSearch[nStoryIndex];
                for (; nCtxBoxIndex < stsi.Count; nCtxBoxIndex++)
                {
                    StringTransfer stringTransfer = stsi[nCtxBoxIndex].StringTransfer;
                    if (!stringTransfer.HasData)
                    {
                        continue;
                    }

                    string strValue = stringTransfer.ToString();

                    // check to see if we're wrapped around and are starting
                    //  back at the beginning
                    // note: that it's possible that this stringTransfer
                    //  does not have a TextBox (e.g. if it isn't visible) OR
                    //  if its in the ConNotes panes (which are HTML thingys)
                    CtrlTextBox ctrlTextBox = stringTransfer.TextBox;

                    // get the index *after* the selected text (our starting index
                    //  of the search)
                    int nStartIndex = 0;
                    if (ctrlTextBox != null)
                    {
                        // if the length of the text in the text box is not the same
                        //  length as the text in the StringTransfer, then this
                        //  assumption is probably no good
                        System.Diagnostics.Debug.Assert(ctrlTextBox.TextLength == strValue.Length);

                        if (ctbStopWhereWeStarted == ctrlTextBox)
                        {
                            ShowNotFound();
                            return;
                        }

                        nStartIndex = nLastCharIndex;
                        if (nLastCharIndex != 0)
                        {
                            nLastCharIndex = 0;                             // only do that once
                            ctrlTextBox.Select(0, 0);                       // don't leave it selected
                        }
                    }

                    int nFoundIndex = -1, nLengthToSelect = 0;
                    if (regex != null)
                    {
                        Match match = regex.Match(strValue, nStartIndex);
                        if (match.Success)
                        {
                            nFoundIndex     = match.Index;
                            nLengthToSelect = match.Length;
                        }
                    }
                    else
                    {
                        nFoundIndex     = strValue.IndexOf(strToSearchFor, nStartIndex);
                        nLengthToSelect = strToSearchFor.Length;
                    }

                    if (nFoundIndex != -1)
                    {
                        // found a match!
                        VerseString vs = stsi[nCtxBoxIndex];
                        System.Diagnostics.Debug.Assert(vs.StringTransfer == stringTransfer);
                        TheSE.NavigateTo(stsi.StoryName,
                                         vs.ViewToInsureIsOn,
                                         false,
                                         stringTransfer.TextBox);

                        // The navigation process should make it visible as well.
                        if (stringTransfer.TextBox != null)
                        {
                            stringTransfer.TextBox.Select(nFoundIndex, nLengthToSelect);
                            LastCharIndex = CaptureNextStartingCharIndex(stringTransfer.TextBox);
                        }
                        else if (stringTransfer.HtmlConNoteCtrl != null)
                        {
                            stringTransfer.HtmlConNoteCtrl.SelectFoundText(stringTransfer.HtmlElementId, nFoundIndex,
                                                                           nLengthToSelect);
                            LastCharIndex = nFoundIndex + nLengthToSelect;
                        }

                        LastStoryIndex        = nStoryIndex;
                        LastCtxBoxIndex       = nCtxBoxIndex;
                        buttonReplace.Enabled = true;
                        return;
                    }
                }

                // if we've reached the end of the verses in *this* story...
                if (!FindProperties.SearchAll)
                {
                    // if we were already searching from the beginning...
                    if (nLastCtxBoxIndex == 0)
                    {
                        // ... then we couldn't find it
                        ShowNotFound();
                        return;
                    }

                    // otherwise, see if the user wants to start over from 0
                    if (MessageBox.Show(Properties.Resources.IDS_StartFromBeginning,
                                        Properties.Resources.IDS_Caption, MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                    {
                        nCtxBoxIndex = 0;

                        // have it stop where we started
                        ctbStopWhereWeStarted = CtrlTextBox._inTextBox ?? stsi[0].StringTransfer.TextBox;
                    }
                    else
                    {
                        return;                         // user said *don't* start over
                    }
                }

                // otherwise, we're supposed to search the next story as well.
                else
                {
                    nStoryIndex++;
                    nCtxBoxIndex = 0;
                }
            }

            // if we reach here, it's because we were searching all the stories
            //  and we reached the end and couldn't find it
            // if we were already searching from the beginning...
            if ((nLastStoryIndex == 0) && (nLastCtxBoxIndex == 0))
            {
                // ... then we couldn't find it
                ShowNotFound();
                return;
            }

            // otherwise, see if the user wants to start over from 0.0
            if (MessageBox.Show(Properties.Resources.IDS_StartFromBeginning,
                                Properties.Resources.IDS_Caption, MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {
                LastStoryIndex = LastCtxBoxIndex = LastCharIndex = 0;
                DoFindNext();
            }
        }