Skip to content

Commit d891761

Browse files
masnobleDevtools-frontend LUCI CQ
authored andcommitted
Add icon and primary options to Infobar for page reload warning
Example of usage in mock: https://screenshot.googleplex.com/9hiSHMsEzf3aFtT.png Implementation: https://screenshot.googleplex.com/6tb4cm3K4sNxTYf.png Bug: 375352611 Change-Id: I174c4e45543608507d92b9680bb996b5559a2db3 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6017335 Reviewed-by: Kateryna Prokopenko <[email protected]> Reviewed-by: Danil Somsikov <[email protected]> Commit-Queue: Joshua Thomas <[email protected]>
1 parent 8b86f92 commit d891761

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

front_end/ui/legacy/Infobar.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ export class Infobar {
9595
buttonClass += ' primary-button';
9696
}
9797

98+
const buttonVariant = action.buttonVariant ?? Buttons.Button.Variant.OUTLINED;
99+
98100
const button = createTextButton(action.text, actionCallback, {
99101
className: buttonClass,
100102
jslogContext: action.jslogContext,
103+
variant: buttonVariant,
104+
icon: action.icon,
101105
});
102106
if (action.highlight && !this.#firstFocusableElement) {
103107
this.#firstFocusableElement = button;
@@ -246,6 +250,8 @@ export interface InfobarAction {
246250
highlight: boolean;
247251
delegate: (() => void)|null;
248252
dismiss: boolean;
253+
buttonVariant?: Buttons.Button.Variant;
254+
icon?: string;
249255
jslogContext?: string;
250256
}
251257

front_end/ui/legacy/InspectorView.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import * as Common from '../../core/common/common.js';
3232
import * as Host from '../../core/host/host.js';
3333
import * as i18n from '../../core/i18n/i18n.js';
3434
import * as Root from '../../core/root/root.js';
35+
import * as Buttons from '../../ui/components/buttons/buttons.js';
3536
import * as IconButton from '../components/icon_button/icon_button.js';
3637
import * as VisualLogging from '../visual_logging/visual_logging.js';
3738

3839
import type {ActionDelegate as ActionDelegateInterface} from './ActionRegistration.js';
40+
import {ActionRegistry} from './ActionRegistry.js';
3941
import * as ARIAUtils from './ARIAUtils.js';
4042
import type {Context} from './Context.js';
4143
import type {ContextMenu} from './ContextMenu.js';
@@ -67,6 +69,10 @@ const UIStrings = {
6769
*@description The aria label for main tabbed pane that contains Panels
6870
*/
6971
panels: 'Panels',
72+
/**
73+
*@description Title of an action that reloads the tab currently being debugged by DevTools
74+
*/
75+
reloadDebuggedTab: 'Reload',
7076
/**
7177
*@description Title of an action that reloads the DevTools
7278
*/
@@ -476,6 +482,36 @@ export class InspectorView extends VBox implements ViewLocationResolver {
476482
}
477483
}
478484

485+
displayDebuggedTabReloadRequiredWarning(message: string): void {
486+
if (!this.reloadRequiredInfobar) {
487+
const infobar = new Infobar(
488+
InfobarType.INFO, message,
489+
[
490+
{
491+
text: i18nString(UIStrings.reloadDebuggedTab),
492+
highlight: true,
493+
delegate: () => {
494+
reloadDebuggedTab();
495+
if (this.reloadRequiredInfobar) {
496+
this.reloadRequiredInfobar.dispose();
497+
}
498+
},
499+
dismiss: false,
500+
buttonVariant: Buttons.Button.Variant.PRIMARY,
501+
icon: 'refresh',
502+
jslogContext: 'main.debug-reload',
503+
},
504+
],
505+
undefined, undefined, 'reload-required');
506+
infobar.setParentView(this);
507+
this.attachInfobar(infobar);
508+
this.reloadRequiredInfobar = infobar;
509+
infobar.setCloseCallback(() => {
510+
delete this.reloadRequiredInfobar;
511+
});
512+
}
513+
}
514+
479515
displayReloadRequiredWarning(message: string): void {
480516
if (!this.reloadRequiredInfobar) {
481517
const infobar = new Infobar(
@@ -602,6 +638,10 @@ function reloadDevTools(): void {
602638
Host.InspectorFrontendHost.InspectorFrontendHostInstance.reattach(() => window.location.reload());
603639
}
604640

641+
function reloadDebuggedTab(): void {
642+
void ActionRegistry.instance().getAction('inspector-main.reload').execute();
643+
}
644+
605645
export class ActionDelegate implements ActionDelegateInterface {
606646
handleAction(context: Context, actionId: string): boolean {
607647
switch (actionId) {

front_end/ui/legacy/UIUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,12 +1091,15 @@ export function createTextButton(text: string, clickHandler?: ((arg0: Event) =>
10911091
jslogContext?: string,
10921092
variant?: Buttons.Button.Variant,
10931093
title?: string,
1094+
icon?: string,
10941095
}): Buttons.Button.Button {
10951096
const button = new Buttons.Button.Button();
10961097
if (opts?.className) {
10971098
button.className = opts.className;
10981099
}
1100+
10991101
button.textContent = text;
1102+
button.iconName = opts?.icon;
11001103
button.variant = opts?.variant ? opts.variant : Buttons.Button.Variant.OUTLINED;
11011104
if (clickHandler) {
11021105
button.addEventListener('click', clickHandler);

0 commit comments

Comments
 (0)