refactor(desktop): reorganize workspace panels and navigation
This commit is contained in:
1 parent
826745b407
commit
1f73765745
92 files changed
+5811
-2650
No files matched your search
@@ -0,0 +1,163 @@
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../integrations/platform/editor_window_chrome.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../shared/layout/workspace_layout_metrics.dart';
|
||||
import '../../workspace/workspace_mode.dart';
|
||||
|
||||
/// Keeps window chrome outside the shared workspace surface.
|
||||
class DesktopWindowFrame extends StatelessWidget {
|
||||
const DesktopWindowFrame({
|
||||
super.key,
|
||||
required this.integratedTitlebar,
|
||||
required this.headerControls,
|
||||
required this.librarySelected,
|
||||
this.settingsSelected = false,
|
||||
required this.onModeChanged,
|
||||
required this.onLibraryPressed,
|
||||
required this.onSettingsPressed,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
static const railWidth = 44.0;
|
||||
static const railButtonSize = 32.0;
|
||||
static const railIconSize = 22.0;
|
||||
static const headerHeight = 40.0;
|
||||
static const contentInset = WorkspaceLayoutMetrics.desktopSpacing;
|
||||
final bool integratedTitlebar;
|
||||
final Widget headerControls;
|
||||
final bool librarySelected;
|
||||
final bool settingsSelected;
|
||||
final ValueChanged<WorkspaceMode> onModeChanged;
|
||||
final VoidCallback? onLibraryPressed;
|
||||
final VoidCallback onSettingsPressed;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
key: const Key('desktop-window-header'),
|
||||
height: headerHeight,
|
||||
child: WindowHeaderPadding(
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
if (integratedTitlebar)
|
||||
SizedBox(
|
||||
key: const Key('native-window-controls-space'),
|
||||
width: EditorWindowChrome.leadingWidth,
|
||||
height: headerHeight,
|
||||
),
|
||||
headerControls,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
key: const Key('desktop-navigation-rail'),
|
||||
width: railWidth,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final library in [false, true])
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: IconButton.filledTonal(
|
||||
key: ValueKey(
|
||||
library
|
||||
? 'desktop-rail-library'
|
||||
: 'desktop-rail-cut',
|
||||
),
|
||||
tooltip: library
|
||||
? context.l10n.navigationLibrary
|
||||
: context.l10n.navigationChat,
|
||||
isSelected:
|
||||
!settingsSelected && library == librarySelected,
|
||||
style: IconButton.styleFrom(
|
||||
fixedSize: const Size.square(railButtonSize),
|
||||
minimumSize: const Size.square(railButtonSize),
|
||||
maximumSize: const Size.square(railButtonSize),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: railIconSize,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
backgroundColor:
|
||||
!settingsSelected &&
|
||||
library == librarySelected
|
||||
? null
|
||||
: Colors.transparent,
|
||||
),
|
||||
onPressed: library
|
||||
? onLibraryPressed
|
||||
: () => onModeChanged(WorkspaceMode.cut),
|
||||
icon: Icon(
|
||||
library
|
||||
? Icons.video_library_outlined
|
||||
: Icons.chat_bubble_outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
key: const Key('project-settings-button'),
|
||||
tooltip: context.l10n.settings,
|
||||
isSelected: settingsSelected,
|
||||
onPressed: onSettingsPressed,
|
||||
style: IconButton.styleFrom(
|
||||
fixedSize: const Size.square(railButtonSize),
|
||||
minimumSize: const Size.square(railButtonSize),
|
||||
maximumSize: const Size.square(railButtonSize),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: railIconSize,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
icon: const Icon(Icons.settings_outlined),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
right: contentInset,
|
||||
bottom: contentInset,
|
||||
),
|
||||
child: SizedBox(
|
||||
key: const Key('desktop-content-container'),
|
||||
child: WindowHeaderPane(
|
||||
offset: const Offset(railWidth, headerHeight),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
constraints.maxWidth < 200
|
||||
? SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: SizedBox(
|
||||
width: 200,
|
||||
height: constraints.maxHeight,
|
||||
child: child,
|
||||
),
|
||||
)
|
||||
: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1,22 +1,18 @@
|
||||
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/desktop_workspace_controller.dart';
|
||||
import '../adaptive/workspace_layout_policy.dart';
|
||||
import '../../shared/layout/workspace_layout_metrics.dart';
|
||||
import '../../shared/widgets/workspace_card.dart';
|
||||
import '../../shared/widgets/workspace_resize_handle.dart';
|
||||
import '../../workspace/workspace_mode.dart';
|
||||
|
||||
typedef WorkspaceSidebarBuilder = Widget Function(
|
||||
DesktopWorkspaceGeometry geometry,
|
||||
VoidCallback expandEditor,
|
||||
);
|
||||
|
||||
/// Arranges slots and handles splitters; it does not own editing sessions.
|
||||
/// Three independent desktop surfaces with resize gutters between them.
|
||||
class DesktopWorkspaceShell extends StatefulWidget {
|
||||
const DesktopWorkspaceShell({
|
||||
super.key,
|
||||
@@ -27,11 +23,13 @@ class DesktopWorkspaceShell extends StatefulWidget {
|
||||
required this.onSidebarCollapsedChanged,
|
||||
required this.onSidebarWidthChanged,
|
||||
required this.sidebarBuilder,
|
||||
required this.agentBuilder,
|
||||
required this.editor,
|
||||
required this.scaffoldKey,
|
||||
required this.navigationDrawer,
|
||||
});
|
||||
|
||||
static const gutterWidth = WorkspaceLayoutMetrics.desktopSpacing;
|
||||
final WorkspaceMode mode;
|
||||
final DesktopWorkspaceController controller;
|
||||
final bool sidebarCollapsed;
|
||||
@@ -39,6 +37,7 @@ class DesktopWorkspaceShell extends StatefulWidget {
|
||||
final ValueChanged<bool> onSidebarCollapsedChanged;
|
||||
final ValueChanged<double> onSidebarWidthChanged;
|
||||
final WorkspaceSidebarBuilder sidebarBuilder;
|
||||
final WorkspaceSidebarBuilder agentBuilder;
|
||||
final Widget editor;
|
||||
final GlobalKey<ScaffoldState> scaffoldKey;
|
||||
final Widget navigationDrawer;
|
||||
@@ -48,9 +47,6 @@ class DesktopWorkspaceShell extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
double? get _agentWidth => widget.controller.agentWidth;
|
||||
bool get _editorCollapsedByAgent => widget.controller.editorCollapsedByAgent;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -74,65 +70,101 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
double? _sidebarDragStart;
|
||||
double _sidebarDragWidth = 0;
|
||||
double? _agentDragStart;
|
||||
double _agentDragWidth = 0;
|
||||
Widget _card(String name, Widget child) =>
|
||||
WorkspaceCard(key: Key('desktop-$name-card'), child: child);
|
||||
|
||||
Widget _gutter({
|
||||
required String name,
|
||||
required double initialWidth,
|
||||
required ValueChanged<double> onResize,
|
||||
double direction = 1,
|
||||
VoidCallback? onEnd,
|
||||
}) => SizedBox(
|
||||
width: WorkspaceLayoutMetrics.desktopResizeHitExtent,
|
||||
height: double.infinity,
|
||||
child: WorkspaceResizeHandle(
|
||||
key: Key('$name-resize'),
|
||||
axis: Axis.horizontal,
|
||||
initialValue: initialWidth,
|
||||
direction: direction,
|
||||
onResize: onResize,
|
||||
onEnd: onEnd,
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
const gap = DesktopWorkspaceShell.gutterWidth;
|
||||
final width = constraints.maxWidth;
|
||||
final geometry = DesktopWorkspaceGeometry.resolve(
|
||||
width: width,
|
||||
mode: widget.mode,
|
||||
final navigationGap = widget.sidebarCollapsed ? 0.0 : gap;
|
||||
final resolved = DesktopWorkspaceGeometry.resolve(
|
||||
// The geometry policy accounts for a one-pixel divider; reserve gutters.
|
||||
width: width - navigationGap - gap + 1,
|
||||
mode: WorkspaceMode.agent,
|
||||
sidebarCollapsed: widget.sidebarCollapsed,
|
||||
sidebarWidth: widget.sidebarWidth,
|
||||
agentWidth: _agentWidth,
|
||||
editorCollapsedByAgent: _editorCollapsedByAgent,
|
||||
agentWidth: widget.controller.agentWidth,
|
||||
agentFullscreen: widget.controller.agentFullscreen,
|
||||
);
|
||||
final navigationSpace = widget.sidebarCollapsed
|
||||
? 0.0
|
||||
: geometry.sidebarWidth;
|
||||
: resolved.sidebarWidth;
|
||||
final agentHidden =
|
||||
resolved.editorHidden &&
|
||||
widget.mode == WorkspaceMode.cut &&
|
||||
!widget.controller.agentFullscreen;
|
||||
final geometry = DesktopWorkspaceGeometry(
|
||||
sidebarWidth: resolved.sidebarWidth,
|
||||
agentWidth: agentHidden
|
||||
? 0
|
||||
: resolved.editorHidden
|
||||
? width - navigationSpace - navigationGap
|
||||
: resolved.agentWidth,
|
||||
editorHidden: resolved.editorHidden && !agentHidden,
|
||||
);
|
||||
final available = width - navigationSpace - navigationGap;
|
||||
void expandEditor() {
|
||||
final collapseNavigation = width - navigationSpace - 1 < 780;
|
||||
final collapseNavigation =
|
||||
available < 220 + gap + DesktopWorkspaceGeometry.editorMinimumWidth;
|
||||
if (collapseNavigation) widget.onSidebarCollapsedChanged(true);
|
||||
widget.controller.setSplit(
|
||||
width -
|
||||
(collapseNavigation ? 0 : navigationSpace) -
|
||||
DesktopWorkspaceGeometry.editorRestoreWidth -
|
||||
1,
|
||||
editorCollapsed: false,
|
||||
);
|
||||
widget.controller.setAgentFullscreen(false);
|
||||
}
|
||||
|
||||
void resizeAgent(double requested) {
|
||||
final maximum =
|
||||
available - gap - DesktopWorkspaceGeometry.editorMinimumWidth;
|
||||
if (maximum < 220) return;
|
||||
final agentWidth = requested.clamp(220.0, maximum);
|
||||
widget.controller.setAgentWidth(agentWidth);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
key: widget.scaffoldKey,
|
||||
backgroundColor: Colors.transparent,
|
||||
drawer: Drawer(
|
||||
width: 320,
|
||||
child: SafeArea(child: widget.navigationDrawer),
|
||||
),
|
||||
body: Stack(
|
||||
key: const Key('desktop-workspace-shell'),
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (!widget.sidebarCollapsed ||
|
||||
widget.mode == WorkspaceMode.agent)
|
||||
if (!widget.sidebarCollapsed) ...[
|
||||
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),
|
||||
width: navigationSpace,
|
||||
child: _card(
|
||||
'project',
|
||||
widget.sidebarBuilder(geometry, expandEditor),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
key: Key('project-sidebar-divider'),
|
||||
width: gap,
|
||||
),
|
||||
],
|
||||
Expanded(
|
||||
child: Offstage(
|
||||
key: const Key('editor-auto-collapse'),
|
||||
@@ -147,125 +179,66 @@ class _DesktopWorkspaceShellState extends State<DesktopWorkspaceShell> {
|
||||
maxWidth: geometry.editorHidden
|
||||
? DesktopWorkspaceGeometry.editorRestoreWidth
|
||||
: null,
|
||||
child: WindowHeaderPane(
|
||||
offset: Offset(
|
||||
navigationSpace +
|
||||
geometry.agentWidth +
|
||||
(!widget.sidebarCollapsed &&
|
||||
!geometry.editorHidden
|
||||
? 1
|
||||
: 0),
|
||||
0,
|
||||
),
|
||||
child: SizedBox(
|
||||
key: const Key('desktop-editor-card'),
|
||||
child: widget.editor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!agentHidden && !geometry.editorHidden)
|
||||
const SizedBox(width: gap),
|
||||
if (!agentHidden)
|
||||
SizedBox(
|
||||
key: const Key('desktop-agent-slot'),
|
||||
width: geometry.agentWidth,
|
||||
child: _card(
|
||||
'agent',
|
||||
widget.agentBuilder(geometry, expandEditor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!widget.sidebarCollapsed)
|
||||
Positioned(
|
||||
key: const Key('project-sidebar-divider'),
|
||||
top: AppControlSize.panelHeader,
|
||||
left:
|
||||
navigationSpace - WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
top: 0,
|
||||
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(),
|
||||
child: _gutter(
|
||||
name: 'project-sidebar',
|
||||
initialWidth: navigationSpace,
|
||||
onResize: (value) => widget.onSidebarWidthChanged(
|
||||
value.clamp(
|
||||
WorkspaceLayoutMetrics.sidebarMinimumWidth,
|
||||
DesktopWorkspaceGeometry.sidebarMaximum(
|
||||
width - 2 * gap + 1,
|
||||
WorkspaceMode.agent,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.mode == WorkspaceMode.agent &&
|
||||
width - navigationSpace - 1 >= 220)
|
||||
if (!agentHidden && !geometry.editorHidden)
|
||||
Positioned(
|
||||
left: geometry.editorHidden
|
||||
? navigationSpace +
|
||||
navigationGap +
|
||||
(widget.sidebarCollapsed
|
||||
? 0
|
||||
: WorkspaceLayoutMetrics.desktopResizeSlop)
|
||||
: width -
|
||||
geometry.agentWidth -
|
||||
gap -
|
||||
WorkspaceLayoutMetrics.desktopResizeSlop,
|
||||
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(),
|
||||
),
|
||||
child: _gutter(
|
||||
name: 'agent-panel',
|
||||
initialWidth: geometry.agentWidth,
|
||||
direction: -1,
|
||||
onResize: resizeAgent,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user