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

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

Issue 201613004: DevTools: Add context menu option for objects to save to temp variable. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
« no previous file with comments | « Source/devtools/front_end/RemoteObject.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
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 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 WebInspector.RevisionHistoryView.showHistory(uiSourceCode); 1345 WebInspector.RevisionHistoryView.showHistory(uiSourceCode);
1346 }, 1346 },
1347 1347
1348 /** 1348 /**
1349 * @param {!WebInspector.ContextMenu} contextMenu 1349 * @param {!WebInspector.ContextMenu} contextMenu
1350 * @param {!Object} target 1350 * @param {!Object} target
1351 */ 1351 */
1352 appendApplicableItems: function(event, contextMenu, target) 1352 appendApplicableItems: function(event, contextMenu, target)
1353 { 1353 {
1354 this._appendUISourceCodeItems(contextMenu, target); 1354 this._appendUISourceCodeItems(contextMenu, target);
1355 this._appendFunctionItems(contextMenu, target); 1355 this._appendRemoteObjectItems(contextMenu, target);
1356 }, 1356 },
1357 1357
1358 _suggestReload: function() 1358 _suggestReload: function()
1359 { 1359 {
1360 if (window.confirm(WebInspector.UIString("It is recommended to restart i nspector after making these changes. Would you like to restart it?"))) 1360 if (window.confirm(WebInspector.UIString("It is recommended to restart i nspector after making these changes. Would you like to restart it?")))
1361 WebInspector.reload(); 1361 WebInspector.reload();
1362 }, 1362 },
1363 1363
1364 /** 1364 /**
1365 * @param {!WebInspector.UISourceCode} uiSourceCode 1365 * @param {!WebInspector.UISourceCode} uiSourceCode
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 1448
1449 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (target); 1449 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (target);
1450 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMe nuTitles() ? "Local modifications\u2026" : "Local Modifications\u2026"), this._s howLocalHistory.bind(this, uiSourceCode)); 1450 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMe nuTitles() ? "Local modifications\u2026" : "Local Modifications\u2026"), this._s howLocalHistory.bind(this, uiSourceCode));
1451 this._appendUISourceCodeMappingItems(contextMenu, uiSourceCode); 1451 this._appendUISourceCodeMappingItems(contextMenu, uiSourceCode);
1452 }, 1452 },
1453 1453
1454 /** 1454 /**
1455 * @param {!WebInspector.ContextMenu} contextMenu 1455 * @param {!WebInspector.ContextMenu} contextMenu
1456 * @param {!Object} target 1456 * @param {!Object} target
1457 */ 1457 */
1458 _appendFunctionItems: function(contextMenu, target) 1458 _appendRemoteObjectItems: function(contextMenu, target)
1459 { 1459 {
1460 if (!(target instanceof WebInspector.RemoteObject)) 1460 if (!(target instanceof WebInspector.RemoteObject))
1461 return; 1461 return;
1462 var remoteObject = /** @type {!WebInspector.RemoteObject} */ (target); 1462 var remoteObject = /** @type {!WebInspector.RemoteObject} */ (target);
1463 if (remoteObject.type !== "function") 1463 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMe nuTitles() ? "Save to temp variable" : "Save to Temp Variable"), this._saveToTem pVariable.bind(this, remoteObject));
1464 return; 1464 if (remoteObject.type === "function")
1465 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCa seMenuTitles() ? "Show function definition" : "Show Function Definition"), this. _showFunctionDefinition.bind(this, remoteObject));
1466 },
1465 1467
1468 /**
1469 * @param {!WebInspector.RemoteObject} remoteObject
1470 */
1471 _saveToTempVariable: function(remoteObject)
1472 {
1473 /**
1474 * @param {?WebInspector.RemoteObject} result
1475 * @param {?string=} error
1476 * @this {WebInspector.SourcesPanel}
1477 */
1478 function failedToSave(result, error)
1479 {
1480 --this._pendingSavesToTemp;
1481 if (result) {
1482 error = error || result.description;
1483 result.release();
1484 }
1485 var message = "Failed to save to temp variable" + (error ? ": " + er ror : "");
pfeldman 2014/03/17 15:36:43 UIString()
1486 WebInspector.console.showErrorMessage(message)
1487 }
1488
1489 /**
1490 * @param {!WebInspector.RemoteObject} global
1491 * @param {string} name
1492 * @param {?Protocol.Error} error
1493 * @this {WebInspector.SourcesPanel}
1494 */
1495 function didSave(global, name, error)
1496 {
1497 global.release();
1498 if (error) {
1499 failedToSave.call(this, null, error);
1500 } else {
1501 --this._pendingSavesToTemp;
1502 WebInspector.console.evaluate(name);
1503 }
1504 }
1505
1506 /**
1507 * @param {!WebInspector.RemoteObject} global
1508 * @param {?WebInspector.RemoteObject} result
1509 * @param {boolean=} wasThrown
1510 * @this {WebInspector.SourcesPanel}
1511 */
1512 function didGetTempVarName(global, result, wasThrown)
1513 {
1514 if (wasThrown || !result || result.type !== "string") {
1515 global.release();
1516 failedToSave.call(this, result);
1517 return;
1518 }
1519
1520 var name = /** @type {string} */ (result.value);
1521 global.setObjectPropertyValue(name, remoteObject, didSave.bind(this, global, name));
1522 }
1523
1524 /**
1525 * @param {?WebInspector.RemoteObject} global
1526 * @param {boolean=} wasThrown
1527 * @this {WebInspector.SourcesPanel}
1528 */
1529 function didGetGlobalObject(global, wasThrown)
1530 {
1531 /** @this {Window} */
1532 function tempVarName(skip)
1533 {
1534 var prefix = "temp";
1535 var index = 1;
1536 while (skip-- >= 0) {
1537 while ((prefix + index) in this)
1538 ++index;
1539 }
1540 return prefix + index;
1541 }
1542
1543 var skip = this._pendingSavesToTemp || 0;
1544 this._pendingSavesToTemp = skip + 1;
1545
1546 if (wasThrown || !global) {
1547 failedToSave.call(this, global);
1548 return;
1549 }
1550 global.callFunction(tempVarName, [{ value: skip }], didGetTempVarNam e.bind(this, global));
1551 }
1552
1553 WebInspector.runtimeModel.evaluate("window", "", false, true, false, fal se, didGetGlobalObject.bind(this));
pfeldman 2014/03/17 15:36:43 Please implement it top-bottom for better readabil
1554 },
1555
1556 /**
1557 * @param {!WebInspector.RemoteObject} remoteObject
1558 */
1559 _showFunctionDefinition: function(remoteObject)
1560 {
1466 /** 1561 /**
1467 * @param {?Protocol.Error} error 1562 * @param {?Protocol.Error} error
1468 * @param {!DebuggerAgent.FunctionDetails} response 1563 * @param {!DebuggerAgent.FunctionDetails} response
1469 * @this {WebInspector.SourcesPanel} 1564 * @this {WebInspector.SourcesPanel}
1470 */ 1565 */
1471 function didGetDetails(error, response) 1566 function didGetFunctionDetails(error, response)
1472 { 1567 {
1473 if (error) { 1568 if (error) {
1474 console.error(error); 1569 console.error(error);
1475 return; 1570 return;
1476 } 1571 }
1477 1572
1478 var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation( response.location); 1573 var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation( response.location);
1479 if (!uiLocation) 1574 if (!uiLocation)
1480 return; 1575 return;
1481 1576
1482 this.showUILocation(uiLocation, true); 1577 this.showUILocation(uiLocation, true);
1483 } 1578 }
1484 1579 DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetFunctionDe tails.bind(this));
1485 /**
1486 * @this {WebInspector.SourcesPanel}
1487 */
1488 function revealFunction()
1489 {
1490 DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetDetail s.bind(this));
1491 }
1492
1493 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMe nuTitles() ? "Show function definition" : "Show Function Definition"), revealFun ction.bind(this));
1494 }, 1580 },
1495 1581
1496 showGoToSourceDialog: function() 1582 showGoToSourceDialog: function()
1497 { 1583 {
1498 var uiSourceCodes = this._editorContainer.historyUISourceCodes(); 1584 var uiSourceCodes = this._editorContainer.historyUISourceCodes();
1499 /** @type {!Map.<!WebInspector.UISourceCode, number>} */ 1585 /** @type {!Map.<!WebInspector.UISourceCode, number>} */
1500 var defaultScores = new Map(); 1586 var defaultScores = new Map();
1501 for (var i = 1; i < uiSourceCodes.length; ++i) // Skip current element 1587 for (var i = 1; i < uiSourceCodes.length; ++i) // Skip current element
1502 defaultScores.put(uiSourceCodes[i], uiSourceCodes.length - i); 1588 defaultScores.put(uiSourceCodes[i], uiSourceCodes.length - i);
1503 WebInspector.OpenResourceDialog.show(this, this.editorView.mainElement() , undefined, defaultScores); 1589 WebInspector.OpenResourceDialog.show(this, this.editorView.mainElement() , undefined, defaultScores);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1790 { 1876 {
1791 } 1877 }
1792 1878
1793 WebInspector.SourcesPanel.EditorAction.prototype = { 1879 WebInspector.SourcesPanel.EditorAction.prototype = {
1794 /** 1880 /**
1795 * @param {!WebInspector.SourcesPanel} panel 1881 * @param {!WebInspector.SourcesPanel} panel
1796 * @return {!Element} 1882 * @return {!Element}
1797 */ 1883 */
1798 button: function(panel) { } 1884 button: function(panel) { }
1799 } 1885 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/RemoteObject.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698