OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 /** | 292 /** |
293 * @return {boolean} | 293 * @return {boolean} |
294 */ | 294 */ |
295 renderPromptAsBlock: function() | 295 renderPromptAsBlock: function() |
296 { | 296 { |
297 return false; | 297 return false; |
298 }, | 298 }, |
299 | 299 |
300 /** | 300 /** |
301 * @param {!Event=} event | 301 * @return {{element: !Element, value: (string|undefined)}} |
302 * @return {!Array.<!Element|undefined>} | |
303 */ | 302 */ |
304 elementAndValueToEdit: function(event) | 303 elementAndValueToEdit: function() |
305 { | 304 { |
306 return [this.valueElement, (typeof this.valueElement._originalTextConten
t === "string") ? this.valueElement._originalTextContent : undefined]; | 305 return { |
| 306 element: this.valueElement, |
| 307 value: (typeof this.valueElement._originalTextContent === "string")
? this.valueElement._originalTextContent : undefined |
| 308 }; |
307 }, | 309 }, |
308 | 310 |
309 /** | 311 /** |
310 * @param {!Event=} event | 312 * @param {!Event=} event |
311 */ | 313 */ |
312 startEditing: function(event) | 314 startEditing: function(event) |
313 { | 315 { |
314 var elementAndValueToEdit = this.elementAndValueToEdit(event); | 316 var elementAndValueToEdit = this.elementAndValueToEdit(); |
315 var elementToEdit = elementAndValueToEdit[0]; | 317 var elementToEdit = elementAndValueToEdit.element; |
316 var valueToEdit = elementAndValueToEdit[1]; | 318 var valueToEdit = elementAndValueToEdit.value; |
317 | 319 |
318 if (WebInspector.isBeingEdited(elementToEdit) || !this.treeOutline.secti
on.editable || this._readOnly) | 320 if (WebInspector.isBeingEdited(elementToEdit) || !this.treeOutline.secti
on.editable || this._readOnly) |
319 return; | 321 return; |
320 | 322 |
321 // Edit original source. | 323 // Edit original source. |
322 if (typeof valueToEdit !== "undefined") | 324 if (typeof valueToEdit !== "undefined") |
323 elementToEdit.setTextContentTruncatedIfNeeded(valueToEdit, WebInspec
tor.UIString("<string is too large to edit>")); | 325 elementToEdit.setTextContentTruncatedIfNeeded(valueToEdit, WebInspec
tor.UIString("<string is too large to edit>")); |
324 | 326 |
325 var context = { expanded: this.expanded, elementToEdit: elementToEdit, p
reviousContent: elementToEdit.textContent }; | 327 var context = { expanded: this.expanded, elementToEdit: elementToEdit, p
reviousContent: elementToEdit.textContent }; |
326 | 328 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 }, | 372 }, |
371 | 373 |
372 editingCommitted: function(element, userInput, previousContent, context) | 374 editingCommitted: function(element, userInput, previousContent, context) |
373 { | 375 { |
374 if (userInput === previousContent) { | 376 if (userInput === previousContent) { |
375 this.editingCancelled(element, context); // nothing changed, so canc
el | 377 this.editingCancelled(element, context); // nothing changed, so canc
el |
376 return; | 378 return; |
377 } | 379 } |
378 | 380 |
379 this.editingEnded(context); | 381 this.editingEnded(context); |
380 this.applyExpression(userInput, true); | 382 this.applyExpression(userInput); |
381 }, | 383 }, |
382 | 384 |
383 _promptKeyDown: function(context, event) | 385 _promptKeyDown: function(context, event) |
384 { | 386 { |
385 if (isEnterKey(event)) { | 387 if (isEnterKey(event)) { |
386 event.consume(true); | 388 event.consume(true); |
387 this.editingCommitted(null, context.elementToEdit.textContent, conte
xt.previousContent, context); | 389 this.editingCommitted(null, context.elementToEdit.textContent, conte
xt.previousContent, context); |
388 return; | 390 return; |
389 } | 391 } |
390 if (event.keyIdentifier === "U+001B") { // Esc | 392 if (event.keyIdentifier === "U+001B") { // Esc |
391 event.consume(); | 393 event.consume(); |
392 this.editingCancelled(null, context); | 394 this.editingCancelled(null, context); |
393 return; | 395 return; |
394 } | 396 } |
395 }, | 397 }, |
396 | 398 |
397 applyExpression: function(expression, updateInterface) | 399 /** |
| 400 * @param {string} expression |
| 401 */ |
| 402 applyExpression: function(expression) |
398 { | 403 { |
399 expression = expression.trim(); | 404 expression = expression.trim(); |
400 var expressionLength = expression.length; | 405 if (expression) |
| 406 this.property.parentObject.setPropertyValue(this.property.name, expr
ession, callback.bind(this)); |
| 407 else |
| 408 this.property.parentObject.deleteProperty(this.property.name, callba
ck.bind(this)); |
401 | 409 |
402 /** | 410 /** |
403 * @param {?Protocol.Error} error | 411 * @param {?Protocol.Error} error |
404 * @this {WebInspector.ObjectPropertyTreeElement} | 412 * @this {WebInspector.ObjectPropertyTreeElement} |
405 */ | 413 */ |
406 function callback(error) | 414 function callback(error) |
407 { | 415 { |
408 if (!updateInterface) | 416 if (error) { |
| 417 this.update(); |
409 return; | 418 return; |
| 419 } |
410 | 420 |
411 if (error) | 421 if (!expression) { |
412 this.update(); | |
413 | |
414 if (!expressionLength) { | |
415 // The property was deleted, so remove this tree element. | 422 // The property was deleted, so remove this tree element. |
416 this.parent.removeChild(this); | 423 this.parent.removeChild(this); |
417 } else { | 424 } else { |
418 // Call updateSiblings since their value might be based on the v
alue that just changed. | 425 // Call updateSiblings since their value might be based on the v
alue that just changed. |
419 this.updateSiblings(); | 426 this.updateSiblings(); |
420 } | 427 } |
421 }; | 428 }; |
422 this.property.parentObject.setPropertyValue(this.property.name, expressi
on.trim(), callback.bind(this)); | |
423 }, | 429 }, |
424 | 430 |
425 /** | 431 /** |
426 * @return {string|undefined} | 432 * @return {string|undefined} |
427 */ | 433 */ |
428 propertyPath: function() | 434 propertyPath: function() |
429 { | 435 { |
430 if ("_cachedPropertyPath" in this) | 436 if ("_cachedPropertyPath" in this) |
431 return this._cachedPropertyPath; | 437 return this._cachedPropertyPath; |
432 | 438 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 { | 995 { |
990 WebInspector.TextPrompt.call(this, WebInspector.ExecutionContextSelector.com
pletionsForTextPromptInCurrentContext); | 996 WebInspector.TextPrompt.call(this, WebInspector.ExecutionContextSelector.com
pletionsForTextPromptInCurrentContext); |
991 this.setSuggestBoxEnabled(true); | 997 this.setSuggestBoxEnabled(true); |
992 if (renderAsBlock) | 998 if (renderAsBlock) |
993 this.renderAsBlock(); | 999 this.renderAsBlock(); |
994 } | 1000 } |
995 | 1001 |
996 WebInspector.ObjectPropertyPrompt.prototype = { | 1002 WebInspector.ObjectPropertyPrompt.prototype = { |
997 __proto__: WebInspector.TextPrompt.prototype | 1003 __proto__: WebInspector.TextPrompt.prototype |
998 } | 1004 } |
OLD | NEW |