OLD | NEW |
(Empty) | |
| 1 |
| 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. |
| 5 |
| 6 /** |
| 7 * @constructor |
| 8 * @param {!WebInspector.SourcesPanel} sourcesPanel |
| 9 * @param {!WebInspector.Workspace} workspace |
| 10 */ |
| 11 WebInspector.WorkspaceMappingTip = function(sourcesPanel, workspace) |
| 12 { |
| 13 this._sourcesPanel = sourcesPanel; |
| 14 this._workspace = workspace; |
| 15 |
| 16 this._sourcesView = this._sourcesPanel.sourcesView(); |
| 17 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorSel
ected, this._editorSelected.bind(this)); |
| 18 } |
| 19 |
| 20 WebInspector.WorkspaceMappingTip._infobarSymbol = Symbol("infobar"); |
| 21 |
| 22 WebInspector.WorkspaceMappingTip.prototype = { |
| 23 /** |
| 24 * @param {!WebInspector.Event} event |
| 25 */ |
| 26 _editorSelected: function(event) |
| 27 { |
| 28 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data
); |
| 29 if (Runtime.experiments.isEnabled("suggestUsingWorkspace")) { |
| 30 if (this._editorSelectedTimer) |
| 31 clearTimeout(this._editorSelectedTimer); |
| 32 this._editorSelectedTimer = setTimeout(this._updateSuggestedMappingI
nfobar.bind(this, uiSourceCode), 3000); |
| 33 } |
| 34 }, |
| 35 |
| 36 /** |
| 37 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 38 */ |
| 39 _updateSuggestedMappingInfobar: function(uiSourceCode) |
| 40 { |
| 41 var uiSourceCodeFrame = this._sourcesView.viewForFile(uiSourceCode); |
| 42 |
| 43 if (!uiSourceCodeFrame.isShowing()) |
| 44 return; |
| 45 if (uiSourceCode[WebInspector.WorkspaceMappingTip._infobarSymbol]) |
| 46 return; |
| 47 |
| 48 // First try mapping filesystem -> network. |
| 49 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst
em) { |
| 50 var hasMappings = !!uiSourceCode.url; |
| 51 if (hasMappings) |
| 52 return; |
| 53 } |
| 54 |
| 55 var networkProjects = this._workspace.projectsForType(WebInspector.proje
ctTypes.FileSystem); |
| 56 networkProjects = networkProjects.concat(this._workspace.projectsForType
(WebInspector.projectTypes.ContentScripts)); |
| 57 for (var i = 0; i < networkProjects.length; ++i) { |
| 58 var name = uiSourceCode.name(); |
| 59 var networkUiSourceCodes = networkProjects[i].uiSourceCodes(); |
| 60 for (var j = 0; j < networkUiSourceCodes.length; ++j) { |
| 61 if (networkUiSourceCodes[j].name() === name) { |
| 62 this._createMappingInfobar(uiSourceCode, false); |
| 63 return; |
| 64 } |
| 65 } |
| 66 } |
| 67 |
| 68 // Then map network -> filesystem. |
| 69 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network
|| uiSourceCode.project().type() === WebInspector.projectTypes.ContentScripts) { |
| 70 if (this._workspace.uiSourceCodeForURL(uiSourceCode.url) !== uiSourc
eCode) |
| 71 return; |
| 72 |
| 73 var filesystemProjects = this._workspace.projectsForType(WebInspecto
r.projectTypes.FileSystem); |
| 74 for (var i = 0; i < filesystemProjects.length; ++i) { |
| 75 var name = uiSourceCode.name(); |
| 76 var fsUiSourceCodes = filesystemProjects[i].uiSourceCodes(); |
| 77 for (var j = 0; j < fsUiSourceCodes.length; ++j) { |
| 78 if (fsUiSourceCodes[j].name() === name) { |
| 79 this._createMappingInfobar(uiSourceCode, true); |
| 80 return; |
| 81 } |
| 82 } |
| 83 } |
| 84 |
| 85 // There are no matching filesystems. Suggest adding a filesystem in
case of localhost. |
| 86 var originURL = uiSourceCode.originURL().asParsedURL(); |
| 87 if (originURL && originURL.host === "localhost") |
| 88 this._createWorkspaceInfobar(uiSourceCode); |
| 89 } |
| 90 }, |
| 91 |
| 92 /** |
| 93 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 94 */ |
| 95 _createWorkspaceInfobar: function(uiSourceCode) |
| 96 { |
| 97 var infobar = new WebInspector.UISourceCodeFrame.Infobar(WebInspecto
r.UISourceCodeFrame.Infobar.Level.Info, WebInspector.UIString("Serving from the
file system? Add your files into the workspace.")); |
| 98 infobar.createDetailsRowMessage(WebInspector.UIString("If you add fi
les into your DevTools workspace, your changes will be persisted to disk.")); |
| 99 infobar.createDetailsRowMessage(WebInspector.UIString("To add a fold
er into the workspace, drag and drop it into the Sources panel.")); |
| 100 this._appendInfobar(uiSourceCode, infobar); |
| 101 }, |
| 102 |
| 103 /** |
| 104 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 105 * @param {boolean} isNetwork |
| 106 */ |
| 107 _createMappingInfobar: function(uiSourceCode, isNetwork) |
| 108 { |
| 109 var title; |
| 110 if (isNetwork) |
| 111 title = WebInspector.UIString("Map network resource '%s' to workspac
e?", uiSourceCode.originURL()); |
| 112 else |
| 113 title = WebInspector.UIString("Map workspace resource '%s' to networ
k?", uiSourceCode.path()); |
| 114 |
| 115 var infobar = new WebInspector.UISourceCodeFrame.Infobar(WebInspector.UI
SourceCodeFrame.Infobar.Level.Info, title); |
| 116 infobar.createDetailsRowMessage(WebInspector.UIString("You can map files
in your workspace to the ones loaded over the network. As a result, changes mad
e in DevTools will be persisted to disk.")); |
| 117 infobar.createDetailsRowMessage(WebInspector.UIString("Use context menu
to establish the mapping at any time.")); |
| 118 var actionLink = infobar.createDetailsRowMessage("").createChild("a"); |
| 119 actionLink.href = ""; |
| 120 actionLink.onclick = this._establishTheMapping.bind(this, uiSourceCode); |
| 121 actionLink.textContent = WebInspector.UIString("Establish the mapping no
w..."); |
| 122 this._appendInfobar(uiSourceCode, infobar); |
| 123 }, |
| 124 |
| 125 /** |
| 126 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 127 * @param {?Event} event |
| 128 */ |
| 129 _establishTheMapping: function(uiSourceCode, event) |
| 130 { |
| 131 event.consume(true); |
| 132 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst
em) |
| 133 this._sourcesPanel.mapFileSystemToNetwork(uiSourceCode); |
| 134 else |
| 135 this._sourcesPanel.mapNetworkToFileSystem(uiSourceCode); |
| 136 }, |
| 137 |
| 138 /** |
| 139 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 140 * @param {!WebInspector.UISourceCodeFrame.Infobar} infobar |
| 141 */ |
| 142 _appendInfobar: function(uiSourceCode, infobar) |
| 143 { |
| 144 var uiSourceCodeFrame = this._sourcesView.viewForFile(uiSourceCode); |
| 145 |
| 146 infobar.createDetailsRowMessage("").createChild("br"); |
| 147 var rowElement = infobar.createDetailsRowMessage(WebInspector.UIString("
For more information on workspaces, refer to the ")); |
| 148 var a = rowElement.createChild("a"); |
| 149 a.textContent = "workspaces documentation"; |
| 150 a.href = "https://developer.chrome.com/devtools/docs/workspaces"; |
| 151 rowElement.createTextChild("."); |
| 152 uiSourceCode[WebInspector.WorkspaceMappingTip._infobarSymbol] = infobar; |
| 153 uiSourceCodeFrame.attachInfobars([infobar]); |
| 154 } |
| 155 } |
OLD | NEW |