Chromium Code Reviews| 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 document.addEventListener('DOMContentLoaded', function() { | 5 document.addEventListener('DOMContentLoaded', function() { |
| 6 if (document.location.hash) // File path passed after the #. | 6 if (document.location.hash) // File path passed after the #. |
| 7 Gallery.openStandalone(decodeURI(document.location.hash.substr(1))); | 7 Gallery.openStandalone(decodeURI(document.location.hash.substr(1))); |
| 8 }); | 8 }); |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 this.enterMode_(opt_callback); | 363 this.enterMode_(opt_callback); |
| 364 }.bind(this)); | 364 }.bind(this)); |
| 365 }; | 365 }; |
| 366 | 366 |
| 367 /** | 367 /** |
| 368 * Delete event handler. | 368 * Delete event handler. |
| 369 * @private | 369 * @private |
| 370 */ | 370 */ |
| 371 Gallery.prototype.onDelete_ = function() { | 371 Gallery.prototype.onDelete_ = function() { |
| 372 // Clone the sorted selected indexes array. | 372 // Clone the sorted selected indexes array. |
| 373 var toRemove = this.selectionModel_.selectedIndexes.slice(); | 373 var indexesToRemove = this.selectionModel_.selectedIndexes.slice(); |
| 374 this.selectionModel_.unselectAll(); | 374 if (!indexesToRemove.length) |
| 375 return; | |
| 375 | 376 |
| 376 // Remove items starting from the highest index. | 377 /* TODO(dgozman): implement Undo delete. */ |
| 377 while (toRemove.length) | |
| 378 this.dataModel_.splice(toRemove.pop(), 1); | |
| 379 | 378 |
| 380 // TODO: delete actual files. | 379 var itemsToRemove = this.getSelectedItems(); |
| 380 var plural = itemsToRemove.length > 1; | |
| 381 var param = plural ? itemsToRemove.length : itemsToRemove[0].getFileName(); | |
| 382 | |
| 383 cr.ui.dialogs.BaseDialog.OK_LABEL = this.displayStringFunction_('OK_LABEL'); | |
| 384 cr.ui.dialogs.BaseDialog.CANCEL_LABEL = | |
| 385 this.displayStringFunction_('CANCEL_LABEL'); | |
| 386 var confirm = new cr.ui.dialogs.ConfirmDialog(this.container_); | |
| 387 confirm.show(this.displayStringFunction_( | |
| 388 plural ? 'CONFIRM_DELETE_SOME' : 'CONFIRM_DELETE_ONE', param), | |
| 389 function() { | |
| 390 this.selectionModel_.unselectAll(); | |
| 391 | |
| 392 // Remove items from the data model, starting from the highest index. | |
| 393 while (indexesToRemove.length) | |
| 394 this.dataModel_.splice(indexesToRemove.pop(), 1); | |
| 395 | |
| 396 // Delete actual files. | |
| 397 var deleteNext = function() { | |
|
dgozman
2012/09/07 10:02:20
You can define this function outside callback to r
Vladislav Kaznacheev
2012/09/07 12:30:16
Done.
| |
| 398 var item = itemsToRemove.pop(); | |
| 399 var url = item.getUrl(); | |
| 400 webkitResolveLocalFileSystemURL(url, | |
| 401 function(entry) { | |
| 402 entry.remove(deleteNext, | |
| 403 util.flog('Error deleting ' + url, deleteNext)); | |
| 404 }, | |
| 405 util.flog('Error resolving ' + url, deleteNext)); | |
| 406 }.bind(this); | |
|
dgozman
2012/09/07 10:02:20
No need to bind here.
Vladislav Kaznacheev
2012/09/07 12:30:16
Done.
| |
| 407 deleteNext(); | |
| 408 }.bind(this)); | |
| 381 }; | 409 }; |
| 382 | 410 |
| 383 /** | 411 /** |
| 384 * @return {Array.<Gallery.Item>} Current selection. | 412 * @return {Array.<Gallery.Item>} Current selection. |
| 385 */ | 413 */ |
| 386 Gallery.prototype.getSelectedItems = function() { | 414 Gallery.prototype.getSelectedItems = function() { |
| 387 return this.selectionModel_.selectedIndexes.map( | 415 return this.selectionModel_.selectedIndexes.map( |
| 388 this.dataModel_.item.bind(this.dataModel_)); | 416 this.dataModel_.item.bind(this.dataModel_)); |
| 389 }; | 417 }; |
| 390 | 418 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 this.toggleShare_(); // Hide the menu. | 666 this.toggleShare_(); // Hide the menu. |
| 639 this.executeWhenReady(api.executeTask.bind(api, taskId, urls)); | 667 this.executeWhenReady(api.executeTask.bind(api, taskId, urls)); |
| 640 }.bind(this, task.taskId)); | 668 }.bind(this, task.taskId)); |
| 641 } | 669 } |
| 642 | 670 |
| 643 var empty = this.shareMenu_.querySelector('.item') == null; | 671 var empty = this.shareMenu_.querySelector('.item') == null; |
| 644 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty); | 672 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty); |
| 645 this.shareMenu_.hidden = wasHidden || empty; | 673 this.shareMenu_.hidden = wasHidden || empty; |
| 646 }.bind(this)); | 674 }.bind(this)); |
| 647 }; | 675 }; |
| OLD | NEW |