Skip to content

Commit

Permalink
Use RoundedButtonGroup for debugger buttons (#6568)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Oct 23, 2023
1 parent d2f59cf commit 8c2d8d5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 132 deletions.
140 changes: 41 additions & 99 deletions packages/devtools_app/lib/src/screens/debugger/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,63 +82,51 @@ class _DebuggingControlsState extends State<DebuggingControls>
required bool resuming,
}) {
final isSystemIsolate = controller.isSystemIsolate;
return RoundedOutlinedBorder(
child: Row(
children: [
DebuggerButton(
title: 'Pause',
icon: Codicons.debugPause,
autofocus: true,
roundedLeftBorder: true,
// Disable when paused or selected isolate is a system isolate.
onPressed: (isPaused || isSystemIsolate)
? null
: () => unawaited(controller.pause()),
),
LeftBorder(
child: DebuggerButton(
title: 'Resume',
icon: Codicons.debugContinue,
roundedRightBorder: true,
// Enable while paused + not resuming and selected isolate is not
// a system isolate.
onPressed: ((isPaused && !resuming) && !isSystemIsolate)
? () => unawaited(controller.resume())
: null,
),
),
],
),
return RoundedButtonGroup(
items: [
ButtonGroupItemData(
tooltip: 'Pause',
icon: Codicons.debugPause,
autofocus: true,
// Disable when paused or selected isolate is a system isolate.
onPressed: (isPaused || isSystemIsolate)
? null
: () => unawaited(controller.pause()),
),
ButtonGroupItemData(
tooltip: 'Resume',
icon: Codicons.debugContinue,
// Enable while paused + not resuming and selected isolate is not
// a system isolate.
onPressed: ((isPaused && !resuming) && !isSystemIsolate)
? () => unawaited(controller.resume())
: null,
),
],
);
}

Widget _stepButtons({required bool canStep}) {
return RoundedOutlinedBorder(
child: Row(
children: [
DebuggerButton(
title: 'Step Over',
icon: Codicons.debugStepOver,
roundedLeftBorder: true,
onPressed: canStep ? () => unawaited(controller.stepOver()) : null,
),
LeftBorder(
child: DebuggerButton(
title: 'Step In',
icon: Codicons.debugStepInto,
onPressed: canStep ? () => unawaited(controller.stepIn()) : null,
),
),
LeftBorder(
child: DebuggerButton(
title: 'Step Out',
icon: Codicons.debugStepOut,
roundedRightBorder: true,
onPressed: canStep ? () => unawaited(controller.stepOut()) : null,
),
),
],
),
return RoundedButtonGroup(
items: [
ButtonGroupItemData(
label: 'Step Over',
icon: Codicons.debugStepOver,
onPressed: canStep ? () => unawaited(controller.stepOver()) : null,
),
ButtonGroupItemData(
label: 'Step In',
icon: Codicons.debugStepInto,
onPressed: canStep ? () => unawaited(controller.stepIn()) : null,
),
ButtonGroupItemData(
label: 'Step Out',
icon: Codicons.debugStepOut,
onPressed: canStep ? () => unawaited(controller.stepOut()) : null,
),
],
minScreenWidthForTextBeforeScaling:
DebuggingControls.minWidthBeforeScaling,
);
}

Expand Down Expand Up @@ -316,49 +304,3 @@ class ExceptionMode {
final String name;
final String description;
}

@visibleForTesting
class DebuggerButton extends StatelessWidget {
const DebuggerButton({
super.key,
required this.title,
required this.icon,
required this.onPressed,
this.autofocus = false,
this.roundedLeftBorder = false,
this.roundedRightBorder = false,
});

final String title;
final IconData icon;
final VoidCallback? onPressed;
final bool autofocus;
final bool roundedLeftBorder;
final bool roundedRightBorder;

@override
Widget build(BuildContext context) {
return DevToolsTooltip(
message: title,
child: OutlinedButton(
autofocus: autofocus,
style: OutlinedButton.styleFrom(
side: BorderSide.none,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.horizontal(
left: roundedLeftBorder ? defaultRadius : Radius.zero,
right: roundedRightBorder ? defaultRadius : Radius.zero,
),
),
),
onPressed: onPressed,
child: MaterialIconLabel(
label: title,
iconData: icon,
minScreenWidthForTextBeforeScaling:
DebuggingControls.minWidthBeforeScaling,
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:codicon/codicon.dart';
import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/screens/debugger/codeview.dart';
import 'package:devtools_app/src/screens/debugger/controls.dart';
import 'package:devtools_app/src/screens/debugger/debugger_model.dart';
import 'package:devtools_app/src/shared/diagnostics/primitives/source_location.dart';
import 'package:devtools_app_shared/ui.dart';
Expand All @@ -15,6 +15,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:vm_service/vm_service.dart';

import '../test_infra/utils/debugger_utils.dart';
import '../test_infra/utils/test_utils.dart';

void main() {
Expand Down Expand Up @@ -88,20 +89,20 @@ void main() {
await tester.pump();

expect(
findDebuggerButtonWithTitle('Pause'),
findDebuggerButtonWithIcon(Codicons.debugPause),
findsOneWidget,
);
final pause = getWidgetFromFinder<DebuggerButton>(
findDebuggerButtonWithTitle('Pause'),
final pause = getWidgetFromFinder<OutlinedButton>(
findDebuggerButtonWithIcon(Codicons.debugPause),
);
expect(pause.onPressed, isNull);

expect(
findDebuggerButtonWithTitle('Resume'),
findDebuggerButtonWithIcon(Codicons.debugContinue),
findsOneWidget,
);
final resume = getWidgetFromFinder<DebuggerButton>(
findDebuggerButtonWithTitle('Resume'),
final resume = getWidgetFromFinder<OutlinedButton>(
findDebuggerButtonWithIcon(Codicons.debugContinue),
);
expect(resume.onPressed, isNotNull);
},
Expand Down Expand Up @@ -183,10 +184,6 @@ final _stackFrame2 = StackFrameAndSourcePosition(
position: const SourcePosition(line: _stackFrame2Line, column: 1),
);

Finder findDebuggerButtonWithTitle(String title) => find.byWidgetPredicate(
(Widget widget) => widget is DebuggerButton && widget.title == title,
);

Finder findStackFrameWithText(String text) => find.byWidgetPredicate(
(Widget widget) =>
widget is RichText && widget.text.toPlainText().contains(text),
Expand Down
33 changes: 11 additions & 22 deletions packages/devtools_app/test/debugger/debugger_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:codicon/codicon.dart';
import 'package:collection/collection.dart';
import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/screens/debugger/controls.dart';
import 'package:devtools_app/src/screens/debugger/debugger_model.dart';
import 'package:devtools_app/src/shared/console/widgets/console_pane.dart';
import 'package:devtools_app_shared/ui.dart';
Expand All @@ -16,6 +16,8 @@ import 'package:mockito/mockito.dart';
import 'package:vm_service/vm_service.dart';

import '../test_infra/test_data/debugger/vm_service_object_tree.dart';
import '../test_infra/utils/debugger_utils.dart';
import '../test_infra/utils/test_utils.dart';
import '../test_infra/utils/tree_utils.dart';

void main() {
Expand Down Expand Up @@ -114,15 +116,6 @@ void main() {
},
);

WidgetPredicate createDebuggerButtonPredicate(String title) {
return (Widget widget) {
if (widget is DebuggerButton && widget.title == title) {
return true;
}
return false;
};
}

testWidgetsWithWindowSize(
'debugger controls running',
windowSize,
Expand All @@ -135,21 +128,21 @@ void main() {
);

expect(
find.byWidgetPredicate(createDebuggerButtonPredicate('Pause')),
findDebuggerButtonWithIcon(Codicons.debugPause),
findsOneWidget,
);
final pause = _getWidgetFromFinder(
find.byWidgetPredicate(createDebuggerButtonPredicate('Pause')),
) as DebuggerButton;
final pause = getWidgetFromFinder<OutlinedButton>(
findDebuggerButtonWithIcon(Codicons.debugPause),
);
expect(pause.onPressed, isNotNull);

expect(
find.byWidgetPredicate(createDebuggerButtonPredicate('Resume')),
findDebuggerButtonWithIcon(Codicons.debugContinue),
findsOneWidget,
);
final resume = _getWidgetFromFinder(
find.byWidgetPredicate(createDebuggerButtonPredicate('Resume')),
) as DebuggerButton;
final resume = getWidgetFromFinder<OutlinedButton>(
findDebuggerButtonWithIcon(Codicons.debugContinue),
);
expect(resume.onPressed, isNull);
},
);
Expand Down Expand Up @@ -252,7 +245,3 @@ void main() {
},
);
}

Widget _getWidgetFromFinder(Finder finder) {
return finder.first.evaluate().first.widget;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions packages/devtools_app/test/test_infra/utils/debugger_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2023 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:devtools_app_shared/ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

Finder findDebuggerButtonWithIcon(IconData icon) => find.ancestor(
of: find.byWidgetPredicate(
(Widget widget) =>
widget is MaterialIconLabel && widget.iconData == icon,
),
matching: find.byType(OutlinedButton),
);

0 comments on commit 8c2d8d5

Please sign in to comment.