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

Side by Side Diff: chrome/browser/resources/bookmark_manager/js/main.js

Issue 10244005: convert bookmark manager to loadTimeData from localStrings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remember to git add Created 8 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** @const */ var BookmarkList = bmm.BookmarkList; 5 /** @const */ var BookmarkList = bmm.BookmarkList;
6 /** @const */ var BookmarkTree = bmm.BookmarkTree; 6 /** @const */ var BookmarkTree = bmm.BookmarkTree;
7 /** @const */ var Command = cr.ui.Command; 7 /** @const */ var Command = cr.ui.Command;
8 /** @const */ var CommandBinding = cr.ui.CommandBinding; 8 /** @const */ var CommandBinding = cr.ui.CommandBinding;
9 /** @const */ var LinkKind = cr.LinkKind; 9 /** @const */ var LinkKind = cr.LinkKind;
10 /** @const */ var ListItem = cr.ui.ListItem; 10 /** @const */ var ListItem = cr.ui.ListItem;
11 /** @const */ var Menu = cr.ui.Menu; 11 /** @const */ var Menu = cr.ui.Menu;
12 /** @const */ var MenuButton = cr.ui.MenuButton; 12 /** @const */ var MenuButton = cr.ui.MenuButton;
13 /** @const */ var Promise = cr.Promise; 13 /** @const */ var Promise = cr.Promise;
14 /** @const */ var Splitter = cr.ui.Splitter; 14 /** @const */ var Splitter = cr.ui.Splitter;
15 /** @const */ var TreeItem = cr.ui.TreeItem; 15 /** @const */ var TreeItem = cr.ui.TreeItem;
16 16
17 // Sometimes the extension API is not initialized. 17 // Sometimes the extension API is not initialized.
18 if (!chrome.bookmarks) 18 if (!chrome.bookmarks)
19 console.error('Bookmarks extension API is not available'); 19 console.error('Bookmarks extension API is not available');
20 20
21 /**
22 * The local strings object which is used to do the translation.
23 * @type {!LocalStrings}
24 */
25 var localStrings = new LocalStrings;
26
27 // Get the localized strings from the backend. 21 // Get the localized strings from the backend.
28 chrome.experimental.bookmarkManager.getStrings(function(data) { 22 chrome.experimental.bookmarkManager.getStrings(function(data) {
29 // The strings may contain & which we need to strip. 23 // The strings may contain & which we need to strip.
30 for (var key in data) { 24 for (var key in data) {
31 data[key] = data[key].replace(/&/, ''); 25 data[key] = data[key].replace(/&/, '');
32 } 26 }
33 27
34 localStrings.templateData = data; 28 loadTimeData.data = data;
35 i18nTemplate.process(document, data); 29 i18nTemplate.process(document, loadTimeData);
36 30
37 recentTreeItem.label = localStrings.getString('recent'); 31 recentTreeItem.label = loadTimeData.getString('recent');
38 searchTreeItem.label = localStrings.getString('search'); 32 searchTreeItem.label = loadTimeData.getString('search');
39 if (!isRTL()) 33 if (!isRTL())
40 searchTreeItem.icon = 'images/bookmark_manager_search.png' 34 searchTreeItem.icon = 'images/bookmark_manager_search.png'
41 else 35 else
42 searchTreeItem.icon = 'images/bookmark_manager_search_rtl.png' 36 searchTreeItem.icon = 'images/bookmark_manager_search_rtl.png'
43 }); 37 });
44 38
45 /** 39 /**
46 * The id of the bookmark root. 40 * The id of the bookmark root.
47 * @type {number} 41 * @type {number}
48 */ 42 */
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 for (var i = 0; i < node.children.length; i++) { 876 for (var i = 0; i < node.children.length; i++) {
883 if (!bmm.isFolder(node.children[i])) 877 if (!bmm.isFolder(node.children[i]))
884 return true; 878 return true;
885 } 879 }
886 return false; 880 return false;
887 } 881 }
888 882
889 var commandDisabled = false; 883 var commandDisabled = false;
890 switch (command.id) { 884 switch (command.id) {
891 case 'open-in-new-tab-command': 885 case 'open-in-new-tab-command':
892 command.label = localStrings.getString(multiple ? 886 command.label = loadTimeData.getString(multiple ?
893 'open_all' : 'open_in_new_tab'); 887 'open_all' : 'open_in_new_tab');
894 break; 888 break;
895 889
896 case 'open-in-new-window-command': 890 case 'open-in-new-window-command':
897 command.label = localStrings.getString(multiple ? 891 command.label = loadTimeData.getString(multiple ?
898 'open_all_new_window' : 'open_in_new_window'); 892 'open_all_new_window' : 'open_in_new_window');
899 // Disabled when incognito is forced. 893 // Disabled when incognito is forced.
900 commandDisabled = incognitoModeAvailability == 'forced'; 894 commandDisabled = incognitoModeAvailability == 'forced';
901 break; 895 break;
902 case 'open-incognito-window-command': 896 case 'open-incognito-window-command':
903 command.label = localStrings.getString(multiple ? 897 command.label = loadTimeData.getString(multiple ?
904 'open_all_incognito' : 'open_incognito'); 898 'open_all_incognito' : 'open_incognito');
905 // Not available withn incognito is disabled. 899 // Not available withn incognito is disabled.
906 commandDisabled = incognitoModeAvailability == 'disabled'; 900 commandDisabled = incognitoModeAvailability == 'disabled';
907 break; 901 break;
908 } 902 }
909 e.canExecute = selectionCount > 0 && !!selectedItem && !commandDisabled; 903 e.canExecute = selectionCount > 0 && !!selectedItem && !commandDisabled;
910 if (isFolder && e.canExecute) { 904 if (isFolder && e.canExecute) {
911 // We need to get all the bookmark items in this tree. If the tree does not 905 // We need to get all the bookmark items in this tree. If the tree does not
912 // contain any non-folders, we need to disable the command. 906 // contain any non-folders, we need to disable the command.
913 var p = bmm.loadSubtree(selectedItem.id); 907 var p = bmm.loadSubtree(selectedItem.id);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1250 }
1257 1251
1258 var linkController; 1252 var linkController;
1259 1253
1260 /** 1254 /**
1261 * @return {!cr.LinkController} The link controller used to open links based on 1255 * @return {!cr.LinkController} The link controller used to open links based on
1262 * user clicks and keyboard actions. 1256 * user clicks and keyboard actions.
1263 */ 1257 */
1264 function getLinkController() { 1258 function getLinkController() {
1265 return linkController || 1259 return linkController ||
1266 (linkController = new cr.LinkController(localStrings)); 1260 (linkController = new cr.LinkController(loadTimeData));
Dan Beam 2012/05/08 22:34:25 nit: I think this could be less succinct but more
Evan Stade 2012/05/08 23:32:13 I was not the author, and I have no trouble readin
Dan Beam 2012/05/08 23:46:51 I think it'd be more readable as: if (!linkCont
Evan Stade 2012/05/09 23:16:54 actually, it's not a matter of preference in C++,
1267 } 1261 }
1268 1262
1269 /** 1263 /**
1270 * Returns the selected bookmark nodes of the active element. Only call this 1264 * Returns the selected bookmark nodes of the active element. Only call this
1271 * if the list or the tree is focused. 1265 * if the list or the tree is focused.
1272 * @return {!Array} Array of bookmark nodes. 1266 * @return {!Array} Array of bookmark nodes.
1273 */ 1267 */
1274 function getSelectedBookmarkNodes() { 1268 function getSelectedBookmarkNodes() {
1275 if (document.activeElement == list) { 1269 if (document.activeElement == list) {
1276 return list.selectedItems; 1270 return list.selectedItems;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 } 1415 }
1422 1416
1423 /** 1417 /**
1424 * Callback for the new folder command. This creates a new folder and starts 1418 * Callback for the new folder command. This creates a new folder and starts
1425 * a rename of it. 1419 * a rename of it.
1426 */ 1420 */
1427 function newFolder() { 1421 function newFolder() {
1428 var parentId = list.parentId; 1422 var parentId = list.parentId;
1429 var isTree = document.activeElement == tree; 1423 var isTree = document.activeElement == tree;
1430 chrome.bookmarks.create({ 1424 chrome.bookmarks.create({
1431 title: localStrings.getString('new_folder_name'), 1425 title: loadTimeData.getString('new_folder_name'),
1432 parentId: parentId 1426 parentId: parentId
1433 }, function(newNode) { 1427 }, function(newNode) {
1434 // This callback happens before the event that triggers the tree/list to 1428 // This callback happens before the event that triggers the tree/list to
1435 // get updated so delay the work so that the tree/list gets updated first. 1429 // get updated so delay the work so that the tree/list gets updated first.
1436 setTimeout(function() { 1430 setTimeout(function() {
1437 var newItem; 1431 var newItem;
1438 if (isTree) { 1432 if (isTree) {
1439 newItem = bmm.treeLookup[newNode.id]; 1433 newItem = bmm.treeLookup[newNode.id];
1440 tree.selectedItem = newItem; 1434 tree.selectedItem = newItem;
1441 newItem.editing = true; 1435 newItem.editing = true;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 document.addEventListener('copy', handle('copy-command')); 1637 document.addEventListener('copy', handle('copy-command'));
1644 document.addEventListener('cut', handle('cut-command')); 1638 document.addEventListener('cut', handle('cut-command'));
1645 1639
1646 var pasteHandler = handle('paste-command'); 1640 var pasteHandler = handle('paste-command');
1647 document.addEventListener('paste', function(e) { 1641 document.addEventListener('paste', function(e) {
1648 // Paste is a bit special since we need to do an async call to see if we can 1642 // Paste is a bit special since we need to do an async call to see if we can
1649 // paste because the paste command might not be up to date. 1643 // paste because the paste command might not be up to date.
1650 updatePasteCommand(pasteHandler); 1644 updatePasteCommand(pasteHandler);
1651 }); 1645 });
1652 })(); 1646 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698