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

Unified Diff: Source/devtools/front_end/ScriptSnippetModel.js

Issue 14672033: DevTools: Make snippets renaming work through SnippetsProjectDelegate. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/NavigatorView.js ('k') | Source/devtools/front_end/ScriptsNavigator.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/ScriptSnippetModel.js
diff --git a/Source/devtools/front_end/ScriptSnippetModel.js b/Source/devtools/front_end/ScriptSnippetModel.js
index f92476ab4689a72d93cb9f8c41648cc156b422b6..f181a03007e6b464d83f83a6ca434ff85f149ba2 100644
--- a/Source/devtools/front_end/ScriptSnippetModel.js
+++ b/Source/devtools/front_end/ScriptSnippetModel.js
@@ -46,7 +46,7 @@ WebInspector.ScriptSnippetModel = function(workspace)
this._snippetStorage = new WebInspector.SnippetStorage("script", "Script snippet #");
this._lastSnippetEvaluationIndexSetting = WebInspector.settings.createSetting("lastSnippetEvaluationIndex", 0);
this._snippetScriptMapping = new WebInspector.SnippetScriptMapping(this);
- this._projectDelegate = new WebInspector.SnippetsProjectDelegate();
+ this._projectDelegate = new WebInspector.SnippetsProjectDelegate(this);
this._workspace.addProject(this._projectDelegate);
this.reset();
WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
@@ -109,18 +109,26 @@ WebInspector.ScriptSnippetModel.prototype = {
},
/**
- * @param {WebInspector.UISourceCode} uiSourceCode
+ * @param {string} name
* @param {string} newName
+ * @param {function(boolean, string=)} callback
*/
- renameScriptSnippet: function(uiSourceCode, newName)
+ renameScriptSnippet: function(name, newName, callback)
{
- var breakpointLocations = this._removeBreakpoints(uiSourceCode);
- var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode);
- var snippet = this._snippetStorage.snippetForId(snippetId);
- if (!snippet || !newName || snippet.name === newName)
+ newName = newName.trim();
+ if (!newName || newName.indexOf("/") !== -1 || name === newName || this._snippetStorage.snippetForName(newName)) {
+ callback(false);
return;
+ }
+ var snippet = this._snippetStorage.snippetForName(name);
+ console.assert(snippet, "Snippet '" + name + "' was not found.");
+ var uiSourceCode = this._uiSourceCodeForSnippetId[snippet.id];
+ console.assert(uiSourceCode, "No uiSourceCode was found for snippet '" + name + "'.");
+
+ var breakpointLocations = this._removeBreakpoints(uiSourceCode);
snippet.name = newName;
this._restoreBreakpoints(uiSourceCode, breakpointLocations);
+ callback(true, newName);
},
/**
@@ -543,10 +551,12 @@ WebInspector.SnippetContentProvider.prototype = {
/**
* @constructor
* @extends {WebInspector.ContentProviderBasedProjectDelegate}
+ * @param {WebInspector.ScriptSnippetModel} model
*/
-WebInspector.SnippetsProjectDelegate = function()
+WebInspector.SnippetsProjectDelegate = function(model)
{
WebInspector.ContentProviderBasedProjectDelegate.call(this, WebInspector.projectTypes.Snippets);
+ this._model = model;
}
WebInspector.SnippetsProjectDelegate.prototype = {
@@ -569,6 +579,24 @@ WebInspector.SnippetsProjectDelegate.prototype = {
return this.addContentProvider([name], name, contentProvider, true, false);
},
+ /**
+ * @return {boolean}
+ */
+ canRename: function()
+ {
+ return true;
+ },
+
+ /**
+ * @param {Array.<string>} path
+ * @param {string} newName
+ * @param {function(boolean, string=)} callback
+ */
+ rename: function(path, newName, callback)
+ {
+ this._model.renameScriptSnippet(path[0], newName, callback);
+ },
+
__proto__: WebInspector.ContentProviderBasedProjectDelegate.prototype
}
« no previous file with comments | « Source/devtools/front_end/NavigatorView.js ('k') | Source/devtools/front_end/ScriptsNavigator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698