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

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: leave all_tabs alone 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 BookmarkList = bmm.BookmarkList; 5 const BookmarkList = bmm.BookmarkList;
6 const BookmarkTree = bmm.BookmarkTree; 6 const BookmarkTree = bmm.BookmarkTree;
7 const ListItem = cr.ui.ListItem; 7 const ListItem = cr.ui.ListItem;
8 const TreeItem = cr.ui.TreeItem; 8 const TreeItem = cr.ui.TreeItem;
9 const LinkKind = cr.LinkKind; 9 const LinkKind = cr.LinkKind;
10 const Command = cr.ui.Command; 10 const Command = cr.ui.Command;
11 const CommandBinding = cr.ui.CommandBinding; 11 const CommandBinding = cr.ui.CommandBinding;
12 const Menu = cr.ui.Menu; 12 const Menu = cr.ui.Menu;
13 const MenuButton = cr.ui.MenuButton; 13 const MenuButton = cr.ui.MenuButton;
14 const Promise = cr.Promise; 14 const Promise = cr.Promise;
15 15
16 // Sometimes the extension API is not initialized. 16 // Sometimes the extension API is not initialized.
17 if (!chrome.bookmarks) 17 if (!chrome.bookmarks)
18 console.error('Bookmarks extension API is not available'); 18 console.error('Bookmarks extension API is not available');
19 19
20 /**
21 * The local strings object which is used to do the translation.
22 * @type {!LocalStrings}
23 */
24 var localStrings = new LocalStrings;
25
26 // Get the localized strings from the backend. 20 // Get the localized strings from the backend.
27 chrome.experimental.bookmarkManager.getStrings(function(data) { 21 chrome.experimental.bookmarkManager.getStrings(function(data) {
28 // The strings may contain & which we need to strip. 22 // The strings may contain & which we need to strip.
29 for (var key in data) { 23 for (var key in data) {
30 data[key] = data[key].replace(/&/, ''); 24 data[key] = data[key].replace(/&/, '');
31 } 25 }
32 26
33 localStrings.templateData = data; 27 loadTimeData.data = data;
34 i18nTemplate.process(document, data); 28 var process = document.createElement('script');
29 process.src = 'chrome://resources/js/i18n_template2.js';
arv (Not doing code reviews) 2012/05/03 02:13:40 I don't like. Why is this done in this way?
Dan Beam 2012/05/03 03:33:55 I assumed because we're only setting the loadTimeD
Evan Stade 2012/05/03 21:14:44 yes. i18n_template2.js automatically processes.
30 document.body.appendChild(process);
35 31
36 recentTreeItem.label = localStrings.getString('recent'); 32 recentTreeItem.label = loadTimeData.getString('recent');
37 searchTreeItem.label = localStrings.getString('search'); 33 searchTreeItem.label = loadTimeData.getString('search');
38 if (!isRTL()) 34 if (!isRTL())
39 searchTreeItem.icon = 'images/bookmark_manager_search.png' 35 searchTreeItem.icon = 'images/bookmark_manager_search.png'
40 else 36 else
41 searchTreeItem.icon = 'images/bookmark_manager_search_rtl.png' 37 searchTreeItem.icon = 'images/bookmark_manager_search_rtl.png'
42 }); 38 });
43 39
44 /** 40 /**
45 * The id of the bookmark root. 41 * The id of the bookmark root.
46 * @type {number} 42 * @type {number}
47 */ 43 */
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 for (var i = 0; i < node.children.length; i++) { 864 for (var i = 0; i < node.children.length; i++) {
869 if (!bmm.isFolder(node.children[i])) 865 if (!bmm.isFolder(node.children[i]))
870 return true; 866 return true;
871 } 867 }
872 return false; 868 return false;
873 } 869 }
874 870
875 var commandDisabled = false; 871 var commandDisabled = false;
876 switch (command.id) { 872 switch (command.id) {
877 case 'open-in-new-tab-command': 873 case 'open-in-new-tab-command':
878 command.label = localStrings.getString(multiple ? 874 command.label = loadTimeData.getString(multiple ?
879 'open_all' : 'open_in_new_tab'); 875 'open_all' : 'open_in_new_tab');
880 break; 876 break;
881 877
882 case 'open-in-new-window-command': 878 case 'open-in-new-window-command':
883 command.label = localStrings.getString(multiple ? 879 command.label = loadTimeData.getString(multiple ?
884 'open_all_new_window' : 'open_in_new_window'); 880 'open_all_new_window' : 'open_in_new_window');
885 // Disabled when incognito is forced. 881 // Disabled when incognito is forced.
886 commandDisabled = incognitoModeAvailability == 'forced'; 882 commandDisabled = incognitoModeAvailability == 'forced';
887 break; 883 break;
888 case 'open-incognito-window-command': 884 case 'open-incognito-window-command':
889 command.label = localStrings.getString(multiple ? 885 command.label = loadTimeData.getString(multiple ?
890 'open_all_incognito' : 'open_incognito'); 886 'open_all_incognito' : 'open_incognito');
891 // Not available withn incognito is disabled. 887 // Not available withn incognito is disabled.
892 commandDisabled = incognitoModeAvailability == 'disabled'; 888 commandDisabled = incognitoModeAvailability == 'disabled';
893 break; 889 break;
894 } 890 }
895 e.canExecute = selectionCount > 0 && !!selectedItem && !commandDisabled; 891 e.canExecute = selectionCount > 0 && !!selectedItem && !commandDisabled;
896 if (isFolder && e.canExecute) { 892 if (isFolder && e.canExecute) {
897 // We need to get all the bookmark items in this tree. If the tree does not 893 // We need to get all the bookmark items in this tree. If the tree does not
898 // contain any non-folders, we need to disable the command. 894 // contain any non-folders, we need to disable the command.
899 var p = bmm.loadSubtree(selectedItem.id); 895 var p = bmm.loadSubtree(selectedItem.id);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 } 1222 }
1227 1223
1228 var linkController; 1224 var linkController;
1229 1225
1230 /** 1226 /**
1231 * @return {!cr.LinkController} The link controller used to open links based on 1227 * @return {!cr.LinkController} The link controller used to open links based on
1232 * user clicks and keyboard actions. 1228 * user clicks and keyboard actions.
1233 */ 1229 */
1234 function getLinkController() { 1230 function getLinkController() {
1235 return linkController || 1231 return linkController ||
1236 (linkController = new cr.LinkController(localStrings)); 1232 (linkController = new cr.LinkController(loadTimeData));
1237 } 1233 }
1238 1234
1239 /** 1235 /**
1240 * Returns the selected bookmark nodes of the active element. Only call this 1236 * Returns the selected bookmark nodes of the active element. Only call this
1241 * if the list or the tree is focused. 1237 * if the list or the tree is focused.
1242 * @return {!Array} Array of bookmark nodes. 1238 * @return {!Array} Array of bookmark nodes.
1243 */ 1239 */
1244 function getSelectedBookmarkNodes() { 1240 function getSelectedBookmarkNodes() {
1245 if (document.activeElement == list) { 1241 if (document.activeElement == list) {
1246 return list.selectedItems; 1242 return list.selectedItems;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 } 1325 }
1330 1326
1331 /** 1327 /**
1332 * Callback for the new folder command. This creates a new folder and starts 1328 * Callback for the new folder command. This creates a new folder and starts
1333 * a rename of it. 1329 * a rename of it.
1334 */ 1330 */
1335 function newFolder() { 1331 function newFolder() {
1336 var parentId = list.parentId; 1332 var parentId = list.parentId;
1337 var isTree = document.activeElement == tree; 1333 var isTree = document.activeElement == tree;
1338 chrome.bookmarks.create({ 1334 chrome.bookmarks.create({
1339 title: localStrings.getString('new_folder_name'), 1335 title: loadTimeData.getString('new_folder_name'),
1340 parentId: parentId 1336 parentId: parentId
1341 }, function(newNode) { 1337 }, function(newNode) {
1342 // This callback happens before the event that triggers the tree/list to 1338 // This callback happens before the event that triggers the tree/list to
1343 // get updated so delay the work so that the tree/list gets updated first. 1339 // get updated so delay the work so that the tree/list gets updated first.
1344 setTimeout(function() { 1340 setTimeout(function() {
1345 var newItem; 1341 var newItem;
1346 if (isTree) { 1342 if (isTree) {
1347 newItem = bmm.treeLookup[newNode.id]; 1343 newItem = bmm.treeLookup[newNode.id];
1348 tree.selectedItem = newItem; 1344 tree.selectedItem = newItem;
1349 newItem.editing = true; 1345 newItem.editing = true;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 document.addEventListener('copy', handle('copy-command')); 1540 document.addEventListener('copy', handle('copy-command'));
1545 document.addEventListener('cut', handle('cut-command')); 1541 document.addEventListener('cut', handle('cut-command'));
1546 1542
1547 var pasteHandler = handle('paste-command'); 1543 var pasteHandler = handle('paste-command');
1548 document.addEventListener('paste', function(e) { 1544 document.addEventListener('paste', function(e) {
1549 // Paste is a bit special since we need to do an async call to see if we can 1545 // Paste is a bit special since we need to do an async call to see if we can
1550 // paste because the paste command might not be up to date. 1546 // paste because the paste command might not be up to date.
1551 updatePasteCommand(pasteHandler); 1547 updatePasteCommand(pasteHandler);
1552 }); 1548 });
1553 })(); 1549 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/bookmark_manager/js/bmm/bookmark_list.js ('k') | chrome/browser/resources/bookmark_manager/main.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698