| 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 26 matching lines...) Expand all Loading... |
| 37 * @private | 37 * @private |
| 38 */ | 38 */ |
| 39 this.selectionHandler_ = null; | 39 this.selectionHandler_ = null; |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * VolumeInfo of the current volume. | 42 * VolumeInfo of the current volume. |
| 43 * @type {VolumeInfo} | 43 * @type {VolumeInfo} |
| 44 * @private | 44 * @private |
| 45 */ | 45 */ |
| 46 this.currentVolumeInfo_ = null; | 46 this.currentVolumeInfo_ = null; |
| 47 |
| 48 /** |
| 49 * Whether to show dot files in the non-Drive folder. Default: false. |
| 50 * @type {boolean} |
| 51 * @private |
| 52 */ |
| 53 this.dotFilesHidden_ = false; |
| 47 } | 54 } |
| 48 | 55 |
| 49 FileManager.prototype = { | 56 FileManager.prototype = { |
| 50 __proto__: cr.EventTarget.prototype, | 57 __proto__: cr.EventTarget.prototype, |
| 51 get directoryModel() { | 58 get directoryModel() { |
| 52 return this.directoryModel_; | 59 return this.directoryModel_; |
| 53 }, | 60 }, |
| 54 get navigationList() { | 61 get navigationList() { |
| 55 return this.navigationList_; | 62 return this.navigationList_; |
| 56 }, | 63 }, |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 // view that is not in use. | 907 // view that is not in use. |
| 901 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); | 908 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); |
| 902 this.emptySelectionModel_ = new cr.ui.ListSelectionModel(); | 909 this.emptySelectionModel_ = new cr.ui.ListSelectionModel(); |
| 903 | 910 |
| 904 var singleSelection = | 911 var singleSelection = |
| 905 this.dialogType == DialogType.SELECT_OPEN_FILE || | 912 this.dialogType == DialogType.SELECT_OPEN_FILE || |
| 906 this.dialogType == DialogType.SELECT_FOLDER || | 913 this.dialogType == DialogType.SELECT_FOLDER || |
| 907 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER || | 914 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER || |
| 908 this.dialogType == DialogType.SELECT_SAVEAS_FILE; | 915 this.dialogType == DialogType.SELECT_SAVEAS_FILE; |
| 909 | 916 |
| 910 this.fileFilter_ = new FileFilter( | 917 this.fileFilter_ = new FileFilter(this.metadataCache_); |
| 911 this.metadataCache_, | |
| 912 false /* Don't show dot files by default. */); | |
| 913 | 918 |
| 914 this.fileWatcher_ = new FileWatcher(this.metadataCache_); | 919 this.fileWatcher_ = new FileWatcher(this.metadataCache_); |
| 915 this.fileWatcher_.addEventListener( | 920 this.fileWatcher_.addEventListener( |
| 916 'watcher-metadata-changed', | 921 'watcher-metadata-changed', |
| 917 this.onWatcherMetadataChanged_.bind(this)); | 922 this.onWatcherMetadataChanged_.bind(this)); |
| 918 | 923 |
| 919 this.directoryModel_ = new DirectoryModel( | 924 this.directoryModel_ = new DirectoryModel( |
| 920 singleSelection, | 925 singleSelection, |
| 921 this.fileFilter_, | 926 this.fileFilter_, |
| 922 this.fileWatcher_, | 927 this.fileWatcher_, |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 var regexp = new RegExp('.*(' + | 1311 var regexp = new RegExp('.*(' + |
| 1307 this.fileTypes_[selectedIndex - 1].extensions.join('|') + ')$', 'i'); | 1312 this.fileTypes_[selectedIndex - 1].extensions.join('|') + ')$', 'i'); |
| 1308 var filter = function(entry) { | 1313 var filter = function(entry) { |
| 1309 return entry.isDirectory || regexp.test(entry.name); | 1314 return entry.isDirectory || regexp.test(entry.name); |
| 1310 }; | 1315 }; |
| 1311 this.fileFilter_.addFilter('fileType', filter); | 1316 this.fileFilter_.addFilter('fileType', filter); |
| 1312 } | 1317 } |
| 1313 }; | 1318 }; |
| 1314 | 1319 |
| 1315 /** | 1320 /** |
| 1321 * Filters dot files if the setting is enabled and the current directory is |
| 1322 * '/Downloads'. |
| 1323 * |
| 1324 * @return {boolean} True if the filter is enabled, false otherwise. |
| 1325 * @private |
| 1326 */ |
| 1327 FileManager.prototype.updateDotFilesFilter_ = function() { |
| 1328 var enabled = |
| 1329 this.dotFilesHidden_ && |
| 1330 this.currentVolumeInfo_ && |
| 1331 this.currentVolumeInfo_.volumeType !== util.VolumeType.DRIVE; |
| 1332 |
| 1333 if (enabled) { |
| 1334 this.fileFilter_.addFilter( |
| 1335 'dot-file-hidden', |
| 1336 function(entry) { |
| 1337 return (entry.name.charAt(0) !== '.'); |
| 1338 }); |
| 1339 } else { |
| 1340 this.fileFilter_.removeFilter('dot-file-hidden'); |
| 1341 } |
| 1342 |
| 1343 return enabled; |
| 1344 }; |
| 1345 |
| 1346 /** |
| 1316 * Resize details and thumb views to fit the new window size. | 1347 * Resize details and thumb views to fit the new window size. |
| 1317 * @private | 1348 * @private |
| 1318 */ | 1349 */ |
| 1319 FileManager.prototype.onResize_ = function() { | 1350 FileManager.prototype.onResize_ = function() { |
| 1320 if (this.listType_ == FileManager.ListType.THUMBNAIL) | 1351 if (this.listType_ == FileManager.ListType.THUMBNAIL) |
| 1321 this.grid_.relayout(); | 1352 this.grid_.relayout(); |
| 1322 else | 1353 else |
| 1323 this.table_.relayout(); | 1354 this.table_.relayout(); |
| 1324 | 1355 |
| 1325 // May not be available during initialization. | 1356 // May not be available during initialization. |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2301 this.selectionHandler_.onFileSelectionChanged(); | 2332 this.selectionHandler_.onFileSelectionChanged(); |
| 2302 this.ui_.searchBox.clear(); | 2333 this.ui_.searchBox.clear(); |
| 2303 // TODO(mtomasz): Use Entry.toURL() instead of fullPath. | 2334 // TODO(mtomasz): Use Entry.toURL() instead of fullPath. |
| 2304 // TODO(mtomasz): Consider remembering the selection. | 2335 // TODO(mtomasz): Consider remembering the selection. |
| 2305 util.updateAppState( | 2336 util.updateAppState( |
| 2306 this.getCurrentDirectoryEntry() ? | 2337 this.getCurrentDirectoryEntry() ? |
| 2307 this.getCurrentDirectoryEntry().fullPath : '', | 2338 this.getCurrentDirectoryEntry().fullPath : '', |
| 2308 '' /* selectionPath */, | 2339 '' /* selectionPath */, |
| 2309 '' /* opt_param */); | 2340 '' /* opt_param */); |
| 2310 | 2341 |
| 2342 this.updateDotFilesFilter_(); |
| 2343 |
| 2311 if (this.commandHandler) | 2344 if (this.commandHandler) |
| 2312 this.commandHandler.updateAvailability(); | 2345 this.commandHandler.updateAvailability(); |
| 2313 | 2346 |
| 2314 this.updateUnformattedVolumeStatus_(); | 2347 this.updateUnformattedVolumeStatus_(); |
| 2315 this.updateTitle_(); | 2348 this.updateTitle_(); |
| 2316 | 2349 |
| 2317 var currentEntry = this.getCurrentDirectoryEntry(); | 2350 var currentEntry = this.getCurrentDirectoryEntry(); |
| 2318 this.previewPanel_.currentEntry = util.isFakeEntry(currentEntry) ? | 2351 this.previewPanel_.currentEntry = util.isFakeEntry(currentEntry) ? |
| 2319 null : currentEntry; | 2352 null : currentEntry; |
| 2320 }; | 2353 }; |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2834 * @private | 2867 * @private |
| 2835 */ | 2868 */ |
| 2836 FileManager.prototype.onKeyDown_ = function(event) { | 2869 FileManager.prototype.onKeyDown_ = function(event) { |
| 2837 if (event.srcElement === this.renameInput_) { | 2870 if (event.srcElement === this.renameInput_) { |
| 2838 // Ignore keydown handler in the rename input box. | 2871 // Ignore keydown handler in the rename input box. |
| 2839 return; | 2872 return; |
| 2840 } | 2873 } |
| 2841 | 2874 |
| 2842 switch (util.getKeyModifiers(event) + event.keyCode) { | 2875 switch (util.getKeyModifiers(event) + event.keyCode) { |
| 2843 case 'Ctrl-190': // Ctrl-. => Toggle filter files. | 2876 case 'Ctrl-190': // Ctrl-. => Toggle filter files. |
| 2844 this.fileFilter_.setFilterHidden( | 2877 this.dotFilesHidden_ = !this.dotFilesHidden_; |
| 2845 !this.fileFilter_.isFilterHiddenOn()); | 2878 this.updateDotFilesFilter_(); |
| 2846 event.preventDefault(); | |
| 2847 return; | 2879 return; |
| 2848 | 2880 |
| 2849 case '27': // Escape => Cancel dialog. | 2881 case '27': // Escape => Cancel dialog. |
| 2850 if (this.dialogType != DialogType.FULL_PAGE) { | 2882 if (this.dialogType != DialogType.FULL_PAGE) { |
| 2851 // If there is nothing else for ESC to do, then cancel the dialog. | 2883 // If there is nothing else for ESC to do, then cancel the dialog. |
| 2852 event.preventDefault(); | 2884 event.preventDefault(); |
| 2853 this.cancelButton_.click(); | 2885 this.cancelButton_.click(); |
| 2854 } | 2886 } |
| 2855 break; | 2887 break; |
| 2856 } | 2888 } |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3303 FileManager.prototype.validateFileName_ = function( | 3335 FileManager.prototype.validateFileName_ = function( |
| 3304 parentEntry, name, onDone) { | 3336 parentEntry, name, onDone) { |
| 3305 var msg; | 3337 var msg; |
| 3306 var testResult = /[\/\\\<\>\:\?\*\"\|]/.exec(name); | 3338 var testResult = /[\/\\\<\>\:\?\*\"\|]/.exec(name); |
| 3307 if (testResult) { | 3339 if (testResult) { |
| 3308 msg = strf('ERROR_INVALID_CHARACTER', testResult[0]); | 3340 msg = strf('ERROR_INVALID_CHARACTER', testResult[0]); |
| 3309 } else if (/^\s*$/i.test(name)) { | 3341 } else if (/^\s*$/i.test(name)) { |
| 3310 msg = str('ERROR_WHITESPACE_NAME'); | 3342 msg = str('ERROR_WHITESPACE_NAME'); |
| 3311 } else if (/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(name)) { | 3343 } else if (/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(name)) { |
| 3312 msg = str('ERROR_RESERVED_NAME'); | 3344 msg = str('ERROR_RESERVED_NAME'); |
| 3313 } else if (this.fileFilter_.isFilterHiddenOn() && name[0] == '.') { | 3345 } else if (this.updateDotFilesFilter_() && name[0] == '.') { |
| 3314 msg = str('ERROR_HIDDEN_NAME'); | 3346 msg = str('ERROR_HIDDEN_NAME'); |
| 3315 } | 3347 } |
| 3316 | 3348 |
| 3317 if (msg) { | 3349 if (msg) { |
| 3318 this.alert.show(msg, function() { | 3350 this.alert.show(msg, function() { |
| 3319 onDone(false); | 3351 onDone(false); |
| 3320 }); | 3352 }); |
| 3321 return; | 3353 return; |
| 3322 } | 3354 } |
| 3323 | 3355 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3683 callback(this.preferences_); | 3715 callback(this.preferences_); |
| 3684 return; | 3716 return; |
| 3685 } | 3717 } |
| 3686 | 3718 |
| 3687 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3719 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
| 3688 this.preferences_ = prefs; | 3720 this.preferences_ = prefs; |
| 3689 callback(prefs); | 3721 callback(prefs); |
| 3690 }.bind(this)); | 3722 }.bind(this)); |
| 3691 }; | 3723 }; |
| 3692 })(); | 3724 })(); |
| OLD | NEW |