-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathcontrols.dart
More file actions
305 lines (279 loc) · 9.72 KB
/
controls.dart
File metadata and controls
305 lines (279 loc) · 9.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
// Copyright 2020 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
import 'dart:async';
import 'package:devtools_app_shared/ui.dart';
import 'package:devtools_app_shared/utils.dart';
import 'package:flutter/material.dart' hide Stack;
import 'package:vm_service/vm_service.dart';
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/globals.dart';
import '../../shared/primitives/utils.dart';
import '../../shared/ui/common_widgets.dart';
import 'debugger_controller.dart';
class DebuggingControls extends StatefulWidget {
const DebuggingControls({super.key});
static const minWidth = 1750.0;
// The icon size for the material_symbol icons needs to be increased to
// account for padding included in the icon assets.
static const materialIconSize = defaultIconSize + 3.0;
@override
State<DebuggingControls> createState() => _DebuggingControlsState();
}
class _DebuggingControlsState extends State<DebuggingControls>
with AutoDisposeMixin {
late DebuggerController controller;
@override
void initState() {
super.initState();
controller = screenControllers.lookup<DebuggerController>();
addAutoDisposeListener(
serviceConnection
.serviceManager
.isolateManager
.mainIsolateState
?.isPaused,
);
addAutoDisposeListener(controller.resuming);
addAutoDisposeListener(controller.stackFramesWithLocation);
}
@override
Widget build(BuildContext context) {
final resuming = controller.resuming.value;
final canStep = controller.canStep;
final isVmApp =
serviceConnection.serviceManager.connectedApp?.isRunningOnDartVM ??
false;
return SizedBox(
height: defaultButtonHeight,
child: Row(
children: [
_pauseAndResumeButtons(
isPaused: serviceConnection.serviceManager.isMainIsolatePaused,
resuming: resuming,
),
const SizedBox(width: denseSpacing),
_stepButtons(canStep: canStep),
const SizedBox(width: denseSpacing),
BreakOnExceptionsControl(controller: controller),
if (isVmApp) ...[
const SizedBox(width: denseSpacing),
CodeStatisticsControls(controller: controller),
],
const Expanded(child: SizedBox(width: denseSpacing)),
_librariesButton(),
],
),
);
}
Widget _pauseAndResumeButtons({
required bool isPaused,
required bool resuming,
}) {
final isSystemIsolate = controller.isSystemIsolate;
// Note: this could be refactored to use a single [GaDevToolsButton] instead
// of a [RoundedButtonGroup] with only one child, but this would require
// changes to the underlying [DevToolsButton] widget from
// package:devtools_app_shared to accept an `iconAsset` as a parameter.
return RoundedButtonGroup(
items: [
!isPaused
? ButtonGroupItemData(
tooltip: 'Pause',
icon: Icons.pause,
autofocus: true,
// Disable when selected isolate is a system isolate.
onPressed: isSystemIsolate
? null
: () => unawaited(controller.pause()),
)
: ButtonGroupItemData(
tooltip: 'Resume',
iconAsset: 'icons/material_symbols/resume.png',
iconSize: DebuggingControls.materialIconSize,
// Enable not resuming and selected isolate is not a system
// isolate.
onPressed: (!resuming && !isSystemIsolate)
? () => unawaited(controller.resume())
: null,
),
],
);
}
Widget _stepButtons({required bool canStep}) {
return RoundedButtonGroup(
items: [
ButtonGroupItemData(
label: 'Step Over',
iconAsset: 'icons/material_symbols/step_over.png',
iconSize: DebuggingControls.materialIconSize,
onPressed: canStep ? () => unawaited(controller.stepOver()) : null,
),
ButtonGroupItemData(
label: 'Step In',
iconAsset: 'icons/material_symbols/step_into.png',
iconSize: DebuggingControls.materialIconSize,
onPressed: canStep ? () => unawaited(controller.stepIn()) : null,
),
ButtonGroupItemData(
label: 'Step Out',
iconAsset: 'icons/material_symbols/step_out.png',
iconSize: DebuggingControls.materialIconSize,
onPressed: canStep ? () => unawaited(controller.stepOut()) : null,
),
],
minScreenWidthForText: DebuggingControls.minWidth,
);
}
Widget _librariesButton() {
return ValueListenableBuilder<bool>(
valueListenable: controller.codeViewController.fileExplorerVisible,
builder: (context, visible, _) {
return GaDevToolsButton(
icon: Icons.folder_outlined,
label: 'File Explorer',
onPressed: controller.codeViewController.toggleLibrariesVisible,
gaScreen: gac.debugger,
gaSelection: visible
? gac.DebuggerEvents.hideFileExplorer.name
: gac.DebuggerEvents.showFileExplorer.name,
minScreenWidthForText: DebuggingControls.minWidth,
);
},
);
}
}
class CodeStatisticsControls extends StatelessWidget {
const CodeStatisticsControls({super.key, required this.controller});
final DebuggerController controller;
@override
Widget build(BuildContext context) {
return MultiValueListenableBuilder(
listenables: [
controller.codeViewController.showCodeCoverage,
controller.codeViewController.showProfileInformation,
],
builder: (context, values, _) {
final showCodeCoverage = values.first as bool;
final showProfileInformation = values.second as bool;
return Row(
children: [
// TODO(kenz): clean up this button group when records are
// available.
DevToolsToggleButtonGroup(
selectedStates: [showCodeCoverage, showProfileInformation],
children: const [
_CodeStatsControl(
tooltip: 'Show code coverage',
icon: Icons.checklist,
),
_CodeStatsControl(
tooltip: 'Show profiler hits',
icon: Icons.local_fire_department,
),
],
onPressed: (index) {
if (index == 0) {
controller.codeViewController.toggleShowCodeCoverage();
} else if (index == 1) {
controller.codeViewController.toggleShowProfileInformation();
}
},
),
const SizedBox(width: denseSpacing),
RefreshButton(
iconOnly: true,
tooltip: 'Refresh statistics',
gaScreen: gac.debugger,
gaSelection: gac.DebuggerEvents.refreshStatistics.name,
onPressed: showCodeCoverage || showProfileInformation
? () => unawaited(
controller.codeViewController.refreshCodeStatistics(),
)
: null,
),
],
);
},
);
}
}
class _CodeStatsControl extends StatelessWidget {
const _CodeStatsControl({required this.icon, required this.tooltip});
final IconData icon;
final String tooltip;
@override
Widget build(BuildContext context) {
return DevToolsTooltip(
message: tooltip,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: defaultSpacing),
child: Icon(icon, size: defaultIconSize),
),
);
}
}
class BreakOnExceptionsControl extends StatelessWidget {
const BreakOnExceptionsControl({super.key, required this.controller});
final DebuggerController controller;
@override
Widget build(BuildContext context) {
final isInSmallMode =
MediaQuery.of(context).size.width < DebuggingControls.minWidth;
return ValueListenableBuilder<String?>(
valueListenable: controller.exceptionPauseMode,
builder: (BuildContext context, modeId, _) {
final exceptionMode = ExceptionMode.from(modeId);
return DevToolsTooltip(
message: exceptionMode.description,
child: RoundedDropDownButton<ExceptionMode>(
value: exceptionMode,
// Cannot set exception pause mode for system isolates.
onChanged: controller.isSystemIsolate
? null
: (ExceptionMode? mode) {
unawaited(controller.setIsolatePauseMode(mode!.id));
},
isDense: true,
items: [
for (final mode in ExceptionMode.modes)
DropdownMenuItem<ExceptionMode>(
value: mode,
child: Text(isInSmallMode ? mode.name : mode.description),
),
],
),
);
},
);
}
}
class ExceptionMode {
ExceptionMode(this.id, this.name, this.description);
static final modes = [
ExceptionMode(
ExceptionPauseMode.kNone,
'Ignore exceptions',
"Don't stop on exceptions",
),
ExceptionMode(
ExceptionPauseMode.kUnhandled,
'Uncaught exceptions',
'Stop on uncaught exceptions',
),
ExceptionMode(
ExceptionPauseMode.kAll,
'All exceptions',
'Stop on all exceptions',
),
];
static ExceptionMode from(String? id) {
return modes.singleWhere(
(mode) => mode.id == id,
orElse: () => modes.first,
);
}
final String id;
final String name;
final String description;
}