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

Side by Side Diff: chrome/browser/resources/file_manager/js/default_action_dialog.js

Issue 10411018: [FileBrowser] Added DefaultAction dialog to choose default action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5
6 /**
7 * PromptDialog contains a message, a text input, an ok button, and a
dgozman 2012/05/18 14:50:06 Copypasted comment.
Dmitry Zvorygin 2012/05/22 14:32:59 Done.
8 * cancel button.
9 */
10 cr.define('cr.filebrowser', function() {
11 function DefaultActionDialog(parentNode) {
dgozman 2012/05/18 14:50:06 No JSDoc.
Dmitry Zvorygin 2012/05/22 14:32:59 Done.
12 cr.ui.dialogs.BaseDialog.apply(this, [parentNode]);
dgozman 2012/05/18 14:50:06 If you have explicit arguments, better use |call|.
Dmitry Zvorygin 2012/05/22 14:32:59 Done.
13
14 this.list_ = this.document_.createElement('list');
15 this.list_.id = 'default-actions-list';
16 this.frame_.insertBefore(this.list_, this.text_.nextSibling);
17
18 cr.ui.List.decorate(this.list_);
dgozman 2012/05/18 14:50:06 I believe, you can just |this.list_ = new cr.ui.Li
Dmitry Zvorygin 2012/05/22 14:32:59 Done.
19 this.selectionModel_ = this.list_.selectionModel =
20 new cr.ui.ListSingleSelectionModel();
21 this.dataModel_ = this.list_.dataModel = new cr.ui.ArrayDataModel([]);
22 this.list_.autoExpands = true;
dgozman 2012/05/18 14:50:06 This really means that dialog is not constrained i
Dmitry Zvorygin 2012/05/22 14:32:59 Added comment.
23 this.list_.activateItemAtIndex = this.activateItemAtIndex_.bind(this);
24
25 this.initialFocusElement_ = this.list_;
26
27 var self = this;
28
29 this.list_.itemConstructor = function(item) {
dgozman 2012/05/18 14:50:06 this.list_.itemConstructor = this.renderItem.bind(
Dmitry Zvorygin 2012/05/22 14:32:59 Binding stuff doesn't work with constructors. See
30 return self.renderItem(item);
31 }
32 }
33
34 DefaultActionDialog.prototype = {
35 __proto__: cr.ui.dialogs.BaseDialog.prototype
36 };
37
38 DefaultActionDialog.prototype.onInputFocus = function() {
39 this.list_.select();
40 };
41
42 DefaultActionDialog.prototype.onKeyDown_ = function(event) {
43 if (event.keyCode == 13) // Enter
44 this.onOkClick_(event);
45 };
46
47 DefaultActionDialog.prototype.renderItem = function(item) {
48 var result = this.document_.createElement('li');
49
50 var iconNode = this.document_.createElement('img');
51 iconNode.src = item.iconUrl;
52 result.appendChild(iconNode);
53
54 var labelNode = this.document_.createElement('span');
55 labelNode.textContent = item.title;
56 result.appendChild(labelNode);
57
58 cr.defineProperty(result, 'lead', cr.PropertyKind.BOOL_ATTR);
59 cr.defineProperty(result, 'selected', cr.PropertyKind.BOOL_ATTR);
60
61 return result;
62 }
63
64 DefaultActionDialog.prototype.show = function(message, tasksList, onOk,
65 onCancel, onShow) {
66
67 cr.ui.dialogs.BaseDialog.prototype.show.apply(this,
68 [message, onOk, onCancel, onShow]);
69
70 this.list_.startBatchUpdates();
71
72 this.dataModel_.splice(0, this.dataModel_.length);
73
74 for (var i = 0; i < tasksList.length; i++) {
75 this.dataModel_.push(tasksList[i]);
dgozman 2012/05/18 14:50:06 Instead of pushing n times, use one splice?
Dmitry Zvorygin 2012/05/22 14:32:59 Splice requires items passed as parameters, not as
76 }
77
78 this.selectionModel_.selectedIndex = 0;
79
80 this.list_.endBatchUpdates();
81 };
82
83 DefaultActionDialog.prototype.getValue = function() {
84 return this.list_.value;
dgozman 2012/05/18 14:50:06 Wow, list has |value| method?
Dmitry Zvorygin 2012/05/22 14:32:59 Done.
85 };
86
87 DefaultActionDialog.prototype.activateItemAtIndex_ = function(index) {
88 this.hide();
89 if (this.onOk_)
90 this.onOk_(this.dataModel_.item(index));
91 }
92
93 DefaultActionDialog.prototype.onOkClick_ = function() {
94 this.activateItemAtIndex_(this.selectionModel_.selectedIndex);
95 };
96
97 DefaultActionDialog.prototype.onContainerKeyDown_ = function(event) {
dgozman 2012/05/18 14:50:06 Where do you add this listener?
Dmitry Zvorygin 2012/05/22 14:32:59 Added comment.
98 // Handle Escape.
99 if (event.keyCode == 27 && !this.cancelButton_.disabled) {
100 this.onCancelClick_(event);
101 event.preventDefault();
102 } else if (!this.okButton_.disabled &&
dgozman 2012/05/18 14:50:06 How can it be disabled?
Dmitry Zvorygin 2012/05/22 14:32:59 Done.
103 (event.keyCode == 32 || event.keyCode == 13)) {
104 this.onOkClick_();
105 event.preventDefault();
106 }
107 };
108
109 return {DefaultActionDialog: DefaultActionDialog};
110 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698