diff options
author | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 20:11:36 +0000 |
---|---|---|
committer | sidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 20:11:36 +0000 |
commit | 1efeafb447ba7ac799a2235b13a305fa03b2b8a3 (patch) | |
tree | 7ced20e0d56011fae6016d7b6b7bd5bbf00b84d6 /chrome/browser/views | |
parent | 0e1e30e2f72e301d808a841128cb14e936748b95 (diff) | |
download | chromium_src-1efeafb447ba7ac799a2235b13a305fa03b2b8a3.zip chromium_src-1efeafb447ba7ac799a2235b13a305fa03b2b8a3.tar.gz chromium_src-1efeafb447ba7ac799a2235b13a305fa03b2b8a3.tar.bz2 |
Fix the bug: Scrolling the Spell-checker drop-down box adds the languages scrolled. Basically, when a spell check language changes, it is added to the accept languages list so that it is remembered later. However, when the list gets scrolled, it keeps adding all the languages it scrolled. So, I decided to fix this by adding only the latest language selected as the spell check dictionary language in the drop down.
Issue=8374
Review URL: http://codereview.chromium.org/40145
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/options/languages_page_view.cc | 45 | ||||
-rw-r--r-- | chrome/browser/views/options/languages_page_view.h | 1 |
2 files changed, 44 insertions, 2 deletions
diff --git a/chrome/browser/views/options/languages_page_view.cc b/chrome/browser/views/options/languages_page_view.cc index 945c37d0..5f9a5b8 100644 --- a/chrome/browser/views/options/languages_page_view.cc +++ b/chrome/browser/views/options/languages_page_view.cc @@ -323,6 +323,10 @@ class LanguageOrderTableModel : public views::TableModel { // Removes the entry at the specified index. void Remove(int index); + // Returns index corresponding to a given language. Returns -1 if the + // language is not found. + int GetIndex(const std::wstring& language); + // Move down the entry at the specified index. void MoveDown(int index); @@ -398,6 +402,22 @@ void LanguageOrderTableModel::Remove(int index) { observer_->OnItemsRemoved(index, 1); } +int LanguageOrderTableModel::GetIndex(const std::wstring& language) { + if (language.empty()) + return -1; + + int index = 0; + for (std::vector<std::wstring>::const_iterator cit = languages_.begin(); + cit != languages_.end(); ++cit) { + if (*cit == language) + return index; + + index++; + } + + return -1; +} + void LanguageOrderTableModel::MoveDown(int index) { if (index < 0 || index >= RowCount() - 1) return; @@ -730,9 +750,30 @@ void LanguagesPageView::ItemChanged(views::ComboBox* sender, language_warning_shown_ = true; } } else if (sender == change_dictionary_language_combobox_) { + // Set the spellcheck language selected. spellcheck_language_index_selected_ = new_index; - OnAddLanguage(dictionary_language_model_->GetLocaleFromIndex(new_index)); - language_table_edited_ = true; + + // Remove the previously added spell check language to the accept list. + if (!spellcheck_language_added_.empty()) { + int old_index = language_order_table_model_->GetIndex( + spellcheck_language_added_); + if (old_index > -1) + language_order_table_model_->Remove(old_index); + } + + // Add this new spell check language only if it is not already in the + // accept language list. + std::wstring language = + dictionary_language_model_->GetLocaleFromIndex(new_index); + int index = language_order_table_model_->GetIndex(language); + if (index == -1) { + // Add the new language. + OnAddLanguage(language); + language_table_edited_ = true; + spellcheck_language_added_ = language; + } else { + spellcheck_language_added_ = L""; + } } } diff --git a/chrome/browser/views/options/languages_page_view.h b/chrome/browser/views/options/languages_page_view.h index e79a4ab..3a7b104 100644 --- a/chrome/browser/views/options/languages_page_view.h +++ b/chrome/browser/views/options/languages_page_view.h @@ -100,6 +100,7 @@ class LanguagesPageView : public OptionsPageView, // This is assigned the new index of spellcheck language if the language // is changed. Otherwise, it remains -1, and pref members are not updated. int spellcheck_language_index_selected_; + std::wstring spellcheck_language_added_; bool language_table_edited_; bool language_warning_shown_; |