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 * FileManager constructor. | 8 * FileManager constructor. |
| 9 * | 9 * |
| 10 * FileManager objects encapsulate the functionality of the file selector | 10 * FileManager objects encapsulate the functionality of the file selector |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 /** | 26 /** |
| 27 * True while a user is pressing <Tab>. | 27 * True while a user is pressing <Tab>. |
| 28 * This is used for identifying the trigger causing the filelist to | 28 * This is used for identifying the trigger causing the filelist to |
| 29 * be focused. | 29 * be focused. |
| 30 * @type {boolean} | 30 * @type {boolean} |
| 31 * @private | 31 * @private |
| 32 */ | 32 */ |
| 33 this.pressingTab_ = false; | 33 this.pressingTab_ = false; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * True while a user is pressing <Ctrl>. | |
| 37 * | |
| 38 * TODO(fukino): This key is used only for controlling gear menu, so it | |
| 39 * shoudl be moved to GearMenu class. crbug.com/366032. | |
| 40 * | |
| 41 * @type {boolean} | |
| 42 * @private | |
| 43 */ | |
| 44 this.pressingCtrl_ = false; | |
| 45 | |
| 46 /** | |
| 47 * True if shown gear menu is in secret mode. | |
| 48 * | |
| 49 * TODO(fukino): The state of gear menu should be moved to GearMenu class. | |
| 50 * crbug.com/366032. | |
| 51 * | |
| 52 * @type {boolean} | |
| 53 * @private | |
| 54 */ | |
| 55 this.isOnSecretGearMenu_ = false; | |
|
yoshiki
2014/04/24 05:10:47
nit: How about using "isSecretGearMenuShown"?
fukino
2014/04/24 10:28:53
Done. Yes, it looks more readable. Thanks!
| |
| 56 | |
| 57 /** | |
| 36 * SelectionHandler. | 58 * SelectionHandler. |
| 37 * @type {SelectionHandler} | 59 * @type {SelectionHandler} |
| 38 * @private | 60 * @private |
| 39 */ | 61 */ |
| 40 this.selectionHandler_ = null; | 62 this.selectionHandler_ = null; |
| 41 | 63 |
| 42 /** | 64 /** |
| 43 * VolumeInfo of the current volume. | 65 * VolumeInfo of the current volume. |
| 44 * @type {VolumeInfo} | 66 * @type {VolumeInfo} |
| 45 * @private | 67 * @private |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 this.dialogDom_.querySelector('#directory-tree-context-menu'); | 453 this.dialogDom_.querySelector('#directory-tree-context-menu'); |
| 432 cr.ui.Menu.decorate(this.directoryTreeContextMenu_); | 454 cr.ui.Menu.decorate(this.directoryTreeContextMenu_); |
| 433 this.directoryTree_.contextMenuForSubitems = this.directoryTreeContextMenu_; | 455 this.directoryTree_.contextMenuForSubitems = this.directoryTreeContextMenu_; |
| 434 | 456 |
| 435 this.textContextMenu_ = | 457 this.textContextMenu_ = |
| 436 this.dialogDom_.querySelector('#text-context-menu'); | 458 this.dialogDom_.querySelector('#text-context-menu'); |
| 437 cr.ui.Menu.decorate(this.textContextMenu_); | 459 cr.ui.Menu.decorate(this.textContextMenu_); |
| 438 | 460 |
| 439 this.gearButton_ = this.dialogDom_.querySelector('#gear-button'); | 461 this.gearButton_ = this.dialogDom_.querySelector('#gear-button'); |
| 440 this.gearButton_.addEventListener('menushow', | 462 this.gearButton_.addEventListener('menushow', |
| 441 this.refreshRemainingSpace_.bind(this, | 463 this.onShowGearMenu_.bind(this)); |
| 442 false /* Without loading caption. */)); | |
| 443 chrome.fileBrowserPrivate.onDesktopChanged.addListener(function() { | 464 chrome.fileBrowserPrivate.onDesktopChanged.addListener(function() { |
| 444 this.updateVisitDesktopMenus_(); | 465 this.updateVisitDesktopMenus_(); |
| 445 this.ui_.updateProfileBadge(); | 466 this.ui_.updateProfileBadge(); |
| 446 }.bind(this)); | 467 }.bind(this)); |
| 447 chrome.fileBrowserPrivate.onProfileAdded.addListener( | 468 chrome.fileBrowserPrivate.onProfileAdded.addListener( |
| 448 this.updateVisitDesktopMenus_.bind(this)); | 469 this.updateVisitDesktopMenus_.bind(this)); |
| 449 this.updateVisitDesktopMenus_(); | 470 this.updateVisitDesktopMenus_(); |
| 450 | 471 |
| 451 this.dialogDom_.querySelector('#gear-menu').menuItemSelector = | 472 this.dialogDom_.querySelector('#gear-menu').menuItemSelector = |
| 452 'menuitem, hr'; | 473 'menuitem, hr'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 if (appWindow.isMaximized()) | 515 if (appWindow.isMaximized()) |
| 495 appWindow.restore(); | 516 appWindow.restore(); |
| 496 else | 517 else |
| 497 appWindow.maximize(); | 518 appWindow.maximize(); |
| 498 }; | 519 }; |
| 499 | 520 |
| 500 FileManager.prototype.onClose = function() { | 521 FileManager.prototype.onClose = function() { |
| 501 window.close(); | 522 window.close(); |
| 502 }; | 523 }; |
| 503 | 524 |
| 525 FileManager.prototype.onShowGearMenu_ = function() { | |
| 526 this.refreshRemainingSpace_(false); /* Without loading caption. */ | |
| 527 | |
| 528 // If the menu is opened while CTRL key pressed, secret menu itemscan be | |
| 529 // shown. | |
| 530 this.isOnSecretGearMenu_ = this.pressingCtrl_; | |
| 531 | |
| 532 // Update view of drive-related settings. | |
| 533 this.commandHandler.updateAvailability(); | |
| 534 this.document_.getElementById('drive-separator').hidden = | |
| 535 !this.shouldShowDriveSettings(); | |
| 536 }; | |
| 537 | |
| 504 /** | 538 /** |
| 505 * One-time initialization of commands. | 539 * One-time initialization of commands. |
| 506 * @private | 540 * @private |
| 507 */ | 541 */ |
| 508 FileManager.prototype.initCommands_ = function() { | 542 FileManager.prototype.initCommands_ = function() { |
| 509 this.commandHandler = new CommandHandler(this); | 543 this.commandHandler = new CommandHandler(this); |
| 510 | 544 |
| 511 // TODO(hirono): Move the following block to the UI part. | 545 // TODO(hirono): Move the following block to the UI part. |
| 512 var commandButtons = this.dialogDom_.querySelectorAll('button[command]'); | 546 var commandButtons = this.dialogDom_.querySelectorAll('button[command]'); |
| 513 for (var j = 0; j < commandButtons.length; j++) | 547 for (var j = 0; j < commandButtons.length; j++) |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 this.onCancelBound_ = this.onCancel_.bind(this); | 837 this.onCancelBound_ = this.onCancel_.bind(this); |
| 804 this.cancelButton_.addEventListener('click', this.onCancelBound_); | 838 this.cancelButton_.addEventListener('click', this.onCancelBound_); |
| 805 | 839 |
| 806 this.decorateSplitter( | 840 this.decorateSplitter( |
| 807 this.dialogDom_.querySelector('#navigation-list-splitter')); | 841 this.dialogDom_.querySelector('#navigation-list-splitter')); |
| 808 this.decorateSplitter( | 842 this.decorateSplitter( |
| 809 this.dialogDom_.querySelector('#middlebar-splitter')); | 843 this.dialogDom_.querySelector('#middlebar-splitter')); |
| 810 | 844 |
| 811 this.dialogContainer_ = this.dialogDom_.querySelector('.dialog-container'); | 845 this.dialogContainer_ = this.dialogDom_.querySelector('.dialog-container'); |
| 812 | 846 |
| 813 this.syncButton = this.dialogDom_.querySelector('#drive-sync-settings'); | 847 this.syncButton = this.dialogDom_.querySelector( |
| 814 this.syncButton.addEventListener('click', this.onDrivePrefClick_.bind( | 848 '#gear-menu-drive-sync-settings'); |
| 815 this, 'cellularDisabled', false /* not inverted */)); | 849 this.hostedButton = this.dialogDom_.querySelector( |
| 816 | 850 '#gear-menu-drive-hosted-settings'); |
| 817 this.hostedButton = this.dialogDom_.querySelector('#drive-hosted-settings'); | |
| 818 this.hostedButton.addEventListener('click', this.onDrivePrefClick_.bind( | |
| 819 this, 'hostedFilesDisabled', true /* inverted */)); | |
| 820 | 851 |
| 821 this.detailViewButton_ = | 852 this.detailViewButton_ = |
| 822 this.dialogDom_.querySelector('#detail-view'); | 853 this.dialogDom_.querySelector('#detail-view'); |
| 823 this.detailViewButton_.addEventListener('activate', | 854 this.detailViewButton_.addEventListener('activate', |
| 824 this.onDetailViewButtonClick_.bind(this)); | 855 this.onDetailViewButtonClick_.bind(this)); |
| 825 | 856 |
| 826 this.thumbnailViewButton_ = | 857 this.thumbnailViewButton_ = |
| 827 this.dialogDom_.querySelector('#thumbnail-view'); | 858 this.dialogDom_.querySelector('#thumbnail-view'); |
| 828 this.thumbnailViewButton_.addEventListener('activate', | 859 this.thumbnailViewButton_.addEventListener('activate', |
| 829 this.onThumbnailViewButtonClick_.bind(this)); | 860 this.onThumbnailViewButtonClick_.bind(this)); |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1696 */ | 1727 */ |
| 1697 FileManager.prototype.isOnDrive = function() { | 1728 FileManager.prototype.isOnDrive = function() { |
| 1698 var rootType = this.directoryModel_.getCurrentRootType(); | 1729 var rootType = this.directoryModel_.getCurrentRootType(); |
| 1699 return rootType === RootType.DRIVE || | 1730 return rootType === RootType.DRIVE || |
| 1700 rootType === RootType.DRIVE_SHARED_WITH_ME || | 1731 rootType === RootType.DRIVE_SHARED_WITH_ME || |
| 1701 rootType === RootType.DRIVE_RECENT || | 1732 rootType === RootType.DRIVE_RECENT || |
| 1702 rootType === RootType.DRIVE_OFFLINE; | 1733 rootType === RootType.DRIVE_OFFLINE; |
| 1703 }; | 1734 }; |
| 1704 | 1735 |
| 1705 /** | 1736 /** |
| 1737 * Check if the drive-related setting items should be shown on currently | |
| 1738 * displayed gear menu. | |
| 1739 * @return {boolean} True if those setting items should be shown. | |
| 1740 */ | |
| 1741 FileManager.prototype.shouldShowDriveSettings = function() { | |
| 1742 return this.isOnDrive() && this.isOnSecretGearMenu_; | |
| 1743 }; | |
| 1744 | |
| 1745 /** | |
| 1706 * Overrides default handling for clicks on hyperlinks. | 1746 * Overrides default handling for clicks on hyperlinks. |
| 1707 * In a packaged apps links with targer='_blank' open in a new tab by | 1747 * In a packaged apps links with targer='_blank' open in a new tab by |
| 1708 * default, other links do not open at all. | 1748 * default, other links do not open at all. |
| 1709 * | 1749 * |
| 1710 * @param {Event} event Click event. | 1750 * @param {Event} event Click event. |
| 1711 * @private | 1751 * @private |
| 1712 */ | 1752 */ |
| 1713 FileManager.prototype.onExternalLinkClick_ = function(event) { | 1753 FileManager.prototype.onExternalLinkClick_ = function(event) { |
| 1714 if (event.target.tagName != 'A' || !event.target.href) | 1754 if (event.target.tagName != 'A' || !event.target.href) |
| 1715 return; | 1755 return; |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2179 return; | 2219 return; |
| 2180 | 2220 |
| 2181 this.document_.title = this.currentVolumeInfo_.label; | 2221 this.document_.title = this.currentVolumeInfo_.label; |
| 2182 }; | 2222 }; |
| 2183 | 2223 |
| 2184 /** | 2224 /** |
| 2185 * Update the gear menu. | 2225 * Update the gear menu. |
| 2186 * @private | 2226 * @private |
| 2187 */ | 2227 */ |
| 2188 FileManager.prototype.updateGearMenu_ = function() { | 2228 FileManager.prototype.updateGearMenu_ = function() { |
| 2189 var hideItemsForDrive = !this.isOnDrive(); | |
| 2190 this.syncButton.hidden = hideItemsForDrive; | |
| 2191 this.hostedButton.hidden = hideItemsForDrive; | |
| 2192 this.document_.getElementById('drive-separator').hidden = | |
| 2193 hideItemsForDrive; | |
| 2194 this.refreshRemainingSpace_(true); // Show loading caption. | 2229 this.refreshRemainingSpace_(true); // Show loading caption. |
| 2195 }; | 2230 }; |
| 2196 | 2231 |
| 2197 /** | 2232 /** |
| 2198 * Update menus that move the window to the other profile's desktop. | 2233 * Update menus that move the window to the other profile's desktop. |
| 2199 * TODO(hirono): Add the GearMenu class and make it a member of the class. | 2234 * TODO(hirono): Add the GearMenu class and make it a member of the class. |
| 2200 * TODO(hirono): Handle the case where a profile is added while the menu is | 2235 * TODO(hirono): Handle the case where a profile is added while the menu is |
| 2201 * opened. | 2236 * opened. |
| 2202 * @private | 2237 * @private |
| 2203 */ | 2238 */ |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2853 }; | 2888 }; |
| 2854 | 2889 |
| 2855 /** | 2890 /** |
| 2856 * KeyDown event handler for the document. | 2891 * KeyDown event handler for the document. |
| 2857 * @param {Event} event Key event. | 2892 * @param {Event} event Key event. |
| 2858 * @private | 2893 * @private |
| 2859 */ | 2894 */ |
| 2860 FileManager.prototype.onKeyDown_ = function(event) { | 2895 FileManager.prototype.onKeyDown_ = function(event) { |
| 2861 if (event.keyCode === 9) // Tab | 2896 if (event.keyCode === 9) // Tab |
| 2862 this.pressingTab_ = true; | 2897 this.pressingTab_ = true; |
| 2898 if (event.keyCode === 17) // Ctrl | |
| 2899 this.pressingCtrl_ = true; | |
| 2863 | 2900 |
| 2864 if (event.srcElement === this.renameInput_) { | 2901 if (event.srcElement === this.renameInput_) { |
| 2865 // Ignore keydown handler in the rename input box. | 2902 // Ignore keydown handler in the rename input box. |
| 2866 return; | 2903 return; |
| 2867 } | 2904 } |
| 2868 | 2905 |
| 2869 switch (util.getKeyModifiers(event) + event.keyCode) { | 2906 switch (util.getKeyModifiers(event) + event.keyCode) { |
| 2870 case 'Ctrl-190': // Ctrl-. => Toggle filter files. | 2907 case 'Ctrl-190': // Ctrl-. => Toggle filter files. |
| 2871 this.fileFilter_.setFilterHidden( | 2908 this.fileFilter_.setFilterHidden( |
| 2872 !this.fileFilter_.isFilterHiddenOn()); | 2909 !this.fileFilter_.isFilterHiddenOn()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2884 }; | 2921 }; |
| 2885 | 2922 |
| 2886 /** | 2923 /** |
| 2887 * KeyUp event handler for the document. | 2924 * KeyUp event handler for the document. |
| 2888 * @param {Event} event Key event. | 2925 * @param {Event} event Key event. |
| 2889 * @private | 2926 * @private |
| 2890 */ | 2927 */ |
| 2891 FileManager.prototype.onKeyUp_ = function(event) { | 2928 FileManager.prototype.onKeyUp_ = function(event) { |
| 2892 if (event.keyCode === 9) // Tab | 2929 if (event.keyCode === 9) // Tab |
| 2893 this.pressingTab_ = false; | 2930 this.pressingTab_ = false; |
| 2931 if (event.keyCode == 17) // Ctrl | |
| 2932 this.pressingCtrl_ = false; | |
| 2894 }; | 2933 }; |
| 2895 | 2934 |
| 2896 /** | 2935 /** |
| 2897 * KeyDown event handler for the div#list-container element. | 2936 * KeyDown event handler for the div#list-container element. |
| 2898 * @param {Event} event Key event. | 2937 * @param {Event} event Key event. |
| 2899 * @private | 2938 * @private |
| 2900 */ | 2939 */ |
| 2901 FileManager.prototype.onListKeyDown_ = function(event) { | 2940 FileManager.prototype.onListKeyDown_ = function(event) { |
| 2902 if (event.srcElement.tagName == 'INPUT') { | 2941 if (event.srcElement.tagName == 'INPUT') { |
| 2903 // Ignore keydown handler in the rename input box. | 2942 // Ignore keydown handler in the rename input box. |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3362 if (!valid) { | 3401 if (!valid) { |
| 3363 self.alert.show(str('ERROR_LONG_NAME'), | 3402 self.alert.show(str('ERROR_LONG_NAME'), |
| 3364 function() { onDone(false); }); | 3403 function() { onDone(false); }); |
| 3365 } else { | 3404 } else { |
| 3366 onDone(true); | 3405 onDone(true); |
| 3367 } | 3406 } |
| 3368 }); | 3407 }); |
| 3369 }; | 3408 }; |
| 3370 | 3409 |
| 3371 /** | 3410 /** |
| 3372 * Handler invoked on preference setting in drive context menu. | 3411 * Toggle whether mobile data is used for sync. |
| 3373 * | |
| 3374 * @param {string} pref The preference to alter. | |
| 3375 * @param {boolean} inverted Invert the value if true. | |
| 3376 * @param {Event} event The click event. | |
| 3377 * @private | |
| 3378 */ | 3412 */ |
| 3379 FileManager.prototype.onDrivePrefClick_ = function(pref, inverted, event) { | 3413 FileManager.prototype.toggleDriveSyncSettings = function() { |
| 3380 var newValue = !event.target.hasAttribute('checked'); | 3414 // If checked, the sync is disabled. |
| 3381 if (newValue) | 3415 var nowCellularDisabled = this.syncButton.hasAttribute('checked'); |
| 3382 event.target.setAttribute('checked', 'checked'); | 3416 var changeInfo = {cellularDisabled: !nowCellularDisabled}; |
| 3383 else | |
| 3384 event.target.removeAttribute('checked'); | |
| 3385 | |
| 3386 var changeInfo = {}; | |
| 3387 changeInfo[pref] = inverted ? !newValue : newValue; | |
| 3388 chrome.fileBrowserPrivate.setPreferences(changeInfo); | 3417 chrome.fileBrowserPrivate.setPreferences(changeInfo); |
| 3389 }; | 3418 }; |
| 3390 | 3419 |
| 3420 /** | |
| 3421 * Toggle whether Google Docs files are shown. | |
| 3422 */ | |
| 3423 FileManager.prototype.toggleDriveHostedSettings = function() { | |
| 3424 // If checked, showing drive hosted files is enabled. | |
| 3425 var nowHostedFilesEnabled = this.hostedButton.hasAttribute('checked'); | |
| 3426 var nowHostedFilesDisabled = !nowHostedFilesEnabled; | |
| 3427 var changeInfo = {hostedFilesDisabled: !nowHostedFilesDisabled}; | |
| 3428 chrome.fileBrowserPrivate.setPreferences(changeInfo); | |
| 3429 }; | |
| 3430 | |
| 3391 /** | 3431 /** |
| 3392 * Invoked when the search box is changed. | 3432 * Invoked when the search box is changed. |
| 3393 * | 3433 * |
| 3394 * @param {Event} event The changed event. | 3434 * @param {Event} event The changed event. |
| 3395 * @private | 3435 * @private |
| 3396 */ | 3436 */ |
| 3397 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 3437 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
| 3398 var searchString = this.searchBox_.value; | 3438 var searchString = this.searchBox_.value; |
| 3399 | 3439 |
| 3400 if (this.isOnDrive()) { | 3440 if (this.isOnDrive()) { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3703 callback(this.preferences_); | 3743 callback(this.preferences_); |
| 3704 return; | 3744 return; |
| 3705 } | 3745 } |
| 3706 | 3746 |
| 3707 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3747 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
| 3708 this.preferences_ = prefs; | 3748 this.preferences_ = prefs; |
| 3709 callback(prefs); | 3749 callback(prefs); |
| 3710 }.bind(this)); | 3750 }.bind(this)); |
| 3711 }; | 3751 }; |
| 3712 })(); | 3752 })(); |
| OLD | NEW |