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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/FileSystemWorkspaceBinding.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.FileSystemWorkspaceBinding = class { 34 Bindings.FileSystemWorkspaceBinding = class {
35 /** 35 /**
36 * @param {!WebInspector.IsolatedFileSystemManager} isolatedFileSystemManager 36 * @param {!Workspace.IsolatedFileSystemManager} isolatedFileSystemManager
37 * @param {!WebInspector.Workspace} workspace 37 * @param {!Workspace.Workspace} workspace
38 */ 38 */
39 constructor(isolatedFileSystemManager, workspace) { 39 constructor(isolatedFileSystemManager, workspace) {
40 this._isolatedFileSystemManager = isolatedFileSystemManager; 40 this._isolatedFileSystemManager = isolatedFileSystemManager;
41 this._workspace = workspace; 41 this._workspace = workspace;
42 this._eventListeners = [ 42 this._eventListeners = [
43 this._isolatedFileSystemManager.addEventListener( 43 this._isolatedFileSystemManager.addEventListener(
44 WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, this._o nFileSystemAdded, this), 44 Workspace.IsolatedFileSystemManager.Events.FileSystemAdded, this._onFi leSystemAdded, this),
45 this._isolatedFileSystemManager.addEventListener( 45 this._isolatedFileSystemManager.addEventListener(
46 WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, this. _onFileSystemRemoved, this), 46 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._on FileSystemRemoved, this),
47 this._isolatedFileSystemManager.addEventListener( 47 this._isolatedFileSystemManager.addEventListener(
48 WebInspector.IsolatedFileSystemManager.Events.FileSystemFilesChanged, this._fileSystemFilesChanged, this) 48 Workspace.IsolatedFileSystemManager.Events.FileSystemFilesChanged, thi s._fileSystemFilesChanged, this)
49 ]; 49 ];
50 /** @type {!Map.<string, !WebInspector.FileSystemWorkspaceBinding.FileSystem >} */ 50 /** @type {!Map.<string, !Bindings.FileSystemWorkspaceBinding.FileSystem>} * /
51 this._boundFileSystems = new Map(); 51 this._boundFileSystems = new Map();
52 this._isolatedFileSystemManager.waitForFileSystems().then(this._onFileSystem sLoaded.bind(this)); 52 this._isolatedFileSystemManager.waitForFileSystems().then(this._onFileSystem sLoaded.bind(this));
53 } 53 }
54 54
55 /** 55 /**
56 * @param {string} fileSystemPath 56 * @param {string} fileSystemPath
57 * @return {string} 57 * @return {string}
58 */ 58 */
59 static projectId(fileSystemPath) { 59 static projectId(fileSystemPath) {
60 return fileSystemPath; 60 return fileSystemPath;
61 } 61 }
62 62
63 /** 63 /**
64 * @param {!WebInspector.UISourceCode} uiSourceCode 64 * @param {!Workspace.UISourceCode} uiSourceCode
65 * @return {!Array<string>} 65 * @return {!Array<string>}
66 */ 66 */
67 static relativePath(uiSourceCode) { 67 static relativePath(uiSourceCode) {
68 var baseURL = 68 var baseURL =
69 /** @type {!WebInspector.FileSystemWorkspaceBinding.FileSystem}*/ (uiSou rceCode.project())._fileSystemBaseURL; 69 /** @type {!Bindings.FileSystemWorkspaceBinding.FileSystem}*/ (uiSourceC ode.project())._fileSystemBaseURL;
70 return uiSourceCode.url().substring(baseURL.length).split('/'); 70 return uiSourceCode.url().substring(baseURL.length).split('/');
71 } 71 }
72 72
73 /** 73 /**
74 * @param {!WebInspector.Project} project 74 * @param {!Workspace.Project} project
75 * @param {string} relativePath 75 * @param {string} relativePath
76 * @return {string} 76 * @return {string}
77 */ 77 */
78 static completeURL(project, relativePath) { 78 static completeURL(project, relativePath) {
79 var fsProject = /** @type {!WebInspector.FileSystemWorkspaceBinding.FileSyst em}*/ (project); 79 var fsProject = /** @type {!Bindings.FileSystemWorkspaceBinding.FileSystem}* / (project);
80 return fsProject._fileSystemBaseURL + relativePath; 80 return fsProject._fileSystemBaseURL + relativePath;
81 } 81 }
82 82
83 /** 83 /**
84 * @param {string} extension 84 * @param {string} extension
85 * @return {!WebInspector.ResourceType} 85 * @return {!Common.ResourceType}
86 */ 86 */
87 static _contentTypeForExtension(extension) { 87 static _contentTypeForExtension(extension) {
88 if (WebInspector.FileSystemWorkspaceBinding._styleSheetExtensions.has(extens ion)) 88 if (Bindings.FileSystemWorkspaceBinding._styleSheetExtensions.has(extension) )
89 return WebInspector.resourceTypes.Stylesheet; 89 return Common.resourceTypes.Stylesheet;
90 if (WebInspector.FileSystemWorkspaceBinding._documentExtensions.has(extensio n)) 90 if (Bindings.FileSystemWorkspaceBinding._documentExtensions.has(extension))
91 return WebInspector.resourceTypes.Document; 91 return Common.resourceTypes.Document;
92 if (WebInspector.FileSystemWorkspaceBinding._imageExtensions.has(extension)) 92 if (Bindings.FileSystemWorkspaceBinding._imageExtensions.has(extension))
93 return WebInspector.resourceTypes.Image; 93 return Common.resourceTypes.Image;
94 if (WebInspector.FileSystemWorkspaceBinding._scriptExtensions.has(extension) ) 94 if (Bindings.FileSystemWorkspaceBinding._scriptExtensions.has(extension))
95 return WebInspector.resourceTypes.Script; 95 return Common.resourceTypes.Script;
96 return WebInspector.resourceTypes.Other; 96 return Common.resourceTypes.Other;
97 } 97 }
98 98
99 /** 99 /**
100 * @param {string} projectId 100 * @param {string} projectId
101 * @return {string} 101 * @return {string}
102 */ 102 */
103 static fileSystemPath(projectId) { 103 static fileSystemPath(projectId) {
104 return projectId; 104 return projectId;
105 } 105 }
106 106
107 /** 107 /**
108 * @return {!WebInspector.IsolatedFileSystemManager} 108 * @return {!Workspace.IsolatedFileSystemManager}
109 */ 109 */
110 fileSystemManager() { 110 fileSystemManager() {
111 return this._isolatedFileSystemManager; 111 return this._isolatedFileSystemManager;
112 } 112 }
113 113
114 /** 114 /**
115 * @param {!Array<!WebInspector.IsolatedFileSystem>} fileSystems 115 * @param {!Array<!Workspace.IsolatedFileSystem>} fileSystems
116 */ 116 */
117 _onFileSystemsLoaded(fileSystems) { 117 _onFileSystemsLoaded(fileSystems) {
118 for (var fileSystem of fileSystems) 118 for (var fileSystem of fileSystems)
119 this._addFileSystem(fileSystem); 119 this._addFileSystem(fileSystem);
120 } 120 }
121 121
122 /** 122 /**
123 * @param {!WebInspector.Event} event 123 * @param {!Common.Event} event
124 */ 124 */
125 _onFileSystemAdded(event) { 125 _onFileSystemAdded(event) {
126 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.data ); 126 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data);
127 this._addFileSystem(fileSystem); 127 this._addFileSystem(fileSystem);
128 } 128 }
129 129
130 /** 130 /**
131 * @param {!WebInspector.IsolatedFileSystem} fileSystem 131 * @param {!Workspace.IsolatedFileSystem} fileSystem
132 */ 132 */
133 _addFileSystem(fileSystem) { 133 _addFileSystem(fileSystem) {
134 var boundFileSystem = new WebInspector.FileSystemWorkspaceBinding.FileSystem (this, fileSystem, this._workspace); 134 var boundFileSystem = new Bindings.FileSystemWorkspaceBinding.FileSystem(thi s, fileSystem, this._workspace);
135 this._boundFileSystems.set(fileSystem.path(), boundFileSystem); 135 this._boundFileSystems.set(fileSystem.path(), boundFileSystem);
136 } 136 }
137 137
138 /** 138 /**
139 * @param {!WebInspector.Event} event 139 * @param {!Common.Event} event
140 */ 140 */
141 _onFileSystemRemoved(event) { 141 _onFileSystemRemoved(event) {
142 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.data ); 142 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data);
143 var boundFileSystem = this._boundFileSystems.get(fileSystem.path()); 143 var boundFileSystem = this._boundFileSystems.get(fileSystem.path());
144 boundFileSystem.dispose(); 144 boundFileSystem.dispose();
145 this._boundFileSystems.remove(fileSystem.path()); 145 this._boundFileSystems.remove(fileSystem.path());
146 } 146 }
147 147
148 /** 148 /**
149 * @param {!WebInspector.Event} event 149 * @param {!Common.Event} event
150 */ 150 */
151 _fileSystemFilesChanged(event) { 151 _fileSystemFilesChanged(event) {
152 var paths = /** @type {!Array<string>} */ (event.data); 152 var paths = /** @type {!Array<string>} */ (event.data);
153 for (var path of paths) { 153 for (var path of paths) {
154 for (var key of this._boundFileSystems.keys()) { 154 for (var key of this._boundFileSystems.keys()) {
155 if (!path.startsWith(key)) 155 if (!path.startsWith(key))
156 continue; 156 continue;
157 this._boundFileSystems.get(key)._fileChanged(path); 157 this._boundFileSystems.get(key)._fileChanged(path);
158 } 158 }
159 } 159 }
160 } 160 }
161 161
162 dispose() { 162 dispose() {
163 WebInspector.EventTarget.removeEventListeners(this._eventListeners); 163 Common.EventTarget.removeEventListeners(this._eventListeners);
164 for (var fileSystem of this._boundFileSystems.values()) { 164 for (var fileSystem of this._boundFileSystems.values()) {
165 fileSystem.dispose(); 165 fileSystem.dispose();
166 this._boundFileSystems.remove(fileSystem._fileSystem.path()); 166 this._boundFileSystems.remove(fileSystem._fileSystem.path());
167 } 167 }
168 } 168 }
169 }; 169 };
170 170
171 WebInspector.FileSystemWorkspaceBinding._styleSheetExtensions = new Set(['css', 'scss', 'sass', 'less']); 171 Bindings.FileSystemWorkspaceBinding._styleSheetExtensions = new Set(['css', 'scs s', 'sass', 'less']);
172 WebInspector.FileSystemWorkspaceBinding._documentExtensions = new Set(['htm', 'h tml', 'asp', 'aspx', 'phtml', 'jsp']); 172 Bindings.FileSystemWorkspaceBinding._documentExtensions = new Set(['htm', 'html' , 'asp', 'aspx', 'phtml', 'jsp']);
173 WebInspector.FileSystemWorkspaceBinding._scriptExtensions = new Set([ 173 Bindings.FileSystemWorkspaceBinding._scriptExtensions = new Set([
174 'asp', 'aspx', 'c', 'cc', 'cljs', 'coffee', 'cpp', 'cs', 'dart', 'java', 'js', 174 'asp', 'aspx', 'c', 'cc', 'cljs', 'coffee', 'cpp', 'cs', 'dart', 'java', 'js',
175 'jsp', 'jsx', 'h', 'm', 'mm', 'py', 'sh', 'ts', 'tsx', 'ls' 175 'jsp', 'jsx', 'h', 'm', 'mm', 'py', 'sh', 'ts', 'tsx', 'ls'
176 ]); 176 ]);
177 177
178 WebInspector.FileSystemWorkspaceBinding._imageExtensions = WebInspector.Isolated FileSystem.ImageExtensions; 178 Bindings.FileSystemWorkspaceBinding._imageExtensions = Workspace.IsolatedFileSys tem.ImageExtensions;
179 179
180 180
181 /** 181 /**
182 * @implements {WebInspector.Project} 182 * @implements {Workspace.Project}
183 * @unrestricted 183 * @unrestricted
184 */ 184 */
185 WebInspector.FileSystemWorkspaceBinding.FileSystem = class extends WebInspector. ProjectStore { 185 Bindings.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Project Store {
186 /** 186 /**
187 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBindin g 187 * @param {!Bindings.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding
188 * @param {!WebInspector.IsolatedFileSystem} isolatedFileSystem 188 * @param {!Workspace.IsolatedFileSystem} isolatedFileSystem
189 * @param {!WebInspector.Workspace} workspace 189 * @param {!Workspace.Workspace} workspace
190 */ 190 */
191 constructor(fileSystemWorkspaceBinding, isolatedFileSystem, workspace) { 191 constructor(fileSystemWorkspaceBinding, isolatedFileSystem, workspace) {
192 var fileSystemPath = isolatedFileSystem.path(); 192 var fileSystemPath = isolatedFileSystem.path();
193 var id = WebInspector.FileSystemWorkspaceBinding.projectId(fileSystemPath); 193 var id = Bindings.FileSystemWorkspaceBinding.projectId(fileSystemPath);
194 console.assert(!workspace.project(id)); 194 console.assert(!workspace.project(id));
195 var displayName = fileSystemPath.substr(fileSystemPath.lastIndexOf('/') + 1) ; 195 var displayName = fileSystemPath.substr(fileSystemPath.lastIndexOf('/') + 1) ;
196 196
197 super(workspace, id, WebInspector.projectTypes.FileSystem, displayName); 197 super(workspace, id, Workspace.projectTypes.FileSystem, displayName);
198 198
199 this._fileSystem = isolatedFileSystem; 199 this._fileSystem = isolatedFileSystem;
200 this._fileSystemBaseURL = this._fileSystem.path() + '/'; 200 this._fileSystemBaseURL = this._fileSystem.path() + '/';
201 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; 201 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding;
202 this._fileSystemPath = fileSystemPath; 202 this._fileSystemPath = fileSystemPath;
203 203
204 workspace.addProject(this); 204 workspace.addProject(this);
205 this.populate(); 205 this.populate();
206 } 206 }
207 207
208 /** 208 /**
209 * @return {string} 209 * @return {string}
210 */ 210 */
211 fileSystemPath() { 211 fileSystemPath() {
212 return this._fileSystemPath; 212 return this._fileSystemPath;
213 } 213 }
214 214
215 /** 215 /**
216 * @return {!Array<string>} 216 * @return {!Array<string>}
217 */ 217 */
218 gitFolders() { 218 gitFolders() {
219 return this._fileSystem.gitFolders().map(folder => this._fileSystemPath + '/ ' + folder); 219 return this._fileSystem.gitFolders().map(folder => this._fileSystemPath + '/ ' + folder);
220 } 220 }
221 221
222 /** 222 /**
223 * @param {!WebInspector.UISourceCode} uiSourceCode 223 * @param {!Workspace.UISourceCode} uiSourceCode
224 * @return {string} 224 * @return {string}
225 */ 225 */
226 _filePathForUISourceCode(uiSourceCode) { 226 _filePathForUISourceCode(uiSourceCode) {
227 return uiSourceCode.url().substring(this._fileSystemPath.length); 227 return uiSourceCode.url().substring(this._fileSystemPath.length);
228 } 228 }
229 229
230 /** 230 /**
231 * @override 231 * @override
232 * @param {!WebInspector.UISourceCode} uiSourceCode 232 * @param {!Workspace.UISourceCode} uiSourceCode
233 * @return {!Promise<?WebInspector.UISourceCodeMetadata>} 233 * @return {!Promise<?Workspace.UISourceCodeMetadata>}
234 */ 234 */
235 requestMetadata(uiSourceCode) { 235 requestMetadata(uiSourceCode) {
236 if (uiSourceCode[WebInspector.FileSystemWorkspaceBinding._metadata]) 236 if (uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata])
237 return uiSourceCode[WebInspector.FileSystemWorkspaceBinding._metadata]; 237 return uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata];
238 var relativePath = this._filePathForUISourceCode(uiSourceCode); 238 var relativePath = this._filePathForUISourceCode(uiSourceCode);
239 var promise = this._fileSystem.getMetadata(relativePath).then(onMetadata); 239 var promise = this._fileSystem.getMetadata(relativePath).then(onMetadata);
240 uiSourceCode[WebInspector.FileSystemWorkspaceBinding._metadata] = promise; 240 uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata] = promise;
241 return promise; 241 return promise;
242 242
243 /** 243 /**
244 * @param {?{modificationTime: !Date, size: number}} metadata 244 * @param {?{modificationTime: !Date, size: number}} metadata
245 * @return {?WebInspector.UISourceCodeMetadata} 245 * @return {?Workspace.UISourceCodeMetadata}
246 */ 246 */
247 function onMetadata(metadata) { 247 function onMetadata(metadata) {
248 if (!metadata) 248 if (!metadata)
249 return null; 249 return null;
250 return new WebInspector.UISourceCodeMetadata(metadata.modificationTime, me tadata.size); 250 return new Workspace.UISourceCodeMetadata(metadata.modificationTime, metad ata.size);
251 } 251 }
252 } 252 }
253 253
254 /** 254 /**
255 * @override 255 * @override
256 * @param {!WebInspector.UISourceCode} uiSourceCode 256 * @param {!Workspace.UISourceCode} uiSourceCode
257 * @param {function(?string)} callback 257 * @param {function(?string)} callback
258 */ 258 */
259 requestFileContent(uiSourceCode, callback) { 259 requestFileContent(uiSourceCode, callback) {
260 var filePath = this._filePathForUISourceCode(uiSourceCode); 260 var filePath = this._filePathForUISourceCode(uiSourceCode);
261 var isImage = 261 var isImage =
262 WebInspector.FileSystemWorkspaceBinding._imageExtensions.has(WebInspecto r.ParsedURL.extractExtension(filePath)); 262 Bindings.FileSystemWorkspaceBinding._imageExtensions.has(Common.ParsedUR L.extractExtension(filePath));
263 263
264 this._fileSystem.requestFileContent(filePath, isImage ? base64CallbackWrappe r : callback); 264 this._fileSystem.requestFileContent(filePath, isImage ? base64CallbackWrappe r : callback);
265 265
266 /** 266 /**
267 * @param {?string} result 267 * @param {?string} result
268 */ 268 */
269 function base64CallbackWrapper(result) { 269 function base64CallbackWrapper(result) {
270 if (!result) { 270 if (!result) {
271 callback(result); 271 callback(result);
272 return; 272 return;
273 } 273 }
274 var index = result.indexOf(','); 274 var index = result.indexOf(',');
275 callback(result.substring(index + 1)); 275 callback(result.substring(index + 1));
276 } 276 }
277 } 277 }
278 278
279 /** 279 /**
280 * @override 280 * @override
281 * @return {boolean} 281 * @return {boolean}
282 */ 282 */
283 canSetFileContent() { 283 canSetFileContent() {
284 return true; 284 return true;
285 } 285 }
286 286
287 /** 287 /**
288 * @override 288 * @override
289 * @param {!WebInspector.UISourceCode} uiSourceCode 289 * @param {!Workspace.UISourceCode} uiSourceCode
290 * @param {string} newContent 290 * @param {string} newContent
291 * @param {function(?string)} callback 291 * @param {function(?string)} callback
292 */ 292 */
293 setFileContent(uiSourceCode, newContent, callback) { 293 setFileContent(uiSourceCode, newContent, callback) {
294 var filePath = this._filePathForUISourceCode(uiSourceCode); 294 var filePath = this._filePathForUISourceCode(uiSourceCode);
295 this._fileSystem.setFileContent(filePath, newContent, callback.bind(this, '' )); 295 this._fileSystem.setFileContent(filePath, newContent, callback.bind(this, '' ));
296 } 296 }
297 297
298 /** 298 /**
299 * @override 299 * @override
300 * @return {boolean} 300 * @return {boolean}
301 */ 301 */
302 canRename() { 302 canRename() {
303 return true; 303 return true;
304 } 304 }
305 305
306 /** 306 /**
307 * @override 307 * @override
308 * @param {!WebInspector.UISourceCode} uiSourceCode 308 * @param {!Workspace.UISourceCode} uiSourceCode
309 * @param {string} newName 309 * @param {string} newName
310 * @param {function(boolean, string=, string=, !WebInspector.ResourceType=)} c allback 310 * @param {function(boolean, string=, string=, !Common.ResourceType=)} callbac k
311 */ 311 */
312 rename(uiSourceCode, newName, callback) { 312 rename(uiSourceCode, newName, callback) {
313 if (newName === uiSourceCode.name()) { 313 if (newName === uiSourceCode.name()) {
314 callback(true, uiSourceCode.name(), uiSourceCode.url(), uiSourceCode.conte ntType()); 314 callback(true, uiSourceCode.name(), uiSourceCode.url(), uiSourceCode.conte ntType());
315 return; 315 return;
316 } 316 }
317 317
318 var filePath = this._filePathForUISourceCode(uiSourceCode); 318 var filePath = this._filePathForUISourceCode(uiSourceCode);
319 this._fileSystem.renameFile(filePath, newName, innerCallback.bind(this)); 319 this._fileSystem.renameFile(filePath, newName, innerCallback.bind(this));
320 320
321 /** 321 /**
322 * @param {boolean} success 322 * @param {boolean} success
323 * @param {string=} newName 323 * @param {string=} newName
324 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem} 324 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem}
325 */ 325 */
326 function innerCallback(success, newName) { 326 function innerCallback(success, newName) {
327 if (!success || !newName) { 327 if (!success || !newName) {
328 callback(false, newName); 328 callback(false, newName);
329 return; 329 return;
330 } 330 }
331 console.assert(newName); 331 console.assert(newName);
332 var slash = filePath.lastIndexOf('/'); 332 var slash = filePath.lastIndexOf('/');
333 var parentPath = filePath.substring(0, slash); 333 var parentPath = filePath.substring(0, slash);
334 filePath = parentPath + '/' + newName; 334 filePath = parentPath + '/' + newName;
335 filePath = filePath.substr(1); 335 filePath = filePath.substr(1);
336 var extension = this._extensionForPath(newName); 336 var extension = this._extensionForPath(newName);
337 var newURL = this._fileSystemBaseURL + filePath; 337 var newURL = this._fileSystemBaseURL + filePath;
338 var newContentType = WebInspector.FileSystemWorkspaceBinding._contentTypeF orExtension(extension); 338 var newContentType = Bindings.FileSystemWorkspaceBinding._contentTypeForEx tension(extension);
339 this.renameUISourceCode(uiSourceCode, newName); 339 this.renameUISourceCode(uiSourceCode, newName);
340 callback(true, newName, newURL, newContentType); 340 callback(true, newName, newURL, newContentType);
341 } 341 }
342 } 342 }
343 343
344 /** 344 /**
345 * @override 345 * @override
346 * @param {!WebInspector.UISourceCode} uiSourceCode 346 * @param {!Workspace.UISourceCode} uiSourceCode
347 * @param {string} query 347 * @param {string} query
348 * @param {boolean} caseSensitive 348 * @param {boolean} caseSensitive
349 * @param {boolean} isRegex 349 * @param {boolean} isRegex
350 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb ack 350 * @param {function(!Array.<!Common.ContentProvider.SearchMatch>)} callback
351 */ 351 */
352 searchInFileContent(uiSourceCode, query, caseSensitive, isRegex, callback) { 352 searchInFileContent(uiSourceCode, query, caseSensitive, isRegex, callback) {
353 var filePath = this._filePathForUISourceCode(uiSourceCode); 353 var filePath = this._filePathForUISourceCode(uiSourceCode);
354 this._fileSystem.requestFileContent(filePath, contentCallback); 354 this._fileSystem.requestFileContent(filePath, contentCallback);
355 355
356 /** 356 /**
357 * @param {?string} content 357 * @param {?string} content
358 */ 358 */
359 function contentCallback(content) { 359 function contentCallback(content) {
360 var result = []; 360 var result = [];
361 if (content !== null) 361 if (content !== null)
362 result = WebInspector.ContentProvider.performSearchInContent(content, qu ery, caseSensitive, isRegex); 362 result = Common.ContentProvider.performSearchInContent(content, query, c aseSensitive, isRegex);
363 callback(result); 363 callback(result);
364 } 364 }
365 } 365 }
366 366
367 /** 367 /**
368 * @override 368 * @override
369 * @param {!WebInspector.ProjectSearchConfig} searchConfig 369 * @param {!Workspace.ProjectSearchConfig} searchConfig
370 * @param {!Array.<string>} filesMathingFileQuery 370 * @param {!Array.<string>} filesMathingFileQuery
371 * @param {!WebInspector.Progress} progress 371 * @param {!Common.Progress} progress
372 * @param {function(!Array.<string>)} callback 372 * @param {function(!Array.<string>)} callback
373 */ 373 */
374 findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress, callback) { 374 findFilesMatchingSearchRequest(searchConfig, filesMathingFileQuery, progress, callback) {
375 var result = filesMathingFileQuery; 375 var result = filesMathingFileQuery;
376 var queriesToRun = searchConfig.queries().slice(); 376 var queriesToRun = searchConfig.queries().slice();
377 if (!queriesToRun.length) 377 if (!queriesToRun.length)
378 queriesToRun.push(''); 378 queriesToRun.push('');
379 progress.setTotalWork(queriesToRun.length); 379 progress.setTotalWork(queriesToRun.length);
380 searchNextQuery.call(this); 380 searchNextQuery.call(this);
381 381
382 /** 382 /**
383 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem} 383 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem}
384 */ 384 */
385 function searchNextQuery() { 385 function searchNextQuery() {
386 if (!queriesToRun.length) { 386 if (!queriesToRun.length) {
387 progress.done(); 387 progress.done();
388 callback(result); 388 callback(result);
389 return; 389 return;
390 } 390 }
391 var query = queriesToRun.shift(); 391 var query = queriesToRun.shift();
392 this._fileSystem.searchInPath(searchConfig.isRegex() ? '' : query, progres s, innerCallback.bind(this)); 392 this._fileSystem.searchInPath(searchConfig.isRegex() ? '' : query, progres s, innerCallback.bind(this));
393 } 393 }
394 394
395 /** 395 /**
396 * @param {!Array.<string>} files 396 * @param {!Array.<string>} files
397 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem} 397 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem}
398 */ 398 */
399 function innerCallback(files) { 399 function innerCallback(files) {
400 files = files.sort(); 400 files = files.sort();
401 progress.worked(1); 401 progress.worked(1);
402 result = result.intersectOrdered(files, String.naturalOrderComparator); 402 result = result.intersectOrdered(files, String.naturalOrderComparator);
403 searchNextQuery.call(this); 403 searchNextQuery.call(this);
404 } 404 }
405 } 405 }
406 406
407 /** 407 /**
408 * @override 408 * @override
409 * @param {!WebInspector.Progress} progress 409 * @param {!Common.Progress} progress
410 */ 410 */
411 indexContent(progress) { 411 indexContent(progress) {
412 this._fileSystem.indexContent(progress); 412 this._fileSystem.indexContent(progress);
413 } 413 }
414 414
415 /** 415 /**
416 * @param {string} path 416 * @param {string} path
417 * @return {string} 417 * @return {string}
418 */ 418 */
419 _extensionForPath(path) { 419 _extensionForPath(path) {
420 var extensionIndex = path.lastIndexOf('.'); 420 var extensionIndex = path.lastIndexOf('.');
421 if (extensionIndex === -1) 421 if (extensionIndex === -1)
422 return ''; 422 return '';
423 return path.substring(extensionIndex + 1).toLowerCase(); 423 return path.substring(extensionIndex + 1).toLowerCase();
424 } 424 }
425 425
426 populate() { 426 populate() {
427 var chunkSize = 1000; 427 var chunkSize = 1000;
428 var filePaths = this._fileSystem.filePaths(); 428 var filePaths = this._fileSystem.filePaths();
429 reportFileChunk.call(this, 0); 429 reportFileChunk.call(this, 0);
430 430
431 /** 431 /**
432 * @param {number} from 432 * @param {number} from
433 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem} 433 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem}
434 */ 434 */
435 function reportFileChunk(from) { 435 function reportFileChunk(from) {
436 var to = Math.min(from + chunkSize, filePaths.length); 436 var to = Math.min(from + chunkSize, filePaths.length);
437 for (var i = from; i < to; ++i) 437 for (var i = from; i < to; ++i)
438 this._addFile(filePaths[i]); 438 this._addFile(filePaths[i]);
439 if (to < filePaths.length) 439 if (to < filePaths.length)
440 setTimeout(reportFileChunk.bind(this, to), 100); 440 setTimeout(reportFileChunk.bind(this, to), 100);
441 } 441 }
442 } 442 }
443 443
(...skipping 15 matching lines...) Expand all
459 if (uiSourceCode.url().startsWith(url)) 459 if (uiSourceCode.url().startsWith(url))
460 this.removeUISourceCode(uiSourceCode.url()); 460 this.removeUISourceCode(uiSourceCode.url());
461 } 461 }
462 } 462 }
463 463
464 /** 464 /**
465 * @override 465 * @override
466 * @param {string} path 466 * @param {string} path
467 * @param {?string} name 467 * @param {?string} name
468 * @param {string} content 468 * @param {string} content
469 * @param {function(?WebInspector.UISourceCode)} callback 469 * @param {function(?Workspace.UISourceCode)} callback
470 */ 470 */
471 createFile(path, name, content, callback) { 471 createFile(path, name, content, callback) {
472 this._fileSystem.createFile(path, name, innerCallback.bind(this)); 472 this._fileSystem.createFile(path, name, innerCallback.bind(this));
473 var createFilePath; 473 var createFilePath;
474 474
475 /** 475 /**
476 * @param {?string} filePath 476 * @param {?string} filePath
477 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem} 477 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem}
478 */ 478 */
479 function innerCallback(filePath) { 479 function innerCallback(filePath) {
480 if (!filePath) { 480 if (!filePath) {
481 callback(null); 481 callback(null);
482 return; 482 return;
483 } 483 }
484 createFilePath = filePath; 484 createFilePath = filePath;
485 if (!content) { 485 if (!content) {
486 contentSet.call(this); 486 contentSet.call(this);
487 return; 487 return;
488 } 488 }
489 this._fileSystem.setFileContent(filePath, content, contentSet.bind(this)); 489 this._fileSystem.setFileContent(filePath, content, contentSet.bind(this));
490 } 490 }
491 491
492 /** 492 /**
493 * @this {WebInspector.FileSystemWorkspaceBinding.FileSystem} 493 * @this {Bindings.FileSystemWorkspaceBinding.FileSystem}
494 */ 494 */
495 function contentSet() { 495 function contentSet() {
496 callback(this._addFile(createFilePath)); 496 callback(this._addFile(createFilePath));
497 } 497 }
498 } 498 }
499 499
500 /** 500 /**
501 * @override 501 * @override
502 * @param {string} path 502 * @param {string} path
503 */ 503 */
504 deleteFile(path) { 504 deleteFile(path) {
505 this._fileSystem.deleteFile(path); 505 this._fileSystem.deleteFile(path);
506 this.removeUISourceCode(path); 506 this.removeUISourceCode(path);
507 } 507 }
508 508
509 /** 509 /**
510 * @override 510 * @override
511 */ 511 */
512 remove() { 512 remove() {
513 this._fileSystemWorkspaceBinding._isolatedFileSystemManager.removeFileSystem (this._fileSystem); 513 this._fileSystemWorkspaceBinding._isolatedFileSystemManager.removeFileSystem (this._fileSystem);
514 } 514 }
515 515
516 /** 516 /**
517 * @param {string} filePath 517 * @param {string} filePath
518 * @return {!WebInspector.UISourceCode} 518 * @return {!Workspace.UISourceCode}
519 */ 519 */
520 _addFile(filePath) { 520 _addFile(filePath) {
521 var extension = this._extensionForPath(filePath); 521 var extension = this._extensionForPath(filePath);
522 var contentType = WebInspector.FileSystemWorkspaceBinding._contentTypeForExt ension(extension); 522 var contentType = Bindings.FileSystemWorkspaceBinding._contentTypeForExtensi on(extension);
523 523
524 var uiSourceCode = this.createUISourceCode(this._fileSystemBaseURL + filePat h, contentType); 524 var uiSourceCode = this.createUISourceCode(this._fileSystemBaseURL + filePat h, contentType);
525 this.addUISourceCode(uiSourceCode); 525 this.addUISourceCode(uiSourceCode);
526 return uiSourceCode; 526 return uiSourceCode;
527 } 527 }
528 528
529 /** 529 /**
530 * @param {string} path 530 * @param {string} path
531 */ 531 */
532 _fileChanged(path) { 532 _fileChanged(path) {
533 var uiSourceCode = this.uiSourceCodeForURL(path); 533 var uiSourceCode = this.uiSourceCodeForURL(path);
534 if (!uiSourceCode) { 534 if (!uiSourceCode) {
535 var contentType = WebInspector.FileSystemWorkspaceBinding._contentTypeForE xtension(this._extensionForPath(path)); 535 var contentType = Bindings.FileSystemWorkspaceBinding._contentTypeForExten sion(this._extensionForPath(path));
536 this.addUISourceCode(this.createUISourceCode(path, contentType)); 536 this.addUISourceCode(this.createUISourceCode(path, contentType));
537 return; 537 return;
538 } 538 }
539 uiSourceCode[WebInspector.FileSystemWorkspaceBinding._metadata] = null; 539 uiSourceCode[Bindings.FileSystemWorkspaceBinding._metadata] = null;
540 uiSourceCode.checkContentUpdated(); 540 uiSourceCode.checkContentUpdated();
541 } 541 }
542 542
543 dispose() { 543 dispose() {
544 this.removeProject(); 544 this.removeProject();
545 } 545 }
546 }; 546 };
547 547
548 WebInspector.FileSystemWorkspaceBinding._metadata = Symbol('FileSystemWorkspaceB inding.Metadata'); 548 Bindings.FileSystemWorkspaceBinding._metadata = Symbol('FileSystemWorkspaceBindi ng.Metadata');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698