OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/views/bookmarks/bookmark_editor_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_editor_view.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 void BookmarkEditorView::Init() { | 261 void BookmarkEditorView::Init() { |
262 bb_model_ = profile_->GetBookmarkModel(); | 262 bb_model_ = profile_->GetBookmarkModel(); |
263 DCHECK(bb_model_); | 263 DCHECK(bb_model_); |
264 bb_model_->AddObserver(this); | 264 bb_model_->AddObserver(this); |
265 | 265 |
266 url_tf_.set_parent_owned(false); | 266 url_tf_.set_parent_owned(false); |
267 title_tf_.set_parent_owned(false); | 267 title_tf_.set_parent_owned(false); |
268 | 268 |
269 std::wstring title; | 269 std::wstring title; |
270 if (details_.type == EditDetails::EXISTING_NODE) | 270 GURL url; |
| 271 if (details_.type == EditDetails::EXISTING_NODE) { |
271 title = details_.existing_node->GetTitle(); | 272 title = details_.existing_node->GetTitle(); |
272 else if (details_.type == EditDetails::NEW_FOLDER) | 273 url = details_.existing_node->GetURL(); |
| 274 } else if (details_.type == EditDetails::NEW_FOLDER) { |
273 title = UTF16ToWide( | 275 title = UTF16ToWide( |
274 l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)); | 276 l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME)); |
| 277 } else if (details_.type == EditDetails::NEW_URL) { |
| 278 string16 title16; |
| 279 bookmark_utils::GetURLAndTitleToBookmarkFromCurrentTab(profile_, |
| 280 &url, &title16); |
| 281 title = UTF16ToWide(title16); |
| 282 } |
275 title_tf_.SetText(title); | 283 title_tf_.SetText(title); |
276 title_tf_.SetController(this); | 284 title_tf_.SetController(this); |
277 | 285 |
278 title_label_ = new views::Label( | 286 title_label_ = new views::Label( |
279 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NAME_LABEL))); | 287 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_NAME_LABEL))); |
280 title_tf_.SetAccessibleName(WideToUTF16Hack(title_label_->GetText())); | 288 title_tf_.SetAccessibleName(WideToUTF16Hack(title_label_->GetText())); |
281 | 289 |
282 string16 url_text; | 290 string16 url_text; |
283 if (details_.type == EditDetails::EXISTING_NODE) { | 291 if (details_.type != EditDetails::NEW_FOLDER) { |
284 std::string languages = profile_ | 292 std::string languages = profile_ |
285 ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) | 293 ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) |
286 : std::string(); | 294 : std::string(); |
287 // Because this gets parsed by FixupURL(), it's safe to omit the scheme or | 295 // Because this gets parsed by FixupURL(), it's safe to omit the scheme or |
288 // trailing slash, and unescape most characters, but we need to not drop any | 296 // trailing slash, and unescape most characters, but we need to not drop any |
289 // username/password, or unescape anything that changes the meaning. | 297 // username/password, or unescape anything that changes the meaning. |
290 url_text = net::FormatUrl(details_.existing_node->GetURL(), languages, | 298 url_text = net::FormatUrl(url, languages, |
291 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, | 299 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, |
292 UnescapeRule::SPACES, NULL, NULL, NULL); | 300 UnescapeRule::SPACES, NULL, NULL, NULL); |
293 } | 301 } |
294 url_tf_.SetText(UTF16ToWide(url_text)); | 302 url_tf_.SetText(UTF16ToWide(url_text)); |
295 url_tf_.SetController(this); | 303 url_tf_.SetController(this); |
296 | 304 |
297 url_label_ = new views::Label( | 305 url_label_ = new views::Label( |
298 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_URL_LABEL))); | 306 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_EDITOR_URL_LABEL))); |
299 url_tf_.SetAccessibleName(WideToUTF16Hack(url_label_->GetText())); | 307 url_tf_.SetAccessibleName(WideToUTF16Hack(url_label_->GetText())); |
300 | 308 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 break; | 586 break; |
579 } | 587 } |
580 } | 588 } |
581 DCHECK(child_bb_node); | 589 DCHECK(child_bb_node); |
582 bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle()); | 590 bb_model_->SetTitle(child_bb_node, child_b_node->GetTitle()); |
583 } | 591 } |
584 ApplyNameChangesAndCreateNewFolders(child_bb_node, child_b_node, | 592 ApplyNameChangesAndCreateNewFolders(child_bb_node, child_b_node, |
585 parent_b_node, parent_bb_node); | 593 parent_b_node, parent_bb_node); |
586 } | 594 } |
587 } | 595 } |
OLD | NEW |