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 * This variable is checked in SelectFileDialogExtensionBrowserTest. | 8 * This variable is checked in SelectFileDialogExtensionBrowserTest. |
9 * @type {number} | 9 * @type {number} |
10 */ | 10 */ |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 /** | 55 /** |
56 * List of dialog types. | 56 * List of dialog types. |
57 * | 57 * |
58 * Keep this in sync with FileManagerDialog::GetDialogTypeAsString, except | 58 * Keep this in sync with FileManagerDialog::GetDialogTypeAsString, except |
59 * FULL_PAGE which is specific to this code. | 59 * FULL_PAGE which is specific to this code. |
60 * | 60 * |
61 * @enum {string} | 61 * @enum {string} |
62 */ | 62 */ |
63 var DialogType = { | 63 var DialogType = { |
64 SELECT_FOLDER: 'folder', | 64 SELECT_FOLDER: 'folder', |
| 65 SELECT_UPLOAD_FOLDER: 'upload-folder', |
65 SELECT_SAVEAS_FILE: 'saveas-file', | 66 SELECT_SAVEAS_FILE: 'saveas-file', |
66 SELECT_OPEN_FILE: 'open-file', | 67 SELECT_OPEN_FILE: 'open-file', |
67 SELECT_OPEN_MULTI_FILE: 'open-multi-file', | 68 SELECT_OPEN_MULTI_FILE: 'open-multi-file', |
68 FULL_PAGE: 'full-page' | 69 FULL_PAGE: 'full-page' |
69 }; | 70 }; |
70 | 71 |
71 /** | 72 /** |
72 * TextMeasure constructor. | 73 * TextMeasure constructor. |
73 * | 74 * |
74 * TextMeasure is a measure for text that returns the width of text. This | 75 * TextMeasure is a measure for text that returns the width of text. This |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 var rect = this.dummySpan_.getBoundingClientRect(); | 112 var rect = this.dummySpan_.getBoundingClientRect(); |
112 return rect ? rect.width : 0; | 113 return rect ? rect.width : 0; |
113 }; | 114 }; |
114 | 115 |
115 /** | 116 /** |
116 * @param {string} type Dialog type. | 117 * @param {string} type Dialog type. |
117 * @return {boolean} Whether the type is modal. | 118 * @return {boolean} Whether the type is modal. |
118 */ | 119 */ |
119 DialogType.isModal = function(type) { | 120 DialogType.isModal = function(type) { |
120 return type == DialogType.SELECT_FOLDER || | 121 return type == DialogType.SELECT_FOLDER || |
| 122 type == DialogType.SELECT_UPLOAD_FOLDER || |
121 type == DialogType.SELECT_SAVEAS_FILE || | 123 type == DialogType.SELECT_SAVEAS_FILE || |
122 type == DialogType.SELECT_OPEN_FILE || | 124 type == DialogType.SELECT_OPEN_FILE || |
123 type == DialogType.SELECT_OPEN_MULTI_FILE; | 125 type == DialogType.SELECT_OPEN_MULTI_FILE; |
124 }; | 126 }; |
125 | 127 |
126 /** | 128 /** |
127 * Bottom magrin of the list and tree for transparent preview panel. | 129 * Bottom magrin of the list and tree for transparent preview panel. |
128 * @const | 130 * @const |
129 */ | 131 */ |
130 var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52; | 132 var BOTTOM_MARGIN_FOR_PREVIEW_PANEL_PX = 52; |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 this.dialogType = this.params_.type || DialogType.FULL_PAGE; | 755 this.dialogType = this.params_.type || DialogType.FULL_PAGE; |
754 this.startupPrefName_ = 'file-manager-' + this.dialogType; | 756 this.startupPrefName_ = 'file-manager-' + this.dialogType; |
755 | 757 |
756 // Used to filter out focusing by mouse. | 758 // Used to filter out focusing by mouse. |
757 this.suppressFocus_ = false; | 759 this.suppressFocus_ = false; |
758 | 760 |
759 // Optional list of file types. | 761 // Optional list of file types. |
760 this.fileTypes_ = this.params_.typeList || []; | 762 this.fileTypes_ = this.params_.typeList || []; |
761 metrics.recordEnum('Create', this.dialogType, | 763 metrics.recordEnum('Create', this.dialogType, |
762 [DialogType.SELECT_FOLDER, | 764 [DialogType.SELECT_FOLDER, |
| 765 DialogType.SELECT_UPLOAD_FOLDER, |
763 DialogType.SELECT_SAVEAS_FILE, | 766 DialogType.SELECT_SAVEAS_FILE, |
764 DialogType.SELECT_OPEN_FILE, | 767 DialogType.SELECT_OPEN_FILE, |
765 DialogType.SELECT_OPEN_MULTI_FILE, | 768 DialogType.SELECT_OPEN_MULTI_FILE, |
766 DialogType.FULL_PAGE]); | 769 DialogType.FULL_PAGE]); |
767 | 770 |
768 this.selectionHandler_ = null; | 771 this.selectionHandler_ = null; |
769 this.ctrlKeyPressed_ = false; | 772 this.ctrlKeyPressed_ = false; |
770 | 773 |
771 this.metadataCache_ = MetadataCache.createFull(); | 774 this.metadataCache_ = MetadataCache.createFull(); |
772 | 775 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 FileManager.prototype.initFileList_ = function() { | 1047 FileManager.prototype.initFileList_ = function() { |
1045 // Always sharing the data model between the detail/thumb views confuses | 1048 // Always sharing the data model between the detail/thumb views confuses |
1046 // them. Instead we maintain this bogus data model, and hook it up to the | 1049 // them. Instead we maintain this bogus data model, and hook it up to the |
1047 // view that is not in use. | 1050 // view that is not in use. |
1048 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); | 1051 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); |
1049 this.emptySelectionModel_ = new cr.ui.ListSelectionModel(); | 1052 this.emptySelectionModel_ = new cr.ui.ListSelectionModel(); |
1050 | 1053 |
1051 var singleSelection = | 1054 var singleSelection = |
1052 this.dialogType == DialogType.SELECT_OPEN_FILE || | 1055 this.dialogType == DialogType.SELECT_OPEN_FILE || |
1053 this.dialogType == DialogType.SELECT_FOLDER || | 1056 this.dialogType == DialogType.SELECT_FOLDER || |
| 1057 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER || |
1054 this.dialogType == DialogType.SELECT_SAVEAS_FILE; | 1058 this.dialogType == DialogType.SELECT_SAVEAS_FILE; |
1055 | 1059 |
1056 var showSpecialSearchRoots = | 1060 var showSpecialSearchRoots = |
1057 this.dialogType == DialogType.SELECT_OPEN_FILE || | 1061 this.dialogType == DialogType.SELECT_OPEN_FILE || |
1058 this.dialogType == DialogType.SELECT_OPEN_MULTI_FILE || | 1062 this.dialogType == DialogType.SELECT_OPEN_MULTI_FILE || |
1059 this.dialogType == DialogType.FULL_PAGE; | 1063 this.dialogType == DialogType.FULL_PAGE; |
1060 | 1064 |
1061 this.fileFilter_ = new FileFilter( | 1065 this.fileFilter_ = new FileFilter( |
1062 this.metadataCache_, | 1066 this.metadataCache_, |
1063 false /* Don't show dot files by default. */); | 1067 false /* Don't show dot files by default. */); |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 */ | 1714 */ |
1711 FileManager.prototype.initDialogType_ = function() { | 1715 FileManager.prototype.initDialogType_ = function() { |
1712 var defaultTitle; | 1716 var defaultTitle; |
1713 var okLabel = str('OPEN_LABEL'); | 1717 var okLabel = str('OPEN_LABEL'); |
1714 | 1718 |
1715 switch (this.dialogType) { | 1719 switch (this.dialogType) { |
1716 case DialogType.SELECT_FOLDER: | 1720 case DialogType.SELECT_FOLDER: |
1717 defaultTitle = str('SELECT_FOLDER_TITLE'); | 1721 defaultTitle = str('SELECT_FOLDER_TITLE'); |
1718 break; | 1722 break; |
1719 | 1723 |
| 1724 case DialogType.SELECT_UPLOAD_FOLDER: |
| 1725 defaultTitle = str('SELECT_UPLOAD_FOLDER_TITLE'); |
| 1726 okLabel = str('UPLOAD_LABEL'); |
| 1727 break; |
| 1728 |
1720 case DialogType.SELECT_OPEN_FILE: | 1729 case DialogType.SELECT_OPEN_FILE: |
1721 defaultTitle = str('SELECT_OPEN_FILE_TITLE'); | 1730 defaultTitle = str('SELECT_OPEN_FILE_TITLE'); |
1722 break; | 1731 break; |
1723 | 1732 |
1724 case DialogType.SELECT_OPEN_MULTI_FILE: | 1733 case DialogType.SELECT_OPEN_MULTI_FILE: |
1725 defaultTitle = str('SELECT_OPEN_MULTI_FILE_TITLE'); | 1734 defaultTitle = str('SELECT_OPEN_MULTI_FILE_TITLE'); |
1726 break; | 1735 break; |
1727 | 1736 |
1728 case DialogType.SELECT_SAVEAS_FILE: | 1737 case DialogType.SELECT_SAVEAS_FILE: |
1729 defaultTitle = str('SELECT_SAVEAS_FILE_TITLE'); | 1738 defaultTitle = str('SELECT_SAVEAS_FILE_TITLE'); |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2935 var path = path.replace(/\/[^\/]+$/, ''); | 2944 var path = path.replace(/\/[^\/]+$/, ''); |
2936 this.directoryModel_.changeDirectory(path); | 2945 this.directoryModel_.changeDirectory(path); |
2937 } | 2946 } |
2938 break; | 2947 break; |
2939 | 2948 |
2940 case '13': // Enter => Change directory or perform default action. | 2949 case '13': // Enter => Change directory or perform default action. |
2941 // TODO(dgozman): move directory action to dispatchSelectionAction. | 2950 // TODO(dgozman): move directory action to dispatchSelectionAction. |
2942 var selection = this.getSelection(); | 2951 var selection = this.getSelection(); |
2943 if (selection.totalCount == 1 && | 2952 if (selection.totalCount == 1 && |
2944 selection.entries[0].isDirectory && | 2953 selection.entries[0].isDirectory && |
2945 this.dialogType != DialogType.SELECT_FOLDER) { | 2954 this.dialogType != DialogType.SELECT_FOLDER && |
| 2955 this.dialogType != DialogType.SELECT_UPLOAD_FOLDER) { |
2946 event.preventDefault(); | 2956 event.preventDefault(); |
2947 this.onDirectoryAction(selection.entries[0]); | 2957 this.onDirectoryAction(selection.entries[0]); |
2948 } else if (this.dispatchSelectionAction_()) { | 2958 } else if (this.dispatchSelectionAction_()) { |
2949 event.preventDefault(); | 2959 event.preventDefault(); |
2950 } | 2960 } |
2951 break; | 2961 break; |
2952 } | 2962 } |
2953 | 2963 |
2954 switch (event.keyIdentifier) { | 2964 switch (event.keyIdentifier) { |
2955 case 'Home': | 2965 case 'Home': |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3254 resolveSuccessCallback, resolveErrorCallback); | 3264 resolveSuccessCallback, resolveErrorCallback); |
3255 }; | 3265 }; |
3256 | 3266 |
3257 this.validateFileName_(currentDirUrl, filename, checkOverwriteAndFinish); | 3267 this.validateFileName_(currentDirUrl, filename, checkOverwriteAndFinish); |
3258 return; | 3268 return; |
3259 } | 3269 } |
3260 | 3270 |
3261 var files = []; | 3271 var files = []; |
3262 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; | 3272 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; |
3263 | 3273 |
3264 if (this.dialogType == DialogType.SELECT_FOLDER && | 3274 if ((this.dialogType == DialogType.SELECT_FOLDER || |
| 3275 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER) && |
3265 selectedIndexes.length == 0) { | 3276 selectedIndexes.length == 0) { |
3266 var url = this.getCurrentDirectoryURL(); | 3277 var url = this.getCurrentDirectoryURL(); |
3267 var singleSelection = { | 3278 var singleSelection = { |
3268 urls: [url], | 3279 urls: [url], |
3269 multiple: false, | 3280 multiple: false, |
3270 filterIndex: this.getSelectedFilterIndex_() | 3281 filterIndex: this.getSelectedFilterIndex_() |
3271 }; | 3282 }; |
3272 this.selectFilesAndClose_(singleSelection); | 3283 this.selectFilesAndClose_(singleSelection); |
3273 return; | 3284 return; |
3274 } | 3285 } |
(...skipping 24 matching lines...) Expand all Loading... |
3299 this.selectFilesAndClose_(multipleSelection); | 3310 this.selectFilesAndClose_(multipleSelection); |
3300 return; | 3311 return; |
3301 } | 3312 } |
3302 | 3313 |
3303 // Everything else must have exactly one. | 3314 // Everything else must have exactly one. |
3304 if (files.length > 1) | 3315 if (files.length > 1) |
3305 throw new Error('Too many files selected!'); | 3316 throw new Error('Too many files selected!'); |
3306 | 3317 |
3307 var selectedEntry = dm.item(selectedIndexes[0]); | 3318 var selectedEntry = dm.item(selectedIndexes[0]); |
3308 | 3319 |
3309 if (this.dialogType == DialogType.SELECT_FOLDER) { | 3320 if (this.dialogType == DialogType.SELECT_FOLDER || |
| 3321 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER) { |
3310 if (!selectedEntry.isDirectory) | 3322 if (!selectedEntry.isDirectory) |
3311 throw new Error('Selected entry is not a folder!'); | 3323 throw new Error('Selected entry is not a folder!'); |
3312 } else if (this.dialogType == DialogType.SELECT_OPEN_FILE) { | 3324 } else if (this.dialogType == DialogType.SELECT_OPEN_FILE) { |
3313 if (!selectedEntry.isFile) | 3325 if (!selectedEntry.isFile) |
3314 throw new Error('Selected entry is not a file!'); | 3326 throw new Error('Selected entry is not a file!'); |
3315 } | 3327 } |
3316 | 3328 |
3317 var singleSelection = { | 3329 var singleSelection = { |
3318 urls: [files[0]], | 3330 urls: [files[0]], |
3319 multiple: false, | 3331 multiple: false, |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3833 */ | 3845 */ |
3834 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { | 3846 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { |
3835 this.ctrlKeyPressed_ = flag; | 3847 this.ctrlKeyPressed_ = flag; |
3836 // Before the DOM is constructed, the key event can be handled. | 3848 // Before the DOM is constructed, the key event can be handled. |
3837 var cacheClearCommand = | 3849 var cacheClearCommand = |
3838 this.document_.querySelector('#drive-clear-local-cache'); | 3850 this.document_.querySelector('#drive-clear-local-cache'); |
3839 if (cacheClearCommand) | 3851 if (cacheClearCommand) |
3840 cacheClearCommand.canExecuteChange(); | 3852 cacheClearCommand.canExecuteChange(); |
3841 }; | 3853 }; |
3842 })(); | 3854 })(); |
OLD | NEW |