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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 2498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2509 var dirPath = this.directoryModel_.currentEntry.fullPath; | 2509 var dirPath = this.directoryModel_.currentEntry.fullPath; |
2510 | 2510 |
2511 // Push a temporary state which will be replaced every time an individual | 2511 // Push a temporary state which will be replaced every time an individual |
2512 // item is selected in the Gallery. | 2512 // item is selected in the Gallery. |
2513 this.updateLocation_(false /*push*/, dirPath); | 2513 this.updateLocation_(false /*push*/, dirPath); |
2514 | 2514 |
2515 galleryFrame.onload = function() { | 2515 galleryFrame.onload = function() { |
2516 self.document_.title = str('GALLERY'); | 2516 self.document_.title = str('GALLERY'); |
2517 galleryFrame.contentWindow.ImageUtil.metrics = metrics; | 2517 galleryFrame.contentWindow.ImageUtil.metrics = metrics; |
2518 galleryFrame.contentWindow.FileType = FileType; | 2518 galleryFrame.contentWindow.FileType = FileType; |
2519 galleryFrame.contentWindow.util = util; | |
2519 | 2520 |
2520 galleryFrame.contentWindow.Gallery.open( | 2521 galleryFrame.contentWindow.Gallery.open( |
2521 self.directoryModel_.currentEntry, | 2522 self.directoryModel_.currentEntry, |
2522 urls, | 2523 urls, |
2523 selectedUrl, | 2524 selectedUrl, |
2524 function(name) { | 2525 function(name) { |
2525 self.updateLocation_(true /*replace*/, dirPath + '/' + name); | 2526 self.updateLocation_(true /*replace*/, dirPath + '/' + name); |
2526 }, | 2527 }, |
2527 function () { history.back(1) }, | 2528 function () { history.back(1) }, |
2528 self.metadataProvider_, | 2529 self.metadataProvider_, |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3352 | 3353 |
3353 FileManager.prototype.onRenameInputKeyDown_ = function(event) { | 3354 FileManager.prototype.onRenameInputKeyDown_ = function(event) { |
3354 if (!this.isRenamingInProgress()) | 3355 if (!this.isRenamingInProgress()) |
3355 return; | 3356 return; |
3356 | 3357 |
3357 // Do not move selection or lead item in list during rename. | 3358 // Do not move selection or lead item in list during rename. |
3358 if (event.keyIdentifier == 'Up' || event.keyIdentifier == 'Down') { | 3359 if (event.keyIdentifier == 'Up' || event.keyIdentifier == 'Down') { |
3359 event.stopPropagation(); | 3360 event.stopPropagation(); |
3360 } | 3361 } |
3361 | 3362 |
3362 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) | 3363 switch (util.getKeyModifiers(event) + event.keyCode) { |
3363 return; | 3364 case '27': // Escape |
3364 | |
3365 switch (event.keyCode) { | |
3366 case 27: // Escape | |
3367 this.cancelRename_(); | 3365 this.cancelRename_(); |
3368 event.preventDefault(); | 3366 event.preventDefault(); |
3369 break; | 3367 break; |
3370 | 3368 |
3371 case 13: // Enter | 3369 case '13': // Enter |
3372 this.commitRename_(); | 3370 this.commitRename_(); |
3373 event.preventDefault(); | 3371 event.preventDefault(); |
3374 break; | 3372 break; |
3375 } | 3373 } |
3376 }; | 3374 }; |
3377 | 3375 |
3378 FileManager.prototype.onRenameInputBlur_ = function(event) { | 3376 FileManager.prototype.onRenameInputBlur_ = function(event) { |
3379 if (this.isRenamingInProgress() && !this.renameInput_.validation_) | 3377 if (this.isRenamingInProgress() && !this.renameInput_.validation_) |
3380 this.cancelRename_(); | 3378 this.cancelRename_(); |
3381 }; | 3379 }; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3433 var parent = this.renameInput_.parentNode; | 3431 var parent = this.renameInput_.parentNode; |
3434 if (parent) { | 3432 if (parent) { |
3435 parent.removeAttribute('renaming'); | 3433 parent.removeAttribute('renaming'); |
3436 parent.removeChild(this.renameInput_); | 3434 parent.removeChild(this.renameInput_); |
3437 } | 3435 } |
3438 this.refocus(); | 3436 this.refocus(); |
3439 }; | 3437 }; |
3440 | 3438 |
3441 FileManager.prototype.onFilenameInputKeyUp_ = function(event) { | 3439 FileManager.prototype.onFilenameInputKeyUp_ = function(event) { |
3442 var enabled = this.updateOkButton_(); | 3440 var enabled = this.updateOkButton_(); |
3443 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) | 3441 if (util.getKeyModifiers(event)) |
3444 return; | 3442 return; |
3445 if (enabled && event.keyCode == 13 /* Enter */) | 3443 if (enabled && event.keyCode == 13 /* Enter */) |
SeRya
2012/03/02 11:00:31
Let's unity approach. Put [util.getKeyModifiers(ev
Vladislav Kaznacheev
2012/03/02 11:05:33
Done.
| |
3446 this.onOk_(); | 3444 this.onOk_(); |
3447 }; | 3445 }; |
3448 | 3446 |
3449 FileManager.prototype.onFilenameInputFocus_ = function(event) { | 3447 FileManager.prototype.onFilenameInputFocus_ = function(event) { |
3450 var input = this.filenameInput_; | 3448 var input = this.filenameInput_; |
3451 | 3449 |
3452 // On focus we want to select everything but the extension, but | 3450 // On focus we want to select everything but the extension, but |
3453 // Chrome will select-all after the focus event completes. We | 3451 // Chrome will select-all after the focus event completes. We |
3454 // schedule a timeout to alter the focus after that happens. | 3452 // schedule a timeout to alter the focus after that happens. |
3455 setTimeout(function() { | 3453 setTimeout(function() { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3556 | 3554 |
3557 /** | 3555 /** |
3558 * KeyDown event handler for the document. | 3556 * KeyDown event handler for the document. |
3559 */ | 3557 */ |
3560 FileManager.prototype.onKeyDown_ = function(event) { | 3558 FileManager.prototype.onKeyDown_ = function(event) { |
3561 if (event.srcElement === this.renameInput_) { | 3559 if (event.srcElement === this.renameInput_) { |
3562 // Ignore keydown handler in the rename input box. | 3560 // Ignore keydown handler in the rename input box. |
3563 return; | 3561 return; |
3564 } | 3562 } |
3565 | 3563 |
3566 if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { | 3564 switch (util.getKeyModifiers(event) + event.keyCode) { |
3567 switch (event.keyCode) { | 3565 case 'Ctrl-190': // Ctrl-. => Toggle filter files. |
3568 case 190: // Ctrl-. => Toggle filter files. | 3566 var dm = this.directoryModel_; |
3569 var dm = this.directoryModel_; | 3567 dm.filterHidden = !dm.filterHidden; |
3570 dm.filterHidden = !dm.filterHidden; | 3568 event.preventDefault(); |
3569 return; | |
3570 | |
3571 case '27': // Escape => Cancel dialog. | |
3572 if (this.copyManager_.getStatus().totalFiles != 0) { | |
3573 // If there is a copy in progress, ESC will cancel it. | |
3571 event.preventDefault(); | 3574 event.preventDefault(); |
3575 this.copyManager_.requestCancel(); | |
3572 return; | 3576 return; |
3573 } | 3577 } |
3574 } | |
3575 | 3578 |
3576 if (!event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { | 3579 if (this.butterTimer_) { |
3577 switch (event.keyCode) { | 3580 // Allow the user to manually dismiss timed butter messages. |
3578 case 27: // Escape => Cancel dialog. | 3581 event.preventDefault(); |
3579 if (this.copyManager_.getStatus().totalFiles != 0) { | 3582 this.hideButter(); |
3580 // If there is a copy in progress, ESC will cancel it. | 3583 return; |
3581 event.preventDefault(); | 3584 } |
3582 this.copyManager_.requestCancel(); | |
3583 return; | |
3584 } | |
3585 | 3585 |
3586 if (this.butterTimer_) { | 3586 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { |
3587 // Allow the user to manually dismiss timed butter messages. | 3587 // If there is nothing else for ESC to do, then cancel the dialog. |
3588 event.preventDefault(); | 3588 event.preventDefault(); |
3589 this.hideButter(); | 3589 this.onCancel_(); |
3590 return; | 3590 } |
3591 } | 3591 break; |
3592 | |
3593 if (this.dialogType_ != FileManager.DialogType.FULL_PAGE) { | |
3594 // If there is nothing else for ESC to do, then cancel the dialog. | |
3595 event.preventDefault(); | |
3596 this.onCancel_(); | |
3597 } | |
3598 break; | |
3599 } | |
3600 } | 3592 } |
3601 }; | 3593 }; |
3602 | 3594 |
3603 /** | 3595 /** |
3604 * KeyDown event handler for the div.list-container element. | 3596 * KeyDown event handler for the div.list-container element. |
3605 */ | 3597 */ |
3606 FileManager.prototype.onListKeyDown_ = function(event) { | 3598 FileManager.prototype.onListKeyDown_ = function(event) { |
3607 if (event.srcElement.tagName == 'INPUT') { | 3599 if (event.srcElement.tagName == 'INPUT') { |
3608 // Ignore keydown handler in the rename input box. | 3600 // Ignore keydown handler in the rename input box. |
3609 return; | 3601 return; |
3610 } | 3602 } |
3611 | 3603 |
3612 var self = this; | 3604 var self = this; |
3613 function handleCommand(name) { | 3605 function handleCommand(name) { |
3614 self.updateCommands_(); | 3606 self.updateCommands_(); |
3615 if (self.commands_[name].disabled) | 3607 if (self.commands_[name].disabled) |
3616 return; | 3608 return; |
3617 event.preventDefault(); | 3609 event.preventDefault(); |
3618 event.stopPropagation(); | 3610 event.stopPropagation(); |
3619 self.commands_[name].execute(); | 3611 self.commands_[name].execute(); |
3620 } | 3612 } |
3621 | 3613 |
3622 if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { | 3614 switch (util.getKeyModifiers(event) + event.keyCode) { |
3623 switch (event.keyCode) { | 3615 case 'Ctrl-32': // Ctrl-Space => New Folder. |
3624 case 32: // Ctrl-Space => New Folder. | 3616 handleCommand('newfolder'); |
3625 handleCommand('newfolder'); | 3617 break; |
3626 break; | |
3627 | 3618 |
3628 case 88: // Ctrl-X => Cut. | 3619 case 'Ctrl-88': // Ctrl-X => Cut. |
3629 handleCommand('cut'); | 3620 handleCommand('cut'); |
3630 break; | 3621 break; |
3631 | 3622 |
3632 case 67: // Ctrl-C => Copy. | 3623 case 'Ctrl-67': // Ctrl-C => Copy. |
3633 handleCommand('copy'); | 3624 handleCommand('copy'); |
3634 break; | 3625 break; |
3635 | 3626 |
3636 case 86: // Ctrl-V => Paste. | 3627 case 'Ctrl-86': // Ctrl-V => Paste. |
3637 handleCommand('paste'); | 3628 handleCommand('paste'); |
3638 break; | 3629 break; |
3639 | 3630 |
3640 case 69: // Ctrl-E => Rename. | 3631 case 'Ctrl-69': // Ctrl-E => Rename. |
3641 handleCommand('rename'); | 3632 handleCommand('rename'); |
3642 break; | 3633 break; |
3643 } | |
3644 } | |
3645 | 3634 |
3646 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) | 3635 case '8': // Backspace => Up one directory. |
3647 return; | |
3648 | |
3649 switch (event.keyCode) { | |
3650 case 8: // Backspace => Up one directory. | |
3651 event.preventDefault(); | 3636 event.preventDefault(); |
3652 var path = this.getCurrentDirectory(); | 3637 var path = this.getCurrentDirectory(); |
3653 if (path && !DirectoryModel.isRootPath(path)) { | 3638 if (path && !DirectoryModel.isRootPath(path)) { |
3654 var path = path.replace(/\/[^\/]+$/, ''); | 3639 var path = path.replace(/\/[^\/]+$/, ''); |
3655 this.directoryModel_.changeDirectory(path); | 3640 this.directoryModel_.changeDirectory(path); |
3656 } | 3641 } |
3657 break; | 3642 break; |
3658 | 3643 |
3659 case 13: // Enter => Change directory or perform default action. | 3644 case '13': // Enter => Change directory or perform default action. |
3660 if (this.selection.totalCount == 1 && | 3645 if (this.selection.totalCount == 1 && |
3661 this.selection.entries[0].isDirectory && | 3646 this.selection.entries[0].isDirectory && |
3662 this.dialogType_ != FileManager.SELECT_FOLDER) { | 3647 this.dialogType_ != FileManager.SELECT_FOLDER) { |
3663 event.preventDefault(); | 3648 event.preventDefault(); |
3664 this.onDirectoryAction(this.selection.entries[0]); | 3649 this.onDirectoryAction(this.selection.entries[0]); |
3665 } else if (this.dispatchSelectionAction_()) { | 3650 } else if (this.dispatchSelectionAction_()) { |
3666 event.preventDefault(); | 3651 event.preventDefault(); |
3667 } | 3652 } |
3668 break; | 3653 break; |
3669 | 3654 |
3670 case 46: // Delete. | 3655 case '46': // Delete. |
3671 handleCommand('delete'); | 3656 handleCommand('delete'); |
3672 break; | 3657 break; |
3673 } | 3658 } |
3674 }; | 3659 }; |
3675 | 3660 |
3676 /** | 3661 /** |
3677 * KeyPress event handler for the div.list-container element. | 3662 * KeyPress event handler for the div.list-container element. |
3678 */ | 3663 */ |
3679 FileManager.prototype.onListKeyPress_ = function(event) { | 3664 FileManager.prototype.onListKeyPress_ = function(event) { |
3680 if (event.srcElement.tagName == 'INPUT') { | 3665 if (event.srcElement.tagName == 'INPUT') { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3932 }); | 3917 }); |
3933 }, onError); | 3918 }, onError); |
3934 | 3919 |
3935 function onError(err) { | 3920 function onError(err) { |
3936 console.log('Error while checking free space: ' + err); | 3921 console.log('Error while checking free space: ' + err); |
3937 setTimeout(doCheck, 1000 * 60); | 3922 setTimeout(doCheck, 1000 * 60); |
3938 } | 3923 } |
3939 } | 3924 } |
3940 } | 3925 } |
3941 })(); | 3926 })(); |
OLD | NEW |