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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 'resize', this.onResize_.bind(this)); | 772 'resize', this.onResize_.bind(this)); |
773 | 773 |
774 if (loadTimeData.getBoolean('ASH')) | 774 if (loadTimeData.getBoolean('ASH')) |
775 this.dialogDom_.setAttribute('ash', 'true'); | 775 this.dialogDom_.setAttribute('ash', 'true'); |
776 | 776 |
777 this.filePopup_ = null; | 777 this.filePopup_ = null; |
778 | 778 |
779 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); | 779 this.searchBox_ = this.dialogDom_.querySelector('#search-box'); |
780 this.searchBox_.addEventListener( | 780 this.searchBox_.addEventListener( |
781 'input', this.onSearchBoxUpdate_.bind(this)); | 781 'input', this.onSearchBoxUpdate_.bind(this)); |
| 782 this.lastSearchQuery_ = ''; |
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 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3048 * @private | 3049 * @private |
3049 */ | 3050 */ |
3050 FileManager.prototype.onSearchBoxUpdate_ = function(event) { | 3051 FileManager.prototype.onSearchBoxUpdate_ = function(event) { |
3051 var searchString = this.searchBox_.value; | 3052 var searchString = this.searchBox_.value; |
3052 | 3053 |
3053 if (this.isOnDrive()) { | 3054 if (this.isOnDrive()) { |
3054 // When the search text is changed, finishes the search and showes back | 3055 // When the search text is changed, finishes the search and showes back |
3055 // the last directory by passing an empty string to | 3056 // the last directory by passing an empty string to |
3056 // {@code DirectoryModel.search()}. | 3057 // {@code DirectoryModel.search()}. |
3057 if (this.directoryModel_.isSearching() && | 3058 if (this.directoryModel_.isSearching() && |
3058 this.lastQuery_ != searchString) { | 3059 this.lastSearchQuery_ != searchString) { |
3059 this.directoryModel_.search('', function() {}, function() {}); | 3060 this.doSearch(''); |
3060 } | 3061 } |
3061 | 3062 |
3062 // On drive, incremental search is not invoked since we have an auto- | 3063 // On drive, incremental search is not invoked since we have an auto- |
3063 // complete suggestion instead. | 3064 // complete suggestion instead. |
3064 return; | 3065 return; |
3065 } | 3066 } |
3066 | 3067 |
3067 this.search_(searchString); | 3068 this.search_(searchString); |
3068 }; | 3069 }; |
3069 | 3070 |
(...skipping 16 matching lines...) Expand all Loading... |
3086 noResultsDiv.setAttribute('show', 'true'); | 3087 noResultsDiv.setAttribute('show', 'true'); |
3087 } else { | 3088 } else { |
3088 noResultsDiv.removeAttribute('show'); | 3089 noResultsDiv.removeAttribute('show'); |
3089 } | 3090 } |
3090 }; | 3091 }; |
3091 | 3092 |
3092 var hideNoResultsDiv = function() { | 3093 var hideNoResultsDiv = function() { |
3093 noResultsDiv.removeAttribute('show'); | 3094 noResultsDiv.removeAttribute('show'); |
3094 }; | 3095 }; |
3095 | 3096 |
3096 this.directoryModel_.search(searchString, | 3097 this.doSearch(searchString, |
3097 reportEmptySearchResults.bind(this), | 3098 reportEmptySearchResults.bind(this), |
3098 hideNoResultsDiv.bind(this)); | 3099 hideNoResultsDiv.bind(this)); |
3099 }; | 3100 }; |
3100 | 3101 |
3101 /** | 3102 /** |
| 3103 * Performs search and displays results. |
| 3104 * |
| 3105 * @param {string} query Query that will be searched for. |
| 3106 * @param {function()=} opt_onSearchRescan Function that will be called when |
| 3107 * the search directory is rescanned (i.e. search results are displayed). |
| 3108 * @param {function()=} opt_onClearSearch Function to be called when search |
| 3109 * state gets cleared. |
| 3110 */ |
| 3111 FileManager.prototype.doSearch = function( |
| 3112 searchString, opt_onSearchRescan, opt_onClearSearch) { |
| 3113 var onSearchRescan = opt_onSearchRescan || function() {}; |
| 3114 var onClearSearch = opt_onClearSearch || function() {}; |
| 3115 |
| 3116 this.lastSearchQuery_ = searchString; |
| 3117 this.directoryModel_.search(searchString, onSearchRescan, onClearSearch); |
| 3118 }; |
| 3119 |
| 3120 /** |
3102 * Requests autocomplete suggestions for files on Drive. | 3121 * Requests autocomplete suggestions for files on Drive. |
3103 * Once the suggestions are returned, the autocomplete popup will show up. | 3122 * Once the suggestions are returned, the autocomplete popup will show up. |
3104 * | 3123 * |
3105 * @param {string} query The text to autocomplete from. | 3124 * @param {string} query The text to autocomplete from. |
3106 * @private | 3125 * @private |
3107 */ | 3126 */ |
3108 FileManager.prototype.requestAutocompleteSuggestions_ = function(query) { | 3127 FileManager.prototype.requestAutocompleteSuggestions_ = function(query) { |
3109 if (!this.isOnDrive()) | 3128 if (!this.isOnDrive()) |
3110 return; | 3129 return; |
3111 | 3130 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3403 callback(this.preferences_); | 3422 callback(this.preferences_); |
3404 return; | 3423 return; |
3405 } | 3424 } |
3406 | 3425 |
3407 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3426 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
3408 this.preferences_ = prefs; | 3427 this.preferences_ = prefs; |
3409 callback(prefs); | 3428 callback(prefs); |
3410 }.bind(this)); | 3429 }.bind(this)); |
3411 }; | 3430 }; |
3412 })(); | 3431 })(); |
OLD | NEW |