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

Side by Side Diff: ui/file_manager/file_manager/foreground/js/navigation_list_model.js

Issue 1052383002: Reland: Add button to add new FSP services to Files app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 /** 5 /**
6 * Base item of NavigationListModel. Should not be created directly. 6 * Base item of NavigationListModel. Should not be created directly.
7 * @param {string} label Label. 7 * @param {string} label Label.
8 * @constructor 8 * @constructor
9 * @struct
9 */ 10 */
10 function NavigationModelItem(label) { 11 function NavigationModelItem(label) {
11 this.label_ = label; 12 this.label_ = label;
12 } 13 }
13 14
15 NavigationModelItem.Type = {
16 SHORTCUT: 'shortcut',
17 VOLUME: 'volume',
18 COMMAND: 'command'
19 };
20
14 NavigationModelItem.prototype = { 21 NavigationModelItem.prototype = {
15 get label() { return this.label_; } 22 get label() { return this.label_; }
16 }; 23 };
17 24
18 /** 25 /**
19 * Check whether given two model items are same.
20 * @param {NavigationModelItem} item1 The first item to be compared.
21 * @param {NavigationModelItem} item2 The second item to be compared.
22 * @return {boolean} True if given two model items are same.
23 */
24 NavigationModelItem.isSame = function(item1, item2) {
25 if (item1.isVolume != item2.isVolume)
26 return false;
27
28 if (item1.isVolume)
29 return item1.volumeInfo === item2.volumeInfo;
30 else
31 return util.isSameEntry(item1.entry, item2.entry);
32 };
33
34 /**
35 * Item of NavigationListModel for shortcuts. 26 * Item of NavigationListModel for shortcuts.
36 * 27 *
37 * @param {string} label Label. 28 * @param {string} label Label.
38 * @param {!DirectoryEntry} entry Entry. Cannot be null. 29 * @param {!DirectoryEntry} entry Entry. Cannot be null.
39 * @constructor 30 * @constructor
40 * @extends {NavigationModelItem} 31 * @extends {NavigationModelItem}
32 * @struct
41 */ 33 */
42 function NavigationModelShortcutItem(label, entry) { 34 function NavigationModelShortcutItem(label, entry) {
43 NavigationModelItem.call(this, label); 35 NavigationModelItem.call(this, label);
44 this.entry_ = entry; 36 this.entry_ = entry;
45 Object.freeze(this);
46 } 37 }
47 38
48 NavigationModelShortcutItem.prototype = { 39 NavigationModelShortcutItem.prototype = {
49 __proto__: NavigationModelItem.prototype, 40 __proto__: NavigationModelItem.prototype,
50 get entry() { return this.entry_; }, 41 get entry() { return this.entry_; },
51 get isVolume() { return false; }, 42 get type() { return NavigationModelItem.Type.SHORTCUT; }
52 get isShortcut() { return true; }
53 }; 43 };
54 44
55 /** 45 /**
56 * Item of NavigationListModel for volumes. 46 * Item of NavigationListModel for volumes.
57 * 47 *
58 * @param {string} label Label. 48 * @param {string} label Label.
59 * @param {!VolumeInfo} volumeInfo Volume info for the volume. Cannot be null. 49 * @param {!VolumeInfo} volumeInfo Volume info for the volume. Cannot be null.
60 * @constructor 50 * @constructor
61 * @extends {NavigationModelItem} 51 * @extends {NavigationModelItem}
52 * @struct
62 */ 53 */
63 function NavigationModelVolumeItem(label, volumeInfo) { 54 function NavigationModelVolumeItem(label, volumeInfo) {
64 NavigationModelItem.call(this, label); 55 NavigationModelItem.call(this, label);
65 this.volumeInfo_ = volumeInfo; 56 this.volumeInfo_ = volumeInfo;
66 // Start resolving the display root because it is used 57 // Start resolving the display root because it is used
67 // for determining executability of commands. 58 // for determining executability of commands.
68 this.volumeInfo_.resolveDisplayRoot( 59 this.volumeInfo_.resolveDisplayRoot(
69 function() {}, function() {}); 60 function() {}, function() {});
70 Object.freeze(this);
71 } 61 }
72 62
73 NavigationModelVolumeItem.prototype = { 63 NavigationModelVolumeItem.prototype = {
74 __proto__: NavigationModelItem.prototype, 64 __proto__: NavigationModelItem.prototype,
75 get volumeInfo() { return this.volumeInfo_; }, 65 get volumeInfo() { return this.volumeInfo_; },
76 get isVolume() { return true; }, 66 get type() { return NavigationModelItem.Type.VOLUME; }
77 get isShortcut() { return false; }
78 }; 67 };
79 68
80 /** 69 /**
81 * A navigation list model. This model combines the 2 lists. 70 * Item of NavigationListModel for commands.
71 *
72 * @param {cr.ui.Command} command
73 * @constructor
74 * @extends {NavigationModelItem}
75 * @struct
76 */
77 function NavigationModelCommandItem(command) {
78 NavigationModelItem.call(this, command.label);
79 this.command_ = command;
80 }
81
82 NavigationModelCommandItem.prototype = {
83 __proto__: NavigationModelItem.prototype,
84 get command() { return this.command_; },
85 get type() { return NavigationModelItem.Type.COMMAND; }
86 };
87
88 /**
89 * A navigation list model. This model combines multiple models.
82 * @param {VolumeManagerWrapper} volumeManager VolumeManagerWrapper instance. 90 * @param {VolumeManagerWrapper} volumeManager VolumeManagerWrapper instance.
83 * @param {(cr.ui.ArrayDataModel|FolderShortcutsDataModel)} shortcutListModel 91 * @param {(cr.ui.ArrayDataModel|FolderShortcutsDataModel)} shortcutListModel
84 * The list of folder shortcut. 92 * The list of folder shortcut.
93 * @param {NavigationModelCommandItem} commandModel, Command button at the
94 * end of the list.
85 * @constructor 95 * @constructor
86 * @extends {cr.EventTarget} 96 * @extends {cr.EventTarget}
87 */ 97 */
88 function NavigationListModel(volumeManager, shortcutListModel) { 98 function NavigationListModel(volumeManager, shortcutListModel, commandModel) {
89 cr.EventTarget.call(this); 99 cr.EventTarget.call(this);
90 100
91 this.volumeManager_ = volumeManager; 101 this.volumeManager_ = volumeManager;
92 this.shortcutListModel_ = shortcutListModel; 102 this.shortcutListModel_ = shortcutListModel;
103 this.commandModel_ = commandModel;
93 104
94 var volumeInfoToModelItem = function(volumeInfo) { 105 var volumeInfoToModelItem = function(volumeInfo) {
95 return new NavigationModelVolumeItem( 106 return new NavigationModelVolumeItem(
96 volumeInfo.label, 107 volumeInfo.label,
97 volumeInfo); 108 volumeInfo);
98 }.bind(this); 109 }.bind(this);
99 110
100 var entryToModelItem = function(entry) { 111 var entryToModelItem = function(entry) {
101 var item = new NavigationModelShortcutItem( 112 var item = new NavigationModelShortcutItem(
102 entry.name, 113 entry.name,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 get length() { return this.length_(); }, 246 get length() { return this.length_(); },
236 get folderShortcutList() { return this.shortcutList_; } 247 get folderShortcutList() { return this.shortcutList_; }
237 }; 248 };
238 249
239 /** 250 /**
240 * Returns the item at the given index. 251 * Returns the item at the given index.
241 * @param {number} index The index of the entry to get. 252 * @param {number} index The index of the entry to get.
242 * @return {NavigationModelItem} The item at the given index. 253 * @return {NavigationModelItem} The item at the given index.
243 */ 254 */
244 NavigationListModel.prototype.item = function(index) { 255 NavigationListModel.prototype.item = function(index) {
245 var offset = this.volumeList_.length; 256 if (index < this.volumeList_.length)
246 if (index < offset)
247 return this.volumeList_[index]; 257 return this.volumeList_[index];
248 return this.shortcutList_[index - offset]; 258 if (index < this.volumeList_.length + this.shortcutList_.length)
259 return this.shortcutList_[index - this.volumeList_.length];
260 if (index === this.length_() - 1)
261 return this.commandModel_;
249 }; 262 };
250 263
251 /** 264 /**
252 * Returns the number of items in the model. 265 * Returns the number of items in the model.
253 * @return {number} The length of the model. 266 * @return {number} The length of the model.
254 * @private 267 * @private
255 */ 268 */
256 NavigationListModel.prototype.length_ = function() { 269 NavigationListModel.prototype.length_ = function() {
257 return this.volumeList_.length + this.shortcutList_.length; 270 return this.volumeList_.length + this.shortcutList_.length +
271 (this.commandModel_ ? 1 : 0);
258 }; 272 };
259 273
260 /** 274 /**
261 * Returns the first matching item. 275 * Returns the first matching item.
262 * @param {NavigationModelItem} modelItem The entry to find. 276 * @param {NavigationModelItem} modelItem The entry to find.
263 * @param {number=} opt_fromIndex If provided, then the searching start at 277 * @param {number=} opt_fromIndex If provided, then the searching start at
264 * the {@code opt_fromIndex}. 278 * the {@code opt_fromIndex}.
265 * @return {number} The index of the first found element or -1 if not found. 279 * @return {number} The index of the first found element or -1 if not found.
266 */ 280 */
267 NavigationListModel.prototype.indexOf = function(modelItem, opt_fromIndex) { 281 NavigationListModel.prototype.indexOf = function(modelItem, opt_fromIndex) {
268 for (var i = opt_fromIndex || 0; i < this.length; i++) { 282 for (var i = opt_fromIndex || 0; i < this.length; i++) {
269 if (modelItem === this.item(i)) 283 if (modelItem === this.item(i))
270 return i; 284 return i;
271 } 285 }
272 return -1; 286 return -1;
273 }; 287 };
274 288
275 /** 289 /**
276 * Called externally when one of the items is not found on the filesystem. 290 * Called externally when one of the items is not found on the filesystem.
277 * @param {NavigationModelItem} modelItem The entry which is not found. 291 * @param {NavigationModelItem} modelItem The entry which is not found.
278 */ 292 */
279 NavigationListModel.prototype.onItemNotFoundError = function(modelItem) { 293 NavigationListModel.prototype.onItemNotFoundError = function(modelItem) {
280 if (modelItem.isVolume) { 294 if (modelItem.type === NavigationModelItem.Type.SHORTCUT)
281 // TODO(mtomasz, yoshiki): Implement when needed.
282 return;
283 }
284 if (modelItem.isShortcut) {
285 // For shortcuts, lets the shortcut model handle this situation.
286 this.shortcutListModel_.onItemNotFoundError(modelItem.entry); 295 this.shortcutListModel_.onItemNotFoundError(modelItem.entry);
287 }
288 }; 296 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698