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