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..231ab6334d6ddcfc0b1ee509aeaa299822890b58 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_; } |
}; |
/** |
@@ -48,8 +38,7 @@ function NavigationModelShortcutItem(label, entry) { |
NavigationModelShortcutItem.prototype = { |
__proto__: NavigationModelItem.prototype, |
get entry() { return this.entry_; }, |
- get isVolume() { return false; }, |
- get isShortcut() { return true; } |
+ get type() { return NavigationModelItem.Type.SHORTCUT; } |
}; |
/** |
@@ -73,23 +62,48 @@ function NavigationModelVolumeItem(label, volumeInfo) { |
NavigationModelVolumeItem.prototype = { |
__proto__: NavigationModelItem.prototype, |
get volumeInfo() { return this.volumeInfo_; }, |
- get isVolume() { return true; }, |
- get isShortcut() { return false; } |
+ get type() { return NavigationModelItem.Type.VOLUME; } |
}; |
/** |
- * A navigation list model. This model combines the 2 lists. |
+ * Item of NavigationListModel for commands. |
hirono
2015/04/01 11:50:36
Cannot be this wrapper of cr.ui.Command? We usuall
mtomasz
2015/04/02 02:24:27
Done.
|
+ * |
+ * @param {string} label |
+ * @param {string} icon |
+ * @param {function()} callback |
+ * @constructor |
+ * @extends {NavigationModelItem} |
hirono
2015/04/01 11:50:36
Can we add @struct?
mtomasz
2015/04/02 02:24:27
Done.
|
+ */ |
+function NavigationModelCommandItem(label, icon, callback) { |
+ NavigationModelItem.call(this, label); |
+ this.icon_ = icon; |
+ this.callback_ = callback; |
+ Object.freeze(this); |
hirono
2015/04/01 11:50:36
We no longer relay on Object.freeze. crbug.com/412
mtomasz
2015/04/02 02:24:27
Done.
|
+} |
+ |
+NavigationModelCommandItem.prototype = { |
+ __proto__: NavigationModelItem.prototype, |
+ get icon() { return this.icon_; }, |
+ get callback() { return this.callback_; }, |
+ get type() { return NavigationModelItem.Type.COMMAND; } |
+}; |
+ |
+/** |
+ * 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 +256,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 +270,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); |
hirono
2015/04/01 11:50:36
nit: Please fix indent.
hirono
2015/04/02 04:27:24
Please fix this.
mtomasz
2015/04/02 04:51:50
Done.
|
}; |
/** |
@@ -277,12 +294,13 @@ 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. |
- this.shortcutListModel_.onItemNotFoundError(modelItem.entry); |
+ switch (modelItem.type) { |
+ case NavigationModelItem.Type.VOLUME: |
+ // TODO(mtomasz, yoshiki): Implement when needed. |
hirono
2015/04/01 11:50:36
If we know when it becomes to be needed, please ad
hirono
2015/04/02 04:27:24
ditto.
mtomasz
2015/04/02 04:51:50
Done.
|
+ break; |
+ case NavigationModelItem.Type.SHORTCUT: |
+ // For shortcuts, lets the shortcut model handle this situation. |
+ this.shortcutListModel_.onItemNotFoundError(modelItem.entry); |
+ break; |
} |
}; |