Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/gtk/options/content_exceptions_window_gtk.cc

Issue 2876034: Sorry, this is making the Heapcheck bot unhappy. http://build.chromium.org/b... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/gtk/options/content_exceptions_window_gtk.h" 5 #include "chrome/browser/gtk/options/content_exceptions_window_gtk.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 } 41 }
42 42
43 ContentExceptionsWindowGtk::~ContentExceptionsWindowGtk() { 43 ContentExceptionsWindowGtk::~ContentExceptionsWindowGtk() {
44 } 44 }
45 45
46 ContentExceptionsWindowGtk::ContentExceptionsWindowGtk( 46 ContentExceptionsWindowGtk::ContentExceptionsWindowGtk(
47 GtkWindow* parent, 47 GtkWindow* parent,
48 HostContentSettingsMap* map, 48 HostContentSettingsMap* map,
49 ContentSettingsType type) { 49 ContentSettingsType type) {
50 // Build the list backing that GTK uses, along with an adapter which will 50 // Build the model adapters that translate views and TableModels into
51 // sort stuff without changing the underlying backing store. 51 // something GTK can use.
52 list_store_ = gtk_list_store_new(COL_COUNT, G_TYPE_STRING, G_TYPE_STRING); 52 list_store_ = gtk_list_store_new(COL_COUNT, G_TYPE_STRING, G_TYPE_STRING);
53 sort_list_store_ = gtk_tree_model_sort_new_with_model( 53 treeview_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store_));
54 GTK_TREE_MODEL(list_store_));
55 treeview_ = gtk_tree_view_new_with_model(GTK_TREE_MODEL(sort_list_store_));
56 g_object_unref(list_store_); 54 g_object_unref(list_store_);
57 g_object_unref(sort_list_store_);
58 55
59 // Set up the properties of the treeview 56 // Set up the properties of the treeview
60 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview_), TRUE); 57 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview_), TRUE);
61 g_signal_connect(treeview_, "row-activated", 58 g_signal_connect(treeview_, "row-activated",
62 G_CALLBACK(OnTreeViewRowActivateThunk), this); 59 G_CALLBACK(OnTreeViewRowActivateThunk), this);
63 60
64 GtkTreeViewColumn* pattern_column = gtk_tree_view_column_new_with_attributes( 61 GtkTreeViewColumn* pattern_column = gtk_tree_view_column_new_with_attributes(
65 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_PATTERN_HEADER).c_str(), 62 l10n_util::GetStringUTF8(IDS_EXCEPTIONS_PATTERN_HEADER).c_str(),
66 gtk_cell_renderer_text_new(), 63 gtk_cell_renderer_text_new(),
67 "text", COL_PATTERN, 64 "text", COL_PATTERN,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 178
182 gtk_tree::SelectAndFocusRowNum(new_index, GTK_TREE_VIEW(treeview_)); 179 gtk_tree::SelectAndFocusRowNum(new_index, GTK_TREE_VIEW(treeview_));
183 180
184 UpdateButtonState(); 181 UpdateButtonState();
185 } 182 }
186 183
187 void ContentExceptionsWindowGtk::UpdateButtonState() { 184 void ContentExceptionsWindowGtk::UpdateButtonState() {
188 int num_selected = gtk_tree_selection_count_selected_rows( 185 int num_selected = gtk_tree_selection_count_selected_rows(
189 treeview_selection_); 186 treeview_selection_);
190 int row_count = gtk_tree_model_iter_n_children( 187 int row_count = gtk_tree_model_iter_n_children(
191 GTK_TREE_MODEL(sort_list_store_), NULL); 188 GTK_TREE_MODEL(list_store_), NULL);
192 189
193 // TODO(erg): http://crbug.com/34177 , support editing of more than one entry 190 // TODO(erg): http://crbug.com/34177 , support editing of more than one entry
194 // at a time. 191 // at a time.
195 gtk_widget_set_sensitive(edit_button_, num_selected == 1); 192 gtk_widget_set_sensitive(edit_button_, num_selected == 1);
196 gtk_widget_set_sensitive(remove_button_, num_selected >= 1); 193 gtk_widget_set_sensitive(remove_button_, num_selected >= 1);
197 gtk_widget_set_sensitive(remove_all_button_, row_count > 0); 194 gtk_widget_set_sensitive(remove_all_button_, row_count > 0);
198 } 195 }
199 196
200 void ContentExceptionsWindowGtk::Add(GtkWidget* widget) { 197 void ContentExceptionsWindowGtk::Add(GtkWidget* widget) {
201 new ContentExceptionEditor(GTK_WINDOW(dialog_), 198 new ContentExceptionEditor(GTK_WINDOW(dialog_),
202 this, model_.get(), -1, 199 this, model_.get(), -1,
203 HostContentSettingsMap::Pattern(), 200 HostContentSettingsMap::Pattern(),
204 CONTENT_SETTING_BLOCK); 201 CONTENT_SETTING_BLOCK);
205 } 202 }
206 203
207 void ContentExceptionsWindowGtk::Edit(GtkWidget* widget) { 204 void ContentExceptionsWindowGtk::Edit(GtkWidget* widget) {
208 std::set<std::pair<int, int> > indices; 205 std::set<int> indices;
209 GetSelectedModelIndices(&indices); 206 gtk_tree::GetSelectedIndices(treeview_selection_, &indices);
210 DCHECK_GT(indices.size(), 0u); 207 DCHECK_GT(indices.size(), 0u);
211 int index = indices.begin()->first; 208 int index = *indices.begin();
212 const HostContentSettingsMap::PatternSettingPair& entry = 209 const HostContentSettingsMap::PatternSettingPair& entry =
213 model_->entry_at(index); 210 model_->entry_at(index);
214 new ContentExceptionEditor(GTK_WINDOW(dialog_), this, model_.get(), index, 211 new ContentExceptionEditor(GTK_WINDOW(dialog_), this, model_.get(), index,
215 entry.first, entry.second); 212 entry.first, entry.second);
216 } 213 }
217 214
218 void ContentExceptionsWindowGtk::Remove(GtkWidget* widget) { 215 void ContentExceptionsWindowGtk::Remove(GtkWidget* widget) {
219 std::set<std::pair<int, int> > model_selected_indices; 216 std::set<int> selected_indices;
220 GetSelectedModelIndices(&model_selected_indices); 217 gtk_tree::GetSelectedIndices(treeview_selection_, &selected_indices);
221 218
222 int selected_row = gtk_tree_model_iter_n_children( 219 int selected_row = 0;
223 GTK_TREE_MODEL(sort_list_store_), NULL); 220 for (std::set<int>::reverse_iterator i = selected_indices.rbegin();
224 for (std::set<std::pair<int, int> >::reverse_iterator i = 221 i != selected_indices.rend(); ++i) {
225 model_selected_indices.rbegin(); 222 model_->RemoveException(*i);
226 i != model_selected_indices.rend(); ++i) { 223 selected_row = *i;
227 model_->RemoveException(i->first);
228 selected_row = std::min(selected_row, i->second);
229 } 224 }
230 225
231 int row_count = model_->RowCount(); 226 int row_count = model_->RowCount();
232 if (row_count <= 0) 227 if (row_count <= 0)
233 return; 228 return;
234 if (selected_row >= row_count) 229 if (selected_row >= row_count)
235 selected_row = row_count - 1; 230 selected_row = row_count - 1;
236 gtk_tree::SelectAndFocusRowNum(selected_row, 231 gtk_tree::SelectAndFocusRowNum(selected_row,
237 GTK_TREE_VIEW(treeview_)); 232 GTK_TREE_VIEW(treeview_));
238 233
(...skipping 16 matching lines...) Expand all
255 case CONTENT_SETTINGS_TYPE_PLUGINS: 250 case CONTENT_SETTINGS_TYPE_PLUGINS:
256 return l10n_util::GetStringUTF8(IDS_PLUGINS_EXCEPTION_TITLE); 251 return l10n_util::GetStringUTF8(IDS_PLUGINS_EXCEPTION_TITLE);
257 case CONTENT_SETTINGS_TYPE_POPUPS: 252 case CONTENT_SETTINGS_TYPE_POPUPS:
258 return l10n_util::GetStringUTF8(IDS_POPUP_EXCEPTION_TITLE); 253 return l10n_util::GetStringUTF8(IDS_POPUP_EXCEPTION_TITLE);
259 default: 254 default:
260 NOTREACHED(); 255 NOTREACHED();
261 } 256 }
262 return std::string(); 257 return std::string();
263 } 258 }
264 259
265 void ContentExceptionsWindowGtk::GetSelectedModelIndices(
266 std::set<std::pair<int, int> >* indices) {
267 GtkTreeModel* model;
268 GList* paths = gtk_tree_selection_get_selected_rows(treeview_selection_,
269 &model);
270 for (GList* item = paths; item; item = item->next) {
271 GtkTreePath* sorted_path = reinterpret_cast<GtkTreePath*>(item->data);
272 int sorted_row = gtk_tree::GetRowNumForPath(sorted_path);
273 GtkTreePath* path = gtk_tree_model_sort_convert_path_to_child_path(
274 GTK_TREE_MODEL_SORT(sort_list_store_), sorted_path);
275 int row = gtk_tree::GetRowNumForPath(path);
276 gtk_tree_path_free(path);
277 indices->insert(std::make_pair(row, sorted_row));
278 }
279
280 g_list_foreach(paths, (GFunc)gtk_tree_path_free, NULL);
281 g_list_free(paths);
282 }
283
284 void ContentExceptionsWindowGtk::OnTreeViewRowActivate( 260 void ContentExceptionsWindowGtk::OnTreeViewRowActivate(
285 GtkWidget* sender, 261 GtkWidget* sender,
286 GtkTreePath* path, 262 GtkTreePath* path,
287 GtkTreeViewColumn* column) { 263 GtkTreeViewColumn* column) {
288 Edit(sender); 264 Edit(sender);
289 } 265 }
290 266
291 void ContentExceptionsWindowGtk::OnWindowDestroy(GtkWidget* widget) { 267 void ContentExceptionsWindowGtk::OnWindowDestroy(GtkWidget* widget) {
292 instances[model_->content_type()] = NULL; 268 instances[model_->content_type()] = NULL;
293 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 269 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
294 } 270 }
295 271
296 void ContentExceptionsWindowGtk::OnTreeSelectionChanged( 272 void ContentExceptionsWindowGtk::OnTreeSelectionChanged(
297 GtkWidget* selection) { 273 GtkWidget* selection) {
298 UpdateButtonState(); 274 UpdateButtonState();
299 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698