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

Side by Side Diff: chrome/browser/gtk/bookmark_editor_gtk.cc

Issue 271115: Makes canceling 'bookmark all tabs' delete the folder. Or rather,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/bookmark_editor_gtk.h" 5 #include "chrome/browser/gtk/bookmark_editor_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/gfx/gtk_util.h" 9 #include "app/gfx/gtk_util.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 22 matching lines...) Expand all
33 // Preferred initial dimensions, in pixels, of the folder tree. 33 // Preferred initial dimensions, in pixels, of the folder tree.
34 static const int kTreeWidth = 300; 34 static const int kTreeWidth = 300;
35 static const int kTreeHeight = 150; 35 static const int kTreeHeight = 150;
36 36
37 } // namespace 37 } // namespace
38 38
39 // static 39 // static
40 void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd, 40 void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd,
41 Profile* profile, 41 Profile* profile,
42 const BookmarkNode* parent, 42 const BookmarkNode* parent,
43 const BookmarkNode* node, 43 const EditDetails& details,
44 Configuration configuration, 44 Configuration configuration,
45 Handler* handler) { 45 Handler* handler) {
46 DCHECK(profile); 46 DCHECK(profile);
47 BookmarkEditorGtk* editor = 47 BookmarkEditorGtk* editor =
48 new BookmarkEditorGtk(parent_hwnd, profile, parent, node, configuration, 48 new BookmarkEditorGtk(parent_hwnd, profile, parent, details,
49 handler); 49 configuration, handler);
50 editor->Show(); 50 editor->Show();
51 } 51 }
52 52
53 BookmarkEditorGtk::BookmarkEditorGtk( 53 BookmarkEditorGtk::BookmarkEditorGtk(
54 GtkWindow* window, 54 GtkWindow* window,
55 Profile* profile, 55 Profile* profile,
56 const BookmarkNode* parent, 56 const BookmarkNode* parent,
57 const BookmarkNode* node, 57 const EditDetails& details,
58 BookmarkEditor::Configuration configuration, 58 BookmarkEditor::Configuration configuration,
59 BookmarkEditor::Handler* handler) 59 BookmarkEditor::Handler* handler)
60 : profile_(profile), 60 : profile_(profile),
61 dialog_(NULL), 61 dialog_(NULL),
62 parent_(parent), 62 parent_(parent),
63 node_(node), 63 details_(details),
64 running_menu_for_root_(false), 64 running_menu_for_root_(false),
65 show_tree_(configuration == SHOW_TREE), 65 show_tree_(configuration == SHOW_TREE),
66 handler_(handler) { 66 handler_(handler) {
67 DCHECK(profile); 67 DCHECK(profile);
68 Init(window); 68 Init(window);
69 } 69 }
70 70
71 BookmarkEditorGtk::~BookmarkEditorGtk() { 71 BookmarkEditorGtk::~BookmarkEditorGtk() {
72 // The tree model is deleted before the view. Reset the model otherwise the 72 // The tree model is deleted before the view. Reset the model otherwise the
73 // tree will reference a deleted model. 73 // tree will reference a deleted model.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // |||+- GtkTreeViewColumn |name_column| -----------------------+||| 118 // |||+- GtkTreeViewColumn |name_column| -----------------------+|||
119 // |||| |||| 119 // |||| ||||
120 // |||| |||| 120 // |||| ||||
121 // |||| |||| 121 // |||| ||||
122 // |||| |||| 122 // |||| ||||
123 // |||+---------------------------------------------------------+||| 123 // |||+---------------------------------------------------------+|||
124 // ||+-----------------------------------------------------------+|| 124 // ||+-----------------------------------------------------------+||
125 // |+-------------------------------------------------------------+| 125 // |+-------------------------------------------------------------+|
126 // +---------------------------------------------------------------+ 126 // +---------------------------------------------------------------+
127 // 127 //
128 // * The url and corresponding label are not shown if node_ is a folder. 128 // * The url and corresponding label are not shown if creating a new folder.
129 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; 129 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox;
130 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); 130 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing);
131 131
132 GtkWidget* vbox = gtk_vbox_new(FALSE, 12); 132 GtkWidget* vbox = gtk_vbox_new(FALSE, 12);
133 133
134 name_entry_ = gtk_entry_new(); 134 name_entry_ = gtk_entry_new();
135 gtk_entry_set_text(GTK_ENTRY(name_entry_), 135 std::string title;
136 node_ ? WideToUTF8(node_->GetTitle()).c_str() : ""); 136 if (details_.type == EditDetails::EXISTING_NODE) {
137 title = WideToUTF8(details_.existing_node->GetTitle());
138 } else if (details_.type == EditDetails::NEW_FOLDER) {
139 title = WideToUTF8(
140 l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME));
141 }
142 gtk_entry_set_text(GTK_ENTRY(name_entry_), title.c_str());
137 g_signal_connect(G_OBJECT(name_entry_), "changed", 143 g_signal_connect(G_OBJECT(name_entry_), "changed",
138 G_CALLBACK(OnEntryChanged), this); 144 G_CALLBACK(OnEntryChanged), this);
139 gtk_entry_set_activates_default(GTK_ENTRY(name_entry_), TRUE); 145 gtk_entry_set_activates_default(GTK_ENTRY(name_entry_), TRUE);
140 146
141 GtkWidget* table; 147 GtkWidget* table;
142 if (!IsEditingFolder()) { 148 if (details_.type != EditDetails::NEW_FOLDER) {
143 url_entry_ = gtk_entry_new(); 149 url_entry_ = gtk_entry_new();
144 gtk_entry_set_text(GTK_ENTRY(url_entry_), 150 std::string url_spec;
145 node_ ? node_->GetURL().spec().c_str() : ""); 151 if (details_.type == EditDetails::EXISTING_NODE)
152 url_spec = details_.existing_node->GetURL().spec();
153 gtk_entry_set_text(GTK_ENTRY(url_entry_), url_spec.c_str());
146 g_signal_connect(G_OBJECT(url_entry_), "changed", 154 g_signal_connect(G_OBJECT(url_entry_), "changed",
147 G_CALLBACK(OnEntryChanged), this); 155 G_CALLBACK(OnEntryChanged), this);
148 gtk_entry_set_activates_default(GTK_ENTRY(url_entry_), TRUE); 156 gtk_entry_set_activates_default(GTK_ENTRY(url_entry_), TRUE);
149 table = gtk_util::CreateLabeledControlsGroup(NULL, 157 table = gtk_util::CreateLabeledControlsGroup(NULL,
150 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str(), 158 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str(),
151 name_entry_, 159 name_entry_,
152 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_URL_LABEL).c_str(), 160 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_URL_LABEL).c_str(),
153 url_entry_, 161 url_entry_,
154 NULL); 162 NULL);
155 163
156 } else { 164 } else {
157 url_entry_ = NULL; 165 url_entry_ = NULL;
158 table = gtk_util::CreateLabeledControlsGroup(NULL, 166 table = gtk_util::CreateLabeledControlsGroup(NULL,
159 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str(), 167 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str(),
160 name_entry_, 168 name_entry_,
161 NULL); 169 NULL);
162 } 170 }
163 171
164 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); 172 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
165 173
166 if (show_tree_) { 174 if (show_tree_) {
167 GtkTreeIter selected_iter; 175 GtkTreeIter selected_iter;
168 int64 selected_id = parent_ ? parent_->id() : 0; 176 int64 selected_id = 0;
169 const BookmarkNode* node_to_ignore = IsEditingFolder() ? node_ : NULL; 177 if (details_.type == EditDetails::EXISTING_NODE)
178 selected_id = details_.existing_node->GetParent()->id();
179 else if (parent_)
180 selected_id = parent_->id();
170 tree_store_ = bookmark_utils::MakeFolderTreeStore(); 181 tree_store_ = bookmark_utils::MakeFolderTreeStore();
171 bookmark_utils::AddToTreeStore(bb_model_, selected_id, node_to_ignore, 182 bookmark_utils::AddToTreeStore(bb_model_, selected_id, tree_store_,
172 tree_store_, &selected_iter); 183 &selected_iter);
173 tree_view_ = bookmark_utils::MakeTreeViewForStore(tree_store_); 184 tree_view_ = bookmark_utils::MakeTreeViewForStore(tree_store_);
174 gtk_widget_set_size_request(tree_view_, kTreeWidth, kTreeHeight); 185 gtk_widget_set_size_request(tree_view_, kTreeWidth, kTreeHeight);
175 tree_selection_ = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view_)); 186 tree_selection_ = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view_));
176 187
177 GtkTreePath* path = NULL; 188 GtkTreePath* path = NULL;
178 if (selected_id) { 189 if (selected_id) {
179 path = gtk_tree_model_get_path(GTK_TREE_MODEL(tree_store_), 190 path = gtk_tree_model_get_path(GTK_TREE_MODEL(tree_store_),
180 &selected_iter); 191 &selected_iter);
181 } else { 192 } else {
182 // We don't have a selected parent (Probably because we're making a new 193 // We don't have a selected parent (Probably because we're making a new
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 void BookmarkEditorGtk::BookmarkNodeAdded(BookmarkModel* model, 250 void BookmarkEditorGtk::BookmarkNodeAdded(BookmarkModel* model,
240 const BookmarkNode* parent, 251 const BookmarkNode* parent,
241 int index) { 252 int index) {
242 Reset(); 253 Reset();
243 } 254 }
244 255
245 void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model, 256 void BookmarkEditorGtk::BookmarkNodeRemoved(BookmarkModel* model,
246 const BookmarkNode* parent, 257 const BookmarkNode* parent,
247 int index, 258 int index,
248 const BookmarkNode* node) { 259 const BookmarkNode* node) {
249 if ((node_ && node_->HasAncestor(node)) || 260 if ((details_.type == EditDetails::EXISTING_NODE &&
261 details_.existing_node->HasAncestor(node)) ||
250 (parent_ && parent_->HasAncestor(node))) { 262 (parent_ && parent_->HasAncestor(node))) {
251 // The node, or its parent was removed. Close the dialog. 263 // The node, or its parent was removed. Close the dialog.
252 Close(); 264 Close();
253 } else { 265 } else {
254 Reset(); 266 Reset();
255 } 267 }
256 } 268 }
257 269
258 void BookmarkEditorGtk::BookmarkNodeChildrenReordered( 270 void BookmarkEditorGtk::BookmarkNodeChildrenReordered(
259 BookmarkModel* model, const BookmarkNode* node) { 271 BookmarkModel* model, const BookmarkNode* node) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // We're going to apply edits to the bookmark bar model, which will call us 310 // We're going to apply edits to the bookmark bar model, which will call us
299 // back. Normally when a structural edit occurs we reset the tree model. 311 // back. Normally when a structural edit occurs we reset the tree model.
300 // We don't want to do that here, so we remove ourselves as an observer. 312 // We don't want to do that here, so we remove ourselves as an observer.
301 bb_model_->RemoveObserver(this); 313 bb_model_->RemoveObserver(this);
302 314
303 GURL new_url(GetInputURL()); 315 GURL new_url(GetInputURL());
304 std::wstring new_title(GetInputTitle()); 316 std::wstring new_title(GetInputTitle());
305 317
306 if (!show_tree_ || !selected_parent) { 318 if (!show_tree_ || !selected_parent) {
307 bookmark_utils::ApplyEditsWithNoGroupChange( 319 bookmark_utils::ApplyEditsWithNoGroupChange(
308 bb_model_, parent_, node_, new_title, new_url, handler_.get()); 320 bb_model_, parent_, details_, new_title, new_url, handler_.get());
309 return; 321 return;
310 } 322 }
311 323
312 // Create the new groups and update the titles. 324 // Create the new groups and update the titles.
313 const BookmarkNode* new_parent = 325 const BookmarkNode* new_parent =
314 bookmark_utils::CommitTreeStoreDifferencesBetween( 326 bookmark_utils::CommitTreeStoreDifferencesBetween(
315 bb_model_, tree_store_, selected_parent); 327 bb_model_, tree_store_, selected_parent);
316 328
317 if (!new_parent) { 329 if (!new_parent) {
318 // Bookmarks must be parented. 330 // Bookmarks must be parented.
319 NOTREACHED(); 331 NOTREACHED();
320 return; 332 return;
321 } 333 }
322 334
323 bookmark_utils::ApplyEditsWithPossibleGroupChange( 335 bookmark_utils::ApplyEditsWithPossibleGroupChange(
324 bb_model_, new_parent, node_, new_title, new_url, handler_.get()); 336 bb_model_, new_parent, details_, new_title, new_url, handler_.get());
325 } 337 }
326 338
327 void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) { 339 void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) {
328 gtk_tree_store_append(tree_store_, child, parent); 340 gtk_tree_store_append(tree_store_, child, parent);
329 gtk_tree_store_set( 341 gtk_tree_store_set(
330 tree_store_, child, 342 tree_store_, child,
331 bookmark_utils::FOLDER_ICON, GtkThemeProvider::GetFolderIcon(true), 343 bookmark_utils::FOLDER_ICON, GtkThemeProvider::GetFolderIcon(true),
332 bookmark_utils::FOLDER_NAME, 344 bookmark_utils::FOLDER_NAME,
333 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME).c_str(), 345 l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME).c_str(),
334 bookmark_utils::ITEM_ID, static_cast<int64>(0), 346 bookmark_utils::ITEM_ID, static_cast<int64>(0),
335 bookmark_utils::IS_EDITABLE, TRUE, 347 bookmark_utils::IS_EDITABLE, TRUE,
336 -1); 348 -1);
337 } 349 }
338 350
339 bool BookmarkEditorGtk::IsEditingFolder() const {
340 return node_ && node_->is_folder();
341 }
342
343 // static 351 // static
344 void BookmarkEditorGtk::OnSelectionChanged(GtkTreeSelection* selection, 352 void BookmarkEditorGtk::OnSelectionChanged(GtkTreeSelection* selection,
345 BookmarkEditorGtk* dialog) { 353 BookmarkEditorGtk* dialog) {
346 if (!gtk_tree_selection_get_selected(dialog->tree_selection_, NULL, NULL)) 354 if (!gtk_tree_selection_get_selected(dialog->tree_selection_, NULL, NULL))
347 gtk_widget_set_sensitive(dialog->new_folder_button_, FALSE); 355 gtk_widget_set_sensitive(dialog->new_folder_button_, FALSE);
348 else 356 else
349 gtk_widget_set_sensitive(dialog->new_folder_button_, TRUE); 357 gtk_widget_set_sensitive(dialog->new_folder_button_, TRUE);
350 } 358 }
351 359
352 // static 360 // static
353 void BookmarkEditorGtk::OnResponse(GtkDialog* dialog, int response_id, 361 void BookmarkEditorGtk::OnResponse(GtkDialog* dialog, int response_id,
354 BookmarkEditorGtk* window) { 362 BookmarkEditorGtk* window) {
355 if (response_id == GTK_RESPONSE_ACCEPT) { 363 if (response_id == GTK_RESPONSE_ACCEPT)
356 window->ApplyEdits(); 364 window->ApplyEdits();
357 }
358 365
359 window->Close(); 366 window->Close();
360 } 367 }
361 368
362 // static 369 // static
363 gboolean BookmarkEditorGtk::OnWindowDeleteEvent( 370 gboolean BookmarkEditorGtk::OnWindowDeleteEvent(
364 GtkWidget* widget, 371 GtkWidget* widget,
365 GdkEvent* event, 372 GdkEvent* event,
366 BookmarkEditorGtk* dialog) { 373 BookmarkEditorGtk* dialog) {
367 dialog->Close(); 374 dialog->Close();
368 375
369 // Return true to prevent the gtk dialog from being destroyed. Close will 376 // Return true to prevent the gtk dialog from being destroyed. Close will
370 // destroy it for us and the default gtk_dialog_delete_event_handler() will 377 // destroy it for us and the default gtk_dialog_delete_event_handler() will
371 // force the destruction without us being able to stop it. 378 // force the destruction without us being able to stop it.
372 return TRUE; 379 return TRUE;
373 } 380 }
374 381
375 // static 382 // static
376 void BookmarkEditorGtk::OnWindowDestroy(GtkWidget* widget, 383 void BookmarkEditorGtk::OnWindowDestroy(GtkWidget* widget,
377 BookmarkEditorGtk* dialog) { 384 BookmarkEditorGtk* dialog) {
378 MessageLoop::current()->DeleteSoon(FROM_HERE, dialog); 385 MessageLoop::current()->DeleteSoon(FROM_HERE, dialog);
379 } 386 }
380 387
381 // static 388 // static
382 void BookmarkEditorGtk::OnEntryChanged(GtkEditable* entry, 389 void BookmarkEditorGtk::OnEntryChanged(GtkEditable* entry,
383 BookmarkEditorGtk* dialog) { 390 BookmarkEditorGtk* dialog) {
384 gboolean can_close = TRUE; 391 gboolean can_close = TRUE;
385 if (dialog->IsEditingFolder()) { 392 if (dialog->details_.type == EditDetails::NEW_FOLDER) {
386 if (dialog->GetInputTitle().empty()) { 393 if (dialog->GetInputTitle().empty()) {
387 gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, &kErrorColor ); 394 gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, &kErrorColor );
Evan Stade 2009/10/16 20:08:06 80
388 can_close = FALSE; 395 can_close = FALSE;
389 } else { 396 } else {
390 gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, NULL); 397 gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, NULL);
391 } 398 }
392 } else { 399 } else {
393 GURL url(dialog->GetInputURL()); 400 GURL url(dialog->GetInputURL());
394 if (!url.is_valid()) { 401 if (!url.is_valid()) {
395 gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, &kErrorColor) ; 402 gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, &kErrorColor) ;
Evan Stade 2009/10/16 20:08:06 80
396 can_close = FALSE; 403 can_close = FALSE;
397 } else { 404 } else {
398 gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, NULL); 405 gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, NULL);
399 } 406 }
400 } 407 }
401 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog->dialog_), 408 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog->dialog_),
402 GTK_RESPONSE_ACCEPT, can_close); 409 GTK_RESPONSE_ACCEPT, can_close);
403 } 410 }
404 411
405 // static 412 // static
(...skipping 17 matching lines...) Expand all
423 GTK_TREE_MODEL(dialog->tree_store_), &new_item_iter); 430 GTK_TREE_MODEL(dialog->tree_store_), &new_item_iter);
424 gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dialog->tree_view_), path); 431 gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dialog->tree_view_), path);
425 432
426 // Make the folder name editable. 433 // Make the folder name editable.
427 gtk_tree_view_set_cursor(GTK_TREE_VIEW(dialog->tree_view_), path, 434 gtk_tree_view_set_cursor(GTK_TREE_VIEW(dialog->tree_view_), path,
428 gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->tree_view_), 0), 435 gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->tree_view_), 0),
429 TRUE); 436 TRUE);
430 437
431 gtk_tree_path_free(path); 438 gtk_tree_path_free(path);
432 } 439 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/bookmark_editor_gtk.h ('k') | chrome/browser/gtk/bookmark_editor_gtk_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698