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

Unified Diff: ui/file_manager/file_manager/foreground/js/navigation_list_model.js

Issue 1056433003: Add button to add new FSP services to Files app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tests. Created 5 years, 9 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
Index: ui/file_manager/file_manager/foreground/js/navigation_list_model.js
diff --git a/ui/file_manager/file_manager/foreground/js/navigation_list_model.js b/ui/file_manager/file_manager/foreground/js/navigation_list_model.js
index 5195f867673925289f87e0910dd6c6e74efd891c..38f26719112b1f04bd4d113cecb97c7826ffd934 100644
--- a/ui/file_manager/file_manager/foreground/js/navigation_list_model.js
+++ b/ui/file_manager/file_manager/foreground/js/navigation_list_model.js
@@ -11,24 +11,14 @@ function NavigationModelItem(label) {
this.label_ = label;
}
-NavigationModelItem.prototype = {
- get label() { return this.label_; }
+NavigationModelItem.Type = {
+ SHORTCUT: 'shortcut',
+ VOLUME: 'volume',
+ COMMAND: 'command'
};
-/**
- * Check whether given two model items are same.
- * @param {NavigationModelItem} item1 The first item to be compared.
- * @param {NavigationModelItem} item2 The second item to be compared.
- * @return {boolean} True if given two model items are same.
- */
-NavigationModelItem.isSame = function(item1, item2) {
- if (item1.isVolume != item2.isVolume)
- return false;
-
- if (item1.isVolume)
- return item1.volumeInfo === item2.volumeInfo;
- else
- return util.isSameEntry(item1.entry, item2.entry);
+NavigationModelItem.prototype = {
+ get label() { return this.label_; }
};
/**
@@ -38,18 +28,17 @@ NavigationModelItem.isSame = function(item1, item2) {
* @param {!DirectoryEntry} entry Entry. Cannot be null.
* @constructor
* @extends {NavigationModelItem}
+ * @struct
*/
function NavigationModelShortcutItem(label, entry) {
NavigationModelItem.call(this, label);
this.entry_ = entry;
- Object.freeze(this);
}
NavigationModelShortcutItem.prototype = {
__proto__: NavigationModelItem.prototype,
get entry() { return this.entry_; },
- get isVolume() { return false; },
- get isShortcut() { return true; }
+ get type() { return NavigationModelItem.Type.SHORTCUT; }
};
/**
@@ -59,6 +48,7 @@ NavigationModelShortcutItem.prototype = {
* @param {!VolumeInfo} volumeInfo Volume info for the volume. Cannot be null.
* @constructor
* @extends {NavigationModelItem}
+ * @struct
*/
function NavigationModelVolumeItem(label, volumeInfo) {
NavigationModelItem.call(this, label);
@@ -67,29 +57,49 @@ function NavigationModelVolumeItem(label, volumeInfo) {
// for determining executability of commands.
this.volumeInfo_.resolveDisplayRoot(
function() {}, function() {});
- Object.freeze(this);
}
NavigationModelVolumeItem.prototype = {
__proto__: NavigationModelItem.prototype,
get volumeInfo() { return this.volumeInfo_; },
- get isVolume() { return true; },
- get isShortcut() { return false; }
+ get type() { return NavigationModelItem.Type.VOLUME; }
+};
+
+/**
+ * Item of NavigationListModel for commands.
+ *
+ * @param {cr.ui.Command} command
+ * @constructor
+ * @extends {NavigationModelItem}
+ * @struct
+ */
+function NavigationModelCommandItem(command) {
+ NavigationModelItem.call(this, command.label);
+ this.command_ = command;
+}
+
+NavigationModelCommandItem.prototype = {
+ __proto__: NavigationModelItem.prototype,
+ get command() { return this.command_; },
+ get type() { return NavigationModelItem.Type.COMMAND; }
};
/**
- * A navigation list model. This model combines the 2 lists.
+ * A navigation list model. This model combines multiple models.
* @param {VolumeManagerWrapper} volumeManager VolumeManagerWrapper instance.
* @param {(cr.ui.ArrayDataModel|FolderShortcutsDataModel)} shortcutListModel
* The list of folder shortcut.
+ * @param {NavigationModelCommandItem} commandModel, Command button at the
+ * end of the list.
* @constructor
* @extends {cr.EventTarget}
*/
-function NavigationListModel(volumeManager, shortcutListModel) {
+function NavigationListModel(volumeManager, shortcutListModel, commandModel) {
cr.EventTarget.call(this);
this.volumeManager_ = volumeManager;
this.shortcutListModel_ = shortcutListModel;
+ this.commandModel_ = commandModel;
var volumeInfoToModelItem = function(volumeInfo) {
return new NavigationModelVolumeItem(
@@ -242,10 +252,12 @@ NavigationListModel.prototype = {
* @return {NavigationModelItem} The item at the given index.
*/
NavigationListModel.prototype.item = function(index) {
- var offset = this.volumeList_.length;
- if (index < offset)
+ if (index < this.volumeList_.length)
return this.volumeList_[index];
- return this.shortcutList_[index - offset];
+ if (index < this.volumeList_.length + this.shortcutList_.length)
+ return this.shortcutList_[index - this.volumeList_.length];
+ if (index === this.length_() - 1)
+ return this.commandModel_;
};
/**
@@ -254,7 +266,8 @@ NavigationListModel.prototype.item = function(index) {
* @private
*/
NavigationListModel.prototype.length_ = function() {
- return this.volumeList_.length + this.shortcutList_.length;
+ return this.volumeList_.length + this.shortcutList_.length +
+ (this.commandModel_ ? 1 : 0);
};
/**
@@ -277,12 +290,6 @@ NavigationListModel.prototype.indexOf = function(modelItem, opt_fromIndex) {
* @param {NavigationModelItem} modelItem The entry which is not found.
*/
NavigationListModel.prototype.onItemNotFoundError = function(modelItem) {
- if (modelItem.isVolume) {
- // TODO(mtomasz, yoshiki): Implement when needed.
- return;
- }
- if (modelItem.isShortcut) {
- // For shortcuts, lets the shortcut model handle this situation.
+ if (modelItem.type === NavigationModelItem.Type.SHORTCUT)
this.shortcutListModel_.onItemNotFoundError(modelItem.entry);
- }
};

Powered by Google App Engine
This is Rietveld 408576698