Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(948)

Side by Side Diff: chrome/browser/resources/file_manager/foreground/js/file_manager.js

Issue 230073002: Files.app: Reland r261616: Add a test to rename a file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a test. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after
2409 }; 2409 };
2410 2410
2411 FileManager.prototype.initiateRename = function() { 2411 FileManager.prototype.initiateRename = function() {
2412 var item = this.currentList_.ensureLeadItemExists(); 2412 var item = this.currentList_.ensureLeadItemExists();
2413 if (!item) 2413 if (!item)
2414 return; 2414 return;
2415 var label = item.querySelector('.filename-label'); 2415 var label = item.querySelector('.filename-label');
2416 var input = this.renameInput_; 2416 var input = this.renameInput_;
2417 2417
2418 input.value = label.textContent; 2418 input.value = label.textContent;
2419 label.parentNode.setAttribute('renaming', ''); 2419 item.setAttribute('renaming', '');
2420 label.parentNode.appendChild(input); 2420 label.parentNode.appendChild(input);
2421 input.focus(); 2421 input.focus();
2422 var selectionEnd = input.value.lastIndexOf('.'); 2422 var selectionEnd = input.value.lastIndexOf('.');
2423 if (selectionEnd == -1) { 2423 if (selectionEnd == -1) {
2424 input.select(); 2424 input.select();
2425 } else { 2425 } else {
2426 input.selectionStart = 0; 2426 input.selectionStart = 0;
2427 input.selectionEnd = selectionEnd; 2427 input.selectionEnd = selectionEnd;
2428 } 2428 }
2429 2429
2430 // This has to be set late in the process so we don't handle spurious 2430 // This has to be set late in the process so we don't handle spurious
2431 // blur events. 2431 // blur events.
2432 input.currentEntry = this.currentList_.dataModel.item(item.listIndex); 2432 input.currentEntry = this.currentList_.dataModel.item(item.listIndex);
2433 this.table_.startBatchUpdates();
2434 this.grid_.startBatchUpdates();
2433 }; 2435 };
2434 2436
2435 /** 2437 /**
2436 * @type {Event} Key event. 2438 * @type {Event} Key event.
2437 * @private 2439 * @private
2438 */ 2440 */
2439 FileManager.prototype.onRenameInputKeyDown_ = function(event) { 2441 FileManager.prototype.onRenameInputKeyDown_ = function(event) {
2440 if (!this.isRenamingInProgress()) 2442 if (!this.isRenamingInProgress())
2441 return; 2443 return;
2442 2444
(...skipping 30 matching lines...) Expand all
2473 FileManager.prototype.commitRename_ = function() { 2475 FileManager.prototype.commitRename_ = function() {
2474 var input = this.renameInput_; 2476 var input = this.renameInput_;
2475 var entry = input.currentEntry; 2477 var entry = input.currentEntry;
2476 var newName = input.value; 2478 var newName = input.value;
2477 2479
2478 if (newName == entry.name) { 2480 if (newName == entry.name) {
2479 this.cancelRename_(); 2481 this.cancelRename_();
2480 return; 2482 return;
2481 } 2483 }
2482 2484
2483 var nameNode = this.findListItemForNode_(this.renameInput_). 2485 var renamedItemElement = this.findListItemForNode_(this.renameInput_);
2484 querySelector('.filename-label'); 2486 var nameNode = renamedItemElement.querySelector('.filename-label');
2485 2487
2486 input.validation_ = true; 2488 input.validation_ = true;
2487 var validationDone = function(valid) { 2489 var validationDone = function(valid) {
2488 input.validation_ = false; 2490 input.validation_ = false;
2489 // Alert dialog restores focus unless the item removed from DOM. 2491
2490 if (this.document_.activeElement != input) 2492 if (!valid) {
2491 this.cancelRename_(); 2493 // Cancel rename if it fails to restore focus from alert dialog.
2492 if (!valid) 2494 // Otherwise, just cancel the commitment and continue to rename.
2495 if (this.document_.activeElement != input)
2496 this.cancelRename_();
2493 return; 2497 return;
2498 }
2494 2499
2495 // Validation succeeded. Do renaming. 2500 // Validation succeeded. Do renaming.
2501 this.renameInput_.currentEntry = null;
2502 if (this.renameInput_.parentNode)
2503 this.renameInput_.parentNode.removeChild(this.renameInput_);
2504 renamedItemElement.setAttribute('renaming', 'provisional');
2496 2505
2497 this.cancelRename_();
2498 // Optimistically apply new name immediately to avoid flickering in 2506 // Optimistically apply new name immediately to avoid flickering in
2499 // case of success. 2507 // case of success.
2500 nameNode.textContent = newName; 2508 nameNode.textContent = newName;
2501 2509
2502 util.rename( 2510 util.rename(
2503 entry, newName, 2511 entry, newName,
2504 function(newEntry) { 2512 function(newEntry) {
2505 this.directoryModel_.onRenameEntry(entry, newEntry); 2513 this.directoryModel_.onRenameEntry(entry, newEntry);
2514 renamedItemElement.removeAttribute('renaming');
2515 this.table_.endBatchUpdates();
2516 this.grid_.endBatchUpdates();
2506 }.bind(this), 2517 }.bind(this),
2507 function(error) { 2518 function(error) {
2508 // Write back to the old name. 2519 // Write back to the old name.
2509 nameNode.textContent = entry.name; 2520 nameNode.textContent = entry.name;
2521 renamedItemElement.removeAttribute('renaming');
2522 this.table_.endBatchUpdates();
2523 this.grid_.endBatchUpdates();
2510 2524
2511 // Show error dialog. 2525 // Show error dialog.
2512 var message; 2526 var message;
2513 if (error.name == util.FileError.PATH_EXISTS_ERR || 2527 if (error.name == util.FileError.PATH_EXISTS_ERR ||
2514 error.name == util.FileError.TYPE_MISMATCH_ERR) { 2528 error.name == util.FileError.TYPE_MISMATCH_ERR) {
2515 // Check the existing entry is file or not. 2529 // Check the existing entry is file or not.
2516 // 1) If the entry is a file: 2530 // 1) If the entry is a file:
2517 // a) If we get PATH_EXISTS_ERR, a file exists. 2531 // a) If we get PATH_EXISTS_ERR, a file exists.
2518 // b) If we get TYPE_MISMATCH_ERR, a directory exists. 2532 // b) If we get TYPE_MISMATCH_ERR, a directory exists.
2519 // 2) If the entry is a directory: 2533 // 2) If the entry is a directory:
(...skipping 23 matching lines...) Expand all
2543 newName, 2557 newName,
2544 validationDone.bind(this)); 2558 validationDone.bind(this));
2545 }; 2559 };
2546 2560
2547 /** 2561 /**
2548 * @private 2562 * @private
2549 */ 2563 */
2550 FileManager.prototype.cancelRename_ = function() { 2564 FileManager.prototype.cancelRename_ = function() {
2551 this.renameInput_.currentEntry = null; 2565 this.renameInput_.currentEntry = null;
2552 2566
2567 var item = this.findListItemForNode_(this.renameInput_);
2568 if (item)
2569 item.removeAttribute('renaming');
2570
2553 var parent = this.renameInput_.parentNode; 2571 var parent = this.renameInput_.parentNode;
2554 if (parent) { 2572 if (parent)
2555 parent.removeAttribute('renaming');
2556 parent.removeChild(this.renameInput_); 2573 parent.removeChild(this.renameInput_);
2557 } 2574
2575 this.table_.endBatchUpdates();
2576 this.grid_.endBatchUpdates();
2558 }; 2577 };
2559 2578
2560 /** 2579 /**
2561 * @param {Event} Key event. 2580 * @param {Event} Key event.
2562 * @private 2581 * @private
2563 */ 2582 */
2564 FileManager.prototype.onFilenameInputInput_ = function() { 2583 FileManager.prototype.onFilenameInputInput_ = function() {
2565 this.selectionHandler_.updateOkButton(); 2584 this.selectionHandler_.updateOkButton();
2566 }; 2585 };
2567 2586
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 callback(this.preferences_); 3735 callback(this.preferences_);
3717 return; 3736 return;
3718 } 3737 }
3719 3738
3720 chrome.fileBrowserPrivate.getPreferences(function(prefs) { 3739 chrome.fileBrowserPrivate.getPreferences(function(prefs) {
3721 this.preferences_ = prefs; 3740 this.preferences_ = prefs;
3722 callback(prefs); 3741 callback(prefs);
3723 }.bind(this)); 3742 }.bind(this));
3724 }; 3743 };
3725 })(); 3744 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698