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

Side by Side Diff: chrome/browser/resources/file_manager/js/photo/gallery.js

Issue 10909095: Delete images in Photo Editor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comment, changed bg color, fixed an exception Created 8 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/file_manager/js/mock_chrome.js ('k') | 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 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|streaming'; 142 Gallery.METADATA_TYPE = 'thumbnail|filesystem|media|streaming';
143 143
144 /** 144 /**
145 * Initialize listeners. 145 * Initialize listeners.
146 * @private 146 * @private
147 */ 147 */
148 148
149 Gallery.prototype.initListeners_ = function() { 149 Gallery.prototype.initListeners_ = function() {
150 this.document_.oncontextmenu = function(e) { e.preventDefault(); }; 150 this.document_.oncontextmenu = function(e) { e.preventDefault(); };
151 151
152 this.document_.body.addEventListener('keydown', this.onKeyDown_.bind(this)); 152 this.keyDownBound_ = this.onKeyDown_.bind(this);
153 this.document_.body.addEventListener('keydown', this.keyDownBound_);
153 154
154 this.inactivityWatcher_ = new MouseInactivityWatcher( 155 this.inactivityWatcher_ = new MouseInactivityWatcher(
155 this.container_, Gallery.FADE_TIMEOUT, this.hasActiveTool.bind(this)); 156 this.container_, Gallery.FADE_TIMEOUT, this.hasActiveTool.bind(this));
156 157
157 // Show tools when the user touches the screen. 158 // Show tools when the user touches the screen.
158 this.document_.body.addEventListener('touchstart', 159 this.document_.body.addEventListener('touchstart',
159 this.inactivityWatcher_.startActivity.bind(this.inactivityWatcher_)); 160 this.inactivityWatcher_.startActivity.bind(this.inactivityWatcher_));
160 var initiateFading = 161 var initiateFading =
161 this.inactivityWatcher_.stopActivity.bind(this.inactivityWatcher_, 162 this.inactivityWatcher_.stopActivity.bind(this.inactivityWatcher_,
162 Gallery.FADE_TIMEOUT); 163 Gallery.FADE_TIMEOUT);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 this.setCurrentMode_.bind(this, this.slideMode_)); 375 this.setCurrentMode_.bind(this, this.slideMode_));
375 } 376 }
376 }; 377 };
377 378
378 /** 379 /**
379 * Delete event handler. 380 * Delete event handler.
380 * @private 381 * @private
381 */ 382 */
382 Gallery.prototype.onDelete_ = function() { 383 Gallery.prototype.onDelete_ = function() {
383 // Clone the sorted selected indexes array. 384 // Clone the sorted selected indexes array.
384 var toRemove = this.selectionModel_.selectedIndexes.slice(); 385 var indexesToRemove = this.selectionModel_.selectedIndexes.slice();
385 this.selectionModel_.unselectAll(); 386 if (!indexesToRemove.length)
387 return;
386 388
387 // Remove items starting from the highest index. 389 /* TODO(dgozman): Implement Undo delete, Remove the confirmation dialog. */
388 while (toRemove.length)
389 this.dataModel_.splice(toRemove.pop(), 1);
390 390
391 // TODO: delete actual files. 391 var itemsToRemove = this.getSelectedItems();
392 var plural = itemsToRemove.length > 1;
393 var param = plural ? itemsToRemove.length : itemsToRemove[0].getFileName();
394
395 function deleteNext() {
396 if (!itemsToRemove.length)
397 return; // All deleted.
398
399 var url = itemsToRemove.pop().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 }
407
408 // Prevent the Gallery from handling Esc and Enter.
409 this.document_.body.removeEventListener('keydown', this.keyDownBound_);
410 var restoreListener = function() {
411 this.document_.body.addEventListener('keydown', this.keyDownBound_);
412 }.bind(this);
413
414 cr.ui.dialogs.BaseDialog.OK_LABEL = this.displayStringFunction_('OK_LABEL');
415 cr.ui.dialogs.BaseDialog.CANCEL_LABEL =
416 this.displayStringFunction_('CANCEL_LABEL');
417 var confirm = new cr.ui.dialogs.ConfirmDialog(this.container_);
418 confirm.show(this.displayStringFunction_(
419 plural ? 'CONFIRM_DELETE_SOME' : 'CONFIRM_DELETE_ONE', param),
420 function() {
421 restoreListener();
422 this.selectionModel_.unselectAll();
423 this.selectionModel_.leadIndex = -1;
424 // Remove items from the data model, starting from the highest index.
425 while (indexesToRemove.length)
426 this.dataModel_.splice(indexesToRemove.pop(), 1);
427 // Delete actual files.
428 deleteNext();
429 }.bind(this),
430 restoreListener);
392 }; 431 };
393 432
394 /** 433 /**
395 * @return {Array.<Gallery.Item>} Current selection. 434 * @return {Array.<Gallery.Item>} Current selection.
396 */ 435 */
397 Gallery.prototype.getSelectedItems = function() { 436 Gallery.prototype.getSelectedItems = function() {
398 return this.selectionModel_.selectedIndexes.map( 437 return this.selectionModel_.selectedIndexes.map(
399 this.dataModel_.item.bind(this.dataModel_)); 438 this.dataModel_.item.bind(this.dataModel_));
400 }; 439 };
401 440
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 this.toggleShare_(); // Hide the menu. 688 this.toggleShare_(); // Hide the menu.
650 this.executeWhenReady(api.executeTask.bind(api, taskId, urls)); 689 this.executeWhenReady(api.executeTask.bind(api, taskId, urls));
651 }.bind(this, task.taskId)); 690 }.bind(this, task.taskId));
652 } 691 }
653 692
654 var empty = this.shareMenu_.querySelector('.item') == null; 693 var empty = this.shareMenu_.querySelector('.item') == null;
655 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty); 694 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty);
656 this.shareMenu_.hidden = wasHidden || empty; 695 this.shareMenu_.hidden = wasHidden || empty;
657 }.bind(this)); 696 }.bind(this));
658 }; 697 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/mock_chrome.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698