public void Search(TextBox searchInput, TextBox strokeInput, ListBox resultOutput, TextBox outputMessage, TextBox outputReading, TextBox outputMeaning)
        {
            // Searching for an empty string should move the cursor back to the result output list if it's not empty.
            if (searchInput.Text == "")
            {
                if (resultOutput.Items.Count > 0)
                {
                    resultOutput.Focus();
                    SelectionInfoHandler.ShowKanjiSelectionInfo(resultOutput.Text, outputMessage, outputReading, outputMeaning);
                    return;
                }
                else
                {
                    return;
                }
            }

            int strokes = -1;

            if (strokeInput.Text != "")
            {
                strokes = System.Int32.Parse(strokeInput.Text);
            }

            if (!_kanjiSearchCache.IsCached(searchInput.Text + ";" + strokeInput.Text))
            {
                List <KanjiData> filteredResultKanji
                    = FilterByStrokes(BuildKanjiDataList(_kanjiSearch.Search(searchInput.Text)), strokes);

                if (filteredResultKanji.Count > 0)
                {
                    _kanjiSearchCache.CacheSearchCriteria(searchInput.Text + ";" + strokeInput.Text);
                    filteredResultKanji.Sort();
                    resultOutput.Items.Clear();
                    resultOutput.Items.AddRange(filteredResultKanji.ToArray());
                    resultOutput.Focus();
                    resultOutput.SelectedIndex = 0;
                    SelectionInfoHandler.ShowKanjiSelectionInfo(resultOutput.Text, outputMessage, outputReading, outputMeaning);
                }
                else
                {
                    outputMessage.Text = "No matching kanji.";
                    // Don't need to change the last focus or last search set here. The results aren't getting cleared or changed.
                    searchInput.Focus();
                }
            }
            else
            {
                resultOutput.Focus();
                SelectionInfoHandler.ShowKanjiSelectionInfo(resultOutput.Text, outputMessage, outputReading, outputMeaning);
            }
        }
Beispiel #2
0
        public void Search(TextBox searchCriteria, ListBox resultOutput, TextBox outputMessage, TextBox outputReading)
        {
            // Update Japanese punctuation and malformed wildcards to appropriate values.
            TextConverter.ConvertPunctuation(searchCriteria);

            // Do kana or radical conversion.
            // If only romaji were entered, this should just do a straight kana conversion anyway, so
            // no need to do the special checks to see if only romaji were present.
            TextConverter.ConvertToRadicalOrKana(searchCriteria);

            // Find the matches.
            if (!_compoundSearchCache.IsCached(searchCriteria.Text))
            {
                // Cache the search string so that the system doesn't search again if the input criteria hasn't changed.
                _compoundSearchCache.CacheSearchCriteria(searchCriteria.Text);

                // Perform the actual search.
                List <Compound> matchResults = _compoundSearch.Search(searchCriteria.Text);

                if (matchResults.Count() > 0)
                {
                    // Don't update this until we get results -- this should really store the last GOOD string.
                    matchResults.Sort();
                    MoveExactMatchToFront(matchResults, searchCriteria.Text);
                    resultOutput.Items.Clear();
                    resultOutput.Items.AddRange(matchResults.ToArray());
                    resultOutput.Focus();
                    resultOutput.SelectedIndex = 0;
                    SelectionInfoHandler.ShowCompoundSelectionInfo((Compound)resultOutput.SelectedItem, outputMessage, outputReading);

                    // Add the search string to history.
                    // Doing this here to stop adding the same search string multiple times/remove failed searches.
                    _compoundSearchHistory.AddHistory(searchCriteria.Text);
                }
                else
                {
                    outputMessage.Text = "No matching compounds.";
                }
            }
            else
            {
                // Don't change focus if the box is blank.
                if (resultOutput.Items.Count > 0)
                {
                    resultOutput.Focus();
                    outputMessage.Text = "";
                }
            }
        }