| 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 * @override | 564 * @override |
| 555 * @return {string} | 565 * @return {string} |
| 556 */ | 566 */ |
| 557 id: function() | 567 id: function() |
| 558 { | 568 { |
| 559 return WebInspector.projectTypes.Snippets + ":"; | 569 return WebInspector.projectTypes.Snippets + ":"; |
| 560 }, | 570 }, |
| 561 | 571 |
| 562 /** | 572 /** |
| 563 * @param {string} name | 573 * @param {string} name |
| 564 * @param {WebInspector.ContentProvider} contentProvider | 574 * @param {WebInspector.ContentProvider} contentProvider |
| 565 * @return {Array.<string>} | 575 * @return {Array.<string>} |
| 566 */ | 576 */ |
| 567 addFile: function(name, contentProvider) | 577 addFile: function(name, contentProvider) |
| 568 { | 578 { |
| 569 return this.addContentProvider([name], name, contentProvider, true, fals
e); | 579 return this.addContentProvider([name], name, contentProvider, true, fals
e); |
| 570 }, | 580 }, |
| 571 | 581 |
| 582 /** |
| 583 * @return {boolean} |
| 584 */ |
| 585 canRename: function() |
| 586 { |
| 587 return true; |
| 588 }, |
| 589 |
| 590 /** |
| 591 * @param {Array.<string>} path |
| 592 * @param {string} newName |
| 593 * @param {function(boolean, string=)} callback |
| 594 */ |
| 595 rename: function(path, newName, callback) |
| 596 { |
| 597 this._model.renameScriptSnippet(path[0], newName, callback); |
| 598 }, |
| 599 |
| 572 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype | 600 __proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype |
| 573 } | 601 } |
| 574 | 602 |
| 575 /** | 603 /** |
| 576 * @type {?WebInspector.ScriptSnippetModel} | 604 * @type {?WebInspector.ScriptSnippetModel} |
| 577 */ | 605 */ |
| 578 WebInspector.scriptSnippetModel = null; | 606 WebInspector.scriptSnippetModel = null; |
| OLD | NEW |