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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 this.onTaskItemClicked_.bind(this)); | 770 this.onTaskItemClicked_.bind(this)); |
771 | 771 |
772 this.dialogDom_.ownerDocument.defaultView.addEventListener( | 772 this.dialogDom_.ownerDocument.defaultView.addEventListener( |
773 'resize', this.onResize_.bind(this)); | 773 'resize', this.onResize_.bind(this)); |
774 | 774 |
775 if (loadTimeData.getBoolean('ASH')) | 775 if (loadTimeData.getBoolean('ASH')) |
776 this.dialogDom_.setAttribute('ash', 'true'); | 776 this.dialogDom_.setAttribute('ash', 'true'); |
777 | 777 |
778 this.filePopup_ = null; | 778 this.filePopup_ = null; |
779 | 779 |
780 var searchBox = this.dialogDom_.querySelector('#search-box'); | 780 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); |
781 searchBox.addEventListener('input', this.onSearchBoxUpdate_.bind(this)); | 781 this.searchBox_.addEventListener( |
| 782 'input', this.onSearchBoxUpdate_.bind(this)); |
782 | 783 |
783 var autocompleteList = new cr.ui.AutocompleteList(); | 784 var autocompleteList = new cr.ui.AutocompleteList(); |
784 autocompleteList.id = 'autocomplete-list'; | 785 autocompleteList.id = 'autocomplete-list'; |
785 autocompleteList.autoExpands = true; | 786 autocompleteList.autoExpands = true; |
786 autocompleteList.requestSuggestions = | 787 autocompleteList.requestSuggestions = |
787 this.requestAutocompleteSuggestions_.bind(this); | 788 this.requestAutocompleteSuggestions_.bind(this); |
788 // function(item) {}.bind(this) does not work here, as it's a constructor. | 789 // function(item) {}.bind(this) does not work here, as it's a constructor. |
789 var self = this; | 790 var self = this; |
790 autocompleteList.itemConstructor = function(item) { | 791 autocompleteList.itemConstructor = function(item) { |
791 return self.createAutocompleteListItem_(item); | 792 return self.createAutocompleteListItem_(item); |
(...skipping 22 matching lines...) Expand all Loading... |
814 // the item A and B are highlighted. This is bad. We should change the | 815 // the item A and B are highlighted. This is bad. We should change the |
815 // selection so only the item B is highlighted. | 816 // selection so only the item B is highlighted. |
816 if (event.target.itemInfo) | 817 if (event.target.itemInfo) |
817 autocompleteList.selectedItem = event.target.itemInfo; | 818 autocompleteList.selectedItem = event.target.itemInfo; |
818 }.bind(this)); | 819 }.bind(this)); |
819 | 820 |
820 var container = this.document_.querySelector('.dialog-header'); | 821 var container = this.document_.querySelector('.dialog-header'); |
821 container.appendChild(autocompleteList); | 822 container.appendChild(autocompleteList); |
822 this.autocompleteList_ = autocompleteList; | 823 this.autocompleteList_ = autocompleteList; |
823 | 824 |
824 searchBox.addEventListener('focus', function(event) { | 825 this.searchBox_.addEventListener('focus', function(event) { |
825 this.autocompleteList_.attachToInput(searchBox); | 826 this.autocompleteList_.attachToInput(this.searchBox_); |
826 }.bind(this)); | 827 }.bind(this)); |
827 searchBox.addEventListener('blur', function(event) { | 828 this.searchBox_.addEventListener('blur', function(event) { |
828 this.autocompleteList_.detach(); | 829 this.autocompleteList_.detach(); |
829 }.bind(this)); | 830 }.bind(this)); |
830 | 831 |
831 this.defaultActionMenuItem_ = | 832 this.defaultActionMenuItem_ = |
832 this.dialogDom_.querySelector('#default-action'); | 833 this.dialogDom_.querySelector('#default-action'); |
833 | 834 |
834 this.openWithCommand_ = | 835 this.openWithCommand_ = |
835 this.dialogDom_.querySelector('#open-with'); | 836 this.dialogDom_.querySelector('#open-with'); |
836 | 837 |
837 this.driveBuyMoreStorageCommand_ = | 838 this.driveBuyMoreStorageCommand_ = |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2010 var rootPath = PathUtil.getRootPath(path); | 2011 var rootPath = PathUtil.getRootPath(path); |
2011 this.document_.title = PathUtil.getRootLabel(rootPath) + | 2012 this.document_.title = PathUtil.getRootLabel(rootPath) + |
2012 path.substring(rootPath.length); | 2013 path.substring(rootPath.length); |
2013 }; | 2014 }; |
2014 | 2015 |
2015 /** | 2016 /** |
2016 * Updates search box value when directory gets changed. | 2017 * Updates search box value when directory gets changed. |
2017 * @private | 2018 * @private |
2018 */ | 2019 */ |
2019 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { | 2020 FileManager.prototype.updateSearchBoxOnDirChange_ = function() { |
2020 var searchBox = this.dialogDom_.querySelector('#search-box'); | 2021 if (!this.searchBox_.disabled) |
2021 if (!searchBox.disabled) | 2022 this.searchBox_.value = ''; |
2022 searchBox.value = ''; | |
2023 }; | 2023 }; |
2024 | 2024 |
2025 /** | 2025 /** |
2026 * Update the gear menu. | 2026 * Update the gear menu. |
2027 * @private | 2027 * @private |
2028 */ | 2028 */ |
2029 FileManager.prototype.updateGearMenu_ = function() { | 2029 FileManager.prototype.updateGearMenu_ = function() { |
2030 this.syncButton.hidden = !this.isOnDrive(); | 2030 this.syncButton.hidden = !this.isOnDrive(); |
2031 this.hostedButton.hidden = !this.isOnDrive(); | 2031 this.hostedButton.hidden = !this.isOnDrive(); |
2032 | 2032 |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2965 if (newValue) | 2965 if (newValue) |
2966 event.target.setAttribute('checked', 'checked'); | 2966 event.target.setAttribute('checked', 'checked'); |
2967 else | 2967 else |
2968 event.target.removeAttribute('checked'); | 2968 event.target.removeAttribute('checked'); |
2969 | 2969 |
2970 var changeInfo = {}; | 2970 var changeInfo = {}; |
2971 changeInfo[pref] = inverted ? !newValue : newValue; | 2971 changeInfo[pref] = inverted ? !newValue : newValue; |
2972 chrome.fileBrowserPrivate.setPreferences(changeInfo); | 2972 chrome.fileBrowserPrivate.setPreferences(changeInfo); |
2973 }; | 2973 }; |
2974 | 2974 |
| 2975 /** |
| 2976 * Invoked when the sarch box is changed. |
| 2977 * |
| 2978 * @param {Event} event The 'changed' event. |
| 2979 * @private |
| 2980 */ |
2975 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 2981 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
2976 var searchString = this.document_.getElementById('search-box').value; | 2982 if (this.isOnDrive()) |
| 2983 return; |
| 2984 |
| 2985 var searchString = this.searchBox_.value; |
| 2986 this.search_(searchString); |
| 2987 }; |
| 2988 |
| 2989 /** |
| 2990 * Search files and update the list with the search result. |
| 2991 * |
| 2992 * @param {string} searchString String to be searched with. |
| 2993 * @private |
| 2994 */ |
| 2995 FileManager.prototype.search_ = function(searchString) { |
2977 var noResultsDiv = this.document_.getElementById('no-search-results'); | 2996 var noResultsDiv = this.document_.getElementById('no-search-results'); |
2978 | 2997 |
2979 var reportEmptySearchResults = function() { | 2998 var reportEmptySearchResults = function() { |
2980 if (this.directoryModel_.getFileList().length === 0) { | 2999 if (this.directoryModel_.getFileList().length === 0) { |
2981 // The string 'SEARCH_NO_MATCHING_FILES_HTML' may contain HTML tags, | 3000 // The string 'SEARCH_NO_MATCHING_FILES_HTML' may contain HTML tags, |
2982 // hence we escapes |searchString| here. | 3001 // hence we escapes |searchString| here. |
2983 var html = strf('SEARCH_NO_MATCHING_FILES_HTML', | 3002 var html = strf('SEARCH_NO_MATCHING_FILES_HTML', |
2984 util.htmlEscape(searchString)); | 3003 util.htmlEscape(searchString)); |
2985 noResultsDiv.innerHTML = html; | 3004 noResultsDiv.innerHTML = html; |
2986 noResultsDiv.setAttribute('show', 'true'); | 3005 noResultsDiv.setAttribute('show', 'true'); |
(...skipping 14 matching lines...) Expand all Loading... |
3001 /** | 3020 /** |
3002 * Requests autocomplete suggestions for files on Drive. | 3021 * Requests autocomplete suggestions for files on Drive. |
3003 * Once the suggestions are returned, the autocomplete popup will show up. | 3022 * Once the suggestions are returned, the autocomplete popup will show up. |
3004 * | 3023 * |
3005 * @param {string} query The text to autocomplete from. | 3024 * @param {string} query The text to autocomplete from. |
3006 * @private | 3025 * @private |
3007 */ | 3026 */ |
3008 FileManager.prototype.requestAutocompleteSuggestions_ = function(query) { | 3027 FileManager.prototype.requestAutocompleteSuggestions_ = function(query) { |
3009 if (!this.isOnDrive()) | 3028 if (!this.isOnDrive()) |
3010 return; | 3029 return; |
| 3030 |
3011 this.lastQuery_ = query; | 3031 this.lastQuery_ = query; |
3012 | 3032 |
3013 // The autocomplete list should be resized and repositioned here as the | 3033 // The autocomplete list should be resized and repositioned here as the |
3014 // search box is resized when it's focused. | 3034 // search box is resized when it's focused. |
3015 this.autocompleteList_.syncWidthAndPositionToInput(); | 3035 this.autocompleteList_.syncWidthAndPositionToInput(); |
3016 | 3036 |
| 3037 if (!query) { |
| 3038 this.autocompleteList_.suggestions = []; |
| 3039 return; |
| 3040 } |
| 3041 |
| 3042 var headerItem = {isHeaderItem: true, searchQuery: query}; |
| 3043 if (!this.autocompleteList_.dataModel || |
| 3044 this.autocompleteList_.dataModel.length == 0) |
| 3045 this.autocompleteList_.suggestions = [headerItem]; |
| 3046 else |
| 3047 // Updates only the head item to prevent a flickering on typing. |
| 3048 this.autocompleteList_.dataModel.splice(0, 1, headerItem); |
| 3049 |
3017 chrome.fileBrowserPrivate.searchDriveMetadata( | 3050 chrome.fileBrowserPrivate.searchDriveMetadata( |
3018 query, | 3051 query, |
3019 function(suggestions) { | 3052 function(suggestions) { |
3020 // searchDriveMetadata() is asynchronous hence the result of an old | 3053 // searchDriveMetadata() is asynchronous hence the result of an old |
3021 // query could be delivered at a later time. | 3054 // query could be delivered at a later time. |
3022 if (query != this.lastQuery_) | 3055 if (query != this.lastQuery_) |
3023 return; | 3056 return; |
3024 this.autocompleteList_.suggestions = suggestions; | 3057 |
| 3058 // Keeps the items in the initial list. |
| 3059 this.autocompleteList_.suggestions = [headerItem].concat(suggestions); |
3025 }.bind(this)); | 3060 }.bind(this)); |
3026 }; | 3061 }; |
3027 | 3062 |
3028 /** | 3063 /** |
3029 * Creates a ListItem element for autocomple. | 3064 * Creates a ListItem element for autocomple. |
3030 * | 3065 * |
3031 * @param {Object} item An object representing a suggestion. | 3066 * @param {Object} item An object representing a suggestion. |
3032 * @return {HTMLElement} Element containing the autocomplete suggestions. | 3067 * @return {HTMLElement} Element containing the autocomplete suggestions. |
3033 * @private | 3068 * @private |
3034 */ | 3069 */ |
3035 FileManager.prototype.createAutocompleteListItem_ = function(item) { | 3070 FileManager.prototype.createAutocompleteListItem_ = function(item) { |
3036 var li = new cr.ui.ListItem(); | 3071 var li = new cr.ui.ListItem(); |
3037 li.itemInfo = item; | 3072 li.itemInfo = item; |
3038 var iconType = FileType.getIcon(item.entry); | 3073 |
3039 var icon = this.document_.createElement('div'); | 3074 var icon = this.document_.createElement('div'); |
3040 icon.className = 'detail-icon'; | 3075 icon.className = 'detail-icon'; |
3041 icon.setAttribute('file-type-icon', iconType); | 3076 |
3042 var text = this.document_.createElement('div'); | 3077 var text = this.document_.createElement('div'); |
3043 text.className = 'detail-text'; | 3078 text.className = 'detail-text'; |
3044 // highlightedBaseName is a piece of HTML with meta characters properly | 3079 |
3045 // escaped. See the comment at fileBrowserPrivate.searchDriveMetadata(). | 3080 if (item.isHeaderItem) { |
3046 text.innerHTML = item.highlightedBaseName; | 3081 icon.setAttribute('search-icon'); |
| 3082 text.innerHTML = |
| 3083 strf('SEARCH_DRIVE_HTML', util.htmlEscape(item.searchQuery)); |
| 3084 } else { |
| 3085 var iconType = FileType.getIcon(item.entry); |
| 3086 icon.setAttribute('file-type-icon', iconType); |
| 3087 // highlightedBaseName is a piece of HTML with meta characters properly |
| 3088 // escaped. See the comment at fileBrowserPrivate.searchDriveMetadata(). |
| 3089 text.innerHTML = item.highlightedBaseName; |
| 3090 } |
3047 li.appendChild(icon); | 3091 li.appendChild(icon); |
3048 li.appendChild(text); | 3092 li.appendChild(text); |
3049 return li; | 3093 return li; |
3050 }; | 3094 }; |
3051 | 3095 |
3052 /** | 3096 /** |
3053 * Opens the currently selected suggestion item. | 3097 * Opens the currently selected suggestion item. |
3054 * @private | 3098 * @private |
3055 */ | 3099 */ |
3056 FileManager.prototype.openAutocompleteSuggestion_ = function() { | 3100 FileManager.prototype.openAutocompleteSuggestion_ = function() { |
3057 var entry = this.autocompleteList_.selectedItem.entry; | 3101 var selectedItem = this.autocompleteList_.selectedItem; |
| 3102 |
| 3103 // If the entry is the search item or no entry is selected, just change to |
| 3104 // the search result. |
| 3105 if (!selectedItem || selectedItem.isHeaderItem) { |
| 3106 var query = selectedItem ? |
| 3107 selectedItem.searchQuery : this.searchBox_.value; |
| 3108 this.search_(query); |
| 3109 return; |
| 3110 } |
| 3111 |
| 3112 var entry = selectedItem.entry; |
3058 // If the entry is a directory, just change the directory. | 3113 // If the entry is a directory, just change the directory. |
3059 if (entry.isDirectory) { | 3114 if (entry.isDirectory) { |
3060 this.onDirectoryAction(entry); | 3115 this.onDirectoryAction(entry); |
3061 return; | 3116 return; |
3062 } | 3117 } |
3063 | 3118 |
3064 var urls = [entry.toURL()]; | 3119 var urls = [entry.toURL()]; |
3065 var self = this; | 3120 var self = this; |
3066 | 3121 |
3067 // To open a file, first get the mime type. | 3122 // To open a file, first get the mime type. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 callback(this.preferences_); | 3285 callback(this.preferences_); |
3231 return; | 3286 return; |
3232 } | 3287 } |
3233 | 3288 |
3234 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3289 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
3235 this.preferences_ = prefs; | 3290 this.preferences_ = prefs; |
3236 callback(prefs); | 3291 callback(prefs); |
3237 }.bind(this)); | 3292 }.bind(this)); |
3238 }; | 3293 }; |
3239 })(); | 3294 })(); |
OLD | NEW |