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/bookmarks/bookmark_utils.h" | 5 #include "chrome/browser/bookmarks/bookmark_utils.h" |
6 | 6 |
7 #include "app/clipboard/clipboard.h" | 7 #include "app/clipboard/clipboard.h" |
8 #include "app/drag_drop_types.h" | 8 #include "app/drag_drop_types.h" |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/tree_node_iterator.h" | 10 #include "app/tree_node_iterator.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 16 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
17 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
18 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
19 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" | 19 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" |
20 #endif | 20 #endif |
21 #include "chrome/browser/browser.h" | 21 #include "chrome/browser/browser.h" |
22 #include "chrome/browser/browser_list.h" | 22 #include "chrome/browser/browser_list.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/browser_window.h" | 24 #include "chrome/browser/browser_window.h" |
25 #include "chrome/browser/history/query_parser.h" | 25 #include "chrome/browser/history/query_parser.h" |
| 26 #include "chrome/browser/platform_util.h" |
26 #include "chrome/browser/pref_service.h" | 27 #include "chrome/browser/pref_service.h" |
27 #include "chrome/browser/profile.h" | 28 #include "chrome/browser/profile.h" |
28 #include "chrome/browser/tab_contents/page_navigator.h" | 29 #include "chrome/browser/tab_contents/page_navigator.h" |
29 #include "chrome/browser/tab_contents/tab_contents.h" | 30 #include "chrome/browser/tab_contents/tab_contents.h" |
30 #include "chrome/common/notification_service.h" | 31 #include "chrome/common/notification_service.h" |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
32 #include "grit/app_strings.h" | 33 #include "grit/app_strings.h" |
33 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
35 #include "net/base/net_util.h" | 36 #include "net/base/net_util.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 158 } |
158 | 159 |
159 bool ShouldOpenAll(gfx::NativeWindow parent, | 160 bool ShouldOpenAll(gfx::NativeWindow parent, |
160 const std::vector<const BookmarkNode*>& nodes) { | 161 const std::vector<const BookmarkNode*>& nodes) { |
161 int descendant_count = 0; | 162 int descendant_count = 0; |
162 for (size_t i = 0; i < nodes.size(); ++i) | 163 for (size_t i = 0; i < nodes.size(); ++i) |
163 descendant_count += DescendantURLCount(nodes[i]); | 164 descendant_count += DescendantURLCount(nodes[i]); |
164 if (descendant_count < bookmark_utils::num_urls_before_prompting) | 165 if (descendant_count < bookmark_utils::num_urls_before_prompting) |
165 return true; | 166 return true; |
166 | 167 |
167 // Bug 40011: we should refactor this into a cross-platform "prompt before | 168 string16 message = l10n_util::GetStringFUTF16( |
168 // continuing" function. | |
169 #if defined(OS_WIN) | |
170 std::wstring message = | |
171 l10n_util::GetStringF(IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL, | |
172 IntToWString(descendant_count)); | |
173 return MessageBox(parent, message.c_str(), | |
174 l10n_util::GetString(IDS_PRODUCT_NAME).c_str(), | |
175 MB_YESNO | MB_ICONWARNING | MB_TOPMOST) == IDYES; | |
176 #elif defined(TOOLKIT_GTK) | |
177 std::string message = l10n_util::GetStringFUTF8( | |
178 IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL, | 169 IDS_BOOKMARK_BAR_SHOULD_OPEN_ALL, |
179 IntToString16(descendant_count)); | 170 IntToString16(descendant_count)); |
180 GtkWidget* dialog = gtk_message_dialog_new(parent, | 171 string16 title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
181 static_cast<GtkDialogFlags>( | 172 return platform_util::SimpleYesNoBox(parent, title, message); |
182 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), | |
183 GTK_MESSAGE_QUESTION, | |
184 GTK_BUTTONS_YES_NO, | |
185 "%s", message.c_str()); | |
186 gtk_util::ApplyMessageDialogQuirks(dialog); | |
187 gtk_window_set_title(GTK_WINDOW(dialog), | |
188 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME).c_str()); | |
189 gint result = gtk_dialog_run(GTK_DIALOG(dialog)); | |
190 gtk_widget_destroy(dialog); | |
191 return (result == GTK_RESPONSE_YES); | |
192 #else | |
193 // TODO(port): Display a dialog prompt. | |
194 // http://crbug.com/34481 | |
195 NOTIMPLEMENTED(); | |
196 return true; | |
197 #endif | |
198 } | 173 } |
199 | 174 |
200 // Comparison function that compares based on date modified of the two nodes. | 175 // Comparison function that compares based on date modified of the two nodes. |
201 bool MoreRecentlyModified(const BookmarkNode* n1, const BookmarkNode* n2) { | 176 bool MoreRecentlyModified(const BookmarkNode* n1, const BookmarkNode* n2) { |
202 return n1->date_group_modified() > n2->date_group_modified(); | 177 return n1->date_group_modified() > n2->date_group_modified(); |
203 } | 178 } |
204 | 179 |
205 // Returns true if |text| contains each string in |words|. This is used when | 180 // Returns true if |text| contains each string in |words|. This is used when |
206 // searching for bookmarks. | 181 // searching for bookmarks. |
207 bool DoesBookmarkTextContainWords(const string16& text, | 182 bool DoesBookmarkTextContainWords(const string16& text, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 const std::vector<const BookmarkNode*>& nodes, | 326 const std::vector<const BookmarkNode*>& nodes, |
352 gfx::NativeView view) { | 327 gfx::NativeView view) { |
353 DCHECK(!nodes.empty()); | 328 DCHECK(!nodes.empty()); |
354 | 329 |
355 #if defined(TOOLKIT_VIEWS) | 330 #if defined(TOOLKIT_VIEWS) |
356 // Set up our OLE machinery | 331 // Set up our OLE machinery |
357 OSExchangeData data; | 332 OSExchangeData data; |
358 BookmarkDragData drag_data(nodes); | 333 BookmarkDragData drag_data(nodes); |
359 drag_data.Write(profile, &data); | 334 drag_data.Write(profile, &data); |
360 | 335 |
361 views::RootView* root_view = views::Widget::GetWidgetFromNativeView(view)->Get
RootView(); | 336 views::RootView* root_view = |
| 337 views::Widget::GetWidgetFromNativeView(view)->GetRootView(); |
362 | 338 |
363 // Allow nested message loop so we get DnD events as we drag this around. | 339 // Allow nested message loop so we get DnD events as we drag this around. |
364 bool was_nested = MessageLoop::current()->IsNested(); | 340 bool was_nested = MessageLoop::current()->IsNested(); |
365 MessageLoop::current()->SetNestableTasksAllowed(true); | 341 MessageLoop::current()->SetNestableTasksAllowed(true); |
366 | 342 |
367 root_view->StartDragForViewFromMouseEvent(NULL, data, | 343 root_view->StartDragForViewFromMouseEvent(NULL, data, |
368 DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE | | 344 DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_MOVE | |
369 DragDropTypes::DRAG_LINK); | 345 DragDropTypes::DRAG_LINK); |
370 | 346 |
371 MessageLoop::current()->SetNestableTasksAllowed(was_nested); | 347 MessageLoop::current()->SetNestableTasksAllowed(was_nested); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 } | 652 } |
677 } else { | 653 } else { |
678 *index = real_parent->GetChildCount(); | 654 *index = real_parent->GetChildCount(); |
679 } | 655 } |
680 } | 656 } |
681 | 657 |
682 return real_parent; | 658 return real_parent; |
683 } | 659 } |
684 | 660 |
685 } // namespace bookmark_utils | 661 } // namespace bookmark_utils |
OLD | NEW |