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

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

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

Powered by Google App Engine
This is Rietveld 408576698