feat(app): finish native run Changes wiring and scaled form menus
This commit is contained in:
@@ -10,6 +10,7 @@ import '../domain/file_change.dart';
|
||||
import '../domain/unified_patch.dart';
|
||||
import 'change_style.dart';
|
||||
import 'patch_view.dart';
|
||||
import 'raw_patch_view.dart';
|
||||
|
||||
/// The reusable viewer for one recorded file change: its kind, path, stat,
|
||||
/// tags, the rendered or raw unified patch, Copy patch (the server's exact
|
||||
@@ -38,6 +39,8 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _selectForm(DiffForm value) => setState(() => _form = value);
|
||||
|
||||
void _close() {
|
||||
final close = widget.onClose;
|
||||
if (close != null) {
|
||||
@@ -147,16 +150,33 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (file.hasPatch)
|
||||
diffFormControl(
|
||||
context,
|
||||
form: _form,
|
||||
onChanged: (value) => setState(() => _form = value),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Two native segmented-control segments cannot show both
|
||||
// fixed words at 2x text on a narrow host; their menu
|
||||
// shows the same labels whole, one per row.
|
||||
final control =
|
||||
diffFormSegmentsFit(context, constraints.maxWidth)
|
||||
? diffFormControl(
|
||||
context,
|
||||
form: _form,
|
||||
onChanged: _selectForm,
|
||||
)
|
||||
: diffFormMenu(
|
||||
context,
|
||||
form: _form,
|
||||
onChanged: _selectForm,
|
||||
);
|
||||
return control;
|
||||
},
|
||||
),
|
||||
_scrollsWhenTooWide(
|
||||
copyPatchControl(
|
||||
context,
|
||||
enabled: file.hasPatch,
|
||||
copied: _copied,
|
||||
onPressed: _copy,
|
||||
),
|
||||
copyPatchControl(
|
||||
context,
|
||||
enabled: file.hasPatch,
|
||||
copied: _copied,
|
||||
onPressed: _copy,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -167,13 +187,13 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
? CupertinoColors.separator.resolveFrom(context)
|
||||
: Theme.of(context).dividerColor,
|
||||
),
|
||||
Flexible(child: _body(context, cupertino, mono)),
|
||||
Flexible(child: _body(context, mono)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(BuildContext context, bool cupertino, TextStyle mono) {
|
||||
Widget _body(BuildContext context, TextStyle mono) {
|
||||
final file = widget.file;
|
||||
if (file.binary) return _message(context, binaryDiffMessage);
|
||||
if (!file.hasPatch) {
|
||||
@@ -184,24 +204,7 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
container: true,
|
||||
label: 'Raw patch for ${file.path}',
|
||||
value: file.patch,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: SingleChildScrollView(
|
||||
// Raw patch bytes are one line each: scroll them sideways like the
|
||||
// web view instead of wrapping a continuation under a new line.
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: ExcludeSemantics(
|
||||
child: SelectionArea(
|
||||
child: Text(
|
||||
file.patch!,
|
||||
style: mono,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.visible,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: RawPatchView(patch: file.patch!, style: mono),
|
||||
);
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
@@ -218,6 +221,15 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives a native control its intrinsic width and lets it scroll sideways when
|
||||
/// the dialog is narrower than the control, instead of letting the control clip
|
||||
/// or break one of its fixed labels.
|
||||
///
|
||||
/// The scroll view shrink-wraps when the control already fits, so the action
|
||||
/// keeps its usual layout until scaled text or a narrow phone demands more room.
|
||||
Widget _scrollsWhenTooWide(Widget control) =>
|
||||
SingleChildScrollView(scrollDirection: Axis.horizontal, child: control);
|
||||
|
||||
/// Open [file] in the platform's standard modal: a Material dialog on
|
||||
/// Android/desktop/web, a Cupertino dialog with a popup surface on iOS/macOS.
|
||||
Future<void> showFileDiffViewer(BuildContext context, FileChange file) {
|
||||
@@ -231,15 +243,20 @@ Future<void> showFileDiffViewer(BuildContext context, FileChange file) {
|
||||
// A popup surface spans the window unless it is inset; on a phone the
|
||||
// screen edge would clip its native rounded corners.
|
||||
final width = MediaQuery.sizeOf(dialogContext).width;
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: width < 600 ? 16 : 40,
|
||||
vertical: 24,
|
||||
),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 900),
|
||||
child: CupertinoPopupSurface(child: SafeArea(child: viewer)),
|
||||
return Theme(
|
||||
// Dialogs open on the app Navigator, above the Changes page's own
|
||||
// brightness-aware theme, so the popup needs its own.
|
||||
data: hostTextTheme(dialogContext),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: width < 600 ? 16 : 40,
|
||||
vertical: 24,
|
||||
),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 900),
|
||||
child: CupertinoPopupSurface(child: SafeArea(child: viewer)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user