Пример #1
0
        /// <summary>
        /// Attempts to update the suggestion form with the currently entered string
        /// </summary>
        void    UpdateSuggestionForm()
        {
            if (m_selectedTag == null)
            {
                m_suggestionForm.Visible = false;
                return;
            }

            // Retrieve the currently unrecognized tag for the character we just typed
            m_firstUnRecognizedTag = null;
            m_lastUnRecognizedTag  = m_selectedTag.FirstUnRecognized;
            if (m_lastUnRecognizedTag == null)
            {
                m_suggestionForm.Visible = false;
                return;
            }

            string unRecognizedTagName = null;

            do
            {
                m_firstUnRecognizedTag = m_lastUnRecognizedTag;
                m_lastUnRecognizedTag  = m_firstUnRecognizedTag.CollateUnRecognizedTags(out unRecognizedTagName);
            } while (!m_firstUnRecognizedTag.ContainsTag(m_lastUnRecognizedTag, m_selectedTag));

            m_matches.Clear();
            if (unRecognizedTagName != null)
            {
                // Handle auto-completion
                m_applicationForm.Database.FindNearestTagMatches(unRecognizedTagName, RecognizedTags, m_matches);
                if (m_matches.Count > 0)
                {
                    // Show potential matches
                    string[] matchStrings = new string[Math.Min(MAX_MATCHES, m_matches.Count)];
                    for (int matchIndex = 0; matchIndex < matchStrings.Length; matchIndex++)
                    {
                        matchStrings[matchIndex] = m_matches[matchIndex].Title;
                    }

                    m_suggestionForm.UpdateList(matchStrings, 10);
                }
            }

            if (!m_suggestionForm.Visible && m_matches.Count > 0)
            {
                m_suggestionForm.Show(this);
                this.Focus();                   // We must keep the focus!
            }
            m_suggestionForm.Visible = m_matches.Count > 0;
        }