| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 /** @return {!Action} */ | 135 /** @return {!Action} */ |
| 136 function deselectItems() { | 136 function deselectItems() { |
| 137 return { | 137 return { |
| 138 name: 'deselect-items', | 138 name: 'deselect-items', |
| 139 }; | 139 }; |
| 140 } | 140 } |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * @param {string} id | 143 * @param {string} id |
| 144 * @param {boolean} add | |
| 145 * @param {boolean} range | |
| 146 * @param {BookmarksPageState} state | 144 * @param {BookmarksPageState} state |
| 145 * @param {{ |
| 146 * clear: boolean, |
| 147 * range: boolean, |
| 148 * toggle: boolean}} config Options for how the selection should change: |
| 149 * - clear: If true, clears the previous selection before adding this one |
| 150 * - range: If true, selects all items from the anchor to this item |
| 151 * - toggle: If true, toggles the selection state of the item. Cannot be |
| 152 * used with clear or range. |
| 147 * @return {!Action} | 153 * @return {!Action} |
| 148 */ | 154 */ |
| 149 function selectItem(id, add, range, state) { | 155 function selectItem(id, state, config) { |
| 156 assert(!config.toggle || !config.range); |
| 157 assert(!config.toggle || !config.clear); |
| 158 |
| 150 var anchor = state.selection.anchor; | 159 var anchor = state.selection.anchor; |
| 151 var toSelect = []; | 160 var toSelect = []; |
| 152 var newAnchor = id; | 161 var newAnchor = id; |
| 153 | 162 |
| 154 // TODO(tsergeant): Make it possible to deselect items by ctrl-clicking them | 163 if (config.range && anchor) { |
| 155 // again. | |
| 156 if (range && anchor) { | |
| 157 var displayedList = bookmarks.util.getDisplayedList(state); | 164 var displayedList = bookmarks.util.getDisplayedList(state); |
| 158 var selectedIndex = displayedList.indexOf(id); | 165 var selectedIndex = displayedList.indexOf(id); |
| 159 assert(selectedIndex != -1); | 166 assert(selectedIndex != -1); |
| 160 var anchorIndex = displayedList.indexOf(anchor); | 167 var anchorIndex = displayedList.indexOf(anchor); |
| 161 if (anchorIndex == -1) | 168 if (anchorIndex == -1) |
| 162 anchorIndex = selectedIndex; | 169 anchorIndex = selectedIndex; |
| 163 | 170 |
| 164 // When performing a range selection, don't change the anchor from what | 171 // When performing a range selection, don't change the anchor from what |
| 165 // was used in this selection. | 172 // was used in this selection. |
| 166 newAnchor = displayedList[anchorIndex]; | 173 newAnchor = displayedList[anchorIndex]; |
| 167 | 174 |
| 168 var startIndex = Math.min(anchorIndex, selectedIndex); | 175 var startIndex = Math.min(anchorIndex, selectedIndex); |
| 169 var endIndex = Math.max(anchorIndex, selectedIndex); | 176 var endIndex = Math.max(anchorIndex, selectedIndex); |
| 170 | 177 |
| 171 for (var i = startIndex; i <= endIndex; i++) | 178 for (var i = startIndex; i <= endIndex; i++) |
| 172 toSelect.push(displayedList[i]); | 179 toSelect.push(displayedList[i]); |
| 173 } else { | 180 } else { |
| 174 toSelect.push(id); | 181 toSelect.push(id); |
| 175 } | 182 } |
| 176 | 183 |
| 177 return { | 184 return { |
| 178 name: 'select-items', | 185 name: 'select-items', |
| 179 add: add, | 186 clear: config.clear, |
| 187 toggle: config.toggle, |
| 180 anchor: newAnchor, | 188 anchor: newAnchor, |
| 181 items: toSelect, | 189 items: toSelect, |
| 182 }; | 190 }; |
| 183 } | 191 } |
| 184 | 192 |
| 185 /** | 193 /** |
| 186 * @param {string} term | 194 * @param {string} term |
| 187 * @return {!Action} | 195 * @return {!Action} |
| 188 */ | 196 */ |
| 189 function setSearchTerm(term) { | 197 function setSearchTerm(term) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 216 moveBookmark: moveBookmark, | 224 moveBookmark: moveBookmark, |
| 217 refreshNodes: refreshNodes, | 225 refreshNodes: refreshNodes, |
| 218 removeBookmark: removeBookmark, | 226 removeBookmark: removeBookmark, |
| 219 reorderChildren: reorderChildren, | 227 reorderChildren: reorderChildren, |
| 220 selectFolder: selectFolder, | 228 selectFolder: selectFolder, |
| 221 selectItem: selectItem, | 229 selectItem: selectItem, |
| 222 setSearchResults: setSearchResults, | 230 setSearchResults: setSearchResults, |
| 223 setSearchTerm: setSearchTerm, | 231 setSearchTerm: setSearchTerm, |
| 224 }; | 232 }; |
| 225 }); | 233 }); |
| OLD | NEW |