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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 this.dialogType = this.params_.type || DialogType.FULL_PAGE; | 843 this.dialogType = this.params_.type || DialogType.FULL_PAGE; |
842 this.startupPrefName_ = 'file-manager-' + this.dialogType; | 844 this.startupPrefName_ = 'file-manager-' + this.dialogType; |
843 | 845 |
844 // Used to filter out focusing by mouse. | 846 // Used to filter out focusing by mouse. |
845 this.suppressFocus_ = false; | 847 this.suppressFocus_ = false; |
846 | 848 |
847 // Optional list of file types. | 849 // Optional list of file types. |
848 this.fileTypes_ = this.params_.typeList || []; | 850 this.fileTypes_ = this.params_.typeList || []; |
849 metrics.recordEnum('Create', this.dialogType, | 851 metrics.recordEnum('Create', this.dialogType, |
850 [DialogType.SELECT_FOLDER, | 852 [DialogType.SELECT_FOLDER, |
| 853 DialogType.SELECT_UPLOAD_FOLDER, |
851 DialogType.SELECT_SAVEAS_FILE, | 854 DialogType.SELECT_SAVEAS_FILE, |
852 DialogType.SELECT_OPEN_FILE, | 855 DialogType.SELECT_OPEN_FILE, |
853 DialogType.SELECT_OPEN_MULTI_FILE, | 856 DialogType.SELECT_OPEN_MULTI_FILE, |
854 DialogType.FULL_PAGE]); | 857 DialogType.FULL_PAGE]); |
855 | 858 |
856 this.selectionHandler_ = null; | 859 this.selectionHandler_ = null; |
857 this.ctrlKeyPressed_ = false; | 860 this.ctrlKeyPressed_ = false; |
858 | 861 |
859 this.metadataCache_ = MetadataCache.createFull(); | 862 this.metadataCache_ = MetadataCache.createFull(); |
860 | 863 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 FileManager.prototype.initFileList_ = function() { | 1135 FileManager.prototype.initFileList_ = function() { |
1133 // Always sharing the data model between the detail/thumb views confuses | 1136 // Always sharing the data model between the detail/thumb views confuses |
1134 // them. Instead we maintain this bogus data model, and hook it up to the | 1137 // them. Instead we maintain this bogus data model, and hook it up to the |
1135 // view that is not in use. | 1138 // view that is not in use. |
1136 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); | 1139 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); |
1137 this.emptySelectionModel_ = new cr.ui.ListSelectionModel(); | 1140 this.emptySelectionModel_ = new cr.ui.ListSelectionModel(); |
1138 | 1141 |
1139 var singleSelection = | 1142 var singleSelection = |
1140 this.dialogType == DialogType.SELECT_OPEN_FILE || | 1143 this.dialogType == DialogType.SELECT_OPEN_FILE || |
1141 this.dialogType == DialogType.SELECT_FOLDER || | 1144 this.dialogType == DialogType.SELECT_FOLDER || |
| 1145 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER || |
1142 this.dialogType == DialogType.SELECT_SAVEAS_FILE; | 1146 this.dialogType == DialogType.SELECT_SAVEAS_FILE; |
1143 | 1147 |
1144 var showSpecialSearchRoots = | 1148 var showSpecialSearchRoots = |
1145 this.dialogType == DialogType.SELECT_OPEN_FILE || | 1149 this.dialogType == DialogType.SELECT_OPEN_FILE || |
1146 this.dialogType == DialogType.SELECT_OPEN_MULTI_FILE || | 1150 this.dialogType == DialogType.SELECT_OPEN_MULTI_FILE || |
1147 this.dialogType == DialogType.FULL_PAGE; | 1151 this.dialogType == DialogType.FULL_PAGE; |
1148 | 1152 |
1149 this.fileFilter_ = new FileFilter( | 1153 this.fileFilter_ = new FileFilter( |
1150 this.metadataCache_, | 1154 this.metadataCache_, |
1151 false /* Don't show dot files by default. */); | 1155 false /* Don't show dot files by default. */); |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 */ | 1788 */ |
1785 FileManager.prototype.initDialogType_ = function() { | 1789 FileManager.prototype.initDialogType_ = function() { |
1786 var defaultTitle; | 1790 var defaultTitle; |
1787 var okLabel = str('OPEN_LABEL'); | 1791 var okLabel = str('OPEN_LABEL'); |
1788 | 1792 |
1789 switch (this.dialogType) { | 1793 switch (this.dialogType) { |
1790 case DialogType.SELECT_FOLDER: | 1794 case DialogType.SELECT_FOLDER: |
1791 defaultTitle = str('SELECT_FOLDER_TITLE'); | 1795 defaultTitle = str('SELECT_FOLDER_TITLE'); |
1792 break; | 1796 break; |
1793 | 1797 |
| 1798 case DialogType.SELECT_UPLOAD_FOLDER: |
| 1799 defaultTitle = str('SELECT_UPLOAD_FOLDER_TITLE'); |
| 1800 okLabel = str('UPLOAD_LABEL'); |
| 1801 break; |
| 1802 |
1794 case DialogType.SELECT_OPEN_FILE: | 1803 case DialogType.SELECT_OPEN_FILE: |
1795 defaultTitle = str('SELECT_OPEN_FILE_TITLE'); | 1804 defaultTitle = str('SELECT_OPEN_FILE_TITLE'); |
1796 break; | 1805 break; |
1797 | 1806 |
1798 case DialogType.SELECT_OPEN_MULTI_FILE: | 1807 case DialogType.SELECT_OPEN_MULTI_FILE: |
1799 defaultTitle = str('SELECT_OPEN_MULTI_FILE_TITLE'); | 1808 defaultTitle = str('SELECT_OPEN_MULTI_FILE_TITLE'); |
1800 break; | 1809 break; |
1801 | 1810 |
1802 case DialogType.SELECT_SAVEAS_FILE: | 1811 case DialogType.SELECT_SAVEAS_FILE: |
1803 defaultTitle = str('SELECT_SAVEAS_FILE_TITLE'); | 1812 defaultTitle = str('SELECT_SAVEAS_FILE_TITLE'); |
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3009 var path = path.replace(/\/[^\/]+$/, ''); | 3018 var path = path.replace(/\/[^\/]+$/, ''); |
3010 this.directoryModel_.changeDirectory(path); | 3019 this.directoryModel_.changeDirectory(path); |
3011 } | 3020 } |
3012 break; | 3021 break; |
3013 | 3022 |
3014 case '13': // Enter => Change directory or perform default action. | 3023 case '13': // Enter => Change directory or perform default action. |
3015 // TODO(dgozman): move directory action to dispatchSelectionAction. | 3024 // TODO(dgozman): move directory action to dispatchSelectionAction. |
3016 var selection = this.getSelection(); | 3025 var selection = this.getSelection(); |
3017 if (selection.totalCount == 1 && | 3026 if (selection.totalCount == 1 && |
3018 selection.entries[0].isDirectory && | 3027 selection.entries[0].isDirectory && |
3019 this.dialogType != DialogType.SELECT_FOLDER) { | 3028 this.dialogType != DialogType.SELECT_FOLDER && |
| 3029 this.dialogType != DialogType.SELECT_UPLOAD_FOLDER) { |
3020 event.preventDefault(); | 3030 event.preventDefault(); |
3021 this.onDirectoryAction(selection.entries[0]); | 3031 this.onDirectoryAction(selection.entries[0]); |
3022 } else if (this.dispatchSelectionAction_()) { | 3032 } else if (this.dispatchSelectionAction_()) { |
3023 event.preventDefault(); | 3033 event.preventDefault(); |
3024 } | 3034 } |
3025 break; | 3035 break; |
3026 } | 3036 } |
3027 | 3037 |
3028 switch (event.keyIdentifier) { | 3038 switch (event.keyIdentifier) { |
3029 case 'Home': | 3039 case 'Home': |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3328 resolveSuccessCallback, resolveErrorCallback); | 3338 resolveSuccessCallback, resolveErrorCallback); |
3329 }; | 3339 }; |
3330 | 3340 |
3331 this.validateFileName_(currentDirUrl, filename, checkOverwriteAndFinish); | 3341 this.validateFileName_(currentDirUrl, filename, checkOverwriteAndFinish); |
3332 return; | 3342 return; |
3333 } | 3343 } |
3334 | 3344 |
3335 var files = []; | 3345 var files = []; |
3336 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; | 3346 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; |
3337 | 3347 |
3338 if (this.dialogType == DialogType.SELECT_FOLDER && | 3348 if ((this.dialogType == DialogType.SELECT_FOLDER || |
| 3349 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER) && |
3339 selectedIndexes.length == 0) { | 3350 selectedIndexes.length == 0) { |
3340 var url = this.getCurrentDirectoryURL(); | 3351 var url = this.getCurrentDirectoryURL(); |
3341 var singleSelection = { | 3352 var singleSelection = { |
3342 urls: [url], | 3353 urls: [url], |
3343 multiple: false, | 3354 multiple: false, |
3344 filterIndex: this.getSelectedFilterIndex_() | 3355 filterIndex: this.getSelectedFilterIndex_() |
3345 }; | 3356 }; |
3346 this.selectFilesAndClose_(singleSelection); | 3357 this.selectFilesAndClose_(singleSelection); |
3347 return; | 3358 return; |
3348 } | 3359 } |
(...skipping 24 matching lines...) Expand all Loading... |
3373 this.selectFilesAndClose_(multipleSelection); | 3384 this.selectFilesAndClose_(multipleSelection); |
3374 return; | 3385 return; |
3375 } | 3386 } |
3376 | 3387 |
3377 // Everything else must have exactly one. | 3388 // Everything else must have exactly one. |
3378 if (files.length > 1) | 3389 if (files.length > 1) |
3379 throw new Error('Too many files selected!'); | 3390 throw new Error('Too many files selected!'); |
3380 | 3391 |
3381 var selectedEntry = dm.item(selectedIndexes[0]); | 3392 var selectedEntry = dm.item(selectedIndexes[0]); |
3382 | 3393 |
3383 if (this.dialogType == DialogType.SELECT_FOLDER) { | 3394 if (this.dialogType == DialogType.SELECT_FOLDER || |
| 3395 this.dialogType == DialogType.SELECT_UPLOAD_FOLDER) { |
3384 if (!selectedEntry.isDirectory) | 3396 if (!selectedEntry.isDirectory) |
3385 throw new Error('Selected entry is not a folder!'); | 3397 throw new Error('Selected entry is not a folder!'); |
3386 } else if (this.dialogType == DialogType.SELECT_OPEN_FILE) { | 3398 } else if (this.dialogType == DialogType.SELECT_OPEN_FILE) { |
3387 if (!selectedEntry.isFile) | 3399 if (!selectedEntry.isFile) |
3388 throw new Error('Selected entry is not a file!'); | 3400 throw new Error('Selected entry is not a file!'); |
3389 } | 3401 } |
3390 | 3402 |
3391 var singleSelection = { | 3403 var singleSelection = { |
3392 urls: [files[0]], | 3404 urls: [files[0]], |
3393 multiple: false, | 3405 multiple: false, |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3907 */ | 3919 */ |
3908 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { | 3920 FileManager.prototype.setCtrlKeyPressed_ = function(flag) { |
3909 this.ctrlKeyPressed_ = flag; | 3921 this.ctrlKeyPressed_ = flag; |
3910 // Before the DOM is constructed, the key event can be handled. | 3922 // Before the DOM is constructed, the key event can be handled. |
3911 var cacheClearCommand = | 3923 var cacheClearCommand = |
3912 this.document_.querySelector('#drive-clear-local-cache'); | 3924 this.document_.querySelector('#drive-clear-local-cache'); |
3913 if (cacheClearCommand) | 3925 if (cacheClearCommand) |
3914 cacheClearCommand.canExecuteChange(); | 3926 cacheClearCommand.canExecuteChange(); |
3915 }; | 3927 }; |
3916 })(); | 3928 })(); |
OLD | NEW |