OLD | NEW |
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_context_menu.h" | 5 #include "chrome/browser/gtk/bookmark_context_menu.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "chrome/browser/bookmarks/bookmark_editor.h" | 9 #include "chrome/browser/bookmarks/bookmark_editor.h" |
10 #include "chrome/browser/bookmarks/bookmark_manager.h" | 10 #include "chrome/browser/bookmarks/bookmark_manager.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 // BookmarkContextMenu ------------------------------------------- | 209 // BookmarkContextMenu ------------------------------------------- |
210 | 210 |
211 BookmarkContextMenu::BookmarkContextMenu( | 211 BookmarkContextMenu::BookmarkContextMenu( |
212 gfx::NativeView wnd, | 212 gfx::NativeView wnd, |
213 Profile* profile, | 213 Profile* profile, |
214 Browser* browser, | 214 Browser* browser, |
215 PageNavigator* navigator, | 215 PageNavigator* navigator, |
216 const BookmarkNode* parent, | 216 const BookmarkNode* parent, |
217 const std::vector<const BookmarkNode*>& selection, | 217 const std::vector<const BookmarkNode*>& selection, |
218 ConfigurationType configuration) | 218 ConfigurationType configuration, |
| 219 Delegate* delegate) |
219 : wnd_(wnd), | 220 : wnd_(wnd), |
220 profile_(profile), | 221 profile_(profile), |
221 browser_(browser), | 222 browser_(browser), |
222 navigator_(navigator), | 223 navigator_(navigator), |
223 parent_(parent), | 224 parent_(parent), |
224 selection_(selection), | 225 selection_(selection), |
225 model_(profile->GetBookmarkModel()), | 226 model_(profile->GetBookmarkModel()), |
226 configuration_(configuration) { | 227 configuration_(configuration), |
| 228 delegate_(delegate) { |
227 DCHECK(profile_); | 229 DCHECK(profile_); |
228 DCHECK(model_->IsLoaded()); | 230 DCHECK(model_->IsLoaded()); |
229 CreateMenuObject(); | 231 CreateMenuObject(); |
230 | 232 |
231 if (configuration != BOOKMARK_MANAGER_ORGANIZE_MENU) { | 233 if (configuration != BOOKMARK_MANAGER_ORGANIZE_MENU) { |
232 if (selection.size() == 1 && selection[0]->is_url()) { | 234 if (selection.size() == 1 && selection[0]->is_url()) { |
233 AppendItem(IDS_BOOMARK_BAR_OPEN_ALL, IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB); | 235 AppendItem(IDS_BOOMARK_BAR_OPEN_ALL, IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB); |
234 AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW, | 236 AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW, |
235 IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW); | 237 IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW); |
236 AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO, | 238 AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 289 } |
288 | 290 |
289 model_->AddObserver(this); | 291 model_->AddObserver(this); |
290 } | 292 } |
291 | 293 |
292 BookmarkContextMenu::~BookmarkContextMenu() { | 294 BookmarkContextMenu::~BookmarkContextMenu() { |
293 if (model_) | 295 if (model_) |
294 model_->RemoveObserver(this); | 296 model_->RemoveObserver(this); |
295 } | 297 } |
296 | 298 |
| 299 void BookmarkContextMenu::DelegateDestroyed() { |
| 300 delegate_ = NULL; |
| 301 } |
| 302 |
297 void BookmarkContextMenu::ExecuteCommand(int id) { | 303 void BookmarkContextMenu::ExecuteCommand(int id) { |
| 304 if (delegate_) |
| 305 delegate_->WillExecuteCommand(); |
| 306 |
298 switch (id) { | 307 switch (id) { |
299 case IDS_BOOMARK_BAR_OPEN_ALL: | 308 case IDS_BOOMARK_BAR_OPEN_ALL: |
300 case IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO: | 309 case IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO: |
301 case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW: { | 310 case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW: { |
302 PageNavigator* navigator = browser_ ? | 311 PageNavigator* navigator = browser_ ? |
303 browser_->GetSelectedTabContents() : navigator_; | 312 browser_->GetSelectedTabContents() : navigator_; |
304 WindowOpenDisposition initial_disposition; | 313 WindowOpenDisposition initial_disposition; |
305 if (id == IDS_BOOMARK_BAR_OPEN_ALL) { | 314 if (id == IDS_BOOMARK_BAR_OPEN_ALL) { |
306 initial_disposition = NEW_FOREGROUND_TAB; | 315 initial_disposition = NEW_FOREGROUND_TAB; |
307 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_OpenAll", | 316 UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_OpenAll", |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (NodeHasURLs(selection_[i])) | 558 if (NodeHasURLs(selection_[i])) |
550 return true; | 559 return true; |
551 } | 560 } |
552 return false; | 561 return false; |
553 } | 562 } |
554 | 563 |
555 const BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { | 564 const BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { |
556 return (selection_.size() == 1 && selection_[0]->is_folder()) ? | 565 return (selection_.size() == 1 && selection_[0]->is_folder()) ? |
557 selection_[0] : parent_; | 566 selection_[0] : parent_; |
558 } | 567 } |
OLD | NEW |