OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
6 * @param {DialogType} dialogType | 6 * @param {DialogType} dialogType |
7 * @param {!VolumeManagerWrapper} volumeManager | 7 * @param {!VolumeManagerWrapper} volumeManager |
8 * @param {!FileManagerUI} ui | 8 * @param {!FileManagerUI} ui |
9 * @param {!MetadataModel} metadataModel | 9 * @param {!MetadataModel} metadataModel |
10 * @param {!DirectoryModel} directoryModel | 10 * @param {!DirectoryModel} directoryModel |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 }); | 255 }); |
256 }); | 256 }); |
257 }); | 257 }); |
258 }; | 258 }; |
259 | 259 |
260 /** | 260 /** |
261 * Handles change of selection and clears context menu. | 261 * Handles change of selection and clears context menu. |
262 * @private | 262 * @private |
263 */ | 263 */ |
264 TaskController.prototype.onSelectionChanged_ = function() { | 264 TaskController.prototype.onSelectionChanged_ = function() { |
| 265 this.tasks_ = null; |
265 var selection = this.selectionHandler_.selection; | 266 var selection = this.selectionHandler_.selection; |
266 // Caller of update context menu task items. | 267 // Caller of update context menu task items. |
267 // FileSelectionHandler.EventType.CHANGE | 268 // FileSelectionHandler.EventType.CHANGE |
268 if (this.dialogType_ === DialogType.FULL_PAGE && | 269 if (this.dialogType_ === DialogType.FULL_PAGE && |
269 (selection.directoryCount > 0 || selection.fileCount > 0)) { | 270 (selection.directoryCount > 0 || selection.fileCount > 0)) { |
270 // Show disabled items for position calculation of the menu. They will be | 271 // Show disabled items for position calculation of the menu. They will be |
271 // overridden in this.updateFileSelectionAsync(). | 272 // overridden in this.updateFileSelectionAsync(). |
272 this.updateContextMenuTaskItems_( | 273 this.updateContextMenuTaskItems_( |
273 [TaskController.createTemporaryDisabledTaskItem_()]); | 274 [TaskController.createTemporaryDisabledTaskItem_()]); |
274 } else { | 275 } else { |
275 // Update context menu. | 276 // Update context menu. |
276 this.updateContextMenuTaskItems_([]); | 277 this.updateContextMenuTaskItems_([]); |
277 } | 278 } |
278 }; | 279 }; |
279 | 280 |
280 /** | 281 /** |
281 * Updates available tasks opened from context menu or the open button. | 282 * Updates available tasks opened from context menu or the open button. |
282 * @private | 283 * @private |
283 */ | 284 */ |
284 TaskController.prototype.updateTasks_ = function() { | 285 TaskController.prototype.updateTasks_ = function() { |
285 var selection = this.selectionHandler_.selection; | 286 var selection = this.selectionHandler_.selection; |
286 if (this.dialogType_ === DialogType.FULL_PAGE && | 287 if (this.dialogType_ === DialogType.FULL_PAGE && |
287 (selection.directoryCount > 0 || selection.fileCount > 0)) { | 288 (selection.directoryCount > 0 || selection.fileCount > 0)) { |
288 var previousFileTasksInvalidatePromise = new Promise(function(resolve) { | 289 this.getFileTasks() |
289 if (this.tasks_) { | 290 .then(function(tasks) { |
290 this.getFileTasks() | 291 tasks.display(this.ui_.taskMenuButton); |
291 .then(function(tasks) { | 292 this.updateContextMenuTaskItems_(tasks.getTaskItems()); |
292 if (!util.isSameEntries(tasks.entries, selection.entries)) { | 293 }.bind(this)) |
293 this.tasks_ = null; | 294 .catch(function(error) { |
294 } | 295 if (error) |
295 resolve(); | 296 console.error(error.stack || error); |
296 }.bind(this)) | 297 }); |
297 .catch(function(error) { | |
298 if (error) | |
299 console.log(error.stack || error); | |
300 this.tasks_ = null; | |
301 resolve(); | |
302 }.bind(this)); | |
303 } else { | |
304 resolve(); | |
305 } | |
306 }.bind(this)); | |
307 previousFileTasksInvalidatePromise.then(function() { | |
308 this.getFileTasks() | |
309 .then(function(tasks) { | |
310 tasks.display(this.ui_.taskMenuButton); | |
311 this.updateContextMenuTaskItems_(tasks.getTaskItems()); | |
312 }.bind(this)) | |
313 .catch(function(error) { | |
314 if (error) | |
315 console.error(error.stack || error); | |
316 }); | |
317 }.bind(this)); | |
318 } else { | 298 } else { |
319 this.ui_.taskMenuButton.hidden = true; | 299 this.ui_.taskMenuButton.hidden = true; |
320 } | 300 } |
321 } | 301 } |
322 | 302 |
323 /** | 303 /** |
324 * @return {!Promise<!FileTasks>} | 304 * @return {!Promise<!FileTasks>} |
325 * @public | 305 * @public |
326 */ | 306 */ |
327 TaskController.prototype.getFileTasks = function() { | 307 TaskController.prototype.getFileTasks = function() { |
328 if (this.tasks_) | 308 if (this.tasks_) |
329 return this.tasks_; | 309 return this.tasks_; |
330 | 310 |
331 var selection = this.selectionHandler_.selection; | 311 var selection = this.selectionHandler_.selection; |
332 return this.tasks_ = | 312 return selection.computeAdditional(this.metadataModel_).then( |
333 selection.computeAdditional(this.metadataModel_).then(function() { | 313 function() { |
334 if (this.selectionHandler_.selection !== selection) | 314 if (this.selectionHandler_.selection !== selection) |
335 return Promise.reject(); | 315 return Promise.reject(); |
336 return FileTasks | 316 return FileTasks.create( |
337 .create( | 317 this.volumeManager_, this.metadataModel_, this.directoryModel_, |
338 this.volumeManager_, this.metadataModel_, | 318 this.ui_, selection.entries, assert(selection.mimeTypes)). |
339 this.directoryModel_, this.ui_, selection.entries, | 319 then(function(tasks) { |
340 assert(selection.mimeTypes)) | 320 if (this.selectionHandler_.selection !== selection) |
341 .then(function(tasks) { | 321 return Promise.reject(); |
342 if (this.selectionHandler_.selection !== selection) | 322 return tasks; |
343 return Promise.reject(); | 323 }.bind(this)); |
344 return tasks; | 324 }.bind(this)); |
345 }.bind(this)); | |
346 }.bind(this)); | |
347 }; | 325 }; |
348 | 326 |
349 /** | 327 /** |
350 * Returns whether default task command can be executed or not. | 328 * Returns whether default task command can be executed or not. |
351 * @return {boolean} True if default task command is executable. | 329 * @return {boolean} True if default task command is executable. |
352 */ | 330 */ |
353 TaskController.prototype.canExecuteDefaultTask = function() { | 331 TaskController.prototype.canExecuteDefaultTask = function() { |
354 return this.canExecuteDefaultTask_; | 332 return this.canExecuteDefaultTask_; |
355 }; | 333 }; |
356 | 334 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 this.metadataModel_.get([entry], ['contentMimeType']).then( | 389 this.metadataModel_.get([entry], ['contentMimeType']).then( |
412 function(props) { | 390 function(props) { |
413 FileTasks.create( | 391 FileTasks.create( |
414 this.volumeManager_, this.metadataModel_, this.directoryModel_, | 392 this.volumeManager_, this.metadataModel_, this.directoryModel_, |
415 this.ui_, [entry], [props[0].contentMimeType || null]) | 393 this.ui_, [entry], [props[0].contentMimeType || null]) |
416 .then(function(tasks) { | 394 .then(function(tasks) { |
417 tasks.executeDefault(); | 395 tasks.executeDefault(); |
418 }); | 396 }); |
419 }.bind(this)); | 397 }.bind(this)); |
420 }; | 398 }; |
OLD | NEW |