Files
cutdex/lib/app/shells/desktop_workspace_shell.dart
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

277 lines
10 KiB
Dart

import '../adaptive/desktop_workspace_controller.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import '../../workspace/workspace_mode.dart';
import '../../shared/layout/workspace_layout_metrics.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_native/cutdex_native.dart';
import '../adaptive/workspace_layout_policy.dart';
typedef WorkspaceSidebarBuilder = Widget Function(
DesktopWorkspaceGeometry geometry,
VoidCallback expandEditor,
);
/// Arranges slots and handles splitters; it does not own editing sessions.
class DesktopWorkspaceShell extends StatefulWidget {
const DesktopWorkspaceShell({
super.key,
required this.mode,
required this.controller,
required this.sidebarCollapsed,
required this.sidebarWidth,
required this.onSidebarCollapsedChanged,
required this.onSidebarWidthChanged,
required this.sidebarBuilder,
required this.editor,
required this.scaffoldKey,
required this.navigationDrawer,
});
final WorkspaceMode mode;
final DesktopWorkspaceController controller;
final bool sidebarCollapsed;
final double? sidebarWidth;
final ValueChanged<bool> onSidebarCollapsedChanged;
final ValueChanged<double> onSidebarWidthChanged;
final WorkspaceSidebarBuilder sidebarBuilder;
final Widget editor;
final GlobalKey<ScaffoldState> scaffoldKey;
final Widget navigationDrawer;
@override
State<DesktopWorkspaceShell> createState() => _DesktopWorkspaceShellState();
}
class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
double? get _agentWidth => widget.controller.agentWidth;
bool get _editorCollapsedByAgent => widget.controller.editorCollapsedByAgent;
@override
void initState() {
super.initState();
widget.controller.addListener(_changed);
}
void _changed() => setState(() {});
@override
void didUpdateWidget(covariant DesktopWorkspaceShell oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) {
oldWidget.controller.removeListener(_changed);
widget.controller.addListener(_changed);
}
}
@override
void dispose() {
widget.controller.removeListener(_changed);
super.dispose();
}
double? _sidebarDragStart;
double _sidebarDragWidth = 0;
double? _agentDragStart;
double _agentDragWidth = 0;
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
final width = constraints.maxWidth;
final geometry = DesktopWorkspaceGeometry.resolve(
width: width,
mode: widget.mode,
sidebarCollapsed: widget.sidebarCollapsed,
sidebarWidth: widget.sidebarWidth,
agentWidth: _agentWidth,
editorCollapsedByAgent: _editorCollapsedByAgent,
);
final navigationSpace = widget.sidebarCollapsed
? 0.0
: geometry.sidebarWidth;
void expandEditor() {
final collapseNavigation = width - navigationSpace - 1 < 780;
if (collapseNavigation) widget.onSidebarCollapsedChanged(true);
widget.controller.setSplit(
width -
(collapseNavigation ? 0 : navigationSpace) -
DesktopWorkspaceGeometry.editorRestoreWidth -
1,
editorCollapsed: false,
);
}
return Scaffold(
key: widget.scaffoldKey,
drawer: Drawer(
width: 320,
child: SafeArea(child: widget.navigationDrawer),
),
body: Stack(
key: const Key('desktop-workspace-shell'),
fit: StackFit.expand,
children: [
Row(
children: [
if (!widget.sidebarCollapsed ||
widget.mode == WorkspaceMode.agent)
SizedBox(
width: navigationSpace + geometry.agentWidth,
child: widget.sidebarBuilder(geometry, expandEditor),
),
if (!widget.sidebarCollapsed && !geometry.editorHidden)
SizedBox(
width: 1,
height: double.infinity,
child: ColoredBox(
key: const Key('project-sidebar-separator'),
color: AppTheme.sidebarDividerColor(context),
),
),
Expanded(
child: Offstage(
key: const Key('editor-auto-collapse'),
offstage: geometry.editorHidden,
child: TickerMode(
enabled: !geometry.editorHidden,
child: OverflowBox(
alignment: Alignment.topLeft,
minWidth: geometry.editorHidden
? DesktopWorkspaceGeometry.editorRestoreWidth
: null,
maxWidth: geometry.editorHidden
? DesktopWorkspaceGeometry.editorRestoreWidth
: null,
child: WindowHeaderPane(
offset: Offset(
navigationSpace +
geometry.agentWidth +
(!widget.sidebarCollapsed &&
!geometry.editorHidden
? 1
: 0),
0,
),
child: widget.editor,
),
),
),
),
),
],
),
if (!widget.sidebarCollapsed)
Positioned(
key: const Key('project-sidebar-divider'),
top: AppControlSize.panelHeader,
bottom: 0,
left: geometry.sidebarWidth - 4,
width: 8,
child: MouseRegion(
cursor: SystemMouseCursors.resizeColumn,
child: GestureDetector(
key: const Key('project-sidebar-resize'),
behavior: HitTestBehavior.opaque,
dragStartBehavior: DragStartBehavior.down,
onHorizontalDragStart: (details) {
_sidebarDragStart = details.globalPosition.dx;
_sidebarDragWidth = geometry.sidebarWidth;
},
onHorizontalDragUpdate: (details) {
final start = _sidebarDragStart;
if (start == null) return;
widget.onSidebarWidthChanged(
(_sidebarDragWidth + details.globalPosition.dx - start)
.clamp(
WorkspaceLayoutMetrics.sidebarMinimumWidth,
DesktopWorkspaceGeometry.sidebarMaximum(
width,
widget.mode,
),
)
.toDouble(),
);
},
onHorizontalDragEnd: (_) => _sidebarDragStart = null,
onHorizontalDragCancel: () => _sidebarDragStart = null,
child: const SizedBox.expand(),
),
),
),
if (widget.mode == WorkspaceMode.agent &&
width - navigationSpace - 1 >= 220)
Positioned(
top: 0,
bottom: 0,
left:
navigationSpace +
geometry.agentWidth -
(geometry.editorHidden ? 8 : 4),
width: 8,
child: MouseRegion(
cursor: SystemMouseCursors.resizeColumn,
child: GestureDetector(
key: const Key('agent-panel-resize'),
behavior: HitTestBehavior.opaque,
dragStartBehavior: DragStartBehavior.down,
onHorizontalDragStart: (details) {
_agentDragStart = details.globalPosition.dx;
_agentDragWidth = geometry.agentWidth;
},
onHorizontalDragUpdate: (details) {
final start = _agentDragStart;
if (start == null) return;
final agentWidth =
(_agentDragWidth + details.globalPosition.dx - start)
.clamp(220.0, width - navigationSpace - 1);
final remaining =
width - navigationSpace - agentWidth - 1;
widget.controller.setSplit(
agentWidth,
editorCollapsed: geometry.editorHidden
? remaining <
DesktopWorkspaceGeometry.editorRestoreWidth
: remaining <=
DesktopWorkspaceGeometry.editorCollapseWidth -
DesktopWorkspaceGeometry
.editorCollapseDragBuffer,
);
},
onHorizontalDragEnd: (_) {
_agentDragStart = null;
if (!_editorCollapsedByAgent &&
_agentWidth != null &&
width -
navigationSpace -
DesktopWorkspaceGeometry.editorCollapseWidth -
1 >=
220) {
widget.controller.setSplit(
_agentWidth!.clamp(
220.0,
width -
navigationSpace -
DesktopWorkspaceGeometry.editorCollapseWidth -
1,
),
editorCollapsed: false,
);
}
},
onHorizontalDragCancel: () => _agentDragStart = null,
child: const SizedBox.expand(),
),
),
),
],
),
);
},
);
}