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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/NavigatorView.js

Issue 2536273003: [DevTools] Remove Workspace.projectTypes enum part1. (Closed)
Patch Set: Created 4 years 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) 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 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 10 *
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 _addUISourceCode(uiSourceCode) { 259 _addUISourceCode(uiSourceCode) {
260 if (!this.accept(uiSourceCode)) 260 if (!this.accept(uiSourceCode))
261 return; 261 return;
262 262
263 var binding = Persistence.persistence.binding(uiSourceCode); 263 var binding = Persistence.persistence.binding(uiSourceCode);
264 if (!Runtime.experiments.isEnabled('persistence2') && binding && binding.net work === uiSourceCode) 264 if (!Runtime.experiments.isEnabled('persistence2') && binding && binding.net work === uiSourceCode)
265 return; 265 return;
266 266
267 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap(); 267 var isFromSourceMap = uiSourceCode.contentType().isFromSourceMap();
268 var path; 268 var path;
269 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) 269 if (Persistence.FileSystemWorkspaceBinding.isFileSystemUISourceCode(uiSource Code))
270 path = Persistence.FileSystemWorkspaceBinding.relativePath(uiSourceCode).s lice(0, -1); 270 path = Persistence.FileSystemWorkspaceBinding.relativePath(uiSourceCode).s lice(0, -1);
271 else 271 else
272 path = Common.ParsedURL.extractPath(uiSourceCode.url()).split('/').slice(1 , -1); 272 path = Common.ParsedURL.extractPath(uiSourceCode.url()).split('/').slice(1 , -1);
273 273
274 var project = uiSourceCode.project();
275 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); 274 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
276 var frame = this._uiSourceCodeFrame(uiSourceCode); 275 var frame = this._uiSourceCodeFrame(uiSourceCode);
277 276
278 var folderNode = 277 var folderNode = this._folderNode(uiSourceCode, target, frame, uiSourceCode. origin(), path, isFromSourceMap);
279 this._folderNode(uiSourceCode, project, target, frame, uiSourceCode.orig in(), path, isFromSourceMap);
280 var uiSourceCodeNode = new Sources.NavigatorUISourceCodeTreeNode(this, uiSou rceCode); 278 var uiSourceCodeNode = new Sources.NavigatorUISourceCodeTreeNode(this, uiSou rceCode);
281 this._uiSourceCodeNodes.set(uiSourceCode, uiSourceCodeNode); 279 this._uiSourceCodeNodes.set(uiSourceCode, uiSourceCodeNode);
282 folderNode.appendChild(uiSourceCodeNode); 280 folderNode.appendChild(uiSourceCodeNode);
283 this.uiSourceCodeAdded(uiSourceCode); 281 this.uiSourceCodeAdded(uiSourceCode);
284 } 282 }
285 283
286 /** 284 /**
287 * @param {!Workspace.UISourceCode} uiSourceCode 285 * @param {!Workspace.UISourceCode} uiSourceCode
288 */ 286 */
289 uiSourceCodeAdded(uiSourceCode) { 287 uiSourceCodeAdded(uiSourceCode) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 /** 321 /**
324 * @param {!Workspace.Project} project 322 * @param {!Workspace.Project} project
325 * @param {?SDK.Target} target 323 * @param {?SDK.Target} target
326 * @param {?SDK.ResourceTreeFrame} frame 324 * @param {?SDK.ResourceTreeFrame} frame
327 * @param {string} projectOrigin 325 * @param {string} projectOrigin
328 * @param {string} path 326 * @param {string} path
329 * @return {string} 327 * @return {string}
330 */ 328 */
331 _folderNodeId(project, target, frame, projectOrigin, path) { 329 _folderNodeId(project, target, frame, projectOrigin, path) {
332 var targetId = target ? target.id() : ''; 330 var targetId = target ? target.id() : '';
333 var projectId = project.type() === Workspace.projectTypes.FileSystem ? proje ct.id() : ''; 331 var projectId = Persistence.FileSystemWorkspaceBinding.isFileSystemProject(p roject) ? project.id() : '';
334 var frameId = this._groupByFrame && frame ? frame.id : ''; 332 var frameId = this._groupByFrame && frame ? frame.id : '';
335 return targetId + ':' + projectId + ':' + frameId + ':' + projectOrigin + ': ' + path; 333 return targetId + ':' + projectId + ':' + frameId + ':' + projectOrigin + ': ' + path;
336 } 334 }
337 335
338 /** 336 /**
339 * @param {!Workspace.UISourceCode} uiSourceCode 337 * @param {!Workspace.UISourceCode} uiSourceCode
340 * @param {!Workspace.Project} project
341 * @param {?SDK.Target} target 338 * @param {?SDK.Target} target
342 * @param {?SDK.ResourceTreeFrame} frame 339 * @param {?SDK.ResourceTreeFrame} frame
343 * @param {string} projectOrigin 340 * @param {string} projectOrigin
344 * @param {!Array<string>} path 341 * @param {!Array<string>} path
345 * @param {boolean} fromSourceMap 342 * @param {boolean} fromSourceMap
346 * @return {!Sources.NavigatorTreeNode} 343 * @return {!Sources.NavigatorTreeNode}
347 */ 344 */
348 _folderNode(uiSourceCode, project, target, frame, projectOrigin, path, fromSou rceMap) { 345 _folderNode(uiSourceCode, target, frame, projectOrigin, path, fromSourceMap) {
349 if (project.type() === Workspace.projectTypes.Snippets) 346 var project = uiSourceCode.project();
347 if (Snippets.ScriptSnippetModel.isSnippetUISourceCode(uiSourceCode))
350 return this._rootNode; 348 return this._rootNode;
351 349
352 if (target && !this._groupByFolder && !fromSourceMap) 350 if (target && !this._groupByFolder && !fromSourceMap)
353 return this._domainNode(uiSourceCode, project, target, frame, projectOrigi n); 351 return this._domainNode(uiSourceCode, project, target, frame, projectOrigi n);
354 352
355 var folderPath = path.join('/'); 353 var folderPath = path.join('/');
356 var folderId = this._folderNodeId(project, target, frame, projectOrigin, fol derPath); 354 var folderId = this._folderNodeId(project, target, frame, projectOrigin, fol derPath);
357 var folderNode = this._subfolderNodes.get(folderId); 355 var folderNode = this._subfolderNodes.get(folderId);
358 if (folderNode) 356 if (folderNode)
359 return folderNode; 357 return folderNode;
360 358
361 if (!path.length) { 359 if (!path.length) {
362 if (target) 360 if (target)
363 return this._domainNode(uiSourceCode, project, target, frame, projectOri gin); 361 return this._domainNode(uiSourceCode, project, target, frame, projectOri gin);
364 var fileSystemNode = this._rootNode.child(project.id()); 362 var fileSystemNode = this._rootNode.child(project.id());
365 if (!fileSystemNode) { 363 if (!fileSystemNode) {
366 fileSystemNode = new Sources.NavigatorGroupTreeNode( 364 fileSystemNode = new Sources.NavigatorGroupTreeNode(
367 this, project, project.id(), Sources.NavigatorView.Types.FileSystem, project.displayName()); 365 this, project, project.id(), Sources.NavigatorView.Types.FileSystem, project.displayName());
368 this._rootNode.appendChild(fileSystemNode); 366 this._rootNode.appendChild(fileSystemNode);
369 } 367 }
370 return fileSystemNode; 368 return fileSystemNode;
371 } 369 }
372 370
373 var parentNode = 371 var parentNode = this._folderNode(uiSourceCode, target, frame, projectOrigin , path.slice(0, -1), fromSourceMap);
374 this._folderNode(uiSourceCode, project, target, frame, projectOrigin, pa th.slice(0, -1), fromSourceMap);
375 var type = fromSourceMap ? Sources.NavigatorView.Types.SourceMapFolder : Sou rces.NavigatorView.Types.NetworkFolder; 372 var type = fromSourceMap ? Sources.NavigatorView.Types.SourceMapFolder : Sou rces.NavigatorView.Types.NetworkFolder;
376 if (project.type() === Workspace.projectTypes.FileSystem) 373 if (Persistence.FileSystemWorkspaceBinding.isFileSystemUISourceCode(uiSource Code))
377 type = Sources.NavigatorView.Types.FileSystemFolder; 374 type = Sources.NavigatorView.Types.FileSystemFolder;
378 var name = path[path.length - 1]; 375 var name = path[path.length - 1];
379 376
380 folderNode = new Sources.NavigatorFolderTreeNode(this, project, folderId, ty pe, folderPath, name); 377 folderNode = new Sources.NavigatorFolderTreeNode(this, project, folderId, ty pe, folderPath, name);
381 this._subfolderNodes.set(folderId, folderNode); 378 this._subfolderNodes.set(folderId, folderNode);
382 parentNode.appendChild(folderNode); 379 parentNode.appendChild(folderNode);
383 return folderNode; 380 return folderNode;
384 } 381 }
385 382
386 /** 383 /**
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 603
607 /** 604 /**
608 * @param {!Event} event 605 * @param {!Event} event
609 * @param {!Workspace.UISourceCode} uiSourceCode 606 * @param {!Workspace.UISourceCode} uiSourceCode
610 */ 607 */
611 handleFileContextMenu(event, uiSourceCode) { 608 handleFileContextMenu(event, uiSourceCode) {
612 var contextMenu = new UI.ContextMenu(event); 609 var contextMenu = new UI.ContextMenu(event);
613 contextMenu.appendApplicableItems(uiSourceCode); 610 contextMenu.appendApplicableItems(uiSourceCode);
614 contextMenu.appendSeparator(); 611 contextMenu.appendSeparator();
615 612
616 var project = uiSourceCode.project(); 613 if (Persistence.FileSystemWorkspaceBinding.isFileSystemUISourceCode(uiSource Code)) {
617 if (project.type() === Workspace.projectTypes.FileSystem) {
618 var parentURL = uiSourceCode.parentURL(); 614 var parentURL = uiSourceCode.parentURL();
619 contextMenu.appendItem(Common.UIString('Rename\u2026'), this._handleContex tMenuRename.bind(this, uiSourceCode)); 615 contextMenu.appendItem(Common.UIString('Rename\u2026'), this._handleContex tMenuRename.bind(this, uiSourceCode));
620 contextMenu.appendItem( 616 contextMenu.appendItem(
621 Common.UIString('Make a copy\u2026'), 617 Common.UIString('Make a copy\u2026'),
622 this._handleContextMenuCreate.bind(this, project, parentURL, uiSourceC ode)); 618 this._handleContextMenuCreate.bind(this, uiSourceCode.project(), paren tURL, uiSourceCode));
623 contextMenu.appendItem(Common.UIString('Delete'), this._handleContextMenuD elete.bind(this, uiSourceCode)); 619 contextMenu.appendItem(Common.UIString('Delete'), this._handleContextMenuD elete.bind(this, uiSourceCode));
624 contextMenu.appendSeparator(); 620 contextMenu.appendSeparator();
625 } 621 }
626 622
627 contextMenu.show(); 623 contextMenu.show();
628 } 624 }
629 625
630 /** 626 /**
631 * @param {!Event} event 627 * @param {!Event} event
632 * @param {!Sources.NavigatorFolderTreeNode} node 628 * @param {!Sources.NavigatorFolderTreeNode} node
633 */ 629 */
634 handleFolderContextMenu(event, node) { 630 handleFolderContextMenu(event, node) {
635 var path = node._folderPath; 631 var path = node._folderPath;
636 var project = node._project; 632 var project = node._project;
637 633
638 var contextMenu = new UI.ContextMenu(event); 634 var contextMenu = new UI.ContextMenu(event);
639 635
640 Sources.NavigatorView.appendSearchItem(contextMenu, path); 636 Sources.NavigatorView.appendSearchItem(contextMenu, path);
641 contextMenu.appendSeparator(); 637 contextMenu.appendSeparator();
642 638
643 if (project.type() !== Workspace.projectTypes.FileSystem) 639 if (!Persistence.FileSystemWorkspaceBinding.isFileSystemProject(project))
644 return; 640 return;
645 641
646 contextMenu.appendItem(Common.UIString('New file'), this._handleContextMenuC reate.bind(this, project, path)); 642 contextMenu.appendItem(Common.UIString('New file'), this._handleContextMenuC reate.bind(this, project, path));
647 contextMenu.appendItem(Common.UIString('Exclude folder'), this._handleContex tMenuExclude.bind(this, project, path)); 643 contextMenu.appendItem(Common.UIString('Exclude folder'), this._handleContex tMenuExclude.bind(this, project, path));
648 644
649 function removeFolder() { 645 function removeFolder() {
650 var shouldRemove = window.confirm(Common.UIString('Are you sure you want t o remove this folder?')); 646 var shouldRemove = window.confirm(Common.UIString('Are you sure you want t o remove this folder?'));
651 if (shouldRemove) 647 if (shouldRemove)
652 project.remove(); 648 project.remove();
653 } 649 }
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 new UI.InplaceEditor.Config(commitHandler.bind(this), afterEditing.bind( this, false))); 1358 new UI.InplaceEditor.Config(commitHandler.bind(this), afterEditing.bind( this, false)));
1363 } 1359 }
1364 }; 1360 };
1365 1361
1366 /** 1362 /**
1367 * @unrestricted 1363 * @unrestricted
1368 */ 1364 */
1369 Sources.NavigatorFolderTreeNode = class extends Sources.NavigatorTreeNode { 1365 Sources.NavigatorFolderTreeNode = class extends Sources.NavigatorTreeNode {
1370 /** 1366 /**
1371 * @param {!Sources.NavigatorView} navigatorView 1367 * @param {!Sources.NavigatorView} navigatorView
1372 * @param {?Workspace.Project} project 1368 * @param {!Workspace.Project} project
1373 * @param {string} id 1369 * @param {string} id
1374 * @param {string} type 1370 * @param {string} type
1375 * @param {string} folderPath 1371 * @param {string} folderPath
1376 * @param {string} title 1372 * @param {string} title
1377 */ 1373 */
1378 constructor(navigatorView, project, id, type, folderPath, title) { 1374 constructor(navigatorView, project, id, type, folderPath, title) {
1379 super(id, type); 1375 super(id, type);
1380 this._navigatorView = navigatorView; 1376 this._navigatorView = navigatorView;
1381 this._project = project; 1377 this._project = project;
1382 this._folderPath = folderPath; 1378 this._folderPath = folderPath;
1383 this._title = title; 1379 this._title = title;
1384 } 1380 }
1385 1381
1386 /** 1382 /**
1387 * @override 1383 * @override
1388 * @return {!TreeElement} 1384 * @return {!TreeElement}
1389 */ 1385 */
1390 treeNode() { 1386 treeNode() {
1391 if (this._treeElement) 1387 if (this._treeElement)
1392 return this._treeElement; 1388 return this._treeElement;
1393 this._treeElement = this._createTreeElement(this._title, this); 1389 this._treeElement = this._createTreeElement(this._title, this);
1394 this.updateTitle(); 1390 this.updateTitle();
1395 return this._treeElement; 1391 return this._treeElement;
1396 } 1392 }
1397 1393
1398 updateTitle() { 1394 updateTitle() {
1399 if (!this._treeElement || this._project.type() !== Workspace.projectTypes.Fi leSystem) 1395 if (!this._treeElement || !Persistence.FileSystemWorkspaceBinding.isFileSyst emProject(this._project))
1400 return; 1396 return;
1401 var absoluteFileSystemPath = 1397 var absoluteFileSystemPath =
1402 Persistence.FileSystemWorkspaceBinding.fileSystemPath(this._project.id() ) + '/' + this._folderPath; 1398 Persistence.FileSystemWorkspaceBinding.fileSystemPath(this._project.id() ) + '/' + this._folderPath;
1403 var hasMappedFiles = Runtime.experiments.isEnabled('persistence2') ? 1399 var hasMappedFiles = Runtime.experiments.isEnabled('persistence2') ?
1404 Persistence.persistence.filePathHasBindings(absoluteFileSystemPath) : 1400 Persistence.persistence.filePathHasBindings(absoluteFileSystemPath) :
1405 true; 1401 true;
1406 this._treeElement.listItemElement.classList.toggle('has-mapped-files', hasMa ppedFiles); 1402 this._treeElement.listItemElement.classList.toggle('has-mapped-files', hasMa ppedFiles);
1407 } 1403 }
1408 1404
1409 /** 1405 /**
1410 * @return {!TreeElement} 1406 * @return {!TreeElement}
1411 */ 1407 */
1412 _createTreeElement(title, node) { 1408 _createTreeElement(title, node) {
1413 if (this._project.type() !== Workspace.projectTypes.FileSystem) { 1409 if (!Persistence.FileSystemWorkspaceBinding.isFileSystemProject(this._projec t)) {
1414 try { 1410 try {
1415 title = decodeURI(title); 1411 title = decodeURI(title);
1416 } catch (e) { 1412 } catch (e) {
1417 } 1413 }
1418 } 1414 }
1419 var treeElement = new Sources.NavigatorFolderTreeElement(this._navigatorView , this._type, title); 1415 var treeElement = new Sources.NavigatorFolderTreeElement(this._navigatorView , this._type, title);
1420 treeElement.setNode(node); 1416 treeElement.setNode(node);
1421 return treeElement; 1417 return treeElement;
1422 } 1418 }
1423 1419
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 } 1562 }
1567 1563
1568 /** 1564 /**
1569 * @override 1565 * @override
1570 */ 1566 */
1571 onattach() { 1567 onattach() {
1572 this.updateTitle(); 1568 this.updateTitle();
1573 } 1569 }
1574 1570
1575 updateTitle() { 1571 updateTitle() {
1576 if (!this._treeElement || this._project.type() !== Workspace.projectTypes.Fi leSystem) 1572 if (!this._treeElement || !Persistence.FileSystemWorkspaceBinding.isFileSyst emProject(this._project))
1577 return; 1573 return;
1578 if (!Runtime.experiments.isEnabled('persistence2')) { 1574 if (!Runtime.experiments.isEnabled('persistence2')) {
1579 this._treeElement.listItemElement.classList.add('has-mapped-files'); 1575 this._treeElement.listItemElement.classList.add('has-mapped-files');
1580 return; 1576 return;
1581 } 1577 }
1582 var fileSystemPath = Persistence.FileSystemWorkspaceBinding.fileSystemPath(t his._project.id()); 1578 var fileSystemPath = Persistence.FileSystemWorkspaceBinding.fileSystemPath(t his._project.id());
1583 var wasActive = this._treeElement.listItemElement.classList.contains('has-ma pped-files'); 1579 var wasActive = this._treeElement.listItemElement.classList.contains('has-ma pped-files');
1584 var isActive = Persistence.persistence.filePathHasBindings(fileSystemPath); 1580 var isActive = Persistence.persistence.filePathHasBindings(fileSystemPath);
1585 if (wasActive === isActive) 1581 if (wasActive === isActive)
1586 return; 1582 return;
1587 this._treeElement.listItemElement.classList.toggle('has-mapped-files', isAct ive); 1583 this._treeElement.listItemElement.classList.toggle('has-mapped-files', isAct ive);
1588 if (isActive) 1584 if (isActive)
1589 this._treeElement.expand(); 1585 this._treeElement.expand();
1590 else 1586 else
1591 this._treeElement.collapse(); 1587 this._treeElement.collapse();
1592 } 1588 }
1593 1589
1594 /** 1590 /**
1595 * @param {string} title 1591 * @param {string} title
1596 * @override 1592 * @override
1597 */ 1593 */
1598 setTitle(title) { 1594 setTitle(title) {
1599 this._title = title; 1595 this._title = title;
1600 if (this._treeElement) 1596 if (this._treeElement)
1601 this._treeElement.title = this._title; 1597 this._treeElement.title = this._title;
1602 } 1598 }
1603 }; 1599 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698