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

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

Issue 795483004: In Bookmark manager 'Add page' and 'Add Folder' always add new page or folder at the end. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 (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
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() {
1052 var index = bmm.list.dataModel.length - 1; 1058 var index = bmm.list.dataModel.length - 1;
1059 if (newIndex != undefined)
1060 index = newIndex;
xiyuan 2015/01/07 17:14:03 As Bernhard pointed out, |newIndex| does not neces
Deepak 2015/01/08 13:41:13 @xiyuan Actually the code for bmm.tree and the bmm
1053 var sm = bmm.list.selectionModel; 1061 var sm = bmm.list.selectionModel;
1054 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index; 1062 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index;
1055 scrollIntoViewAndMakeEditable(index); 1063 scrollIntoViewAndMakeEditable(index);
1056 }); 1064 });
1057 } 1065 }
1058 1066
1059 navigateTo(parentId, editNewFolderInList); 1067 navigateTo(parentId, editNewFolderInList);
1060 } 1068 }
1061 1069
1062 /** 1070 /**
(...skipping 10 matching lines...) Expand all
1073 item.editing = true; 1081 item.editing = true;
1074 }, 0); 1082 }, 0);
1075 } 1083 }
1076 1084
1077 /** 1085 /**
1078 * Adds a page to the current folder. This is called by the 1086 * Adds a page to the current folder. This is called by the
1079 * add-new-bookmark-command handler. 1087 * add-new-bookmark-command handler.
1080 */ 1088 */
1081 function addPage() { 1089 function addPage() {
1082 var parentId = computeParentFolderForNewItem(); 1090 var parentId = computeParentFolderForNewItem();
1091 var selectedItem = bmm.list.selectedItem;
1092 var newIndex;
1093 function editNewBookmark() {
1094 if (selectedItem && document.activeElement != bmm.tree &&
1095 !bmm.isFolder(selectedItem)) {
1096 newIndex = bmm.list.dataModel.indexOf(selectedItem) + 1;
1097 }
1083 1098
1084 function editNewBookmark() {
1085 var fakeNode = { 1099 var fakeNode = {
1086 title: '', 1100 title: '',
1087 url: '', 1101 url: '',
1088 parentId: parentId, 1102 parentId: parentId,
1103 index: newIndex,
1089 id: 'new' 1104 id: 'new'
1090 }; 1105 };
1091 var dataModel = bmm.list.dataModel; 1106 var dataModel = bmm.list.dataModel;
1092 var length = dataModel.length; 1107 var index = dataModel.length;
1093 dataModel.splice(length, 0, fakeNode); 1108 if (newIndex != undefined)
1109 index = newIndex;
1110 dataModel.splice(index, 0, fakeNode);
1094 var sm = bmm.list.selectionModel; 1111 var sm = bmm.list.selectionModel;
1095 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = length; 1112 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index;
1096 scrollIntoViewAndMakeEditable(length); 1113 scrollIntoViewAndMakeEditable(index);
1097 }; 1114 };
1098 1115
1099 navigateTo(parentId, editNewBookmark); 1116 navigateTo(parentId, editNewBookmark);
1100 } 1117 }
1101 1118
1102 /** 1119 /**
1103 * This function is used to select items after a user action such as paste, drop 1120 * This function is used to select items after a user action such as paste, drop
1104 * add page etc. 1121 * add page etc.
1105 * @param {BookmarkList|BookmarkTree} target The target of the user action. 1122 * @param {BookmarkList|BookmarkTree} target The target of the user action.
1106 * @param {string=} opt_selectedTreeId If provided, then select that tree id. 1123 * @param {string=} opt_selectedTreeId If provided, then select that tree id.
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 1508
1492 cr.ui.FocusOutlineManager.forDocument(document); 1509 cr.ui.FocusOutlineManager.forDocument(document);
1493 initializeSplitter(); 1510 initializeSplitter();
1494 bmm.addBookmarkModelListeners(); 1511 bmm.addBookmarkModelListeners();
1495 dnd.init(selectItemsAfterUserAction); 1512 dnd.init(selectItemsAfterUserAction);
1496 bmm.tree.reload(); 1513 bmm.tree.reload();
1497 } 1514 }
1498 1515
1499 initializeBookmarkManager(); 1516 initializeBookmarkManager();
1500 })(); 1517 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698