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 * FileManager constructor. | 8 * FileManager constructor. |
9 * | 9 * |
10 * FileManager objects encapsulate the functionality of the file selector | 10 * FileManager objects encapsulate the functionality of the file selector |
(...skipping 2462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2473 FileManager.prototype.commitRename_ = function() { | 2473 FileManager.prototype.commitRename_ = function() { |
2474 var input = this.renameInput_; | 2474 var input = this.renameInput_; |
2475 var entry = input.currentEntry; | 2475 var entry = input.currentEntry; |
2476 var newName = input.value; | 2476 var newName = input.value; |
2477 | 2477 |
2478 if (newName == entry.name) { | 2478 if (newName == entry.name) { |
2479 this.cancelRename_(); | 2479 this.cancelRename_(); |
2480 return; | 2480 return; |
2481 } | 2481 } |
2482 | 2482 |
2483 var nameNode = this.findListItemForNode_(this.renameInput_). | 2483 var renamedItemElement = this.findListItemForNode_(this.renameInput_); |
2484 querySelector('.filename-label'); | 2484 var nameNode = renamedItemElement.querySelector('.filename-label'); |
2485 | 2485 |
2486 input.validation_ = true; | 2486 input.validation_ = true; |
2487 var validationDone = function(valid) { | 2487 var validationDone = function(valid) { |
2488 input.validation_ = false; | 2488 input.validation_ = false; |
2489 // Alert dialog restores focus unless the item removed from DOM. | 2489 // Alert dialog restores focus unless the item removed from DOM. |
2490 if (this.document_.activeElement != input) | 2490 if (this.document_.activeElement != input) |
2491 this.cancelRename_(); | 2491 this.cancelRename_(); |
2492 if (!valid) | 2492 if (!valid) |
2493 return; | 2493 return; |
2494 | 2494 |
2495 // Validation succeeded. Do renaming. | 2495 // Validation succeeded. Do renaming. |
2496 | 2496 |
2497 this.cancelRename_(); | 2497 this.cancelRename_(); |
2498 // Optimistically apply new name immediately to avoid flickering in | 2498 // Optimistically apply new name immediately to avoid flickering in |
2499 // case of success. | 2499 // case of success. |
2500 nameNode.textContent = newName; | 2500 nameNode.textContent = newName; |
| 2501 // Add a marker of the provisional change for test cases. |
| 2502 renamedItemElement.classList.add('provisional'); |
2501 | 2503 |
2502 util.rename( | 2504 util.rename( |
2503 entry, newName, | 2505 entry, newName, |
2504 function(newEntry) { | 2506 function(newEntry) { |
2505 this.directoryModel_.onRenameEntry(entry, newEntry); | 2507 this.directoryModel_.onRenameEntry(entry, newEntry); |
| 2508 renamedItemElement.classList.remove('provisional'); |
2506 }.bind(this), | 2509 }.bind(this), |
2507 function(error) { | 2510 function(error) { |
2508 // Write back to the old name. | 2511 // Write back to the old name. |
2509 nameNode.textContent = entry.name; | 2512 nameNode.textContent = entry.name; |
| 2513 renamedItemElement.classList.remove('provisional'); |
2510 | 2514 |
2511 // Show error dialog. | 2515 // Show error dialog. |
2512 var message; | 2516 var message; |
2513 if (error.name == util.FileError.PATH_EXISTS_ERR || | 2517 if (error.name == util.FileError.PATH_EXISTS_ERR || |
2514 error.name == util.FileError.TYPE_MISMATCH_ERR) { | 2518 error.name == util.FileError.TYPE_MISMATCH_ERR) { |
2515 // Check the existing entry is file or not. | 2519 // Check the existing entry is file or not. |
2516 // 1) If the entry is a file: | 2520 // 1) If the entry is a file: |
2517 // a) If we get PATH_EXISTS_ERR, a file exists. | 2521 // a) If we get PATH_EXISTS_ERR, a file exists. |
2518 // b) If we get TYPE_MISMATCH_ERR, a directory exists. | 2522 // b) If we get TYPE_MISMATCH_ERR, a directory exists. |
2519 // 2) If the entry is a directory: | 2523 // 2) If the entry is a directory: |
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3716 callback(this.preferences_); | 3720 callback(this.preferences_); |
3717 return; | 3721 return; |
3718 } | 3722 } |
3719 | 3723 |
3720 chrome.fileBrowserPrivate.getPreferences(function(prefs) { | 3724 chrome.fileBrowserPrivate.getPreferences(function(prefs) { |
3721 this.preferences_ = prefs; | 3725 this.preferences_ = prefs; |
3722 callback(prefs); | 3726 callback(prefs); |
3723 }.bind(this)); | 3727 }.bind(this)); |
3724 }; | 3728 }; |
3725 })(); | 3729 })(); |
OLD | NEW |