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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/WatchExpressionsSidebarPane.js

Issue 2238003002: DevTools: migrate sources panel sidebar to views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed Created 4 years, 4 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 /* 1 /*
2 * Copyright (C) IBM Corp. 2009 All rights reserved. 2 * Copyright (C) IBM Corp. 2009 All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.SimpleView} 33 * @extends {WebInspector.ThrottledWidget}
34 * @implements {WebInspector.ActionDelegate}
35 * @implements {WebInspector.ToolbarItem.ItemsProvider}
36 * @implements {WebInspector.ContextMenu.Provider}
34 */ 37 */
35 WebInspector.WatchExpressionsSidebarPane = function() 38 WebInspector.WatchExpressionsSidebarPane = function()
36 { 39 {
37 WebInspector.SimpleView.call(this, WebInspector.UIString("Watch")); 40 WebInspector.ThrottledWidget.call(this);
38 this.registerRequiredCSS("components/objectValue.css"); 41 this.registerRequiredCSS("components/objectValue.css");
39 42
40 this._requiresUpdate = true;
41 /** @type {!Array.<!WebInspector.WatchExpression>} */ 43 /** @type {!Array.<!WebInspector.WatchExpression>} */
42 this._watchExpressions = []; 44 this._watchExpressions = [];
43 this._watchExpressionsSetting = WebInspector.settings.createLocalSetting("wa tchExpressions", []); 45 this._watchExpressionsSetting = WebInspector.settings.createLocalSetting("wa tchExpressions", []);
44 46
45 var addButton = new WebInspector.ToolbarButton(WebInspector.UIString("Add ex pression"), "add-toolbar-item"); 47 this._addButton = new WebInspector.ToolbarButton(WebInspector.UIString("Add expression"), "add-toolbar-item");
46 addButton.addEventListener("click", this._addButtonClicked.bind(this)); 48 this._addButton.addEventListener("click", this._addButtonClicked.bind(this)) ;
47 this.addToolbarItem(addButton); 49 this._refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString(" Refresh"), "refresh-toolbar-item");
48 var refreshButton = new WebInspector.ToolbarButton(WebInspector.UIString("Re fresh"), "refresh-toolbar-item"); 50 this._refreshButton.addEventListener("click", this._refreshButtonClicked.bin d(this));
49 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this ));
50 this.addToolbarItem(refreshButton);
51 51
52 this._bodyElement = this.element.createChild("div", "vbox watch-expressions" ); 52 this._bodyElement = this.element.createChild("div", "vbox watch-expressions" );
53 this._bodyElement.addEventListener("contextmenu", this._contextMenu.bind(thi s), false); 53 this._bodyElement.addEventListener("contextmenu", this._contextMenu.bind(thi s), false);
54 this._expandController = new WebInspector.ObjectPropertiesSectionExpandContr oller(); 54 this._expandController = new WebInspector.ObjectPropertiesSectionExpandContr oller();
55 55
56 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this._refreshExpressions, this); 56 WebInspector.context.addFlavorChangeListener(WebInspector.ExecutionContext, this.update, this);
57 WebInspector.context.addFlavorChangeListener(WebInspector.DebuggerModel.Call Frame, this._refreshExpressions, this); 57 WebInspector.context.addFlavorChangeListener(WebInspector.DebuggerModel.Call Frame, this.update, this);
58 this._linkifier = new WebInspector.Linkifier(); 58 this._linkifier = new WebInspector.Linkifier();
59 this.update();
59 } 60 }
60 61
61 WebInspector.WatchExpressionsSidebarPane.prototype = { 62 WebInspector.WatchExpressionsSidebarPane.prototype = {
62 wasShown: function() 63 /**
64 * @override
65 * @return {!Array<!WebInspector.ToolbarItem>}
66 */
67 toolbarItems: function()
63 { 68 {
64 this._refreshExpressionsIfNeeded(); 69 return [this._addButton, this._refreshButton];
65 },
66
67 _refreshExpressions: function()
68 {
69 this._requiresUpdate = true;
70 this._refreshExpressionsIfNeeded();
71 }, 70 },
72 71
73 /** 72 /**
74 * @param {string} expressionString
75 */
76 addExpression: function(expressionString)
77 {
78 this.revealView();
79 if (this._requiresUpdate) {
80 this._rebuildWatchExpressions();
81 delete this._requiresUpdate;
82 }
83 this._createWatchExpression(expressionString);
84 this._saveExpressions();
85 },
86
87 /**
88 * @return {boolean} 73 * @return {boolean}
89 */ 74 */
90 hasExpressions: function() 75 hasExpressions: function()
91 { 76 {
92 return !!this._watchExpressionsSetting.get().length; 77 return !!this._watchExpressionsSetting.get().length;
93 }, 78 },
94 79
95 _saveExpressions: function() 80 _saveExpressions: function()
96 { 81 {
97 var toSave = []; 82 var toSave = [];
98 for (var i = 0; i < this._watchExpressions.length; i++) 83 for (var i = 0; i < this._watchExpressions.length; i++)
99 if (this._watchExpressions[i].expression()) 84 if (this._watchExpressions[i].expression())
100 toSave.push(this._watchExpressions[i].expression()); 85 toSave.push(this._watchExpressions[i].expression());
101 86
102 this._watchExpressionsSetting.set(toSave); 87 this._watchExpressionsSetting.set(toSave);
103 }, 88 },
104 89
105 _refreshExpressionsIfNeeded: function()
106 {
107 if (this._requiresUpdate && this.isShowing()) {
108 this._rebuildWatchExpressions();
109 delete this._requiresUpdate;
110 } else
111 this._requiresUpdate = true;
112 },
113
114 /** 90 /**
115 * @param {!WebInspector.Event=} event 91 * @param {!WebInspector.Event=} event
116 */ 92 */
117 _addButtonClicked: function(event) 93 _addButtonClicked: function(event)
118 { 94 {
119 if (event) 95 if (event)
120 event.consume(true); 96 event.consume(true);
121 this.revealView(); 97 WebInspector.viewManager.showView("sources.watch");
122 this._createWatchExpression(null).startEditing(); 98 this._createWatchExpression(null).startEditing();
123 }, 99 },
124 100
125 /** 101 /**
126 * @param {!WebInspector.Event} event 102 * @param {!WebInspector.Event} event
127 */ 103 */
128 _refreshButtonClicked: function(event) 104 _refreshButtonClicked: function(event)
129 { 105 {
130 event.consume(); 106 event.consume();
131 this._refreshExpressions(); 107 this.update();
132 }, 108 },
133 109
134 _rebuildWatchExpressions: function() 110 /**
111 * @override
112 * @return {!Promise.<?>}
113 */
114 doUpdate: function()
135 { 115 {
136 this._linkifier.reset(); 116 this._linkifier.reset();
137 this._bodyElement.removeChildren(); 117 this._bodyElement.removeChildren();
138 this._watchExpressions = []; 118 this._watchExpressions = [];
139 this._emptyElement = this._bodyElement.createChild("div", "gray-info-mes sage"); 119 this._emptyElement = this._bodyElement.createChild("div", "gray-info-mes sage");
140 this._emptyElement.textContent = WebInspector.UIString("No Watch Express ions"); 120 this._emptyElement.textContent = WebInspector.UIString("No Watch Express ions");
141 var watchExpressionStrings = this._watchExpressionsSetting.get(); 121 var watchExpressionStrings = this._watchExpressionsSetting.get();
142 for (var i = 0; i < watchExpressionStrings.length; ++i) { 122 for (var i = 0; i < watchExpressionStrings.length; ++i) {
143 var expression = watchExpressionStrings[i]; 123 var expression = watchExpressionStrings[i];
144 if (!expression) 124 if (!expression)
145 continue; 125 continue;
146 126
147 this._createWatchExpression(expression); 127 this._createWatchExpression(expression);
148 } 128 }
129 return Promise.resolve();
149 }, 130 },
150 131
151 /** 132 /**
152 * @param {?string} expression 133 * @param {?string} expression
153 * @return {!WebInspector.WatchExpression} 134 * @return {!WebInspector.WatchExpression}
154 */ 135 */
155 _createWatchExpression: function(expression) 136 _createWatchExpression: function(expression)
156 { 137 {
157 this._emptyElement.classList.add("hidden"); 138 this._emptyElement.classList.add("hidden");
158 var watchExpression = new WebInspector.WatchExpression(expression, this. _expandController, this._linkifier); 139 var watchExpression = new WebInspector.WatchExpression(expression, this. _expandController, this._linkifier);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 186
206 for (var watchExpression of this._watchExpressions) 187 for (var watchExpression of this._watchExpressions)
207 if (watchExpression.element().containsEventPoint(event)) 188 if (watchExpression.element().containsEventPoint(event))
208 watchExpression._populateContextMenu(contextMenu, event); 189 watchExpression._populateContextMenu(contextMenu, event);
209 }, 190 },
210 191
211 _deleteAllButtonClicked: function() 192 _deleteAllButtonClicked: function()
212 { 193 {
213 this._watchExpressions = []; 194 this._watchExpressions = [];
214 this._saveExpressions(); 195 this._saveExpressions();
215 this._rebuildWatchExpressions(); 196 this.update();
216 }, 197 },
217 198
218 __proto__: WebInspector.SimpleView.prototype 199 /**
200 * @override
201 * @param {!WebInspector.Context} context
202 * @param {string} actionId
203 * @return {boolean}
204 */
205 handleAction: function(context, actionId)
206 {
207 var frame = WebInspector.context.flavor(WebInspector.UISourceCodeFrame);
208 if (!frame)
209 return false;
210 var text = frame.textEditor.copyRange(frame.textEditor.selection());
211 WebInspector.viewManager.showView("sources.watch");
212 this.doUpdate();
213 this._createWatchExpression(text);
214 this._saveExpressions();
215 return true;
216 },
217
218 /**
219 * @override
220 * @param {!Event} event
221 * @param {!WebInspector.ContextMenu} contextMenu
222 * @param {!Object} target
223 */
224 appendApplicableItems: function(event, contextMenu, target)
225 {
226 contextMenu.appendAction("sources.add-to-watch");
227 },
228
229 __proto__: WebInspector.ThrottledWidget.prototype
219 } 230 }
220 231
221 /** 232 /**
222 * @constructor 233 * @constructor
223 * @extends {WebInspector.Object} 234 * @extends {WebInspector.Object}
224 * @param {?string} expression 235 * @param {?string} expression
225 * @param {!WebInspector.ObjectPropertiesSectionExpandController} expandControll er 236 * @param {!WebInspector.ObjectPropertiesSectionExpandController} expandControll er
226 * @param {!WebInspector.Linkifier} linkifier 237 * @param {!WebInspector.Linkifier} linkifier
227 */ 238 */
228 WebInspector.WatchExpression = function(expression, expandController, linkifier) 239 WebInspector.WatchExpression = function(expression, expandController, linkifier)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 contextMenu.appendApplicableItems(this._result); 449 contextMenu.appendApplicableItems(this._result);
439 }, 450 },
440 451
441 _copyValueButtonClicked: function() 452 _copyValueButtonClicked: function()
442 { 453 {
443 InspectorFrontendHost.copyText(this._valueElement.textContent); 454 InspectorFrontendHost.copyText(this._valueElement.textContent);
444 }, 455 },
445 456
446 __proto__: WebInspector.Object.prototype 457 __proto__: WebInspector.Object.prototype
447 } 458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698