Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/ui/filters-filteractions.js

Issue 4884233277407232: Issue 2257 - Replaced non-standard function expressions with ES6 arrow functions (Closed)
Patch Set: 2nd argument to Utils.runAsync isn't necessary with arrow functions Created April 1, 2015, 5:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 { 94 {
95 E("filters-add-command").setAttribute("disabled", !FilterView.editable); 95 E("filters-add-command").setAttribute("disabled", !FilterView.editable);
96 }, 96 },
97 97
98 /** 98 /**
99 * Called whenever filter actions menu is opened, initializes menu items. 99 * Called whenever filter actions menu is opened, initializes menu items.
100 */ 100 */
101 fillActionsPopup: function() 101 fillActionsPopup: function()
102 { 102 {
103 let editable = FilterView.editable; 103 let editable = FilterView.editable;
104 let items = FilterView.selectedItems.filter(function(i) !i.filter.dummy); 104 let items = FilterView.selectedItems.filter(i => !i.filter.dummy);
105 items.sort(function(entry1, entry2) entry1.index - entry2.index); 105 items.sort((entry1, entry2) => entry1.index - entry2.index);
106 let activeItems = items.filter(function(i) i.filter instanceof ActiveFilter) ; 106 let activeItems = items.filter(i => i.filter instanceof ActiveFilter);
107 107
108 E("filters-edit-command").setAttribute("disabled", !editable || !items.lengt h); 108 E("filters-edit-command").setAttribute("disabled", !editable || !items.lengt h);
109 E("filters-delete-command").setAttribute("disabled", !editable || !items.len gth); 109 E("filters-delete-command").setAttribute("disabled", !editable || !items.len gth);
110 E("filters-resetHitCounts-command").setAttribute("disabled", !activeItems.le ngth); 110 E("filters-resetHitCounts-command").setAttribute("disabled", !activeItems.le ngth);
111 E("filters-moveUp-command").setAttribute("disabled", !editable || FilterView .isSorted() || !items.length || items[0].index == 0); 111 E("filters-moveUp-command").setAttribute("disabled", !editable || FilterView .isSorted() || !items.length || items[0].index == 0);
112 E("filters-moveDown-command").setAttribute("disabled", !editable || FilterVi ew.isSorted() || !items.length || items[items.length - 1].index == FilterView.ro wCount - 1); 112 E("filters-moveDown-command").setAttribute("disabled", !editable || FilterVi ew.isSorted() || !items.length || items[items.length - 1].index == FilterView.ro wCount - 1);
113 E("filters-copy-command").setAttribute("disabled", !items.length); 113 E("filters-copy-command").setAttribute("disabled", !items.length);
114 E("filters-cut-command").setAttribute("disabled", !editable || !items.length ); 114 E("filters-cut-command").setAttribute("disabled", !editable || !items.length );
115 E("filters-paste-command").setAttribute("disabled", !editable || !Utils.clip board.hasDataMatchingFlavors(["text/unicode"], 1, Utils.clipboard.kGlobalClipboa rd)); 115 E("filters-paste-command").setAttribute("disabled", !editable || !Utils.clip board.hasDataMatchingFlavors(["text/unicode"], 1, Utils.clipboard.kGlobalClipboa rd));
116 }, 116 },
(...skipping 18 matching lines...) Expand all
135 }, 135 },
136 136
137 /** 137 /**
138 * Enables or disables all filters in the current selection. 138 * Enables or disables all filters in the current selection.
139 */ 139 */
140 selectionToggleDisabled: function() 140 selectionToggleDisabled: function()
141 { 141 {
142 if (this.treeElement.editingColumn) 142 if (this.treeElement.editingColumn)
143 return; 143 return;
144 144
145 let items = FilterView.selectedItems.filter(function(i) i.filter instanceof ActiveFilter); 145 let items = FilterView.selectedItems.filter(i => i.filter instanceof ActiveF ilter);
146 if (items.length) 146 if (items.length)
147 { 147 {
148 FilterView.boxObject.beginUpdateBatch(); 148 FilterView.boxObject.beginUpdateBatch();
149 let newValue = !items[0].filter.disabled; 149 let newValue = !items[0].filter.disabled;
150 for (let i = 0; i < items.length; i++) 150 for (let i = 0; i < items.length; i++)
151 items[i].filter.disabled = newValue; 151 items[i].filter.disabled = newValue;
152 FilterView.boxObject.endUpdateBatch(); 152 FilterView.boxObject.endUpdateBatch();
153 } 153 }
154 }, 154 },
155 155
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 198 }
199 tree.addEventListener("DOMAttrModified", listener, false); 199 tree.addEventListener("DOMAttrModified", listener, false);
200 }, 200 },
201 201
202 /** 202 /**
203 * Deletes items from the list. 203 * Deletes items from the list.
204 */ 204 */
205 deleteItems: function(/**Array*/ items) 205 deleteItems: function(/**Array*/ items)
206 { 206 {
207 let oldIndex = FilterView.selection.currentIndex; 207 let oldIndex = FilterView.selection.currentIndex;
208 items.sort(function(entry1, entry2) entry2.index - entry1.index); 208 items.sort((entry1, entry2) => entry2.index - entry1.index);
209 209
210 for (let i = 0; i < items.length; i++) 210 for (let i = 0; i < items.length; i++)
211 FilterStorage.removeFilter(items[i].filter, FilterView._subscription, item s[i].index); 211 FilterStorage.removeFilter(items[i].filter, FilterView._subscription, item s[i].index);
212 212
213 FilterView.selectRow(oldIndex); 213 FilterView.selectRow(oldIndex);
214 }, 214 },
215 215
216 /** 216 /**
217 * Deletes selected filters. 217 * Deletes selected filters.
218 */ 218 */
(...skipping 10 matching lines...) Expand all
229 }, 229 },
230 230
231 /** 231 /**
232 * Resets hit counts of the selected filters. 232 * Resets hit counts of the selected filters.
233 */ 233 */
234 resetHitCounts: function() 234 resetHitCounts: function()
235 { 235 {
236 if (this.treeElement.editingColumn) 236 if (this.treeElement.editingColumn)
237 return; 237 return;
238 238
239 let items = FilterView.selectedItems.filter(function(i) i.filter instanceof ActiveFilter); 239 let items = FilterView.selectedItems.filter(i => i.filter instanceof ActiveF ilter);
240 if (items.length) 240 if (items.length)
241 FilterStorage.resetHitCounts(items.map(function(i) i.filter)); 241 FilterStorage.resetHitCounts(items.map(i => i.filter));
242 }, 242 },
243 243
244 /** 244 /**
245 * Moves items to a different position in the list. 245 * Moves items to a different position in the list.
246 * @param {Array} items 246 * @param {Array} items
247 * @param {Integer} offset negative offsets move the items up, positive down 247 * @param {Integer} offset negative offsets move the items up, positive down
248 */ 248 */
249 _moveItems: function(/**Array*/ items, /**Integer*/ offset) 249 _moveItems: function(/**Array*/ items, /**Integer*/ offset)
250 { 250 {
251 if (!items.length) 251 if (!items.length)
252 return; 252 return;
253 253
254 if (offset < 0) 254 if (offset < 0)
255 { 255 {
256 items.sort(function(entry1, entry2) entry1.index - entry2.index); 256 items.sort((entry1, entry2) => entry1.index - entry2.index);
257 let position = items[0].index + offset; 257 let position = items[0].index + offset;
258 if (position < 0) 258 if (position < 0)
259 return; 259 return;
260 260
261 for (let i = 0; i < items.length; i++) 261 for (let i = 0; i < items.length; i++)
262 FilterStorage.moveFilter(items[i].filter, FilterView._subscription, item s[i].index, position++); 262 FilterStorage.moveFilter(items[i].filter, FilterView._subscription, item s[i].index, position++);
263 FilterView.selection.rangedSelect(position - items.length, position - 1, f alse); 263 FilterView.selection.rangedSelect(position - items.length, position - 1, f alse);
264 } 264 }
265 else if (offset > 0) 265 else if (offset > 0)
266 { 266 {
267 items.sort(function(entry1, entry2) entry2.index - entry1.index); 267 items.sort((entry1, entry2) => entry2.index - entry1.index);
268 let position = items[0].index + offset; 268 let position = items[0].index + offset;
269 if (position >= FilterView.rowCount) 269 if (position >= FilterView.rowCount)
270 return; 270 return;
271 271
272 for (let i = 0; i < items.length; i++) 272 for (let i = 0; i < items.length; i++)
273 FilterStorage.moveFilter(items[i].filter, FilterView._subscription, item s[i].index, position--); 273 FilterStorage.moveFilter(items[i].filter, FilterView._subscription, item s[i].index, position--);
274 FilterView.selection.rangedSelect(position + 1, position + items.length, f alse); 274 FilterView.selection.rangedSelect(position + 1, position + items.length, f alse);
275 } 275 }
276 }, 276 },
277 277
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 /** 401 /**
402 * Copies selected items to clipboard and optionally removes them from the 402 * Copies selected items to clipboard and optionally removes them from the
403 * list after that. 403 * list after that.
404 */ 404 */
405 copySelected: function(/**Boolean*/ keep) 405 copySelected: function(/**Boolean*/ keep)
406 { 406 {
407 let items = FilterView.selectedItems; 407 let items = FilterView.selectedItems;
408 if (!items.length) 408 if (!items.length)
409 return; 409 return;
410 410
411 items.sort(function(entry1, entry2) entry1.index - entry2.index); 411 items.sort((entry1, entry2) => entry1.index - entry2.index);
412 let text = items.map(function(i) i.filter.text).join(IO.lineBreak); 412 let text = items.map(i => i.filter.text).join(IO.lineBreak);
413 Utils.clipboardHelper.copyString(text); 413 Utils.clipboardHelper.copyString(text);
414 414
415 if (!keep && FilterView.editable && !this.treeElement.editingColumn) 415 if (!keep && FilterView.editable && !this.treeElement.editingColumn)
416 this.deleteItems(items); 416 this.deleteItems(items);
417 }, 417 },
418 418
419 /** 419 /**
420 * Pastes text from clipboard as filters at the current position. 420 * Pastes text from clipboard as filters at the current position.
421 */ 421 */
422 paste: function() 422 paste: function()
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 458
459 /** 459 /**
460 * Called whenever the user starts a drag operation. 460 * Called whenever the user starts a drag operation.
461 */ 461 */
462 startDrag: function(/**Event*/ event) 462 startDrag: function(/**Event*/ event)
463 { 463 {
464 let items = FilterView.selectedItems; 464 let items = FilterView.selectedItems;
465 if (!items.length) 465 if (!items.length)
466 return; 466 return;
467 467
468 items.sort(function(entry1, entry2) entry1.index - entry2.index); 468 items.sort((entry1, entry2) => entry1.index - entry2.index);
469 event.dataTransfer.setData("text/plain", items.map(function(i) i.filter.text ).join(IO.lineBreak)); 469 event.dataTransfer.setData("text/plain", items.map(i => i.filter.text).join( IO.lineBreak));
470 this.dragItems = items; 470 this.dragItems = items;
471 event.stopPropagation(); 471 event.stopPropagation();
472 }, 472 },
473 473
474 /** 474 /**
475 * Called to check whether moving the items to the given position is possible. 475 * Called to check whether moving the items to the given position is possible.
476 */ 476 */
477 canDrop: function(/**Integer*/ newPosition, /**nsIDOMDataTransfer*/ dataTransf er) 477 canDrop: function(/**Integer*/ newPosition, /**nsIDOMDataTransfer*/ dataTransf er)
478 { 478 {
479 if (!FilterView.editable || this.treeElement.editingColumn) 479 if (!FilterView.editable || this.treeElement.editingColumn)
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return; 548 return;
549 549
550 this.deleteItems(this.dragItems); 550 this.deleteItems(this.dragItems);
551 } 551 }
552 }; 552 };
553 553
554 window.addEventListener("load", function() 554 window.addEventListener("load", function()
555 { 555 {
556 FilterActions.init(); 556 FilterActions.init();
557 }, false); 557 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld