Skip to content

Commit c377d23

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[sources] Add infobar to Sources panel for automatic workspace folders.
This adds a preliminary UI to the Workspace tab in the Sources panel, which allows users to automatically connect workspace folders that are reported via project settings. Doc: http://go/chrome-devtools:automatic-workspace-folders-design Bug: 395562934 Change-Id: If8f7cd03a830a9e6636a94d7e3e4209e061311b9 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6281767 Auto-Submit: Benedikt Meurer <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Benedikt Meurer <[email protected]>
1 parent 43cfc01 commit c377d23

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

front_end/models/persistence/persistence-meta.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const UIStrings = {
5252
*@description Title of a setting under the Persistence category that can be invoked through the Command Menu
5353
*/
5454
disableOverrideNetworkRequests: 'Disable override network requests',
55+
/**
56+
* @description Title of a setting to enable the Automatic Workspace Folders.
57+
*/
58+
enableAutomaticWorkspaceFolders: 'Enable automatic workspace folders',
5559
};
5660
const str_ = i18n.i18n.registerUIStrings('models/persistence/persistence-meta.ts', UIStrings);
5761
const i18nLazyString = i18n.i18n.getLazilyComputedLocalizedString.bind(undefined, str_);
@@ -78,6 +82,14 @@ UI.ViewManager.registerViewExtension({
7882
iconName: 'folder',
7983
});
8084

85+
Common.Settings.registerSettingExtension({
86+
category: Common.Settings.SettingCategory.PERSISTENCE,
87+
title: i18nLazyString(UIStrings.enableAutomaticWorkspaceFolders),
88+
settingName: 'persistence-automatic-workspace-folders',
89+
settingType: Common.Settings.SettingType.BOOLEAN,
90+
defaultValue: false,
91+
});
92+
8193
Common.Settings.registerSettingExtension({
8294
category: Common.Settings.SettingCategory.PERSISTENCE,
8395
title: i18nLazyString(UIStrings.enableLocalOverrides),

front_end/panels/sources/SourcesNavigator.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ const UIStrings = {
109109
*@description Text to save content as a specific file type
110110
*/
111111
saveAs: 'Save as...',
112+
/**
113+
* @description Text in Workspaces tab in the Sources panel when an automatic
114+
* workspace folder is detected.
115+
* @example {/path/to/foo} PH1
116+
*/
117+
automaticWorkspaceFolderDetected: 'Workspace folder {PH1} detected.',
118+
/**
119+
* @description Button description in Workspaces tab in the Sources panel
120+
* to connect to an automatic workspace folder.
121+
*/
122+
automaticWorkspaceFolderConnect: 'Connect...',
112123
};
113124
const str_ = i18n.i18n.registerUIStrings('panels/sources/SourcesNavigator.ts', UIStrings);
114125
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -182,6 +193,10 @@ export class NetworkNavigatorView extends NavigatorView {
182193
}
183194

184195
export class FilesNavigatorView extends NavigatorView {
196+
#automaticFileSystemManager = Persistence.AutomaticFileSystemManager.AutomaticFileSystemManager.instance();
197+
#infobar: UI.Infobar.Infobar|null = null;
198+
#eventListeners: Common.EventTarget.EventDescriptor[] = [];
199+
185200
constructor() {
186201
super('navigator-files');
187202
const placeholder =
@@ -198,6 +213,22 @@ export class FilesNavigatorView extends NavigatorView {
198213
});
199214
}
200215

216+
override wasShown(): void {
217+
super.wasShown();
218+
this.#eventListeners = [
219+
this.#automaticFileSystemManager.addEventListener(
220+
Persistence.AutomaticFileSystemManager.Events.AUTOMATIC_FILE_SYSTEM_CHANGED, this.#automaticFileSystemChanged,
221+
this),
222+
];
223+
this.#automaticFileSystemChanged({data: this.#automaticFileSystemManager.automaticFileSystem});
224+
}
225+
226+
override willHide(): void {
227+
Common.EventTarget.removeEventListeners(this.#eventListeners);
228+
this.#automaticFileSystemChanged({data: null});
229+
super.willHide();
230+
}
231+
201232
override sourceSelected(uiSourceCode: Workspace.UISourceCode.UISourceCode, focusSource: boolean): void {
202233
Host.userMetrics.actionTaken(Host.UserMetrics.Action.WorkspaceSourceSelected);
203234
super.sourceSelected(uiSourceCode, focusSource);
@@ -214,6 +245,33 @@ export class FilesNavigatorView extends NavigatorView {
214245
contextMenu.defaultSection().appendAction('sources.add-folder-to-workspace', undefined, true);
215246
void contextMenu.show();
216247
}
248+
249+
#automaticFileSystemChanged(
250+
event: Common.EventTarget.EventTargetEvent<Persistence.AutomaticFileSystemManager.AutomaticFileSystem|null>):
251+
void {
252+
const automaticFileSystem = event.data;
253+
if (automaticFileSystem === null || automaticFileSystem.state !== 'disconnected') {
254+
this.#infobar?.dispose();
255+
this.#infobar = null;
256+
} else {
257+
this.#infobar = UI.Infobar.Infobar.create(
258+
UI.Infobar.Type.INFO,
259+
i18nString(UIStrings.automaticWorkspaceFolderDetected, {PH1: automaticFileSystem.root}),
260+
[{
261+
text: i18nString(UIStrings.automaticWorkspaceFolderConnect),
262+
highlight: true,
263+
delegate: () => this.#automaticFileSystemManager.connectAutomaticFileSystem(/* addIfMissing= */ true),
264+
dismiss: true,
265+
jslogContext: 'automatic-workspace-folders.connect',
266+
}],
267+
Common.Settings.Settings.instance().moduleSetting('persistence-automatic-workspace-folders'),
268+
'automatic-workspace-folders',
269+
);
270+
if (this.#infobar) {
271+
this.contentElement.append(this.#infobar.element);
272+
}
273+
}
274+
}
217275
}
218276

219277
let overridesNavigatorViewInstance: OverridesNavigatorView;

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ export const knownContextValues = new Set([
484484
'autofill-view',
485485
'autofill-view-documentation',
486486
'autofill-view-feedback',
487+
'automatic-workspace-folders.connect',
487488
'automatically-ignore-list-known-third-party-scripts',
488489
'auxclick',
489490
'avif-format-disabled',
@@ -2610,6 +2611,7 @@ export const knownContextValues = new Set([
26102611
'performance.sidebar-toggle',
26112612
'periodic-background-sync',
26122613
'periodic-sync-tag',
2614+
'persistence-automatic-workspace-folders',
26132615
'persistence-network-overrides-enabled',
26142616
'persistence-network-overrides-enabled-true',
26152617
'perspective',

0 commit comments

Comments
 (0)