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 selectedItem = bmm.list.selectedItem; |
| 1033 var newIndex; |
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 && |
| 1037 !bmm.isFolder(selectedItem)) { |
| 1038 newIndex = bmm.list.dataModel.indexOf(selectedItem) + 1; |
| 1039 } |
1035 chrome.bookmarks.create({ | 1040 chrome.bookmarks.create({ |
1036 title: loadTimeData.getString('new_folder_name'), | 1041 title: loadTimeData.getString('new_folder_name'), |
1037 parentId: parentId | 1042 parentId: parentId, |
| 1043 index: newIndex |
1038 }, callback); | 1044 }, callback); |
1039 } | 1045 } |
1040 | 1046 |
1041 if ((opt_target || document.activeElement) == bmm.tree) { | 1047 if ((opt_target || document.activeElement) == bmm.tree) { |
1042 createFolder(function(newNode) { | 1048 createFolder(function(newNode) { |
1043 navigateTo(newNode.id, function() { | 1049 navigateTo(newNode.id, function() { |
1044 bmm.treeLookup[newNode.id].editing = true; | 1050 bmm.treeLookup[newNode.id].editing = true; |
1045 }); | 1051 }); |
1046 }); | 1052 }); |
1047 return; | 1053 return; |
1048 } | 1054 } |
1049 | 1055 |
1050 function editNewFolderInList() { | 1056 function editNewFolderInList() { |
1051 createFolder(function() { | 1057 createFolder(function(newNode) { |
1052 var index = bmm.list.dataModel.length - 1; | 1058 var index = newNode.index; |
1053 var sm = bmm.list.selectionModel; | 1059 var sm = bmm.list.selectionModel; |
1054 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; | 1060 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; |
1055 scrollIntoViewAndMakeEditable(index); | 1061 scrollIntoViewAndMakeEditable(index); |
1056 }); | 1062 }); |
1057 } | 1063 } |
1058 | 1064 |
1059 navigateTo(parentId, editNewFolderInList); | 1065 navigateTo(parentId, editNewFolderInList); |
1060 } | 1066 } |
1061 | 1067 |
1062 /** | 1068 /** |
(...skipping 10 matching lines...) Expand all Loading... |
1073 item.editing = true; | 1079 item.editing = true; |
1074 }, 0); | 1080 }, 0); |
1075 } | 1081 } |
1076 | 1082 |
1077 /** | 1083 /** |
1078 * Adds a page to the current folder. This is called by the | 1084 * Adds a page to the current folder. This is called by the |
1079 * add-new-bookmark-command handler. | 1085 * add-new-bookmark-command handler. |
1080 */ | 1086 */ |
1081 function addPage() { | 1087 function addPage() { |
1082 var parentId = computeParentFolderForNewItem(); | 1088 var parentId = computeParentFolderForNewItem(); |
| 1089 var selectedItem = bmm.list.selectedItem; |
| 1090 var newIndex; |
| 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 != undefined) |
| 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 |