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

Unified Diff: chrome/browser/resources/file_manager/js/directory_model.js

Issue 10146008: Remember current directory for each volume. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/file_manager.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/file_manager/js/directory_model.js
===================================================================
--- chrome/browser/resources/file_manager/js/directory_model.js (revision 133184)
+++ chrome/browser/resources/file_manager/js/directory_model.js (working copy)
@@ -39,8 +39,13 @@
this.rootsList_ = new cr.ui.ArrayDataModel([]);
this.rootsListSelection_ = new cr.ui.ListSingleSelectionModel();
- this.rootsListSelection_.addEventListener(
- 'change', this.onRootsSelectionChanged_.bind(this));
+ this.currentRootDirEntry_ = root;
+ /**
+ * A map root.fullPath -> currentDirectory.fullPath.
+ * @private
+ * @type {Object.<string, string>}
+ */
+ this.currentDirByRoot_ = {};
// The map 'name' -> callback. Callbacks are function(entry) -> boolean.
this.filters_ = {};
@@ -105,14 +110,6 @@
},
/**
- * Top level Directories from user perspective.
- * @type {cr.ui.ArrayDataModel}
- */
- get rootsList() {
- return this.rootsList_;
- },
-
- /**
* Selection in the rootsList.
* @type {cr.ui.ListSingleSelectionModel}
*/
@@ -120,15 +117,6 @@
return this.rootsListSelection_;
},
- /**
- * Root path for the current directory (parent directory is not navigatable
- * for the user).
- * @type {string}
- */
- get rootPath() {
- return DirectoryModel.getRootPath(this.currentEntry.fullPath);
- },
-
get rootType() {
return DirectoryModel.getRootType(this.currentEntry.fullPath);
},
@@ -138,7 +126,7 @@
},
get rootEntry() {
- return this.rootsList.item(this.rootsListSelection.selectedIndex);
+ return this.rootsList_.item(this.rootsListSelection.selectedIndex);
},
/**
@@ -249,6 +237,21 @@
};
Vladislav Kaznacheev 2012/04/20 14:55:11 nit: if you renamed these functions in place it wo
Oleg Eterevsky 2012/04/20 15:00:32 Unfortunately, they were defined as fields in Dir
/**
+ * @return {cr.ui.ArrayDataModel} The list of roots.
+ */
+DirectoryModel.prototype.getRootsList = function() {
+ return this.rootsList_;
+};
+
+/**
+ * @return {string} Root path for the current directory (parent directory is
+ * not navigatable for the user).
+ */
+DirectoryModel.prototype.getCurrentRootPath = function() {
+ return DirectoryModel.getRootPath(this.currentDirEntry_.fullPath);
+};
+
+/**
* Add a filter for directory contents.
* @param {string} name An identifier of the filter (used when removing it).
* @param {function(Entry):boolean} filter Hide file if false.
@@ -329,8 +332,8 @@
/**
* @private
* @param {Array.<Entry>|cr.ui.ArrayDataModel} list
- * @param {function} successCallback
- * @return {DirectoryModel.Scanner}
+ * @param {function} successCallback Callback on success.
+ * @return {DirectoryModel.Scanner} New Scanner instance.
*/
DirectoryModel.prototype.createScanner_ = function(list, successCallback) {
var self = this;
@@ -666,6 +669,7 @@
this.updateVolumeMetadata_();
this.updateRootsListSelection_();
this.scan_(onRescanComplete);
+ this.currentDirByRoot_[this.getCurrentRootPath()] = dirEntry.fullPath;
var e = new cr.Event('directory-changed');
e.previousDirEntry = previous;
@@ -1001,10 +1005,8 @@
*/
DirectoryModel.prototype.updateRoots = function(opt_callback,
opt_resolveGData) {
- console.log('resolving roots');
var self = this;
this.resolveRoots_(function(rootEntries) {
- console.log('resolved roots:', rootEntries);
var dm = self.rootsList_;
var args = [0, dm.length].concat(rootEntries);
dm.splice.apply(dm, args);
@@ -1017,21 +1019,38 @@
};
/**
+ * Register a listener for a new root element in left menu.
* @private
- * @param {Event} event
+ * @param {HTMLElement} li List item representing a volume.
+ * @param {Entry} entry Root directory entry.
*/
-DirectoryModel.prototype.onRootsSelectionChanged_ = function(event) {
- var root = this.rootsList.item(this.rootsListSelection.selectedIndex);
- if (root && this.rootPath != root.fullPath)
- this.changeDirectory(root.fullPath);
+DirectoryModel.prototype.registerRootClickListener_ = function append(li,
+ entry) {
+ li.addEventListener('click', this.onRootClick_.bind(this, entry));
};
/**
+ * Handler for root item being clicked.
* @private
+ * @param {Entry} entry Entry to navigate to.
+ * @param {Event} event The event.
*/
+DirectoryModel.prototype.onRootClick_ = function(entry, event) {
+ var new_path = entry.fullPath;
+ if (entry.fullPath == this.getCurrentRootPath()) {
+ this.changeDirectory(entry.fullPath);
+ } else {
+ this.changeDirectory(this.currentDirByRoot_[entry.fullPath] ||
+ entry.fullPath);
+ }
+};
+
+/**
+ * @private
+ */
DirectoryModel.prototype.updateRootsListSelection_ = function() {
var roots = this.rootsList_;
- var rootPath = this.rootPath;
+ var rootPath = this.getCurrentRootPath();
for (var index = 0; index < roots.length; index++) {
if (roots.item(index).fullPath == rootPath) {
this.rootsListSelection.selectedIndex = index;
@@ -1068,7 +1087,7 @@
* @private
*/
DirectoryModel.prototype.updateVolumeMetadata_ = function() {
- var rootPath = this.rootPath;
+ var rootPath = this.getCurrentRootPath();
if (this.currentVolumeMetadata_.rootPath != rootPath) {
var metadata = this.currentVolumeMetadata_ = {rootPath: rootPath};
if (DirectoryModel.getRootType(rootPath) ==
@@ -1088,7 +1107,7 @@
};
/**
- * @param {string} path
+ * @param {string} path Any path in the file system.
* @return {string} The root path.
*/
DirectoryModel.getRootPath = function(path) {
@@ -1122,8 +1141,8 @@
};
/**
- * @param {string} path
- * @return {string}
+ * @param {string} path Path.
+ * @return {string} A root type.
*/
DirectoryModel.getRootType = function(path) {
function isTop(dir) {
@@ -1132,11 +1151,11 @@
if (isTop(DirectoryModel.DOWNLOADS_DIRECTORY))
return DirectoryModel.RootType.DOWNLOADS;
- else if (isTop(DirectoryModel.GDATA_DIRECTORY))
+ if (isTop(DirectoryModel.GDATA_DIRECTORY))
return DirectoryModel.RootType.GDATA;
- else if (isTop(DirectoryModel.ARCHIVE_DIRECTORY))
+ if (isTop(DirectoryModel.ARCHIVE_DIRECTORY))
return DirectoryModel.RootType.ARCHIVE;
- else if (isTop(DirectoryModel.REMOVABLE_DIRECTORY))
+ if (isTop(DirectoryModel.REMOVABLE_DIRECTORY))
return DirectoryModel.RootType.REMOVABLE;
return '';
};
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/file_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698