| OLD | NEW |
| 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/geolocation_content_exceptions_window.h" | 5 #include "chrome/browser/gtk/options/geolocation_content_exceptions_window.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 10 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 std::wstring action = model_->GetText(row, IDS_EXCEPTIONS_ACTION_HEADER); | 137 std::wstring action = model_->GetText(row, IDS_EXCEPTIONS_ACTION_HEADER); |
| 138 gtk_list_store_set(list_store_, iter, COL_ACTION, | 138 gtk_list_store_set(list_store_, iter, COL_ACTION, |
| 139 WideToUTF8(action).c_str(), -1); | 139 WideToUTF8(action).c_str(), -1); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void GeolocationContentExceptionsWindow::UpdateButtonState() { | 142 void GeolocationContentExceptionsWindow::UpdateButtonState() { |
| 143 int row_count = gtk_tree_model_iter_n_children( | 143 int row_count = gtk_tree_model_iter_n_children( |
| 144 GTK_TREE_MODEL(list_store_), NULL); | 144 GTK_TREE_MODEL(list_store_), NULL); |
| 145 | 145 |
| 146 gtk_widget_set_sensitive(remove_button_, CountSelectedRemovable() >= 1); | 146 GeolocationContentSettingsTableModel::Rows rows; |
| 147 GetSelectedRows(&rows); |
| 148 gtk_widget_set_sensitive(remove_button_, model_->CanRemoveExceptions(rows)); |
| 147 gtk_widget_set_sensitive(remove_all_button_, row_count > 0); | 149 gtk_widget_set_sensitive(remove_all_button_, row_count > 0); |
| 148 } | 150 } |
| 149 | 151 |
| 150 void GeolocationContentExceptionsWindow::GetSelectedRemovableIndicies( | 152 void GeolocationContentExceptionsWindow::GetSelectedRows( |
| 151 std::set<int>* indicies) { | 153 GeolocationContentSettingsTableModel::Rows* rows) { |
| 152 gtk_tree::GetSelectedIndicies(treeview_selection_, indicies); | |
| 153 | |
| 154 for (std::set<int>::iterator i = indicies->begin(); i != indicies->end(); ) { | |
| 155 std::set<int>::iterator prev = i; | |
| 156 ++i; | |
| 157 if (!model_->CanRemoveException(*prev)) | |
| 158 indicies->erase(prev); | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 int GeolocationContentExceptionsWindow::CountSelectedRemovable() { | |
| 163 std::set<int> indicies; | 154 std::set<int> indicies; |
| 164 GetSelectedRemovableIndicies(&indicies); | 155 gtk_tree::GetSelectedIndicies(treeview_selection_, &indicies); |
| 165 return indicies.size(); | 156 for (std::set<int>::iterator i = indicies.begin(); i != indicies.end(); ++i) |
| 157 rows->insert(*i); |
| 166 } | 158 } |
| 167 | 159 |
| 168 void GeolocationContentExceptionsWindow::Remove(GtkWidget* widget) { | 160 void GeolocationContentExceptionsWindow::Remove(GtkWidget* widget) { |
| 169 std::set<int> indicies; | 161 GeolocationContentSettingsTableModel::Rows rows; |
| 170 GetSelectedRemovableIndicies(&indicies); | 162 GetSelectedRows(&rows); |
| 171 | 163 model_->RemoveExceptions(rows); |
| 172 for (std::set<int>::reverse_iterator i = indicies.rbegin(); | |
| 173 i != indicies.rend(); ++i) { | |
| 174 model_->RemoveException(*i); | |
| 175 } | |
| 176 | |
| 177 UpdateButtonState(); | 164 UpdateButtonState(); |
| 178 } | 165 } |
| 179 | 166 |
| 180 void GeolocationContentExceptionsWindow::RemoveAll(GtkWidget* widget) { | 167 void GeolocationContentExceptionsWindow::RemoveAll(GtkWidget* widget) { |
| 181 model_->RemoveAll(); | 168 model_->RemoveAll(); |
| 182 UpdateButtonState(); | 169 UpdateButtonState(); |
| 183 } | 170 } |
| 184 | 171 |
| 185 void GeolocationContentExceptionsWindow::OnWindowDestroy(GtkWidget* widget) { | 172 void GeolocationContentExceptionsWindow::OnWindowDestroy(GtkWidget* widget) { |
| 186 instance = NULL; | 173 instance = NULL; |
| 187 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 174 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 188 } | 175 } |
| 189 | 176 |
| 190 void GeolocationContentExceptionsWindow::OnTreeSelectionChanged( | 177 void GeolocationContentExceptionsWindow::OnTreeSelectionChanged( |
| 191 GtkWidget* selection) { | 178 GtkWidget* selection) { |
| 192 UpdateButtonState(); | 179 UpdateButtonState(); |
| 193 } | 180 } |
| OLD | NEW |