Commit 8347a8af authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Files.app: Handle change-by-keyboard in the directory tree

This patch fixes the regression, which is that the selection change by keyboard is not handled.

BUG=371715
TEST=manually tested

Review URL: https://codereview.chromium.org/279873002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271346 0039d316-1c4b-4281-b951-d872f2087c98
parent fd495c25
...@@ -647,12 +647,16 @@ DirectoryModel.prototype.createDirectory = function(name, ...@@ -647,12 +647,16 @@ DirectoryModel.prototype.createDirectory = function(name,
}; };
/** /**
* Change the current directory to the directory represented by * Changes the current directory to the directory represented by
* a DirectoryEntry or a fake entry. * a DirectoryEntry or a fake entry.
* *
* Dispatches the 'directory-changed' event when the directory is successfully * Dispatches the 'directory-changed' event when the directory is successfully
* changed. * changed.
* *
* Note : if this is called from UI, please consider to use DirectoryModel.
* activateDirectoryEntry instead of this, which is higher-level function and
* cares about the selection.
*
* @param {DirectoryEntry|Object} dirEntry The entry of the new directory to * @param {DirectoryEntry|Object} dirEntry The entry of the new directory to
* be opened. * be opened.
* @param {function()=} opt_callback Executed if the directory loads * @param {function()=} opt_callback Executed if the directory loads
...@@ -694,6 +698,31 @@ DirectoryModel.prototype.changeDirectoryEntry = function( ...@@ -694,6 +698,31 @@ DirectoryModel.prototype.changeDirectoryEntry = function(
}.bind(this, this.changeDirectorySequence_)); }.bind(this, this.changeDirectorySequence_));
}; };
/**
* Activates the given directry.
* This method:
* - Changes the current directory, if the given directory is the current
* directory.
* - Clears the selection, if the given directory is the current directory.
*
* @param {DirectoryEntry|Object} dirEntry The entry of the new directory to
* be opened.
* @param {function()=} opt_callback Executed if the directory loads
* successfully.
*/
DirectoryModel.prototype.activateDirectoryEntry = function(
dirEntry, opt_callback) {
var currentDirectoryEntry = this.getCurrentDirEntry();
if (currentDirectoryEntry &&
util.isSameEntry(dirEntry, currentDirectoryEntry)) {
// On activating the current directory, clear the selection on the filelist.
this.clearSelection();
} else {
// Otherwise, changes the current directory.
this.changeDirectoryEntry(dirEntry, opt_callback);
}
};
/** /**
* Clears the selection in the file list. * Clears the selection in the file list.
*/ */
......
...@@ -256,19 +256,8 @@ DirectoryItem.prototype.onExpand_ = function(e) { ...@@ -256,19 +256,8 @@ DirectoryItem.prototype.onExpand_ = function(e) {
*/ */
DirectoryItem.prototype.handleClick = function(e) { DirectoryItem.prototype.handleClick = function(e) {
cr.ui.TreeItem.prototype.handleClick.call(this, e); cr.ui.TreeItem.prototype.handleClick.call(this, e);
if (!e.target.classList.contains('expand-icon'))
if (e.target.classList.contains('expand-icon')) this.directoryModel_.activateDirectoryEntry(this.entry);
return;
var currentDirectoryEntry = this.directoryModel_.getCurrentDirEntry();
if (currentDirectoryEntry &&
util.isSameEntry(this.entry, currentDirectoryEntry)) {
// On clicking the current directory, clears the selection on the file list.
this.directoryModel_.clearSelection();
} else {
// Otherwise, changes the current directory.
this.directoryModel_.changeDirectoryEntry(this.entry);
}
}; };
/** /**
...@@ -493,6 +482,12 @@ DirectoryTree.prototype.decorate = function(directoryModel, volumeManager) { ...@@ -493,6 +482,12 @@ DirectoryTree.prototype.decorate = function(directoryModel, volumeManager) {
this.directoryModel_.addEventListener('directory-changed', this.directoryModel_.addEventListener('directory-changed',
this.onCurrentDirectoryChanged_.bind(this)); this.onCurrentDirectoryChanged_.bind(this));
// Add a handler for directory change.
this.addEventListener('change', function() {
if (this.selectedItem)
this.directoryModel_.activateDirectoryEntry(this.selectedItem.entry);
}.bind(this));
this.privateOnDirectoryChangedBound_ = this.privateOnDirectoryChangedBound_ =
this.onDirectoryContentChanged_.bind(this); this.onDirectoryContentChanged_.bind(this);
chrome.fileBrowserPrivate.onDirectoryChanged.addListener( chrome.fileBrowserPrivate.onDirectoryChanged.addListener(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment