OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" | 5 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 prefs->RegisterDictionaryPref(prefs::kKeywordEditorWindowPlacement); | 32 prefs->RegisterDictionaryPref(prefs::kKeywordEditorWindowPlacement); |
33 } | 33 } |
34 | 34 |
35 int KeywordEditorController::AddTemplateURL(const string16& title, | 35 int KeywordEditorController::AddTemplateURL(const string16& title, |
36 const string16& keyword, | 36 const string16& keyword, |
37 const std::string& url) { | 37 const std::string& url) { |
38 DCHECK(!url.empty()); | 38 DCHECK(!url.empty()); |
39 | 39 |
40 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword")); | 40 content::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword")); |
41 | 41 |
42 TemplateURL* template_url = new TemplateURL(); | |
43 template_url->set_short_name(title); | |
44 template_url->set_keyword(keyword); | |
45 template_url->SetURL(url, 0, 0); | |
46 | |
47 // There's a bug (1090726) in TableView with groups enabled such that newly | 42 // There's a bug (1090726) in TableView with groups enabled such that newly |
48 // added items in groups ALWAYS appear at the end, regardless of the index | 43 // added items in groups ALWAYS appear at the end, regardless of the index |
49 // passed in. Worse yet, the selected rows get messed up when this happens | 44 // passed in. Worse yet, the selected rows get messed up when this happens |
50 // causing other problems. As a work around we always add the item to the end | 45 // causing other problems. As a work around we always add the item to the end |
51 // of the list. | 46 // of the list. |
52 const int new_index = table_model_->RowCount(); | 47 const int new_index = table_model_->RowCount(); |
53 table_model_->Add(new_index, template_url); | 48 table_model_->Add(new_index, title, keyword, url); |
54 | 49 |
55 return new_index; | 50 return new_index; |
56 } | 51 } |
57 | 52 |
58 void KeywordEditorController::ModifyTemplateURL(const TemplateURL* template_url, | 53 void KeywordEditorController::ModifyTemplateURL(const TemplateURL* template_url, |
59 const string16& title, | 54 const string16& title, |
60 const string16& keyword, | 55 const string16& keyword, |
61 const std::string& url) { | 56 const std::string& url) { |
62 const int index = table_model_->IndexOfTemplateURL(template_url); | 57 const int index = table_model_->IndexOfTemplateURL(template_url); |
63 if (index == -1) { | 58 if (index == -1) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 return url_model()->loaded(); | 100 return url_model()->loaded(); |
106 } | 101 } |
107 | 102 |
108 const TemplateURL* KeywordEditorController::GetTemplateURL(int index) const { | 103 const TemplateURL* KeywordEditorController::GetTemplateURL(int index) const { |
109 return table_model_->GetTemplateURL(index); | 104 return table_model_->GetTemplateURL(index); |
110 } | 105 } |
111 | 106 |
112 TemplateURLService* KeywordEditorController::url_model() const { | 107 TemplateURLService* KeywordEditorController::url_model() const { |
113 return table_model_->template_url_service(); | 108 return table_model_->template_url_service(); |
114 } | 109 } |
OLD | NEW |