Chromium Code Reviews| Index: ui/file_manager/file_manager/background/js/launcher_search.js |
| diff --git a/ui/file_manager/file_manager/background/js/launcher_search.js b/ui/file_manager/file_manager/background/js/launcher_search.js |
| index 457a59b0f0816963f5461192aadee2822a3d924c..11b56a66d2e9e6637a52c76b19b921cb3967fc3c 100644 |
| --- a/ui/file_manager/file_manager/background/js/launcher_search.js |
| +++ b/ui/file_manager/file_manager/background/js/launcher_search.js |
| @@ -34,6 +34,11 @@ function LauncherSearch() { |
| */ |
| this.onQueryEndedBound_ = this.onQueryEnded_.bind(this); |
| + /** |
| + * @private {function(string)} |
| + */ |
| + this.onOpenResultBound_ = this.onOpenResult_.bind(this); |
| + |
| // This feature is disabled when drive is disabled. |
| chrome.fileManagerPrivate.onPreferencesChanged.addListener( |
| this.onPreferencesChanged_.bind(this)); |
| @@ -69,6 +74,8 @@ LauncherSearch.prototype.initializeEventListeners_ = function(isDriveEnabled) { |
| this.onQueryStartedBound_); |
| chrome.launcherSearchProvider.onQueryEnded.removeListener( |
| this.onQueryEndedBound_); |
| + chrome.launcherSearchProvider.onOpenResult.removeListener( |
| + this.onOpenResultBound_); |
| } |
| // Set queryId_ to null to prevent that on-going search returns search |
| @@ -82,7 +89,8 @@ LauncherSearch.prototype.initializeEventListeners_ = function(isDriveEnabled) { |
| this.onQueryStartedBound_); |
| chrome.launcherSearchProvider.onQueryEnded.addListener( |
| this.onQueryEndedBound_); |
| - // TODO(yawano): Adds listener to onOpenResult when it becomes available. |
| + chrome.launcherSearchProvider.onOpenResult.addListener( |
| + this.onOpenResultBound_); |
| } else { |
| this.enabled_ = false; |
| } |
| @@ -131,3 +139,61 @@ LauncherSearch.prototype.onQueryStarted_ = function(queryId, query, limit) { |
| LauncherSearch.prototype.onQueryEnded_ = function(queryId) { |
| this.queryId_ = null; |
| }; |
| + |
| +/** |
| + * Handles onOpenResult event. |
| + * @param {string} itemId |
| + */ |
| +LauncherSearch.prototype.onOpenResult_ = function(itemId) { |
| + util.urlToEntry(itemId).then(function(entry) { |
| + if (entry.isDirectory) { |
| + // If it's directory, open the directory with file manager. |
| + launchFileManager( |
| + { currentDirectoryURL: entry.toURL() }, |
| + /* App ID */ undefined, |
|
fukino
2015/04/21 08:52:47
nit: We usually add inline comment like this.
unde
yawano
2015/04/21 08:58:45
Done.
|
| + LaunchType.FOCUS_SAME_OR_CREATE); |
| + } else { |
| + // If the file is not directory, try to execute default task. |
| + chrome.fileManagerPrivate.getFileTasks([entry.toURL()], function(tasks) { |
| + // Select default task. |
| + var default_task = null; |
|
fukino
2015/04/21 08:52:47
nit: in JavaScript, variableNamesLikeThis
yawano
2015/04/21 08:58:45
Done.
|
| + for (var i = 0; i < tasks.length; i++) { |
| + var task = tasks[i]; |
| + if (task.isDefault) { |
| + default_task = task; |
| + break; |
| + } |
| + } |
| + |
| + if (default_task) { |
| + // Execute default task. |
| + chrome.fileManagerPrivate.executeTask( |
| + default_task.taskId, |
| + [entry.toURL()], |
| + function(result) { |
| + if (result === 'opened' || result === 'message_sent') |
| + return; |
| + this.openFileManagerWithSelectionURL_(entry.toURL()); |
| + }.bind(this)); |
| + } else { |
| + // If there is no default task for the url, open a file manager with |
| + // selecting it. |
| + // TODO(yawano): Add fallback to view-in-browser as file_tasks.js do. |
| + this.openFileManagerWithSelectionURL_(entry.toURL()); |
| + } |
| + }.bind(this)); |
| + } |
| + }.bind(this)); |
| +}; |
| + |
| +/** |
| + * Opens file manager with selecting a specified url. |
| + * @param {string} selectionURL A url to be selected. |
|
fukino
2015/04/21 08:52:47
nit: @private
yawano
2015/04/21 08:58:45
Done.
|
| + */ |
| +LauncherSearch.prototype.openFileManagerWithSelectionURL_ = function( |
| + selectionURL) { |
| + launchFileManager( |
| + { selectionURL: selectionURL }, |
| + /* App ID */ undefined, |
|
fukino
2015/04/21 08:52:47
ditto
yawano
2015/04/21 08:58:45
Done.
|
| + LaunchType.FOCUS_SAME_OR_CREATE); |
| +}; |