Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 /** | 5 /** |
| 6 * @fileoverview Module for functions which produce action objects. These are | 6 * @fileoverview Module for functions which produce action objects. These are |
| 7 * listed in one place to document available actions and their parameters. | 7 * listed in one place to document available actions and their parameters. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 cr.define('bookmarks.actions', function() { | 10 cr.define('bookmarks.actions', function() { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 */ | 65 */ |
| 66 function changeFolderOpen(id, open) { | 66 function changeFolderOpen(id, open) { |
| 67 return { | 67 return { |
| 68 name: 'change-folder-open', | 68 name: 'change-folder-open', |
| 69 id: id, | 69 id: id, |
| 70 open: open, | 70 open: open, |
| 71 }; | 71 }; |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * @param {string} id | |
| 76 * @param {boolean} add | |
| 77 * @param {boolean} range | |
| 78 * @param {BookmarksPageState} state | |
| 79 * @return {!Action} | |
| 80 */ | |
| 81 function selectItem(id, add, range, state) { | |
| 82 var anchor = state.selection.anchor; | |
| 83 var toSelect = []; | |
| 84 | |
|
calamity
2017/03/14 03:01:45
Add a TODO to deselect already selected items when
tsergeant
2017/03/14 05:42:02
TODO-ed since we'll want to be careful about how t
| |
| 85 if (range && anchor) { | |
| 86 var displayedList = bookmarks.util.getDisplayedList(state); | |
| 87 var selectedIndex = displayedList.indexOf(id); | |
| 88 assert(selectedIndex != -1); | |
| 89 var anchorIndex = displayedList.indexOf(anchor); | |
| 90 assert(anchorIndex != -1); | |
| 91 | |
| 92 var startIndex = Math.min(anchorIndex, selectedIndex); | |
| 93 var endIndex = Math.max(anchorIndex, selectedIndex); | |
| 94 | |
| 95 for (var i = startIndex; i <= endIndex; i++) | |
| 96 toSelect.push(displayedList[i]); | |
| 97 } else { | |
| 98 toSelect.push(id); | |
| 99 } | |
| 100 | |
| 101 return { | |
| 102 name: 'select-items', | |
| 103 add: add, | |
| 104 anchor: id, | |
| 105 items: toSelect, | |
| 106 }; | |
| 107 } | |
| 108 | |
| 109 /** | |
| 75 * @param {string} term | 110 * @param {string} term |
| 76 * @return {!Action} | 111 * @return {!Action} |
| 77 */ | 112 */ |
| 78 function setSearchTerm(term) { | 113 function setSearchTerm(term) { |
| 79 if (!term) | 114 if (!term) |
| 80 return {name: 'clear-search'}; | 115 return {name: 'clear-search'}; |
| 81 | 116 |
| 82 return { | 117 return { |
| 83 name: 'start-search', | 118 name: 'start-search', |
| 84 term: term, | 119 term: term, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 95 results: ids, | 130 results: ids, |
| 96 }; | 131 }; |
| 97 } | 132 } |
| 98 | 133 |
| 99 return { | 134 return { |
| 100 changeFolderOpen: changeFolderOpen, | 135 changeFolderOpen: changeFolderOpen, |
| 101 editBookmark: editBookmark, | 136 editBookmark: editBookmark, |
| 102 refreshNodes: refreshNodes, | 137 refreshNodes: refreshNodes, |
| 103 removeBookmark: removeBookmark, | 138 removeBookmark: removeBookmark, |
| 104 selectFolder: selectFolder, | 139 selectFolder: selectFolder, |
| 140 selectItem: selectItem, | |
| 105 setSearchResults: setSearchResults, | 141 setSearchResults: setSearchResults, |
| 106 setSearchTerm: setSearchTerm, | 142 setSearchTerm: setSearchTerm, |
| 107 }; | 143 }; |
| 108 }); | 144 }); |
| OLD | NEW |