Skip to content

Commit 04fd95c

Browse files
bmeurerDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[sources] Use correct icon for the automatic workspace folders.
Drive-by-fix: Refactor the code a bit to make dealing with file system projects a little bit more consistent. Screenshot: http://screen/8yGPbaqXP97ZxdD.png Fixed: 404170628 Change-Id: Ie341e59d5fdb0e16a3102c6473a86630dad69368 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6445823 Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
1 parent fa38c41 commit 04fd95c

File tree

4 files changed

+48
-36
lines changed

4 files changed

+48
-36
lines changed

front_end/models/persistence/AutomaticFileSystemWorkspaceBinding.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ import * as Workspace from '../workspace/workspace.js';
1212
import {type AutomaticFileSystem, type AutomaticFileSystemManager, Events} from './AutomaticFileSystemManager.js';
1313

1414
/**
15-
* @internal
15+
* Placeholder project that acts as an empty file system within the workspace,
16+
* and automatically disappears when the user connects the automatic workspace
17+
* folder.
1618
*
1719
* @see AutomaticFileSystemWorkspaceBinding
1820
*/
19-
class ConnectableFileSystemProject implements Workspace.Workspace.Project {
21+
export class FileSystem implements Workspace.Workspace.Project {
2022
readonly automaticFileSystem: Readonly<AutomaticFileSystem>;
23+
readonly automaticFileSystemManager: AutomaticFileSystemManager;
2124
readonly #workspace: Workspace.Workspace.WorkspaceImpl;
2225

23-
constructor(automaticFileSystem: Readonly<AutomaticFileSystem>, workspace: Workspace.Workspace.WorkspaceImpl) {
26+
constructor(
27+
automaticFileSystem: Readonly<AutomaticFileSystem>, automaticFileSystemManager: AutomaticFileSystemManager,
28+
workspace: Workspace.Workspace.WorkspaceImpl) {
2429
this.automaticFileSystem = automaticFileSystem;
30+
this.automaticFileSystemManager = automaticFileSystemManager;
2531
this.#workspace = workspace;
2632
}
2733

@@ -156,7 +162,7 @@ let automaticFileSystemWorkspaceBindingInstance: AutomaticFileSystemWorkspaceBin
156162
*/
157163
export class AutomaticFileSystemWorkspaceBinding {
158164
readonly #automaticFileSystemManager: AutomaticFileSystemManager;
159-
#automaticFileSystemProject: ConnectableFileSystemProject|null = null;
165+
#fileSystem: FileSystem|null = null;
160166
readonly #workspace: Workspace.Workspace.WorkspaceImpl;
161167

162168
/**
@@ -206,25 +212,29 @@ export class AutomaticFileSystemWorkspaceBinding {
206212
}
207213

208214
#dispose(): void {
209-
if (this.#automaticFileSystemProject) {
210-
this.#workspace.removeProject(this.#automaticFileSystemProject);
215+
if (this.#fileSystem) {
216+
this.#workspace.removeProject(this.#fileSystem);
211217
}
212218
this.#automaticFileSystemManager.removeEventListener(
213219
Events.AUTOMATIC_FILE_SYSTEM_CHANGED, this.#automaticFileSystemChanged, this);
214220
}
215221

216222
#automaticFileSystemChanged(event: Common.EventTarget.EventTargetEvent<AutomaticFileSystem|null>): void {
217223
const automaticFileSystem = event.data;
218-
if (this.#automaticFileSystemProject !== null) {
219-
if (this.#automaticFileSystemProject.automaticFileSystem === automaticFileSystem) {
224+
if (this.#fileSystem !== null) {
225+
if (this.#fileSystem.automaticFileSystem === automaticFileSystem) {
220226
return;
221227
}
222-
this.#workspace.removeProject(this.#automaticFileSystemProject);
223-
this.#automaticFileSystemProject = null;
228+
this.#workspace.removeProject(this.#fileSystem);
229+
this.#fileSystem = null;
224230
}
225231
if (automaticFileSystem !== null && automaticFileSystem.state !== 'connected') {
226-
this.#automaticFileSystemProject = new ConnectableFileSystemProject(automaticFileSystem, this.#workspace);
227-
this.#workspace.addProject(this.#automaticFileSystemProject);
232+
this.#fileSystem = new FileSystem(
233+
automaticFileSystem,
234+
this.#automaticFileSystemManager,
235+
this.#workspace,
236+
);
237+
this.#workspace.addProject(this.#fileSystem);
228238
}
229239
}
230240
}

front_end/models/persistence/PlatformFileSystem.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ export enum PlatformFileSystemType {
4848
export class PlatformFileSystem {
4949
private readonly pathInternal: Platform.DevToolsPath.UrlString;
5050
#type: PlatformFileSystemType;
51-
#automatic: boolean;
51+
/**
52+
* True if the filesystem was automatically discovered (see
53+
* https://goo.gle/devtools-json-design).
54+
*/
55+
readonly automatic: boolean;
56+
5257
constructor(path: Platform.DevToolsPath.UrlString, type: PlatformFileSystemType, automatic: boolean) {
5358
this.pathInternal = path;
5459
this.#type = type;
55-
this.#automatic = automatic;
60+
this.automatic = automatic;
5661
}
5762

5863
getMetadata(_path: Platform.DevToolsPath.EncodedPathString): Promise<{modificationTime: Date, size: number}|null> {
@@ -79,14 +84,6 @@ export class PlatformFileSystem {
7984
return this.#type;
8085
}
8186

82-
/**
83-
* True if the filesystem was automatically discovered (see
84-
* https://goo.gle/devtools-json-design).
85-
*/
86-
automatic(): boolean {
87-
return this.#automatic;
88-
}
89-
9087
async createFile(_path: Platform.DevToolsPath.EncodedPathString, _name: Platform.DevToolsPath.RawPathString|null):
9188
Promise<Platform.DevToolsPath.EncodedPathString|null> {
9289
return await Promise.resolve(null);

front_end/panels/sources/NavigatorView.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const str_ = i18n.i18n.registerUIStrings('panels/sources/NavigatorView.ts', UISt
168168
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
169169
export const Types = {
170170
Authored: 'authored',
171-
ConnectableFileSystem: 'connectable-fs',
171+
AutomaticFileSystem: 'automatic-fs',
172172
Deployed: 'deployed',
173173
Domain: 'domain',
174174
File: 'file',
@@ -190,7 +190,7 @@ const TYPE_ORDERS = new Map([
190190
[Types.File, 10],
191191
[Types.Frame, 70],
192192
[Types.Worker, 90],
193-
[Types.ConnectableFileSystem, 100],
193+
[Types.AutomaticFileSystem, 100],
194194
[Types.FileSystem, 100],
195195
]);
196196

@@ -567,11 +567,12 @@ export class NavigatorView extends UI.Widget.VBox implements SDK.TargetManager.O
567567
Snippets.ScriptSnippetFileSystem.isSnippetsProject(project) || rootOrDeployed.child(project.id())) {
568568
return;
569569
}
570-
rootOrDeployed.appendChild(new NavigatorGroupTreeNode(
571-
this, project, project.id(),
572-
project.type() === Workspace.Workspace.projectTypes.ConnectableFileSystem ? Types.ConnectableFileSystem :
573-
Types.FileSystem,
574-
project.displayName()));
570+
const type =
571+
(project instanceof Persistence.AutomaticFileSystemWorkspaceBinding.FileSystem ||
572+
(project instanceof Persistence.FileSystemWorkspaceBinding.FileSystem && project.fileSystem().automatic)) ?
573+
Types.AutomaticFileSystem :
574+
Types.FileSystem;
575+
rootOrDeployed.appendChild(new NavigatorGroupTreeNode(this, project, project.id(), type, project.displayName()));
575576
this.selectDefaultTreeNode();
576577
}
577578

@@ -1284,8 +1285,9 @@ export class NavigatorFolderTreeElement extends UI.TreeOutline.TreeElement {
12841285
private hovered?: boolean;
12851286
private isIgnoreListed?: boolean;
12861287

1287-
constructor(navigatorView: NavigatorView, type: string, title: string, hoverCallback?: ((arg0: boolean) => void)) {
1288-
const expandable = type !== Types.ConnectableFileSystem;
1288+
constructor(
1289+
navigatorView: NavigatorView, type: string, title: string, hoverCallback?: ((arg0: boolean) => void),
1290+
expandable = true) {
12891291
super('', expandable, NavigatorFolderTreeElement.#contextForType(type));
12901292
this.listItemElement.classList.add('navigator-' + type + '-tree-item', 'navigator-folder-tree-item');
12911293
UI.ARIAUtils.setLabel(this.listItemElement, `${title}, ${type}`);
@@ -1307,6 +1309,8 @@ export class NavigatorFolderTreeElement extends UI.TreeOutline.TreeElement {
13071309
iconType = 'code';
13081310
} else if (type === Types.Deployed) {
13091311
iconType = 'deployed';
1312+
} else if (type === Types.AutomaticFileSystem) {
1313+
iconType = 'folder-asterisk';
13101314
}
13111315

13121316
const icon = IconButton.Icon.create(iconType);
@@ -2067,11 +2071,12 @@ export class NavigatorGroupTreeNode extends NavigatorTreeNode {
20672071
if (this.treeElement) {
20682072
return this.treeElement;
20692073
}
2070-
this.treeElement = new NavigatorFolderTreeElement(this.navigatorView, this.type, this.title, this.hoverCallback);
2074+
const expandable = !(this.project instanceof Persistence.AutomaticFileSystemWorkspaceBinding.FileSystem);
2075+
this.treeElement =
2076+
new NavigatorFolderTreeElement(this.navigatorView, this.type, this.title, this.hoverCallback, expandable);
20712077
this.treeElement.setNode(this);
2072-
if (this.project && this.project.type() === Workspace.Workspace.projectTypes.ConnectableFileSystem) {
2073-
const automaticFileSystemManager = Persistence.AutomaticFileSystemManager.AutomaticFileSystemManager.instance();
2074-
const {automaticFileSystem} = automaticFileSystemManager;
2078+
if (this.project instanceof Persistence.AutomaticFileSystemWorkspaceBinding.FileSystem) {
2079+
const {automaticFileSystem, automaticFileSystemManager} = this.project;
20752080
switch (automaticFileSystem?.state) {
20762081
case 'connecting': {
20772082
const spinner = new Spinners.Spinner.Spinner();

front_end/panels/sources/navigatorTree.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
color: var(--icon-folder-workspace);
4848
}
4949

50-
.navigator-connectable-fs-tree-item devtools-icon,
50+
.navigator-automatic-fs-tree-item devtools-icon,
5151
.navigator-fs-tree-item devtools-icon {
5252
color: var(--icon-file-authored);
5353
}

0 commit comments

Comments
 (0)