Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 (function() { | 5 (function() { |
| 6 /** @const */ var BookmarkList = bmm.BookmarkList; | 6 /** @const */ var BookmarkList = bmm.BookmarkList; |
| 7 /** @const */ var BookmarkTree = bmm.BookmarkTree; | 7 /** @const */ var BookmarkTree = bmm.BookmarkTree; |
| 8 /** @const */ var Command = cr.ui.Command; | 8 /** @const */ var Command = cr.ui.Command; |
| 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; |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 | 1022 |
| 1023 /** | 1023 /** |
| 1024 * Callback for the new folder command. This creates a new folder and starts | 1024 * Callback for the new folder command. This creates a new folder and starts |
| 1025 * a rename of it. | 1025 * a rename of it. |
| 1026 * @param {EventTarget=} opt_target The target to create a new folder in. | 1026 * @param {EventTarget=} opt_target The target to create a new folder in. |
| 1027 */ | 1027 */ |
| 1028 function newFolder(opt_target) { | 1028 function newFolder(opt_target) { |
| 1029 performGlobalUndo = null; // This can't be undone, so disable global undo. | 1029 performGlobalUndo = null; // This can't be undone, so disable global undo. |
| 1030 | 1030 |
| 1031 var parentId = computeParentFolderForNewItem(); | 1031 var parentId = computeParentFolderForNewItem(); |
| 1032 | 1032 var newIndex, selectedItem = bmm.list.selectedItem; |
|
Bernhard Bauer
2014/12/23 11:54:36
Declare each variable on a separate line.
Deepak
2014/12/23 12:43:23
Done.
| |
| 1033 // Callback is called after tree and list data model updated. | 1033 // Callback is called after tree and list data model updated. |
| 1034 function createFolder(callback) { | 1034 function createFolder(callback) { |
| 1035 if (selectedItem && document.activeElement != bmm.tree && | |
| 1036 !bmm.isFolder(selectedItem)) { | |
| 1037 newIndex = bmm.list.dataModel.indexOf(selectedItem) + 1; | |
| 1038 } | |
| 1035 chrome.bookmarks.create({ | 1039 chrome.bookmarks.create({ |
| 1036 title: loadTimeData.getString('new_folder_name'), | 1040 title: loadTimeData.getString('new_folder_name'), |
| 1037 parentId: parentId | 1041 parentId: parentId, |
| 1042 index: newIndex | |
| 1038 }, callback); | 1043 }, callback); |
| 1039 } | 1044 } |
| 1040 | 1045 |
| 1041 if ((opt_target || document.activeElement) == bmm.tree) { | 1046 if ((opt_target || document.activeElement) == bmm.tree) { |
| 1042 createFolder(function(newNode) { | 1047 createFolder(function(newNode) { |
| 1043 navigateTo(newNode.id, function() { | 1048 navigateTo(newNode.id, function() { |
| 1044 bmm.treeLookup[newNode.id].editing = true; | 1049 bmm.treeLookup[newNode.id].editing = true; |
| 1045 }); | 1050 }); |
| 1046 }); | 1051 }); |
| 1047 return; | 1052 return; |
| 1048 } | 1053 } |
| 1049 | 1054 |
| 1050 function editNewFolderInList() { | 1055 function editNewFolderInList() { |
| 1051 createFolder(function() { | 1056 createFolder(function() { |
| 1052 var index = bmm.list.dataModel.length - 1; | 1057 var index = bmm.list.dataModel.length - 1; |
| 1058 if (newIndex && newIndex <= index) | |
| 1059 index = newIndex; | |
| 1053 var sm = bmm.list.selectionModel; | 1060 var sm = bmm.list.selectionModel; |
| 1054 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; | 1061 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; |
| 1055 scrollIntoViewAndMakeEditable(index); | 1062 scrollIntoViewAndMakeEditable(index); |
| 1056 }); | 1063 }); |
| 1057 } | 1064 } |
| 1058 | 1065 |
| 1059 navigateTo(parentId, editNewFolderInList); | 1066 navigateTo(parentId, editNewFolderInList); |
| 1060 } | 1067 } |
| 1061 | 1068 |
| 1062 /** | 1069 /** |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1073 item.editing = true; | 1080 item.editing = true; |
| 1074 }, 0); | 1081 }, 0); |
| 1075 } | 1082 } |
| 1076 | 1083 |
| 1077 /** | 1084 /** |
| 1078 * Adds a page to the current folder. This is called by the | 1085 * Adds a page to the current folder. This is called by the |
| 1079 * add-new-bookmark-command handler. | 1086 * add-new-bookmark-command handler. |
| 1080 */ | 1087 */ |
| 1081 function addPage() { | 1088 function addPage() { |
| 1082 var parentId = computeParentFolderForNewItem(); | 1089 var parentId = computeParentFolderForNewItem(); |
| 1090 var newIndex, selectedItem = bmm.list.selectedItem; | |
| 1091 function editNewBookmark() { | |
| 1092 if (selectedItem && document.activeElement != bmm.tree && | |
| 1093 !bmm.isFolder(selectedItem)) { | |
| 1094 newIndex = bmm.list.dataModel.indexOf(selectedItem) + 1; | |
| 1095 } | |
| 1083 | 1096 |
| 1084 function editNewBookmark() { | |
| 1085 var fakeNode = { | 1097 var fakeNode = { |
| 1086 title: '', | 1098 title: '', |
| 1087 url: '', | 1099 url: '', |
| 1088 parentId: parentId, | 1100 parentId: parentId, |
| 1101 index: newIndex, | |
| 1089 id: 'new' | 1102 id: 'new' |
| 1090 }; | 1103 }; |
| 1091 var dataModel = bmm.list.dataModel; | 1104 var dataModel = bmm.list.dataModel; |
| 1092 var length = dataModel.length; | 1105 var index = dataModel.length; |
| 1093 dataModel.splice(length, 0, fakeNode); | 1106 if (newIndex && newIndex <= index) |
|
Bernhard Bauer
2014/12/23 11:54:36
You probably want to check for (newIndex != undefi
Deepak
2014/12/23 12:43:23
I agree with you.
Changes done as suggested.
| |
| 1107 index = newIndex; | |
| 1108 dataModel.splice(index, 0, fakeNode); | |
| 1094 var sm = bmm.list.selectionModel; | 1109 var sm = bmm.list.selectionModel; |
| 1095 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = length; | 1110 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; |
| 1096 scrollIntoViewAndMakeEditable(length); | 1111 scrollIntoViewAndMakeEditable(index); |
| 1097 }; | 1112 }; |
| 1098 | 1113 |
| 1099 navigateTo(parentId, editNewBookmark); | 1114 navigateTo(parentId, editNewBookmark); |
| 1100 } | 1115 } |
| 1101 | 1116 |
| 1102 /** | 1117 /** |
| 1103 * This function is used to select items after a user action such as paste, drop | 1118 * This function is used to select items after a user action such as paste, drop |
| 1104 * add page etc. | 1119 * add page etc. |
| 1105 * @param {BookmarkList|BookmarkTree} target The target of the user action. | 1120 * @param {BookmarkList|BookmarkTree} target The target of the user action. |
| 1106 * @param {string=} opt_selectedTreeId If provided, then select that tree id. | 1121 * @param {string=} opt_selectedTreeId If provided, then select that tree id. |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1491 | 1506 |
| 1492 cr.ui.FocusOutlineManager.forDocument(document); | 1507 cr.ui.FocusOutlineManager.forDocument(document); |
| 1493 initializeSplitter(); | 1508 initializeSplitter(); |
| 1494 bmm.addBookmarkModelListeners(); | 1509 bmm.addBookmarkModelListeners(); |
| 1495 dnd.init(selectItemsAfterUserAction); | 1510 dnd.init(selectItemsAfterUserAction); |
| 1496 bmm.tree.reload(); | 1511 bmm.tree.reload(); |
| 1497 } | 1512 } |
| 1498 | 1513 |
| 1499 initializeBookmarkManager(); | 1514 initializeBookmarkManager(); |
| 1500 })(); | 1515 })(); |
| OLD | NEW |