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

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

Issue 18341003: DevTools: [CodeMirror] Add syntax highlighting for some other languages. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebaselined Created 7 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 23 matching lines...) Expand all
34 * @extends {WebInspector.Object} 34 * @extends {WebInspector.Object}
35 * @param {WebInspector.IsolatedFileSystem} isolatedFileSystem 35 * @param {WebInspector.IsolatedFileSystem} isolatedFileSystem
36 * @param {WebInspector.Workspace} workspace 36 * @param {WebInspector.Workspace} workspace
37 */ 37 */
38 WebInspector.FileSystemProjectDelegate = function(isolatedFileSystem, workspace) 38 WebInspector.FileSystemProjectDelegate = function(isolatedFileSystem, workspace)
39 { 39 {
40 this._fileSystem = isolatedFileSystem; 40 this._fileSystem = isolatedFileSystem;
41 this._workspace = workspace; 41 this._workspace = workspace;
42 } 42 }
43 43
44 WebInspector.FileSystemProjectDelegate._scriptExtensions = ["js", "java", "cc", "cpp", "h", "cs", "py", "php"].keySet(); 44 WebInspector.FileSystemProjectDelegate._scriptExtensions = ["js", "java", "coffe e", "ts", "dart"].keySet();
45 WebInspector.FileSystemProjectDelegate._styleSheetExtensions = ["css", "scss", " sass"].keySet(); 45 WebInspector.FileSystemProjectDelegate._styleSheetExtensions = ["css", "scss", " sass", "less"].keySet();
46 WebInspector.FileSystemProjectDelegate._documentExtensions = ["htm", "html", "as p", "aspx", "phtml", "jsp"].keySet();
46 47
47 WebInspector.FileSystemProjectDelegate.projectId = function(fileSystemPath) 48 WebInspector.FileSystemProjectDelegate.projectId = function(fileSystemPath)
48 { 49 {
49 return "filesystem:" + fileSystemPath; 50 return "filesystem:" + fileSystemPath;
50 } 51 }
51 52
52 WebInspector.FileSystemProjectDelegate.prototype = { 53 WebInspector.FileSystemProjectDelegate.prototype = {
53 /** 54 /**
54 * @return {string} 55 * @return {string}
55 */ 56 */
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 requestFileContent: function(path, callback) 99 requestFileContent: function(path, callback)
99 { 100 {
100 var filePath = this._filePathForPath(path); 101 var filePath = this._filePathForPath(path);
101 this._fileSystem.requestFileContent(filePath, innerCallback.bind(this)); 102 this._fileSystem.requestFileContent(filePath, innerCallback.bind(this));
102 103
103 /** 104 /**
104 * @param {?string} content 105 * @param {?string} content
105 */ 106 */
106 function innerCallback(content) 107 function innerCallback(content)
107 { 108 {
108 var contentType = this._contentTypeForPath(path); 109 var extension = this._extensionForPath(path);
109 callback(content, false, contentType.canonicalMimeType()); 110 var mimeType = WebInspector.ResourceType.mimeTypesForExtensions[exte nsion];
111 callback(content, false, mimeType);
110 } 112 }
111 }, 113 },
112 114
113 /** 115 /**
114 * @param {string} path 116 * @param {string} path
115 * @param {function(?Date, ?number)} callback 117 * @param {function(?Date, ?number)} callback
116 */ 118 */
117 requestMetadata: function(path, callback) 119 requestMetadata: function(path, callback)
118 { 120 {
119 var filePath = this._filePathForPath(path); 121 var filePath = this._filePathForPath(path);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 { 179 {
178 var result = []; 180 var result = [];
179 if (content !== null) 181 if (content !== null)
180 result = WebInspector.ContentProvider.performSearchInContent(con tent, query, caseSensitive, isRegex); 182 result = WebInspector.ContentProvider.performSearchInContent(con tent, query, caseSensitive, isRegex);
181 callback(result); 183 callback(result);
182 } 184 }
183 }, 185 },
184 186
185 /** 187 /**
186 * @param {string} path 188 * @param {string} path
189 * @return {string}
190 */
191 _extensionForPath: function(path)
192 {
193 var extensionIndex = path.lastIndexOf(".");
194 if (extensionIndex === -1)
195 return "";
196 return path.substring(extensionIndex + 1).toLowerCase();
197 },
198
199 /**
200 * @param {string} extension
187 * @return {WebInspector.ResourceType} 201 * @return {WebInspector.ResourceType}
188 */ 202 */
189 _contentTypeForPath: function(path) 203 _contentTypeForExtension: function(extension)
190 { 204 {
191 var extensionIndex = path.lastIndexOf(".");
192 var extension = "";
193 if (extensionIndex !== -1)
194 extension = path.substring(extensionIndex + 1).toLowerCase();
195 var contentType = WebInspector.resourceTypes.Other;
196 if (WebInspector.FileSystemProjectDelegate._scriptExtensions[extension]) 205 if (WebInspector.FileSystemProjectDelegate._scriptExtensions[extension])
197 return WebInspector.resourceTypes.Script; 206 return WebInspector.resourceTypes.Script;
198 if (WebInspector.FileSystemProjectDelegate._styleSheetExtensions[extensi on]) 207 if (WebInspector.FileSystemProjectDelegate._styleSheetExtensions[extensi on])
199 return WebInspector.resourceTypes.Stylesheet; 208 return WebInspector.resourceTypes.Stylesheet;
200 if (extension === "html" || extension === "htm") 209 if (WebInspector.FileSystemProjectDelegate._documentExtensions[extension ])
201 return WebInspector.resourceTypes.Document; 210 return WebInspector.resourceTypes.Document;
202 return WebInspector.resourceTypes.Other; 211 return WebInspector.resourceTypes.Other;
203 }, 212 },
204 213
205 populate: function() 214 populate: function()
206 { 215 {
207 this._fileSystem.requestFilesRecursive("", this._addFile.bind(this)); 216 this._fileSystem.requestFilesRecursive("", this._addFile.bind(this));
208 }, 217 },
209 218
210 /** 219 /**
211 * @param {string} filePath 220 * @param {string} filePath
212 */ 221 */
213 _addFile: function(filePath) 222 _addFile: function(filePath)
214 { 223 {
215 if (!filePath) 224 if (!filePath)
216 console.assert(false); 225 console.assert(false);
217 var fullPath = this._fileSystem.path() + "/" + filePath; 226 var fullPath = this._fileSystem.path() + "/" + filePath;
218 227
219 var slash = filePath.lastIndexOf("/"); 228 var slash = filePath.lastIndexOf("/");
220 var parentPath = filePath.substring(0, slash); 229 var parentPath = filePath.substring(0, slash);
221 var name = filePath.substring(slash + 1); 230 var name = filePath.substring(slash + 1);
222 231
223 var url = this._workspace.urlForPath(this._fileSystem.path(), filePath); 232 var url = this._workspace.urlForPath(this._fileSystem.path(), filePath);
224 var contentType = this._contentTypeForPath(filePath); 233 var extension = this._extensionForPath(filePath);
234 var contentType = this._contentTypeForExtension(extension);
235
225 var fileDescriptor = new WebInspector.FileDescriptor(parentPath, name, " file://" + fullPath, url, contentType, true); 236 var fileDescriptor = new WebInspector.FileDescriptor(parentPath, name, " file://" + fullPath, url, contentType, true);
226 this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileAd ded, fileDescriptor); 237 this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileAd ded, fileDescriptor);
227 }, 238 },
228 239
229 /** 240 /**
230 * @param {string} path 241 * @param {string} path
231 */ 242 */
232 _removeFile: function(path) 243 _removeFile: function(path)
233 { 244 {
234 this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileRe moved, path); 245 this.dispatchEventToListeners(WebInspector.ProjectDelegate.Events.FileRe moved, path);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 { 305 {
295 var projectDelegate = this._simpleProjectDelegates[uiSourceCode.project( ).id()]; 306 var projectDelegate = this._simpleProjectDelegates[uiSourceCode.project( ).id()];
296 return projectDelegate.fileSystemPath(); 307 return projectDelegate.fileSystemPath();
297 } 308 }
298 } 309 }
299 310
300 /** 311 /**
301 * @type {?WebInspector.FileSystemWorkspaceProvider} 312 * @type {?WebInspector.FileSystemWorkspaceProvider}
302 */ 313 */
303 WebInspector.fileSystemWorkspaceProvider = null; 314 WebInspector.fileSystemWorkspaceProvider = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698