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

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

Issue 109973002: Migrate from URLs to Entries in the Files App's gallery. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 7 years 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
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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Called from the main frame when unloading. 8 * Called from the main frame when unloading.
9 * @return {string?} User-visible message on null if it is OK to close. 9 * @return {string?} User-visible message on null if it is OK to close.
10 */ 10 */
(...skipping 25 matching lines...) Expand all
36 * the system. 36 * the system.
37 * @class 37 * @class
38 * @constructor 38 * @constructor
39 */ 39 */
40 function Gallery(context, volumeManager) { 40 function Gallery(context, volumeManager) {
41 this.container_ = document.querySelector('.gallery'); 41 this.container_ = document.querySelector('.gallery');
42 this.document_ = document; 42 this.document_ = document;
43 this.context_ = context; 43 this.context_ = context;
44 this.metadataCache_ = context.metadataCache; 44 this.metadataCache_ = context.metadataCache;
45 this.volumeManager_ = volumeManager; 45 this.volumeManager_ = volumeManager;
46 this.selectedEntry_ = null;
46 47
47 this.dataModel_ = new cr.ui.ArrayDataModel([]); 48 this.dataModel_ = new cr.ui.ArrayDataModel([]);
48 this.selectionModel_ = new cr.ui.ListSelectionModel(); 49 this.selectionModel_ = new cr.ui.ListSelectionModel();
49 this.displayStringFunction_ = context.displayStringFunction; 50 this.displayStringFunction_ = context.displayStringFunction;
50 51
51 this.initDom_(); 52 this.initDom_();
52 this.initListeners_(); 53 this.initListeners_();
53 } 54 }
54 55
55 /** 56 /**
56 * Gallery extends cr.EventTarget. 57 * Gallery extends cr.EventTarget.
57 */ 58 */
58 Gallery.prototype.__proto__ = cr.EventTarget.prototype; 59 Gallery.prototype.__proto__ = cr.EventTarget.prototype;
59 60
60 /** 61 /**
61 * Create and initialize a Gallery object based on a context. 62 * Create and initialize a Gallery object based on a context.
62 * 63 *
63 * @param {Object} context Gallery context. 64 * @param {Object} context Gallery context.
64 * @param {VolumeManagerWrapper} volumeManager VolumeManager of the system. 65 * @param {VolumeManagerWrapper} volumeManager VolumeManager of the system.
65 * @param {Array.<string>} urls Array of urls. 66 * @param {Array.<Entry>} entries Array of entries.
66 * @param {Array.<string>} selectedUrls Array of selected urls. 67 * @param {Array.<Entry>} selectedEntries Array of selected entries.
67 */ 68 */
68 Gallery.open = function(context, volumeManager, urls, selectedUrls) { 69 Gallery.open = function(context, volumeManager, entries, selectedEntries) {
69 Gallery.instance = new Gallery(context, volumeManager); 70 Gallery.instance = new Gallery(context, volumeManager);
70 Gallery.instance.load(urls, selectedUrls); 71 Gallery.instance.load(entries, selectedEntries);
71 }; 72 };
72 73
73 /** 74 /**
74 * Tools fade-out timeout im milliseconds. 75 * Tools fade-out timeout im milliseconds.
75 * @const 76 * @const
76 * @type {number} 77 * @type {number}
77 */ 78 */
78 Gallery.FADE_TIMEOUT = 3000; 79 Gallery.FADE_TIMEOUT = 3000;
79 80
80 /** 81 /**
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 this.volumeManager_.addEventListener('externally-unmounted', 125 this.volumeManager_.addEventListener('externally-unmounted',
125 this.onExternallyUnmounted_.bind(this)); 126 this.onExternallyUnmounted_.bind(this));
126 }; 127 };
127 128
128 /** 129 /**
129 * Closes gallery when a volume containing the selected item is unmounted. 130 * Closes gallery when a volume containing the selected item is unmounted.
130 * @param {Event} event The unmount event. 131 * @param {Event} event The unmount event.
131 * @private 132 * @private
132 */ 133 */
133 Gallery.prototype.onExternallyUnmounted_ = function(event) { 134 Gallery.prototype.onExternallyUnmounted_ = function(event) {
134 if (!this.selectedItemFilesystemPath_) 135 if (!this.selectedEntry_)
135 return; 136 return;
136 if (this.selectedItemFilesystemPath_.indexOf(event.mountPath) == 0) 137
138 if (this.selectedEntry_.filesystem.root.toURL() ===
hirono 2013/12/09 06:53:50 Could you compare volume info instead of root URL?
mtomasz 2013/12/10 02:37:34 Done.
139 event.volumeInfo.filesystem.root.toURL())
137 this.onBack_(); 140 this.onBack_();
138 }; 141 };
139 142
140 /** 143 /**
141 * Beforeunload handler. 144 * Beforeunload handler.
142 * @return {string?} User-visible message on null if it is OK to close. 145 * @return {string?} User-visible message on null if it is OK to close.
143 */ 146 */
144 Gallery.prototype.onBeforeUnload = function() { 147 Gallery.prototype.onBeforeUnload = function() {
145 return this.slideMode_.onBeforeUnload(); 148 return this.slideMode_.onBeforeUnload();
146 }; 149 };
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 */ 265 */
263 Gallery.prototype.createToolbarButton_ = function(className, title) { 266 Gallery.prototype.createToolbarButton_ = function(className, title) {
264 var button = util.createChild(this.toolbar_, className, 'button'); 267 var button = util.createChild(this.toolbar_, className, 'button');
265 button.title = this.displayStringFunction_(title); 268 button.title = this.displayStringFunction_(title);
266 return button; 269 return button;
267 }; 270 };
268 271
269 /** 272 /**
270 * Load the content. 273 * Load the content.
271 * 274 *
272 * @param {Array.<string>} urls Array of urls. 275 * @param {Array.<Entry>} entries Array of entries.
273 * @param {Array.<string>} selectedUrls Array of selected urls. 276 * @param {Array.<Entry>} selectedEntries Array of selected entries.
274 */ 277 */
275 Gallery.prototype.load = function(urls, selectedUrls) { 278 Gallery.prototype.load = function(entries, selectedEntries) {
276 var items = []; 279 var items = [];
277 for (var index = 0; index < urls.length; ++index) { 280 for (var index = 0; index < entries.length; ++index) {
278 items.push(new Gallery.Item(urls[index])); 281 items.push(new Gallery.Item(entries[index]));
279 } 282 }
280 this.dataModel_.push.apply(this.dataModel_, items); 283 this.dataModel_.push.apply(this.dataModel_, items);
281 284
282 this.selectionModel_.adjustLength(this.dataModel_.length); 285 this.selectionModel_.adjustLength(this.dataModel_.length);
283 286
284 for (var i = 0; i != selectedUrls.length; i++) { 287 for (var i = 0; i != selectedEntries.length; i++) {
hirono 2013/12/09 06:53:50 !== is preferred.
mtomasz 2013/12/10 02:37:34 Done.
285 var selectedIndex = urls.indexOf(selectedUrls[i]); 288 var selectedIndex = entries.indexOf(selectedEntries[i]);
286 if (selectedIndex >= 0) 289 if (selectedIndex >= 0)
287 this.selectionModel_.setIndexSelected(selectedIndex, true); 290 this.selectionModel_.setIndexSelected(selectedIndex, true);
288 else 291 else
289 console.error('Cannot select ' + selectedUrls[i]); 292 console.error('Cannot select ' + selectedEntries[i]);
290 } 293 }
291 294
292 if (this.selectionModel_.selectedIndexes.length == 0) 295 if (this.selectionModel_.selectedIndexes.length == 0)
293 this.onSelection_(); 296 this.onSelection_();
294 297
295 var mosaic = this.mosaicMode_ && this.mosaicMode_.getMosaic(); 298 var mosaic = this.mosaicMode_ && this.mosaicMode_.getMosaic();
296 299
297 // Mosaic view should show up if most of the selected files are images. 300 // Mosaic view should show up if most of the selected files are images.
298 var imagesCount = 0; 301 var imagesCount = 0;
299 for (var i = 0; i != selectedUrls.length; i++) { 302 for (var i = 0; i != selectedEntries.length; i++) {
hirono 2013/12/09 06:53:50 ditto.
mtomasz 2013/12/10 02:37:34 Done.
300 if (FileType.getMediaType(selectedUrls[i]) == 'image') 303 if (FileType.getMediaType(selectedEntries[i]) == 'image')
hirono 2013/12/09 06:53:50 ditto.
mtomasz 2013/12/10 02:37:34 Done.
301 imagesCount++; 304 imagesCount++;
302 } 305 }
303 var mostlyImages = imagesCount > (selectedUrls.length / 2.0); 306 var mostlyImages = imagesCount > (selectedEntries.length / 2.0);
304 307
305 var forcedMosaic = (this.context_.pageState && 308 var forcedMosaic = (this.context_.pageState &&
306 this.context_.pageState.gallery == 'mosaic'); 309 this.context_.pageState.gallery == 'mosaic');
307 310
308 var showMosaic = (mostlyImages && selectedUrls.length > 1) || forcedMosaic; 311 var showMosaic = (mostlyImages && selectedEntries.length > 1) || forcedMosaic;
309 if (mosaic && showMosaic) { 312 if (mosaic && showMosaic) {
310 this.setCurrentMode_(this.mosaicMode_); 313 this.setCurrentMode_(this.mosaicMode_);
311 mosaic.init(); 314 mosaic.init();
312 mosaic.show(); 315 mosaic.show();
313 this.inactivityWatcher_.check(); // Show the toolbar. 316 this.inactivityWatcher_.check(); // Show the toolbar.
314 cr.dispatchSimpleEvent(this, 'loaded'); 317 cr.dispatchSimpleEvent(this, 'loaded');
315 } else { 318 } else {
316 this.setCurrentMode_(this.slideMode_); 319 this.setCurrentMode_(this.slideMode_);
317 var maybeLoadMosaic = function() { 320 var maybeLoadMosaic = function() {
318 if (mosaic) 321 if (mosaic)
(...skipping 11 matching lines...) Expand all
330 333
331 /** 334 /**
332 * Close the Gallery and go to Files.app. 335 * Close the Gallery and go to Files.app.
333 * @private 336 * @private
334 */ 337 */
335 Gallery.prototype.back_ = function() { 338 Gallery.prototype.back_ = function() {
336 if (util.isFullScreen(this.context_.appWindow)) { 339 if (util.isFullScreen(this.context_.appWindow)) {
337 util.toggleFullScreen(this.context_.appWindow, 340 util.toggleFullScreen(this.context_.appWindow,
338 false); // Leave the full screen mode. 341 false); // Leave the full screen mode.
339 } 342 }
340 this.context_.onBack(this.getSelectedUrls()); 343 this.context_.onBack(this.getSelectedEntries());
341 }; 344 };
342 345
343 /** 346 /**
344 * Handle user's 'Back' action (Escape or a click on the X icon). 347 * Handle user's 'Back' action (Escape or a click on the X icon).
345 * @private 348 * @private
346 */ 349 */
347 Gallery.prototype.onBack_ = function() { 350 Gallery.prototype.onBack_ = function() {
348 this.executeWhenReady(this.back_.bind(this)); 351 this.executeWhenReady(this.back_.bind(this));
349 }; 352 };
350 353
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 /* TODO(dgozman): Implement Undo delete, Remove the confirmation dialog. */ 481 /* TODO(dgozman): Implement Undo delete, Remove the confirmation dialog. */
479 482
480 var itemsToRemove = this.getSelectedItems(); 483 var itemsToRemove = this.getSelectedItems();
481 var plural = itemsToRemove.length > 1; 484 var plural = itemsToRemove.length > 1;
482 var param = plural ? itemsToRemove.length : itemsToRemove[0].getFileName(); 485 var param = plural ? itemsToRemove.length : itemsToRemove[0].getFileName();
483 486
484 function deleteNext() { 487 function deleteNext() {
485 if (!itemsToRemove.length) 488 if (!itemsToRemove.length)
486 return; // All deleted. 489 return; // All deleted.
487 490
488 var url = itemsToRemove.pop().getUrl(); 491 var entry = itemsToRemove.pop().getEntry();
489 webkitResolveLocalFileSystemURL(url, 492 entry.remove(deleteNext, function() {
hirono 2013/12/09 06:53:50 Could you add the TODO comment? TODO(hirono): Use
mtomasz 2013/12/10 02:37:34 Done.
490 function(entry) { 493 util.flog('Error deleting: ' + entry.fullPath, deleteNext);
491 entry.remove(deleteNext, 494 });
492 util.flog('Error deleting ' + url, deleteNext));
493 },
494 util.flog('Error resolving ' + url, deleteNext));
495 } 495 }
496 496
497 // Prevent the Gallery from handling Esc and Enter. 497 // Prevent the Gallery from handling Esc and Enter.
498 this.document_.body.removeEventListener('keydown', this.keyDownBound_); 498 this.document_.body.removeEventListener('keydown', this.keyDownBound_);
499 var restoreListener = function() { 499 var restoreListener = function() {
500 this.document_.body.addEventListener('keydown', this.keyDownBound_); 500 this.document_.body.addEventListener('keydown', this.keyDownBound_);
501 }.bind(this); 501 }.bind(this);
502 502
503 cr.ui.dialogs.BaseDialog.OK_LABEL = this.displayStringFunction_( 503 cr.ui.dialogs.BaseDialog.OK_LABEL = this.displayStringFunction_(
504 'GALLERY_OK_LABEL'); 504 'GALLERY_OK_LABEL');
(...skipping 21 matching lines...) Expand all
526 526
527 /** 527 /**
528 * @return {Array.<Gallery.Item>} Current selection. 528 * @return {Array.<Gallery.Item>} Current selection.
529 */ 529 */
530 Gallery.prototype.getSelectedItems = function() { 530 Gallery.prototype.getSelectedItems = function() {
531 return this.selectionModel_.selectedIndexes.map( 531 return this.selectionModel_.selectedIndexes.map(
532 this.dataModel_.item.bind(this.dataModel_)); 532 this.dataModel_.item.bind(this.dataModel_));
533 }; 533 };
534 534
535 /** 535 /**
536 * @return {Array.<string>} Array of currently selected urls. 536 * @return {Array.<Entry>} Array of currently selected entries.
537 */ 537 */
538 Gallery.prototype.getSelectedUrls = function() { 538 Gallery.prototype.getSelectedEntries = function() {
539 return this.selectionModel_.selectedIndexes.map(function(index) { 539 return this.selectionModel_.selectedIndexes.map(function(index) {
540 return this.dataModel_.item(index).getUrl(); 540 return this.dataModel_.item(index).getEntry();
541 }.bind(this)); 541 }.bind(this));
542 }; 542 };
543 543
544 /** 544 /**
545 * @return {Gallery.Item} Current single selection. 545 * @return {Gallery.Item} Current single selection.
546 */ 546 */
547 Gallery.prototype.getSingleSelectedItem = function() { 547 Gallery.prototype.getSingleSelectedItem = function() {
548 var items = this.getSelectedItems(); 548 var items = this.getSelectedItems();
549 if (items.length > 1) 549 if (items.length > 1)
550 throw new Error('Unexpected multiple selection'); 550 throw new Error('Unexpected multiple selection');
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 * 627 *
628 * @private 628 * @private
629 */ 629 */
630 Gallery.prototype.updateSelectionAndState_ = function() { 630 Gallery.prototype.updateSelectionAndState_ = function() {
631 var path; 631 var path;
632 var displayName = ''; 632 var displayName = '';
633 633
634 var selectedItems = this.getSelectedItems(); 634 var selectedItems = this.getSelectedItems();
635 if (selectedItems.length == 1) { 635 if (selectedItems.length == 1) {
636 var item = selectedItems[0]; 636 var item = selectedItems[0];
637 path = util.extractFilePath(item.getUrl()); 637 var entry = item.getEntry();
638 var fullName = item.getFileName(); 638 window.top.document.title = entry.name;
639 window.top.document.title = fullName; 639 displayName = ImageUtil.getDisplayNameFromName(entry.name);
640 displayName = ImageUtil.getFileNameFromFullName(fullName);
641 } else if (selectedItems.length > 1 && this.context_.curDirEntry) { 640 } else if (selectedItems.length > 1 && this.context_.curDirEntry) {
642 // If the Gallery was opened on search results the search query will not be 641 // If the Gallery was opened on search results the search query will not be
643 // recorded in the app state and the relaunch will just open the gallery 642 // recorded in the app state and the relaunch will just open the gallery
644 // in the curDirEntry directory. 643 // in the curDirEntry directory.
645 path = this.context_.curDirEntry.fullPath; 644 path = this.context_.curDirEntry.fullPath;
646 window.top.document.title = this.context_.curDirEntry.name; 645 window.top.document.title = this.context_.curDirEntry.name;
647 displayName = 646 displayName =
648 this.displayStringFunction_('GALLERY_ITEMS_SELECTED', 647 this.displayStringFunction_('GALLERY_ITEMS_SELECTED',
649 selectedItems.length); 648 selectedItems.length);
650 } 649 }
651 650
652 window.top.util.updateAppState(path, 651 window.top.util.updateAppState(path,
653 {gallery: (this.currentMode_ == this.mosaicMode_ ? 'mosaic' : 'slide')}); 652 {gallery: (this.currentMode_ == this.mosaicMode_ ? 'mosaic' : 'slide')});
654 653
655 // We can't rename files in readonly directory. 654 // We can't rename files in readonly directory.
656 // We can only rename a single file. 655 // We can only rename a single file.
657 this.filenameEdit_.disabled = selectedItems.length != 1 || 656 this.filenameEdit_.disabled = selectedItems.length != 1 ||
658 this.context_.readonlyDirName; 657 this.context_.readonlyDirName;
659 658
660 this.filenameEdit_.value = displayName; 659 this.filenameEdit_.value = displayName;
661 660
662 // Resolve real filesystem path of the current file. 661 // Resolve real filesystem path of the current file.
663 if (this.selectionModel_.selectedIndexes.length) { 662 if (this.selectionModel_.selectedIndexes.length) {
664 var selectedIndex = this.selectionModel_.selectedIndex; 663 var selectedIndex = this.selectionModel_.selectedIndex;
665 var selectedItem = 664 var selectedItem =
666 this.dataModel_.item(this.selectionModel_.selectedIndex); 665 this.dataModel_.item(this.selectionModel_.selectedIndex);
667 666 this.selectedEntry_ = selectedItem.getEntry();
668 this.selectedItemFilesystemPath_ = null;
669 webkitResolveLocalFileSystemURL(selectedItem.getUrl(),
670 function(entry) {
671 if (this.selectionModel_.selectedIndex != selectedIndex)
672 return;
673 this.selectedItemFilesystemPath_ = entry.fullPath;
674 }.bind(this));
675 } 667 }
676 }; 668 };
677 669
678 /** 670 /**
679 * Click event handler on filename edit box 671 * Click event handler on filename edit box
680 * @private 672 * @private
681 */ 673 */
682 Gallery.prototype.onFilenameFocus_ = function() { 674 Gallery.prototype.onFilenameFocus_ = function() {
683 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', true); 675 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', true);
684 this.filenameEdit_.originalValue = this.filenameEdit_.value; 676 this.filenameEdit_.originalValue = this.filenameEdit_.value;
(...skipping 11 matching lines...) Expand all
696 Gallery.prototype.onFilenameEditBlur_ = function(event) { 688 Gallery.prototype.onFilenameEditBlur_ = function(event) {
697 if (this.filenameEdit_.value && this.filenameEdit_.value[0] == '.') { 689 if (this.filenameEdit_.value && this.filenameEdit_.value[0] == '.') {
698 this.prompt_.show('GALLERY_FILE_HIDDEN_NAME', 5000); 690 this.prompt_.show('GALLERY_FILE_HIDDEN_NAME', 5000);
699 this.filenameEdit_.focus(); 691 this.filenameEdit_.focus();
700 event.stopPropagation(); 692 event.stopPropagation();
701 event.preventDefault(); 693 event.preventDefault();
702 return false; 694 return false;
703 } 695 }
704 696
705 var item = this.getSingleSelectedItem(); 697 var item = this.getSingleSelectedItem();
706 var oldUrl = item.getUrl(); 698 var oldEntry = item.getEntry();
707 699
708 var onFileExists = function() { 700 var onFileExists = function() {
709 this.prompt_.show('GALLERY_FILE_EXISTS', 3000); 701 this.prompt_.show('GALLERY_FILE_EXISTS', 3000);
710 this.filenameEdit_.value = name; 702 this.filenameEdit_.value = name;
711 this.filenameEdit_.focus(); 703 this.filenameEdit_.focus();
712 }.bind(this); 704 }.bind(this);
713 705
714 var onSuccess = function() { 706 var onSuccess = function() {
715 var e = new Event('content'); 707 var e = new Event('content');
hirono 2013/12/09 06:53:50 Please replace e with event.
mtomasz 2013/12/10 02:37:34 Done.
716 e.item = item; 708 e.item = item;
717 e.oldUrl = oldUrl; 709 e.oldEntry = oldEntry;
718 e.metadata = null; // Metadata unchanged. 710 e.metadata = null; // Metadata unchanged.
719 this.dataModel_.dispatchEvent(e); 711 this.dataModel_.dispatchEvent(e);
720 }.bind(this); 712 }.bind(this);
721 713
722 if (this.filenameEdit_.value) { 714 if (this.filenameEdit_.value) {
723 this.getSingleSelectedItem().rename( 715 this.getSingleSelectedItem().rename(
724 this.filenameEdit_.value, onSuccess, onFileExists); 716 this.filenameEdit_.value, onSuccess, onFileExists);
725 } 717 }
726 718
727 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', false); 719 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', false);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 if (!this.shareButton_.hasAttribute('disabled')) 782 if (!this.shareButton_.hasAttribute('disabled'))
791 this.shareMenu_.hidden = !this.shareMenu_.hidden; 783 this.shareMenu_.hidden = !this.shareMenu_.hidden;
792 this.inactivityWatcher_.check(); 784 this.inactivityWatcher_.check();
793 }; 785 };
794 786
795 /** 787 /**
796 * Updates available actions list based on the currently selected urls. 788 * Updates available actions list based on the currently selected urls.
797 * @private. 789 * @private.
798 */ 790 */
799 Gallery.prototype.updateShareMenu_ = function() { 791 Gallery.prototype.updateShareMenu_ = function() {
800 var urls = this.getSelectedUrls(); 792 var entries = this.getSelectedEntries();
801 793
802 function isShareAction(task) { 794 function isShareAction(task) {
803 var taskParts = task.taskId.split('|'); 795 var taskParts = task.taskId.split('|');
804 return taskParts[0] != chrome.runtime.id; 796 return taskParts[0] != chrome.runtime.id;
805 } 797 }
806 798
807 var api = Gallery.getFileBrowserPrivate(); 799 var api = Gallery.getFileBrowserPrivate();
808 var mimeTypes = []; // TODO(kaznacheev) Collect mime types properly. 800 var mimeTypes = []; // TODO(kaznacheev) Collect mime types properly.
809 801
810 var createShareMenu = function(tasks) { 802 var createShareMenu = function(tasks) {
811 var wasHidden = this.shareMenu_.hidden; 803 var wasHidden = this.shareMenu_.hidden;
812 this.shareMenu_.hidden = true; 804 this.shareMenu_.hidden = true;
813 var items = this.shareMenu_.querySelectorAll('.item'); 805 var items = this.shareMenu_.querySelectorAll('.item');
814 for (var i = 0; i != items.length; i++) { 806 for (var i = 0; i != items.length; i++) {
815 items[i].parentNode.removeChild(items[i]); 807 items[i].parentNode.removeChild(items[i]);
816 } 808 }
817 809
818 for (var t = 0; t != tasks.length; t++) { 810 for (var t = 0; t != tasks.length; t++) {
819 var task = tasks[t]; 811 var task = tasks[t];
820 if (!isShareAction(task)) continue; 812 if (!isShareAction(task)) continue;
821 813
822 var item = util.createChild(this.shareMenu_, 'item'); 814 var item = util.createChild(this.shareMenu_, 'item');
823 item.textContent = task.title; 815 item.textContent = task.title;
824 item.style.backgroundImage = 'url(' + task.iconUrl + ')'; 816 item.style.backgroundImage = 'url(' + task.iconUrl + ')';
825 item.addEventListener('click', function(taskId) { 817 item.addEventListener('click', function(taskId) {
826 this.toggleShare_(); // Hide the menu. 818 this.toggleShare_(); // Hide the menu.
827 this.executeWhenReady(api.executeTask.bind(api, taskId, urls)); 819 this.executeWhenReady(api.executeTask.bind(api, taskId, entries));
828 }.bind(this, task.taskId)); 820 }.bind(this, task.taskId));
829 } 821 }
830 822
831 var empty = this.shareMenu_.querySelector('.item') == null; 823 var empty = this.shareMenu_.querySelector('.item') == null;
832 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty); 824 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty);
833 this.shareMenu_.hidden = wasHidden || empty; 825 this.shareMenu_.hidden = wasHidden || empty;
834 }.bind(this); 826 }.bind(this);
835 827
836 // Create or update the share menu with a list of sharing tasks and show 828 // Create or update the share menu with a list of sharing tasks and show
837 // or hide the share button. 829 // or hide the share button.
838 if (!urls.length) 830 // TODO(mtomasz): Pass Entries directly, instead of URLs.
831 if (!entries.length)
839 createShareMenu([]); // Empty list of tasks, since there is no selection. 832 createShareMenu([]); // Empty list of tasks, since there is no selection.
840 else 833 else
841 api.getFileTasks(urls, mimeTypes, createShareMenu); 834 api.getFileTasks(util.entriesToURLs(entries), mimeTypes, createShareMenu);
842 }; 835 };
843 836
844 /** 837 /**
845 * Updates thumbnails. 838 * Updates thumbnails.
846 * @private 839 * @private
847 */ 840 */
848 Gallery.prototype.updateThumbnails_ = function() { 841 Gallery.prototype.updateThumbnails_ = function() {
849 if (this.currentMode_ == this.slideMode_) 842 if (this.currentMode_ == this.slideMode_)
850 this.slideMode_.updateThumbnails(); 843 this.slideMode_.updateThumbnails();
851 844
(...skipping 10 matching lines...) Expand all
862 */ 855 */
863 Gallery.prototype.updateButtons_ = function() { 856 Gallery.prototype.updateButtons_ = function() {
864 if (this.modeButton_) { 857 if (this.modeButton_) {
865 var oppositeMode = 858 var oppositeMode =
866 this.currentMode_ == this.slideMode_ ? this.mosaicMode_ : 859 this.currentMode_ == this.slideMode_ ? this.mosaicMode_ :
867 this.slideMode_; 860 this.slideMode_;
868 this.modeButton_.title = 861 this.modeButton_.title =
869 this.displayStringFunction_(oppositeMode.getTitle()); 862 this.displayStringFunction_(oppositeMode.getTitle());
870 } 863 }
871 }; 864 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698