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 = ''; |
|
Bernhard Bauer
2014/12/22 11:58:20
|newIndex| is supposed to be an integer. Just beca
Deepak
2014/12/23 04:27:48
Done.
| |
| 1033 var selectedItem = bmm.list.selectedItem; | |
| 1033 // Callback is called after tree and list data model updated. | 1034 // Callback is called after tree and list data model updated. |
| 1034 function createFolder(callback) { | 1035 function createFolder(callback) { |
| 1036 if (selectedItem && document.activeElement != bmm.tree) { | |
|
Bernhard Bauer
2014/12/22 11:58:20
The indentation is way off in this CL. I would sug
Deepak
2014/12/23 04:27:47
Can you please tell me in specific about this.
Bernhard Bauer
2014/12/23 11:54:36
The issues are fixed now.
| |
| 1037 if (!bmm.isFolder(selectedItem)) | |
| 1038 newIndex = 1 + bmm.list.dataModel.indexOf(selectedItem); | |
|
Bernhard Bauer
2014/12/22 11:58:20
It's more idiomatic to put the constant summand as
Deepak
2014/12/23 04:27:47
Done.
| |
| 1039 } | |
| 1040 if (newIndex != '') { | |
| 1041 chrome.bookmarks.create({ | |
| 1042 title: loadTimeData.getString('new_folder_name'), | |
| 1043 parentId: parentId, | |
| 1044 index: newIndex | |
| 1045 }, callback); | |
| 1046 } else { | |
| 1047 // As create bookmark folder does not create bookmark node for empty index. | |
|
Bernhard Bauer
2014/12/22 11:58:21
I have no idea what this comment is supposed to me
Deepak
2014/12/23 04:27:48
This part of code is not required after taking new
| |
| 1035 chrome.bookmarks.create({ | 1048 chrome.bookmarks.create({ |
| 1036 title: loadTimeData.getString('new_folder_name'), | 1049 title: loadTimeData.getString('new_folder_name'), |
| 1037 parentId: parentId | 1050 parentId: parentId |
| 1038 }, callback); | 1051 }, callback); |
| 1052 } | |
| 1039 } | 1053 } |
| 1040 | 1054 |
| 1041 if ((opt_target || document.activeElement) == bmm.tree) { | 1055 if ((opt_target || document.activeElement) == bmm.tree) { |
| 1042 createFolder(function(newNode) { | 1056 createFolder(function(newNode) { |
| 1043 navigateTo(newNode.id, function() { | 1057 navigateTo(newNode.id, function() { |
| 1044 bmm.treeLookup[newNode.id].editing = true; | 1058 bmm.treeLookup[newNode.id].editing = true; |
| 1045 }); | 1059 }); |
| 1046 }); | 1060 }); |
| 1047 return; | 1061 return; |
| 1048 } | 1062 } |
| 1049 | 1063 |
| 1050 function editNewFolderInList() { | 1064 function editNewFolderInList() { |
| 1051 createFolder(function() { | 1065 createFolder(function() { |
| 1052 var index = bmm.list.dataModel.length - 1; | 1066 var length = bmm.list.dataModel.length - 1; |
| 1067 if (newIndex != '' && newIndex <= length) | |
|
Bernhard Bauer
2014/12/22 11:58:20
This callback will be called asynchronously. What
Deepak
2014/12/23 04:27:47
I understand.
Can you please tell me some way to r
Bernhard Bauer
2014/12/23 11:54:36
I don't know how to reproduce this, but the onus i
| |
| 1068 length = newIndex; | |
|
Bernhard Bauer
2014/12/22 11:58:20
Why do you rename this variable to |length|, but t
Deepak
2014/12/23 04:27:48
Done.
| |
| 1053 var sm = bmm.list.selectionModel; | 1069 var sm = bmm.list.selectionModel; |
| 1054 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; | 1070 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = length; |
| 1055 scrollIntoViewAndMakeEditable(index); | 1071 scrollIntoViewAndMakeEditable(length); |
| 1056 }); | 1072 }); |
| 1057 } | 1073 } |
| 1058 | 1074 |
| 1059 navigateTo(parentId, editNewFolderInList); | 1075 navigateTo(parentId, editNewFolderInList); |
| 1060 } | 1076 } |
| 1061 | 1077 |
| 1062 /** | 1078 /** |
| 1063 * Scrolls the list item into view and makes it editable. | 1079 * Scrolls the list item into view and makes it editable. |
| 1064 * @param {number} index The index of the item to make editable. | 1080 * @param {number} index The index of the item to make editable. |
| 1065 */ | 1081 */ |
| 1066 function scrollIntoViewAndMakeEditable(index) { | 1082 function scrollIntoViewAndMakeEditable(index) { |
| 1067 bmm.list.scrollIndexIntoView(index); | 1083 bmm.list.scrollIndexIntoView(index); |
| 1068 // onscroll is now dispatched asynchronously so we have to postpone | 1084 // onscroll is now dispatched asynchronously so we have to postpone |
| 1069 // the rest. | 1085 // the rest. |
| 1070 setTimeout(function() { | 1086 setTimeout(function() { |
| 1071 var item = bmm.list.getListItemByIndex(index); | 1087 var item = bmm.list.getListItemByIndex(index); |
| 1072 if (item) | 1088 if (item) |
| 1073 item.editing = true; | 1089 item.editing = true; |
| 1074 }, 0); | 1090 }, 0); |
| 1075 } | 1091 } |
| 1076 | 1092 |
| 1077 /** | 1093 /** |
| 1078 * Adds a page to the current folder. This is called by the | 1094 * Adds a page to the current folder. This is called by the |
| 1079 * add-new-bookmark-command handler. | 1095 * add-new-bookmark-command handler. |
| 1080 */ | 1096 */ |
| 1081 function addPage() { | 1097 function addPage() { |
| 1082 var parentId = computeParentFolderForNewItem(); | 1098 var parentId = computeParentFolderForNewItem(); |
| 1099 var newIndex = ''; | |
| 1100 var selectedItem = bmm.list.selectedItem; | |
| 1101 function editNewBookmark() { | |
| 1102 if (selectedItem && document.activeElement != bmm.tree) { | |
| 1103 if (!bmm.isFolder(selectedItem)) | |
| 1104 newIndex = 1 + bmm.list.dataModel.indexOf(selectedItem); | |
| 1105 } | |
| 1083 | 1106 |
| 1084 function editNewBookmark() { | |
| 1085 var fakeNode = { | 1107 var fakeNode = { |
| 1086 title: '', | 1108 title: '', |
| 1087 url: '', | 1109 url: '', |
| 1088 parentId: parentId, | 1110 parentId: parentId, |
| 1111 index: newIndex, | |
| 1089 id: 'new' | 1112 id: 'new' |
| 1090 }; | 1113 }; |
| 1091 var dataModel = bmm.list.dataModel; | 1114 var dataModel = bmm.list.dataModel; |
| 1092 var length = dataModel.length; | 1115 var length = dataModel.length; |
| 1116 if (newIndex != '' && newIndex <= length) | |
| 1117 length = newIndex; | |
|
Bernhard Bauer
2014/12/22 11:58:20
Same here; this is not really a length anymore, it
Deepak
2014/12/23 04:27:47
Done.
| |
| 1093 dataModel.splice(length, 0, fakeNode); | 1118 dataModel.splice(length, 0, fakeNode); |
| 1094 var sm = bmm.list.selectionModel; | 1119 var sm = bmm.list.selectionModel; |
| 1095 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = length; | 1120 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = length; |
| 1096 scrollIntoViewAndMakeEditable(length); | 1121 scrollIntoViewAndMakeEditable(length); |
| 1097 }; | 1122 }; |
| 1098 | 1123 |
| 1099 navigateTo(parentId, editNewBookmark); | 1124 navigateTo(parentId, editNewBookmark); |
| 1100 } | 1125 } |
| 1101 | 1126 |
| 1102 /** | 1127 /** |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1491 | 1516 |
| 1492 cr.ui.FocusOutlineManager.forDocument(document); | 1517 cr.ui.FocusOutlineManager.forDocument(document); |
| 1493 initializeSplitter(); | 1518 initializeSplitter(); |
| 1494 bmm.addBookmarkModelListeners(); | 1519 bmm.addBookmarkModelListeners(); |
| 1495 dnd.init(selectItemsAfterUserAction); | 1520 dnd.init(selectItemsAfterUserAction); |
| 1496 bmm.tree.reload(); | 1521 bmm.tree.reload(); |
| 1497 } | 1522 } |
| 1498 | 1523 |
| 1499 initializeBookmarkManager(); | 1524 initializeBookmarkManager(); |
| 1500 })(); | 1525 })(); |
| OLD | NEW |