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 '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 Loading... | |
| 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 Loading... | |
| 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.volumeManager_.getVolumeInfo(this.selectedEntry_) === | |
| 139 event.volumeInfo) { | |
| 137 this.onBack_(); | 140 this.onBack_(); |
| 141 } | |
| 138 }; | 142 }; |
| 139 | 143 |
| 140 /** | 144 /** |
| 141 * Beforeunload handler. | 145 * Beforeunload handler. |
| 142 * @return {string?} User-visible message on null if it is OK to close. | 146 * @return {string?} User-visible message on null if it is OK to close. |
| 143 */ | 147 */ |
| 144 Gallery.prototype.onBeforeUnload = function() { | 148 Gallery.prototype.onBeforeUnload = function() { |
| 145 return this.slideMode_.onBeforeUnload(); | 149 return this.slideMode_.onBeforeUnload(); |
| 146 }; | 150 }; |
| 147 | 151 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 * @return {HTMLElement} Newly created button. | 264 * @return {HTMLElement} Newly created button. |
| 261 * @private | 265 * @private |
| 262 */ | 266 */ |
| 263 Gallery.prototype.createToolbarButton_ = function(className, title) { | 267 Gallery.prototype.createToolbarButton_ = function(className, title) { |
| 264 var button = util.createChild(this.toolbar_, className, 'button'); | 268 var button = util.createChild(this.toolbar_, className, 'button'); |
| 265 button.title = this.displayStringFunction_(title); | 269 button.title = this.displayStringFunction_(title); |
| 266 return button; | 270 return button; |
| 267 }; | 271 }; |
| 268 | 272 |
| 269 /** | 273 /** |
| 270 * Load the content. | 274 * Load the content. |
|
hirono
2013/12/10 03:36:53
Loads
mtomasz
2013/12/10 05:07:01
Done.
| |
| 271 * | 275 * |
| 272 * @param {Array.<string>} urls Array of urls. | 276 * @param {Array.<Entry>} entries Array of entries. |
| 273 * @param {Array.<string>} selectedUrls Array of selected urls. | 277 * @param {Array.<Entry>} selectedEntries Array of selected entries. |
| 274 */ | 278 */ |
| 275 Gallery.prototype.load = function(urls, selectedUrls) { | 279 Gallery.prototype.load = function(entries, selectedEntries) { |
| 276 var items = []; | 280 var items = []; |
| 277 for (var index = 0; index < urls.length; ++index) { | 281 for (var index = 0; index < entries.length; ++index) { |
| 278 items.push(new Gallery.Item(urls[index])); | 282 items.push(new Gallery.Item(entries[index])); |
| 279 } | 283 } |
| 280 this.dataModel_.push.apply(this.dataModel_, items); | 284 this.dataModel_.push.apply(this.dataModel_, items); |
| 281 | 285 |
| 282 this.selectionModel_.adjustLength(this.dataModel_.length); | 286 this.selectionModel_.adjustLength(this.dataModel_.length); |
| 283 | 287 |
| 284 for (var i = 0; i != selectedUrls.length; i++) { | 288 for (var i = 0; i !== selectedEntries.length; i++) { |
| 285 var selectedIndex = urls.indexOf(selectedUrls[i]); | 289 var selectedIndex = entries.indexOf(selectedEntries[i]); |
|
hirono
2013/12/10 03:36:53
Can we use indexOf to compare Entries?
If it is pr
mtomasz
2013/12/10 05:07:01
Added a comment. Done.
| |
| 286 if (selectedIndex >= 0) | 290 if (selectedIndex >= 0) |
| 287 this.selectionModel_.setIndexSelected(selectedIndex, true); | 291 this.selectionModel_.setIndexSelected(selectedIndex, true); |
| 288 else | 292 else |
| 289 console.error('Cannot select ' + selectedUrls[i]); | 293 console.error('Cannot select ' + selectedEntries[i]); |
| 290 } | 294 } |
| 291 | 295 |
| 292 if (this.selectionModel_.selectedIndexes.length == 0) | 296 if (this.selectionModel_.selectedIndexes.length === 0) |
| 293 this.onSelection_(); | 297 this.onSelection_(); |
| 294 | 298 |
| 295 var mosaic = this.mosaicMode_ && this.mosaicMode_.getMosaic(); | 299 var mosaic = this.mosaicMode_ && this.mosaicMode_.getMosaic(); |
| 296 | 300 |
| 297 // Mosaic view should show up if most of the selected files are images. | 301 // Mosaic view should show up if most of the selected files are images. |
| 298 var imagesCount = 0; | 302 var imagesCount = 0; |
| 299 for (var i = 0; i != selectedUrls.length; i++) { | 303 for (var i = 0; i !== selectedEntries.length; i++) { |
| 300 if (FileType.getMediaType(selectedUrls[i]) == 'image') | 304 if (FileType.getMediaType(selectedEntries[i]) === 'image') |
| 301 imagesCount++; | 305 imagesCount++; |
| 302 } | 306 } |
| 303 var mostlyImages = imagesCount > (selectedUrls.length / 2.0); | 307 var mostlyImages = imagesCount > (selectedEntries.length / 2.0); |
| 304 | 308 |
| 305 var forcedMosaic = (this.context_.pageState && | 309 var forcedMosaic = (this.context_.pageState && |
| 306 this.context_.pageState.gallery == 'mosaic'); | 310 this.context_.pageState.gallery === 'mosaic'); |
| 307 | 311 |
| 308 var showMosaic = (mostlyImages && selectedUrls.length > 1) || forcedMosaic; | 312 var showMosaic = (mostlyImages && selectedEntries.length > 1) || forcedMosaic; |
| 309 if (mosaic && showMosaic) { | 313 if (mosaic && showMosaic) { |
| 310 this.setCurrentMode_(this.mosaicMode_); | 314 this.setCurrentMode_(this.mosaicMode_); |
| 311 mosaic.init(); | 315 mosaic.init(); |
| 312 mosaic.show(); | 316 mosaic.show(); |
| 313 this.inactivityWatcher_.check(); // Show the toolbar. | 317 this.inactivityWatcher_.check(); // Show the toolbar. |
| 314 cr.dispatchSimpleEvent(this, 'loaded'); | 318 cr.dispatchSimpleEvent(this, 'loaded'); |
| 315 } else { | 319 } else { |
| 316 this.setCurrentMode_(this.slideMode_); | 320 this.setCurrentMode_(this.slideMode_); |
| 317 var maybeLoadMosaic = function() { | 321 var maybeLoadMosaic = function() { |
| 318 if (mosaic) | 322 if (mosaic) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 330 | 334 |
| 331 /** | 335 /** |
| 332 * Close the Gallery and go to Files.app. | 336 * Close the Gallery and go to Files.app. |
| 333 * @private | 337 * @private |
| 334 */ | 338 */ |
| 335 Gallery.prototype.back_ = function() { | 339 Gallery.prototype.back_ = function() { |
| 336 if (util.isFullScreen(this.context_.appWindow)) { | 340 if (util.isFullScreen(this.context_.appWindow)) { |
| 337 util.toggleFullScreen(this.context_.appWindow, | 341 util.toggleFullScreen(this.context_.appWindow, |
| 338 false); // Leave the full screen mode. | 342 false); // Leave the full screen mode. |
| 339 } | 343 } |
| 340 this.context_.onBack(this.getSelectedUrls()); | 344 this.context_.onBack(this.getSelectedEntries()); |
| 341 }; | 345 }; |
| 342 | 346 |
| 343 /** | 347 /** |
| 344 * Handle user's 'Back' action (Escape or a click on the X icon). | 348 * Handle user's 'Back' action (Escape or a click on the X icon). |
| 345 * @private | 349 * @private |
| 346 */ | 350 */ |
| 347 Gallery.prototype.onBack_ = function() { | 351 Gallery.prototype.onBack_ = function() { |
| 348 this.executeWhenReady(this.back_.bind(this)); | 352 this.executeWhenReady(this.back_.bind(this)); |
| 349 }; | 353 }; |
| 350 | 354 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 // Show the toolbar and hide it after the default timeout. | 400 // Show the toolbar and hide it after the default timeout. |
| 397 this.inactivityWatcher_.kick(); | 401 this.inactivityWatcher_.kick(); |
| 398 }; | 402 }; |
| 399 | 403 |
| 400 /** | 404 /** |
| 401 * Set the current mode, update the UI. | 405 * Set the current mode, update the UI. |
| 402 * @param {Object} mode Current mode. | 406 * @param {Object} mode Current mode. |
| 403 * @private | 407 * @private |
| 404 */ | 408 */ |
| 405 Gallery.prototype.setCurrentMode_ = function(mode) { | 409 Gallery.prototype.setCurrentMode_ = function(mode) { |
| 406 if (mode != this.slideMode_ && mode != this.mosaicMode_) | 410 if (mode !== this.slideMode_ && mode !== this.mosaicMode_) |
| 407 console.error('Invalid Gallery mode'); | 411 console.error('Invalid Gallery mode'); |
| 408 | 412 |
| 409 this.currentMode_ = mode; | 413 this.currentMode_ = mode; |
| 410 this.container_.setAttribute('mode', this.currentMode_.getName()); | 414 this.container_.setAttribute('mode', this.currentMode_.getName()); |
| 411 this.updateSelectionAndState_(); | 415 this.updateSelectionAndState_(); |
| 412 this.updateButtons_(); | 416 this.updateButtons_(); |
| 413 }; | 417 }; |
| 414 | 418 |
| 415 /** | 419 /** |
| 416 * Mode toggle event handler. | 420 * Mode toggle event handler. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 433 var onModeChanged = function() { | 437 var onModeChanged = function() { |
| 434 this.changingMode_ = false; | 438 this.changingMode_ = false; |
| 435 if (opt_callback) opt_callback(); | 439 if (opt_callback) opt_callback(); |
| 436 }.bind(this); | 440 }.bind(this); |
| 437 | 441 |
| 438 var tileIndex = Math.max(0, this.selectionModel_.selectedIndex); | 442 var tileIndex = Math.max(0, this.selectionModel_.selectedIndex); |
| 439 | 443 |
| 440 var mosaic = this.mosaicMode_.getMosaic(); | 444 var mosaic = this.mosaicMode_.getMosaic(); |
| 441 var tileRect = mosaic.getTileRect(tileIndex); | 445 var tileRect = mosaic.getTileRect(tileIndex); |
| 442 | 446 |
| 443 if (this.currentMode_ == this.slideMode_) { | 447 if (this.currentMode_ === this.slideMode_) { |
| 444 this.setCurrentMode_(this.mosaicMode_); | 448 this.setCurrentMode_(this.mosaicMode_); |
| 445 mosaic.transform( | 449 mosaic.transform( |
| 446 tileRect, this.slideMode_.getSelectedImageRect(), true /* instant */); | 450 tileRect, this.slideMode_.getSelectedImageRect(), true /* instant */); |
| 447 this.slideMode_.leave(tileRect, | 451 this.slideMode_.leave(tileRect, |
| 448 function() { | 452 function() { |
| 449 // Animate back to normal position. | 453 // Animate back to normal position. |
| 450 mosaic.transform(); | 454 mosaic.transform(); |
| 451 mosaic.show(); | 455 mosaic.show(); |
| 452 onModeChanged(); | 456 onModeChanged(); |
| 453 }.bind(this)); | 457 }.bind(this)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 478 /* TODO(dgozman): Implement Undo delete, Remove the confirmation dialog. */ | 482 /* TODO(dgozman): Implement Undo delete, Remove the confirmation dialog. */ |
| 479 | 483 |
| 480 var itemsToRemove = this.getSelectedItems(); | 484 var itemsToRemove = this.getSelectedItems(); |
| 481 var plural = itemsToRemove.length > 1; | 485 var plural = itemsToRemove.length > 1; |
| 482 var param = plural ? itemsToRemove.length : itemsToRemove[0].getFileName(); | 486 var param = plural ? itemsToRemove.length : itemsToRemove[0].getFileName(); |
| 483 | 487 |
| 484 function deleteNext() { | 488 function deleteNext() { |
| 485 if (!itemsToRemove.length) | 489 if (!itemsToRemove.length) |
| 486 return; // All deleted. | 490 return; // All deleted. |
| 487 | 491 |
| 488 var url = itemsToRemove.pop().getUrl(); | 492 // TODO(hirono): Use fileOperationManager. |
| 489 webkitResolveLocalFileSystemURL(url, | 493 var entry = itemsToRemove.pop().getEntry(); |
| 490 function(entry) { | 494 entry.remove(deleteNext, function() { |
| 491 entry.remove(deleteNext, | 495 util.flog('Error deleting: ' + entry.fullPath, deleteNext); |
| 492 util.flog('Error deleting ' + url, deleteNext)); | 496 }); |
| 493 }, | |
| 494 util.flog('Error resolving ' + url, deleteNext)); | |
| 495 } | 497 } |
| 496 | 498 |
| 497 // Prevent the Gallery from handling Esc and Enter. | 499 // Prevent the Gallery from handling Esc and Enter. |
| 498 this.document_.body.removeEventListener('keydown', this.keyDownBound_); | 500 this.document_.body.removeEventListener('keydown', this.keyDownBound_); |
| 499 var restoreListener = function() { | 501 var restoreListener = function() { |
| 500 this.document_.body.addEventListener('keydown', this.keyDownBound_); | 502 this.document_.body.addEventListener('keydown', this.keyDownBound_); |
| 501 }.bind(this); | 503 }.bind(this); |
| 502 | 504 |
| 503 cr.ui.dialogs.BaseDialog.OK_LABEL = this.displayStringFunction_( | 505 cr.ui.dialogs.BaseDialog.OK_LABEL = this.displayStringFunction_( |
| 504 'GALLERY_OK_LABEL'); | 506 'GALLERY_OK_LABEL'); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 526 | 528 |
| 527 /** | 529 /** |
| 528 * @return {Array.<Gallery.Item>} Current selection. | 530 * @return {Array.<Gallery.Item>} Current selection. |
| 529 */ | 531 */ |
| 530 Gallery.prototype.getSelectedItems = function() { | 532 Gallery.prototype.getSelectedItems = function() { |
| 531 return this.selectionModel_.selectedIndexes.map( | 533 return this.selectionModel_.selectedIndexes.map( |
| 532 this.dataModel_.item.bind(this.dataModel_)); | 534 this.dataModel_.item.bind(this.dataModel_)); |
| 533 }; | 535 }; |
| 534 | 536 |
| 535 /** | 537 /** |
| 536 * @return {Array.<string>} Array of currently selected urls. | 538 * @return {Array.<Entry>} Array of currently selected entries. |
| 537 */ | 539 */ |
| 538 Gallery.prototype.getSelectedUrls = function() { | 540 Gallery.prototype.getSelectedEntries = function() { |
| 539 return this.selectionModel_.selectedIndexes.map(function(index) { | 541 return this.selectionModel_.selectedIndexes.map(function(index) { |
| 540 return this.dataModel_.item(index).getUrl(); | 542 return this.dataModel_.item(index).getEntry(); |
| 541 }.bind(this)); | 543 }.bind(this)); |
| 542 }; | 544 }; |
| 543 | 545 |
| 544 /** | 546 /** |
| 545 * @return {Gallery.Item} Current single selection. | 547 * @return {Gallery.Item} Current single selection. |
| 546 */ | 548 */ |
| 547 Gallery.prototype.getSingleSelectedItem = function() { | 549 Gallery.prototype.getSingleSelectedItem = function() { |
| 548 var items = this.getSelectedItems(); | 550 var items = this.getSelectedItems(); |
| 549 if (items.length > 1) | 551 if (items.length > 1) |
| 550 throw new Error('Unexpected multiple selection'); | 552 throw new Error('Unexpected multiple selection'); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 568 this.selectionModel_.adjustLength(this.dataModel_.length); | 570 this.selectionModel_.adjustLength(this.dataModel_.length); |
| 569 }; | 571 }; |
| 570 | 572 |
| 571 /** | 573 /** |
| 572 * Content change event handler. | 574 * Content change event handler. |
| 573 * @param {Event} event Event. | 575 * @param {Event} event Event. |
| 574 * @private | 576 * @private |
| 575 */ | 577 */ |
| 576 Gallery.prototype.onContentChange_ = function(event) { | 578 Gallery.prototype.onContentChange_ = function(event) { |
| 577 var index = this.dataModel_.indexOf(event.item); | 579 var index = this.dataModel_.indexOf(event.item); |
| 578 if (index != this.selectionModel_.selectedIndex) | 580 if (index !== this.selectionModel_.selectedIndex) |
| 579 console.error('Content changed for unselected item'); | 581 console.error('Content changed for unselected item'); |
| 580 this.updateSelectionAndState_(); | 582 this.updateSelectionAndState_(); |
| 581 }; | 583 }; |
| 582 | 584 |
| 583 /** | 585 /** |
| 584 * Keydown handler. | 586 * Keydown handler. |
| 585 * | 587 * |
| 586 * @param {Event} event Event. | 588 * @param {Event} event Event. |
| 587 * @private | 589 * @private |
| 588 */ | 590 */ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 /** | 627 /** |
| 626 * Update the UI related to the selected item and the persistent state. | 628 * Update the UI related to the selected item and the persistent state. |
| 627 * | 629 * |
| 628 * @private | 630 * @private |
| 629 */ | 631 */ |
| 630 Gallery.prototype.updateSelectionAndState_ = function() { | 632 Gallery.prototype.updateSelectionAndState_ = function() { |
| 631 var path; | 633 var path; |
| 632 var displayName = ''; | 634 var displayName = ''; |
| 633 | 635 |
| 634 var selectedItems = this.getSelectedItems(); | 636 var selectedItems = this.getSelectedItems(); |
| 635 if (selectedItems.length == 1) { | 637 if (selectedItems.length === 1) { |
| 636 var item = selectedItems[0]; | 638 var item = selectedItems[0]; |
| 637 path = util.extractFilePath(item.getUrl()); | 639 var entry = item.getEntry(); |
| 638 var fullName = item.getFileName(); | 640 window.top.document.title = entry.name; |
| 639 window.top.document.title = fullName; | 641 displayName = ImageUtil.getDisplayNameFromName(entry.name); |
| 640 displayName = ImageUtil.getFileNameFromFullName(fullName); | |
| 641 } else if (selectedItems.length > 1 && this.context_.curDirEntry) { | 642 } else if (selectedItems.length > 1 && this.context_.curDirEntry) { |
| 642 // If the Gallery was opened on search results the search query will not be | 643 // 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 | 644 // recorded in the app state and the relaunch will just open the gallery |
| 644 // in the curDirEntry directory. | 645 // in the curDirEntry directory. |
| 645 path = this.context_.curDirEntry.fullPath; | 646 path = this.context_.curDirEntry.fullPath; |
| 646 window.top.document.title = this.context_.curDirEntry.name; | 647 window.top.document.title = this.context_.curDirEntry.name; |
| 647 displayName = | 648 displayName = |
| 648 this.displayStringFunction_('GALLERY_ITEMS_SELECTED', | 649 this.displayStringFunction_('GALLERY_ITEMS_SELECTED', |
| 649 selectedItems.length); | 650 selectedItems.length); |
| 650 } | 651 } |
| 651 | 652 |
| 652 window.top.util.updateAppState(path, | 653 window.top.util.updateAppState(path, |
| 653 {gallery: (this.currentMode_ == this.mosaicMode_ ? 'mosaic' : 'slide')}); | 654 {gallery: (this.currentMode_ === this.mosaicMode_ ? 'mosaic' : 'slide')}); |
| 654 | 655 |
| 655 // We can't rename files in readonly directory. | 656 // We can't rename files in readonly directory. |
| 656 // We can only rename a single file. | 657 // We can only rename a single file. |
| 657 this.filenameEdit_.disabled = selectedItems.length != 1 || | 658 this.filenameEdit_.disabled = selectedItems.length !== 1 || |
| 658 this.context_.readonlyDirName; | 659 this.context_.readonlyDirName; |
| 659 | 660 |
| 660 this.filenameEdit_.value = displayName; | 661 this.filenameEdit_.value = displayName; |
| 661 | 662 |
| 662 // Resolve real filesystem path of the current file. | 663 // Resolve real filesystem path of the current file. |
| 663 if (this.selectionModel_.selectedIndexes.length) { | 664 if (this.selectionModel_.selectedIndexes.length) { |
| 664 var selectedIndex = this.selectionModel_.selectedIndex; | 665 var selectedIndex = this.selectionModel_.selectedIndex; |
| 665 var selectedItem = | 666 var selectedItem = |
| 666 this.dataModel_.item(this.selectionModel_.selectedIndex); | 667 this.dataModel_.item(this.selectionModel_.selectedIndex); |
| 667 | 668 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 } | 669 } |
| 676 }; | 670 }; |
| 677 | 671 |
| 678 /** | 672 /** |
| 679 * Click event handler on filename edit box | 673 * Click event handler on filename edit box |
| 680 * @private | 674 * @private |
| 681 */ | 675 */ |
| 682 Gallery.prototype.onFilenameFocus_ = function() { | 676 Gallery.prototype.onFilenameFocus_ = function() { |
| 683 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', true); | 677 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', true); |
| 684 this.filenameEdit_.originalValue = this.filenameEdit_.value; | 678 this.filenameEdit_.originalValue = this.filenameEdit_.value; |
| 685 setTimeout(this.filenameEdit_.select.bind(this.filenameEdit_), 0); | 679 setTimeout(this.filenameEdit_.select.bind(this.filenameEdit_), 0); |
| 686 this.onUserAction_(); | 680 this.onUserAction_(); |
| 687 }; | 681 }; |
| 688 | 682 |
| 689 /** | 683 /** |
| 690 * Blur event handler on filename edit box. | 684 * Blur event handler on filename edit box. |
| 691 * | 685 * |
| 692 * @param {Event} event Blur event. | 686 * @param {Event} event Blur event. |
| 693 * @return {boolean} if default action should be prevented. | 687 * @return {boolean} if default action should be prevented. |
| 694 * @private | 688 * @private |
| 695 */ | 689 */ |
| 696 Gallery.prototype.onFilenameEditBlur_ = function(event) { | 690 Gallery.prototype.onFilenameEditBlur_ = function(event) { |
| 697 if (this.filenameEdit_.value && this.filenameEdit_.value[0] == '.') { | 691 if (this.filenameEdit_.value && this.filenameEdit_.value[0] === '.') { |
| 698 this.prompt_.show('GALLERY_FILE_HIDDEN_NAME', 5000); | 692 this.prompt_.show('GALLERY_FILE_HIDDEN_NAME', 5000); |
| 699 this.filenameEdit_.focus(); | 693 this.filenameEdit_.focus(); |
| 700 event.stopPropagation(); | 694 event.stopPropagation(); |
| 701 event.preventDefault(); | 695 event.preventDefault(); |
| 702 return false; | 696 return false; |
| 703 } | 697 } |
| 704 | 698 |
| 705 var item = this.getSingleSelectedItem(); | 699 var item = this.getSingleSelectedItem(); |
| 706 var oldUrl = item.getUrl(); | 700 var oldEntry = item.getEntry(); |
| 707 | 701 |
| 708 var onFileExists = function() { | 702 var onFileExists = function() { |
| 709 this.prompt_.show('GALLERY_FILE_EXISTS', 3000); | 703 this.prompt_.show('GALLERY_FILE_EXISTS', 3000); |
| 710 this.filenameEdit_.value = name; | 704 this.filenameEdit_.value = name; |
| 711 this.filenameEdit_.focus(); | 705 this.filenameEdit_.focus(); |
| 712 }.bind(this); | 706 }.bind(this); |
| 713 | 707 |
| 714 var onSuccess = function() { | 708 var onSuccess = function() { |
| 715 var e = new Event('content'); | 709 var event = new Event('content'); |
| 716 e.item = item; | 710 event.item = item; |
| 717 e.oldUrl = oldUrl; | 711 event.oldEntry = oldEntry; |
| 718 e.metadata = null; // Metadata unchanged. | 712 event.metadata = null; // Metadata unchanged. |
| 719 this.dataModel_.dispatchEvent(e); | 713 this.dataModel_.dispatchEvent(event); |
| 720 }.bind(this); | 714 }.bind(this); |
| 721 | 715 |
| 722 if (this.filenameEdit_.value) { | 716 if (this.filenameEdit_.value) { |
| 723 this.getSingleSelectedItem().rename( | 717 this.getSingleSelectedItem().rename( |
| 724 this.filenameEdit_.value, onSuccess, onFileExists); | 718 this.filenameEdit_.value, onSuccess, onFileExists); |
| 725 } | 719 } |
| 726 | 720 |
| 727 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', false); | 721 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', false); |
| 728 this.onUserAction_(); | 722 this.onUserAction_(); |
| 729 }; | 723 }; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 if (!this.shareButton_.hasAttribute('disabled')) | 784 if (!this.shareButton_.hasAttribute('disabled')) |
| 791 this.shareMenu_.hidden = !this.shareMenu_.hidden; | 785 this.shareMenu_.hidden = !this.shareMenu_.hidden; |
| 792 this.inactivityWatcher_.check(); | 786 this.inactivityWatcher_.check(); |
| 793 }; | 787 }; |
| 794 | 788 |
| 795 /** | 789 /** |
| 796 * Updates available actions list based on the currently selected urls. | 790 * Updates available actions list based on the currently selected urls. |
| 797 * @private. | 791 * @private. |
| 798 */ | 792 */ |
| 799 Gallery.prototype.updateShareMenu_ = function() { | 793 Gallery.prototype.updateShareMenu_ = function() { |
| 800 var urls = this.getSelectedUrls(); | 794 var entries = this.getSelectedEntries(); |
| 801 | 795 |
| 802 function isShareAction(task) { | 796 function isShareAction(task) { |
| 803 var taskParts = task.taskId.split('|'); | 797 var taskParts = task.taskId.split('|'); |
| 804 return taskParts[0] != chrome.runtime.id; | 798 return taskParts[0] !== chrome.runtime.id; |
| 805 } | 799 } |
| 806 | 800 |
| 807 var api = Gallery.getFileBrowserPrivate(); | 801 var api = Gallery.getFileBrowserPrivate(); |
| 808 var mimeTypes = []; // TODO(kaznacheev) Collect mime types properly. | 802 var mimeTypes = []; // TODO(kaznacheev) Collect mime types properly. |
| 809 | 803 |
| 810 var createShareMenu = function(tasks) { | 804 var createShareMenu = function(tasks) { |
| 811 var wasHidden = this.shareMenu_.hidden; | 805 var wasHidden = this.shareMenu_.hidden; |
| 812 this.shareMenu_.hidden = true; | 806 this.shareMenu_.hidden = true; |
| 813 var items = this.shareMenu_.querySelectorAll('.item'); | 807 var items = this.shareMenu_.querySelectorAll('.item'); |
| 814 for (var i = 0; i != items.length; i++) { | 808 for (var i = 0; i !== items.length; i++) { |
| 815 items[i].parentNode.removeChild(items[i]); | 809 items[i].parentNode.removeChild(items[i]); |
| 816 } | 810 } |
| 817 | 811 |
| 818 for (var t = 0; t != tasks.length; t++) { | 812 for (var t = 0; t !== tasks.length; t++) { |
| 819 var task = tasks[t]; | 813 var task = tasks[t]; |
| 820 if (!isShareAction(task)) continue; | 814 if (!isShareAction(task)) continue; |
| 821 | 815 |
| 822 var item = util.createChild(this.shareMenu_, 'item'); | 816 var item = util.createChild(this.shareMenu_, 'item'); |
| 823 item.textContent = task.title; | 817 item.textContent = task.title; |
| 824 item.style.backgroundImage = 'url(' + task.iconUrl + ')'; | 818 item.style.backgroundImage = 'url(' + task.iconUrl + ')'; |
| 825 item.addEventListener('click', function(taskId) { | 819 item.addEventListener('click', function(taskId) { |
| 826 this.toggleShare_(); // Hide the menu. | 820 this.toggleShare_(); // Hide the menu. |
| 827 this.executeWhenReady(api.executeTask.bind(api, taskId, urls)); | 821 this.executeWhenReady(api.executeTask.bind(api, taskId, entries)); |
| 828 }.bind(this, task.taskId)); | 822 }.bind(this, task.taskId)); |
| 829 } | 823 } |
| 830 | 824 |
| 831 var empty = this.shareMenu_.querySelector('.item') == null; | 825 var empty = this.shareMenu_.querySelector('.item') === null; |
| 832 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty); | 826 ImageUtil.setAttribute(this.shareButton_, 'disabled', empty); |
| 833 this.shareMenu_.hidden = wasHidden || empty; | 827 this.shareMenu_.hidden = wasHidden || empty; |
| 834 }.bind(this); | 828 }.bind(this); |
| 835 | 829 |
| 836 // Create or update the share menu with a list of sharing tasks and show | 830 // Create or update the share menu with a list of sharing tasks and show |
| 837 // or hide the share button. | 831 // or hide the share button. |
| 838 if (!urls.length) | 832 // TODO(mtomasz): Pass Entries directly, instead of URLs. |
| 833 if (!entries.length) | |
| 839 createShareMenu([]); // Empty list of tasks, since there is no selection. | 834 createShareMenu([]); // Empty list of tasks, since there is no selection. |
| 840 else | 835 else |
| 841 api.getFileTasks(urls, mimeTypes, createShareMenu); | 836 api.getFileTasks(util.entriesToURLs(entries), mimeTypes, createShareMenu); |
| 842 }; | 837 }; |
| 843 | 838 |
| 844 /** | 839 /** |
| 845 * Updates thumbnails. | 840 * Updates thumbnails. |
| 846 * @private | 841 * @private |
| 847 */ | 842 */ |
| 848 Gallery.prototype.updateThumbnails_ = function() { | 843 Gallery.prototype.updateThumbnails_ = function() { |
| 849 if (this.currentMode_ == this.slideMode_) | 844 if (this.currentMode_ === this.slideMode_) |
| 850 this.slideMode_.updateThumbnails(); | 845 this.slideMode_.updateThumbnails(); |
| 851 | 846 |
| 852 if (this.mosaicMode_) { | 847 if (this.mosaicMode_) { |
| 853 var mosaic = this.mosaicMode_.getMosaic(); | 848 var mosaic = this.mosaicMode_.getMosaic(); |
| 854 if (mosaic.isInitialized()) | 849 if (mosaic.isInitialized()) |
| 855 mosaic.reload(); | 850 mosaic.reload(); |
| 856 } | 851 } |
| 857 }; | 852 }; |
| 858 | 853 |
| 859 /** | 854 /** |
| 860 * Updates buttons. | 855 * Updates buttons. |
| 861 * @private | 856 * @private |
| 862 */ | 857 */ |
| 863 Gallery.prototype.updateButtons_ = function() { | 858 Gallery.prototype.updateButtons_ = function() { |
| 864 if (this.modeButton_) { | 859 if (this.modeButton_) { |
| 865 var oppositeMode = | 860 var oppositeMode = |
| 866 this.currentMode_ == this.slideMode_ ? this.mosaicMode_ : | 861 this.currentMode_ === this.slideMode_ ? this.mosaicMode_ : |
| 867 this.slideMode_; | 862 this.slideMode_; |
| 868 this.modeButton_.title = | 863 this.modeButton_.title = |
| 869 this.displayStringFunction_(oppositeMode.getTitle()); | 864 this.displayStringFunction_(oppositeMode.getTitle()); |
| 870 } | 865 } |
| 871 }; | 866 }; |
| OLD | NEW |