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

Side by Side Diff: Source/devtools/front_end/FilterBar.js

Issue 72863002: [DevTools] Added regex support to console filters. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Codereview issues. Created 7 years 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
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 /** 152 /**
153 * @return {Element} 153 * @return {Element}
154 */ 154 */
155 element: function() { } 155 element: function() { }
156 } 156 }
157 157
158 /** 158 /**
159 * @constructor 159 * @constructor
160 * @implements {WebInspector.FilterUI} 160 * @implements {WebInspector.FilterUI}
161 * @extends {WebInspector.Object} 161 * @extends {WebInspector.Object}
162 * @param {boolean=} supportRegex
162 */ 163 */
163 WebInspector.TextFilterUI = function() 164 WebInspector.TextFilterUI = function(supportRegex)
164 { 165 {
166 this._supportRegex = !!supportRegex;
167 this._regex = null;
168
165 this._filterElement = document.createElement("div"); 169 this._filterElement = document.createElement("div");
166 this._filterElement.className = "filter-text-filter"; 170 this._filterElement.className = "filter-text-filter";
167 171
168 this._filterInputElement = this._filterElement.createChild("input", "search- replace toolbar-replace-control"); 172 this._filterInputElement = this._filterElement.createChild("input", "search- replace toolbar-replace-control");
169 this._filterInputElement.placeholder = WebInspector.UIString("Filter"); 173 this._filterInputElement.placeholder = WebInspector.UIString("Filter");
170 this._filterInputElement.id = "filter-input-field"; 174 this._filterInputElement.id = "filter-input-field";
171 this._filterInputElement.addEventListener("mousedown", this._onFilterFieldMa nualFocus.bind(this), false); // when the search field is manually selected 175 this._filterInputElement.addEventListener("mousedown", this._onFilterFieldMa nualFocus.bind(this), false); // when the search field is manually selected
172 this._filterInputElement.addEventListener("input", this._onInput.bind(this), false); 176 this._filterInputElement.addEventListener("input", this._onInput.bind(this), false);
173 this._filterInputElement.addEventListener("change", this._onInput.bind(this) , false); 177 this._filterInputElement.addEventListener("change", this._onInput.bind(this) , false);
178
179 if (this._supportRegex) {
180 this._regexCheckBox = this._filterElement.createChild("input");
181 this._regexCheckBox.type = "checkbox";
182 this._regexCheckBox.id = "text-filter-regex";
183 this._regexCheckBox.addEventListener("change", this._onInput.bind(this), false);
184
185 this._regexLabel = this._filterElement.createChild("label");
186 this._regexLabel.htmlFor = "text-filter-regex";
187 this._regexLabel.textContent = WebInspector.UIString("Regex");
188 }
174 } 189 }
175 190
176 WebInspector.TextFilterUI.prototype = { 191 WebInspector.TextFilterUI.prototype = {
177 /** 192 /**
178 * @return {boolean} 193 * @return {boolean}
179 */ 194 */
180 isActive: function() 195 isActive: function()
181 { 196 {
182 return !!this._filterInputElement.value; 197 return !!this._filterInputElement.value;
183 }, 198 },
(...skipping 21 matching lines...) Expand all
205 { 220 {
206 this._filterInputElement.value = value; 221 this._filterInputElement.value = value;
207 this._valueChanged(); 222 this._valueChanged();
208 }, 223 },
209 224
210 /** 225 /**
211 * @return {?RegExp} 226 * @return {?RegExp}
212 */ 227 */
213 regex: function() 228 regex: function()
214 { 229 {
215 if (this._regex !== undefined)
216 return this._regex;
217 var filterQuery = this.value();
218 this._regex = filterQuery ? createPlainTextSearchRegex(filterQuery, "i") : null;
219 return this._regex; 230 return this._regex;
220 }, 231 },
221 232
222 /** 233 /**
223 * @param {Event} event 234 * @param {Event} event
224 */ 235 */
225 _onFilterFieldManualFocus: function(event) 236 _onFilterFieldManualFocus: function(event)
226 { 237 {
227 WebInspector.setCurrentFocusElement(event.target); 238 WebInspector.setCurrentFocusElement(event.target);
228 }, 239 },
229 240
230 /** 241 /**
231 * @param {WebInspector.Event} event 242 * @param {WebInspector.Event} event
232 */ 243 */
233 _onInput: function(event) 244 _onInput: function(event)
234 { 245 {
235 this._valueChanged(); 246 this._valueChanged();
236 }, 247 },
237 248
238 _valueChanged: function() { 249 _valueChanged: function() {
239 delete this._regex; 250 var filterQuery = this.value();
251
252 this._regex = null
253 this._filterInputElement.classList.remove("filter-text-invalid");
254 if (filterQuery) {
vsevik 2013/11/28 10:29:10 nit: if (!filterQuery) return;
Dmitry Zvorygin 2013/11/28 13:48:33 not return but dispatchEventToListeners, so let's
255 if (this._supportRegex && this._regexCheckBox.checked) {
256 try {
257 this._regex = new RegExp(filterQuery, "i");
258 } catch (e) {
259 this._filterInputElement.classList.add("filter-text-invalid" );
260 }
261 } else {
262 this._regex = createPlainTextSearchRegex(filterQuery, "i");
263 }
264 }
265
240 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null); 266 this.dispatchEventToListeners(WebInspector.FilterUI.Events.FilterChanged , null);
241 }, 267 },
242 268
243 __proto__: WebInspector.Object.prototype 269 __proto__: WebInspector.Object.prototype
244 } 270 }
245 271
246 /** 272 /**
247 * @constructor 273 * @constructor
248 * @implements {WebInspector.FilterUI} 274 * @implements {WebInspector.FilterUI}
249 * @extends {WebInspector.Object} 275 * @extends {WebInspector.Object}
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 var label = this._filterElement.createChild("label"); 543 var label = this._filterElement.createChild("label");
518 var checkBorder = label.createChild("div", "checkbox-filter-checkbox"); 544 var checkBorder = label.createChild("div", "checkbox-filter-checkbox");
519 this._checkElement = checkBorder.createChild("div", "checkbox-filter-che ckbox-check"); 545 this._checkElement = checkBorder.createChild("div", "checkbox-filter-che ckbox-check");
520 this._filterElement.addEventListener("click", this._onClick.bind(this), false); 546 this._filterElement.addEventListener("click", this._onClick.bind(this), false);
521 var typeElement = label.createChild("span", "type"); 547 var typeElement = label.createChild("span", "type");
522 typeElement.textContent = title; 548 typeElement.textContent = title;
523 }, 549 },
524 550
525 __proto__: WebInspector.Object.prototype 551 __proto__: WebInspector.Object.prototype
526 } 552 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698