| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 28 matching lines...) Expand all Loading... |
| 39 /** {Object.<string, WebInspector.UISourceCode>} */ | 39 /** {Object.<string, WebInspector.UISourceCode>} */ |
| 40 this._uiSourceCodeForScriptId = {}; | 40 this._uiSourceCodeForScriptId = {}; |
| 41 this._scriptForUISourceCode = new Map(); | 41 this._scriptForUISourceCode = new Map(); |
| 42 /** {Object.<string, WebInspector.UISourceCode>} */ | 42 /** {Object.<string, WebInspector.UISourceCode>} */ |
| 43 this._uiSourceCodeForSnippetId = {}; | 43 this._uiSourceCodeForSnippetId = {}; |
| 44 this._snippetIdForUISourceCode = new Map(); | 44 this._snippetIdForUISourceCode = new Map(); |
| 45 | 45 |
| 46 this._snippetStorage = new WebInspector.SnippetStorage("script", "Script sni
ppet #"); | 46 this._snippetStorage = new WebInspector.SnippetStorage("script", "Script sni
ppet #"); |
| 47 this._lastSnippetEvaluationIndexSetting = WebInspector.settings.createSettin
g("lastSnippetEvaluationIndex", 0); | 47 this._lastSnippetEvaluationIndexSetting = WebInspector.settings.createSettin
g("lastSnippetEvaluationIndex", 0); |
| 48 this._snippetScriptMapping = new WebInspector.SnippetScriptMapping(this); | 48 this._snippetScriptMapping = new WebInspector.SnippetScriptMapping(this); |
| 49 this._projectDelegate = new WebInspector.SnippetsProjectDelegate(); | 49 this._projectDelegate = new WebInspector.SnippetsProjectDelegate(this); |
| 50 this._workspace.addProject(this._projectDelegate); | 50 this._workspace.addProject(this._projectDelegate); |
| 51 this.reset(); | 51 this.reset(); |
| 52 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Event
s.GlobalObjectCleared, this._debuggerReset, this); | 52 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Event
s.GlobalObjectCleared, this._debuggerReset, this); |
| 53 } | 53 } |
| 54 | 54 |
| 55 WebInspector.ScriptSnippetModel.prototype = { | 55 WebInspector.ScriptSnippetModel.prototype = { |
| 56 /** | 56 /** |
| 57 * @return {WebInspector.SnippetScriptMapping} | 57 * @return {WebInspector.SnippetScriptMapping} |
| 58 */ | 58 */ |
| 59 get scriptMapping() | 59 get scriptMapping() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 var snippet = this._snippetStorage.snippetForId(snippetId); | 102 var snippet = this._snippetStorage.snippetForId(snippetId); |
| 103 this._snippetStorage.deleteSnippet(snippet); | 103 this._snippetStorage.deleteSnippet(snippet); |
| 104 this._removeBreakpoints(uiSourceCode); | 104 this._removeBreakpoints(uiSourceCode); |
| 105 this._releaseSnippetScript(uiSourceCode); | 105 this._releaseSnippetScript(uiSourceCode); |
| 106 delete this._uiSourceCodeForSnippetId[snippet.id]; | 106 delete this._uiSourceCodeForSnippetId[snippet.id]; |
| 107 this._snippetIdForUISourceCode.remove(uiSourceCode); | 107 this._snippetIdForUISourceCode.remove(uiSourceCode); |
| 108 this._projectDelegate.removeFile([snippet.name]); | 108 this._projectDelegate.removeFile([snippet.name]); |
| 109 }, | 109 }, |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * @param {WebInspector.UISourceCode} uiSourceCode | 112 * @param {string} name |
| 113 * @param {string} newName | 113 * @param {string} newName |
| 114 * @param {function(boolean, string=)} callback |
| 114 */ | 115 */ |
| 115 renameScriptSnippet: function(uiSourceCode, newName) | 116 renameScriptSnippet: function(name, newName, callback) |
| 116 { | 117 { |
| 118 newName = newName.trim(); |
| 119 if (!newName || newName.indexOf("/") !== -1 || name === newName || this.
_snippetStorage.snippetForName(newName)) { |
| 120 callback(false); |
| 121 return; |
| 122 } |
| 123 var snippet = this._snippetStorage.snippetForName(name); |
| 124 console.assert(snippet, "Snippet '" + name + "' was not found."); |
| 125 var uiSourceCode = this._uiSourceCodeForSnippetId[snippet.id]; |
| 126 console.assert(uiSourceCode, "No uiSourceCode was found for snippet '" +
name + "'."); |
| 127 |
| 117 var breakpointLocations = this._removeBreakpoints(uiSourceCode); | 128 var breakpointLocations = this._removeBreakpoints(uiSourceCode); |
| 118 var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode); | |
| 119 var snippet = this._snippetStorage.snippetForId(snippetId); | |
| 120 if (!snippet || !newName || snippet.name === newName) | |
| 121 return; | |
| 122 snippet.name = newName; | 129 snippet.name = newName; |
| 123 this._restoreBreakpoints(uiSourceCode, breakpointLocations); | 130 this._restoreBreakpoints(uiSourceCode, breakpointLocations); |
| 131 callback(true, newName); |
| 124 }, | 132 }, |
| 125 | 133 |
| 126 /** | 134 /** |
| 127 * @param {WebInspector.UISourceCode} uiSourceCode | 135 * @param {WebInspector.UISourceCode} uiSourceCode |
| 128 * @param {string} newContent | 136 * @param {string} newContent |
| 129 */ | 137 */ |
| 130 _setScriptSnippetContent: function(uiSourceCode, newContent) | 138 _setScriptSnippetContent: function(uiSourceCode, newContent) |
| 131 { | 139 { |
| 132 var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode); | 140 var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode); |
| 133 var snippet = this._snippetStorage.snippetForId(snippetId); | 141 var snippet = this._snippetStorage.snippetForId(snippetId); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 WebInspector.StaticContentProvider.call(this, WebInspector.resourceTypes.Scr
ipt, snippet.content); | 544 WebInspector.StaticContentProvider.call(this, WebInspector.resourceTypes.Scr
ipt, snippet.content); |
| 537 } | 545 } |
| 538 | 546 |
| 539 WebInspector.SnippetContentProvider.prototype = { | 547 WebInspector.SnippetContentProvider.prototype = { |
| 540 __proto__: WebInspector.StaticContentProvider.prototype | 548 __proto__: WebInspector.StaticContentProvider.prototype |
| 541 } | 549 } |
| 542 | 550 |
| 543 /** | 551 /** |
| 544 * @constructor | 552 * @constructor |
| 545 * @extends {WebInspector.ContentProviderBasedProjectDelegate} | 553 * @extends {WebInspector.ContentProviderBasedProjectDelegate} |
| 554 * @param {WebInspector.ScriptSnippetModel} model |
| 546 */ | 555 */ |
| 547 WebInspector.SnippetsProjectDelegate = function() | 556 WebInspector.SnippetsProjectDelegate = function(model) |
| 548 { | 557 { |
| 549 WebInspector.ContentProviderBasedProjectDelegate.call(this, WebInspector.pro
jectTypes.Snippets); | 558 WebInspector.ContentProviderBasedProjectDelegate.call(this, WebInspector.pro
jectTypes.Snippets); |
| 559 this._model = model; |
| 550 } | 560 } |
| 551 | 561 |
| 552 WebInspector.SnippetsProjectDelegate.prototype = { | 562 WebInspector.SnippetsProjectDelegate.prototype = { |
| 553 /** | 563 /** |
| 554 * @return {string} | 564 * @return {string} |
| 555 */ | 565 */ |
| 556 id: function() | 566 id: function() |
| 557 { | 567 { |
| 558 return WebInspector.projectTypes.Snippets + ":"; | 568 return WebInspector.projectTypes.Snippets + ":"; |
| 559 }, | 569 }, |
| 560 | 570 |
| 561 /** | 571 /** |
| 562 * @param {string} name | 572 * @param {string} name |
| 563 * @param {WebInspector.ContentProvider} contentProvider | 573 * @param {WebInspector.ContentProvider} contentProvider |
| 564 * @return {Array.<string>} | 574 * @return {Array.<string>} |
| 565 */ | 575 */ |
| 566 addFile: function(name, contentProvider) | 576 addFile: function(name, contentProvider) |
| 567 { | 577 { |
| 568 return this.addContentProvider([name], name, contentProvider, true, fals
e); | 578 return this.addContentProvider([name], name, contentProvider, true, fals
e); |
| 569 }, | 579 }, |
| 570 | 580 |
| 581 /** |
| 582 * @return {boolean} |
| 583 */ |
| 584 canRename: function() |
| 585 { |
| 586 return true; |
| 587 }, |
| 588 |
| 589 /** |
| 590 * @param {Array.<string>} path |
| 591 * @param {string} newName |
| 592 * @param {function(boolean, string=)} callback |
| 593 */ |
| 594 rename: function(path, newName, callback) |
| 595 { |
| 596 this._model.renameScriptSnippet(path[0], newName, callback); |
| 597 }, |
| 598 |
| 571 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype | 599 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype |
| 572 } | 600 } |
| 573 | 601 |
| 574 /** | 602 /** |
| 575 * @type {?WebInspector.ScriptSnippetModel} | 603 * @type {?WebInspector.ScriptSnippetModel} |
| 576 */ | 604 */ |
| 577 WebInspector.scriptSnippetModel = null; | 605 WebInspector.scriptSnippetModel = null; |
| OLD | NEW |