refactor(desktop): reorganize workspace panels and navigation
Gitea CI / Windows x64 and Android (pull_request) Successful in 16m21s
Gitea CI / Gitea CI passed (pull_request) Successful in 3s

This commit is contained in:
lingjhf committed 2026-10-06 12:11:59 +08:00
1 parent 826745b407
commit 1f73765745
92 files changed
+5811 -2650

No files matched your search

+400 -276
View File
@@ -1,5 +1,8 @@
import 'package:cutdex/shared/widgets/error_notification_host.dart';
import '../../integrations/platform/device_experience.dart';
import 'touch_project_navigation.dart';
import '../media/media_panel.dart';
import 'package:cutdex_ui/theme.dart';
@@ -8,6 +11,9 @@ import 'dart:async';
import 'package:cutdex/l10n/l10n.dart';
import 'package:flutter/material.dart';
import '../../shared/widgets/listenable_selector.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../integrations/platform/editor_window_chrome.dart';
@@ -38,6 +44,8 @@ class ProjectSidebar extends ConsumerStatefulWidget {
super.key,
required this.agent,
this.navigationOnly = false,
this.resourcesSelected = false,
this.externalWindowFrame = false,
this.experience = DeviceExperience.desktop,
this.onNavigationComplete,
required this.mode,
@@ -58,6 +66,8 @@ class ProjectSidebar extends ConsumerStatefulWidget {
final Widget agent;
final bool navigationOnly;
final bool resourcesSelected;
final bool externalWindowFrame;
final DeviceExperience experience;
final VoidCallback? onNavigationComplete;
final ProjectState state;
@@ -80,6 +90,7 @@ class ProjectSidebar extends ConsumerStatefulWidget {
}
class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
bool _resourcesVisited = false;
bool get _touch => widget.experience != DeviceExperience.desktop;
bool _projectHeaderHovered = false;
String? _hoveredProjectId;
@@ -87,6 +98,30 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
final Set<String> _expandedConversationProjects = {};
final Set<String> _collapsedProjects = {};
bool _showTrash = false;
late final ValueNotifier<String?> _projectSelection;
final _groupWidgets = <String, (Object, Widget)>{};
@override
void initState() {
super.initState();
_resourcesVisited = widget.resourcesSelected;
_projectSelection = ValueNotifier(widget.selectedProjectId);
}
@override
void didUpdateWidget(covariant ProjectSidebar oldWidget) {
super.didUpdateWidget(oldWidget);
_resourcesVisited |= widget.resourcesSelected;
_projectSelection.value = widget.selectedProjectId;
final ids = widget.state.recent.map((project) => project.id).toSet();
_groupWidgets.removeWhere((id, _) => !ids.contains(id));
}
@override
void dispose() {
_projectSelection.dispose();
super.dispose();
}
ConversationSidebar get _conversations =>
ref.read(conversationSidebarProvider.notifier);
@@ -98,11 +133,8 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
}
Map<String, List<ConversationMetadata>> get _conversationsByProject =>
_snapshot.groups;
ref.read(conversationSidebarProvider).value?.groups ?? const {};
List<ConversationMetadata> get _trashed => _snapshot.trashed;
String? get _selectedConversationId => ref
.read(conversationSelectionProvider(widget.state.activeProject?.id))
.selectedId;
String? get _conversationError =>
(ref.read(conversationSidebarProvider).hasError || _snapshot.reloadFailed)
? context.l10n.agentSessionRestoreFailed
@@ -253,9 +285,9 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
await _conversations.delete(item);
} catch (_) {
if (mounted) {
ScaffoldMessenger.of(
ErrorNotificationHost.of(
context,
).showSnackBar(SnackBar(content: Text(context.l10n.operationFailed)));
).show(ErrorNotification(content: Text(context.l10n.operationFailed)));
}
}
}
@@ -293,74 +325,84 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
) ==
true;
Widget _conversationRow(ConversationMetadata item) {
final selected =
widget.state.activeProject?.id == item.projectId &&
_selectedConversationId == item.id;
List<Widget> actions(BuildContext context) => [
AppMenuItem(
label: context.l10n.rename,
onPressed: () => _renameConversation(item),
),
AppMenuItem(
label: context.l10n.agentMoveToTrash,
onPressed: () => _trashConversation(item),
),
AppMenuItem(
label: context.l10n.agentRelinkProvider,
onPressed: () => _relinkProvider(item),
),
const AppMenuSeparator(),
AppMenuItem(
label: '${context.l10n.agentDeleteForever}…',
destructive: true,
onPressed: () => _deleteForever(item),
),
];
if (_touch) {
return TouchConversationTile(
id: item.id,
title: item.title,
selected: selected,
onSelect: () => _selectConversation(item),
actions: actions,
Widget _conversationRow(ConversationMetadata item) => Consumer(
builder: (context, ref, _) {
final active = ref.watch(
projectsProvider.select(
(value) => value.value?.activeProject?.id == item.projectId,
),
);
}
return Padding(
padding: AppSidebarMetrics.rowPadding,
child: AppContextMenu(
itemsBuilder: actions,
child: Material(
color: selected
? AppSidebarColors.of(context).hover
: Colors.transparent,
borderRadius: BorderRadius.circular(AppSidebarMetrics.radius),
child: InkWell(
key: ValueKey('sidebar-conversation-${item.id}'),
hoverColor: selected
? Colors.transparent
: AppSidebarColors.of(context).hover,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
final selected =
ref.watch(
conversationSelectionProvider(item.projectId)
.select((value) => value.selectedId == item.id),
) &&
active;
List<Widget> actions(BuildContext context) => [
AppMenuItem(
label: context.l10n.rename,
onPressed: () => _renameConversation(item),
),
AppMenuItem(
label: context.l10n.agentMoveToTrash,
onPressed: () => _trashConversation(item),
),
AppMenuItem(
label: context.l10n.agentRelinkProvider,
onPressed: () => _relinkProvider(item),
),
const AppMenuSeparator(),
AppMenuItem(
label: '${context.l10n.agentDeleteForever}…',
destructive: true,
onPressed: () => _deleteForever(item),
),
];
if (_touch) {
return TouchConversationTile(
id: item.id,
title: item.title,
selected: selected,
onSelect: () => _selectConversation(item),
actions: actions,
);
}
return Padding(
padding: AppSidebarMetrics.rowPadding,
child: AppContextMenu(
itemsBuilder: actions,
child: Material(
color: selected
? AppSidebarColors.of(context).hover
: Colors.transparent,
borderRadius: BorderRadius.circular(AppSidebarMetrics.radius),
onTap: () => _selectConversation(item),
child: SizedBox(
height: AppSidebarMetrics.rowHeight,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: AppSidebarMetrics.textInset,
end: AppSidebarMetrics.cellPadding,
),
child: Text(
item.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppSidebarTypography.style(
context,
fontSize: AppSidebarMetrics.conversationFontSize,
height: AppSidebarMetrics.conversationLineHeight,
child: InkWell(
key: ValueKey('sidebar-conversation-${item.id}'),
hoverColor: selected
? Colors.transparent
: AppSidebarColors.of(context).hover,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
borderRadius: BorderRadius.circular(AppSidebarMetrics.radius),
onTap: () => _selectConversation(item),
child: SizedBox(
height: AppSidebarMetrics.rowHeight,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: AppSidebarMetrics.textInset,
end: AppSidebarMetrics.cellPadding,
),
child: Text(
item.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppSidebarTypography.style(
context,
fontSize: AppSidebarMetrics.conversationFontSize,
height: AppSidebarMetrics.conversationLineHeight,
),
),
),
),
@@ -368,11 +410,39 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
),
),
),
),
);
}
);
},
);
Widget _projectGroup(RecentProject project) {
final configuration = (
project,
_touch,
Localizations.localeOf(context),
Theme.of(context),
_expandedConversationProjects.contains(project.id),
_collapsedProjects.contains(project.id),
_hoveredProjectId == project.id,
widget.state.projectBusy,
);
final cached = _groupWidgets[project.id];
if (cached?.$1 == configuration) return cached!.$2;
final group = Consumer(
key: ValueKey('sidebar-project-binding-${project.id}'),
builder: (context, ref, _) {
ref.watch(
conversationSidebarProvider.select(
(value) => value.value?.groups[project.id],
),
);
return _buildProjectGroup(project);
},
);
_groupWidgets[project.id] = (configuration, group);
return group;
}
Widget _buildProjectGroup(RecentProject project) {
final conversations = _conversationsByProject[project.id] ?? const [];
final expanded = _expandedConversationProjects.contains(project.id);
final collapsed = _collapsedProjects.contains(project.id);
@@ -382,6 +452,7 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
? conversations
: conversations.take(5);
return Column(
key: ValueKey('sidebar-project-group-${project.id}'),
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
MouseRegion(
@@ -391,65 +462,70 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
setState(() => _hoveredProjectId = null);
}
},
child: _touch
? TouchProjectTile(
project: project,
selected: widget.selectedProjectId == project.id,
expanded: !collapsed,
availabilityLabel: _availabilityLabel(
context,
project.availability,
),
onSelect: () => _selectProjectFromNavigation(project),
onToggle: () => setState(() {
if (collapsed) {
_collapsedProjects.remove(project.id);
} else {
_collapsedProjects.add(project.id);
}
}),
onNewConversation:
widget.state.projectBusy || !project.availability.canOpen
? null
: () => _newConversationForProject(project),
onRename: project.availability.canOpen
? () => widget.onRenameProject(project)
: null,
onRemove: widget.state.projectBusy
? null
: () => _removeProject(project),
)
: Padding(
padding: AppSidebarMetrics.rowPadding,
child: _ProjectTile(
child: ListenableSelector(
listenable: _projectSelection,
select: () => _projectSelection.value == project.id,
builder: (context, selected) => _touch
? TouchProjectTile(
project: project,
active: widget.selectedProjectId == project.id,
selected: selected,
expanded: !collapsed,
availabilityLabel: _availabilityLabel(
context,
project.availability,
),
onSelect: () {
_cutProjectsMenu.close();
_selectProjectFromNavigation(project);
},
onRename: () => widget.onRenameProject(project),
onRemove: widget.state.projectBusy
? null
: () => _removeProject(project),
expanded: !collapsed,
onToggleExpanded: () => setState(() {
onSelect: () => _selectProjectFromNavigation(project),
onToggle: () => setState(() {
if (collapsed) {
_collapsedProjects.remove(project.id);
} else {
_collapsedProjects.add(project.id);
}
}),
sidebarStyle: true,
hovered: _hoveredProjectId == project.id,
onNewConversation: () =>
_newConversationForProject(project),
onNewConversation:
widget.state.projectBusy ||
!project.availability.canOpen
? null
: () => _newConversationForProject(project),
onRename: project.availability.canOpen
? () => widget.onRenameProject(project)
: null,
onRemove: widget.state.projectBusy
? null
: () => _removeProject(project),
)
: Padding(
padding: AppSidebarMetrics.rowPadding,
child: _ProjectTile(
project: project,
active: selected,
availabilityLabel: _availabilityLabel(
context,
project.availability,
),
onSelect: () {
_cutProjectsMenu.close();
_selectProjectFromNavigation(project);
},
onRename: () => widget.onRenameProject(project),
onRemove: widget.state.projectBusy
? null
: () => _removeProject(project),
expanded: !collapsed,
onToggleExpanded: () => setState(() {
if (collapsed) {
_collapsedProjects.remove(project.id);
} else {
_collapsedProjects.add(project.id);
}
}),
sidebarStyle: true,
hovered: _hoveredProjectId == project.id,
onNewConversation: () =>
_newConversationForProject(project),
),
),
),
),
),
for (final item in visible) ...[
const SizedBox(height: AppSidebarMetrics.rowGap),
@@ -516,18 +592,21 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
@override
Widget build(BuildContext context) {
ref.watch(conversationSidebarProvider);
ref.watch(conversationSelectionProvider(widget.state.activeProject?.id));
final compact = MediaQuery.sizeOf(context).height < 520;
final headerHeight = widget.navigationOnly
final headerHeight = widget.externalWindowFrame
? 0.0
: widget.navigationOnly
? 48.0
: widget.integratedTitlebar
? AppControlSize.panelHeader
: AppControlSize.headerButton;
final modeTop = headerHeight;
final modeHeader = SizedBox(
key: const Key('project-content-header'),
height:
modeTop + AppSidebarMetrics.modeHeight + AppSidebarMetrics.sectionGap,
modeTop +
(_touch ? AppSidebarMetrics.modeHeight : 0) +
(widget.externalWindowFrame ? 0 : AppSidebarMetrics.sectionGap),
child: Stack(
children: [
Positioned(
@@ -554,94 +633,95 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
),
),
),
Positioned(
top: modeTop,
left: AppSidebarMetrics.outerPadding,
right: AppSidebarMetrics.outerPadding,
height: AppSidebarMetrics.modeHeight,
child: Align(
alignment: AlignmentDirectional.topStart,
child: AppPopover(
width: AppMenuMetrics.modeMenuWidth,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
for (final mode in WorkspaceMode.values)
AppMenuItem(
key: ValueKey('sidebar-mode-${mode.name}'),
label: mode == WorkspaceMode.agent
? context.l10n.workspaceAgent
: context.l10n.workspaceCut,
selected: widget.mode == mode,
description: mode == WorkspaceMode.agent
? context.l10n.agentLayoutDescription
: context.l10n.editingLayoutDescription,
onPressed: () {
widget.onModeChanged(mode);
if (widget.navigationOnly) _finishNavigation();
},
),
],
),
builder: (context, toggle) => TextButton(
key: const Key('sidebar-mode-trigger'),
onPressed: toggle,
style: ButtonStyle(
foregroundColor: sidebarActionButtonStyle(context)
.foregroundColor,
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 8),
),
minimumSize: const WidgetStatePropertyAll(
Size(0, AppSidebarMetrics.modeHeight),
),
alignment: AlignmentDirectional.centerStart,
backgroundColor: WidgetStateProperty.resolveWith(
(states) =>
states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused) ||
states.contains(WidgetState.pressed)
? AppSidebarColors.of(context).hover
: Colors.transparent,
),
overlayColor: const WidgetStatePropertyAll(
Colors.transparent,
),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
child: Row(
if (_touch)
Positioned(
top: modeTop,
left: AppSidebarMetrics.outerPadding,
right: AppSidebarMetrics.outerPadding,
height: AppSidebarMetrics.modeHeight,
child: Align(
alignment: AlignmentDirectional.topStart,
child: AppPopover(
width: AppMenuMetrics.modeMenuWidth,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
widget.mode == WorkspaceMode.agent
for (final mode in WorkspaceMode.values)
AppMenuItem(
key: ValueKey('sidebar-mode-${mode.name}'),
label: mode == WorkspaceMode.agent
? context.l10n.workspaceAgent
: context.l10n.workspaceCut,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppSidebarTypography.style(
context,
fontSize: AppSidebarMetrics.titleFontSize,
height: AppSidebarMetrics.titleLineHeight,
weight: FontWeight.w600,
),
selected: widget.mode == mode,
description: mode == WorkspaceMode.agent
? context.l10n.agentLayoutDescription
: context.l10n.editingLayoutDescription,
onPressed: () {
widget.onModeChanged(mode);
if (widget.navigationOnly) _finishNavigation();
},
),
],
),
builder: (context, toggle) => TextButton(
key: const Key('sidebar-mode-trigger'),
onPressed: toggle,
style: ButtonStyle(
foregroundColor: sidebarActionButtonStyle(context)
.foregroundColor,
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 8),
),
minimumSize: const WidgetStatePropertyAll(
Size(0, AppSidebarMetrics.modeHeight),
),
alignment: AlignmentDirectional.centerStart,
backgroundColor: WidgetStateProperty.resolveWith(
(states) =>
states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused) ||
states.contains(WidgetState.pressed)
? AppSidebarColors.of(context).hover
: Colors.transparent,
),
overlayColor: const WidgetStatePropertyAll(
Colors.transparent,
),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
const SizedBox(width: AppSpacing.small),
const Icon(
Icons.keyboard_arrow_down,
size: AppSidebarMetrics.iconSize,
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
widget.mode == WorkspaceMode.agent
? context.l10n.workspaceAgent
: context.l10n.workspaceCut,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppSidebarTypography.style(
context,
fontSize: AppSidebarMetrics.titleFontSize,
height: AppSidebarMetrics.titleLineHeight,
weight: FontWeight.w600,
),
),
),
const SizedBox(width: AppSpacing.small),
const Icon(
Icons.keyboard_arrow_down,
size: AppSidebarMetrics.iconSize,
),
],
),
),
),
),
),
),
],
),
);
@@ -656,9 +736,9 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
onEnter: (_) => setState(() => _projectHeaderHovered = true),
onExit: (_) => setState(() => _projectHeaderHovered = false),
child: Padding(
padding: const EdgeInsets.fromLTRB(
padding: EdgeInsets.fromLTRB(
AppSidebarMetrics.outerPadding,
0,
_touch ? 0 : AppSpacing.gap,
AppSidebarMetrics.outerPadding,
AppSidebarMetrics.sectionGap,
),
@@ -692,79 +772,102 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
if (index > 0) const SizedBox(height: AppSidebarMetrics.projectGap),
_projectGroup(widget.state.recent[index]),
],
if (_conversationError != null)
Padding(
padding: const EdgeInsets.all(AppSpacing.small),
child: Text(
_conversationError!,
style: Theme.of(context).textTheme.bodySmall,
),
),
if (widget.state.activeProject != null &&
(_trashed.isNotEmpty || _showTrash))
ExpansionTile(
title: Text(
context.l10n.agentTrash,
style: AppSidebarTypography.style(
context,
color: AppSidebarColors.of(context).tertiary,
weight: FontWeight.w500,
Consumer(
builder: (context, ref, _) {
ref.watch(
conversationSidebarProvider.select(
(value) => (value.hasError, value.value?.reloadFailed),
),
),
initiallyExpanded: _showTrash,
onExpansionChanged: (value) => setState(() => _showTrash = value),
trailing: _trashed.isEmpty
? null
: TextButton(
onPressed: _emptyTrash,
child: Text(context.l10n.agentEmptyTrash),
),
children: [
ListView.builder(
primary: false,
shrinkWrap: true,
itemCount: _trashed.length,
itemBuilder: (context, index) {
final item = _trashed[index];
return ListTile(
dense: true,
title: Text(
item.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppSidebarTypography.style(
context,
fontSize: AppSidebarMetrics.fontSize,
height: AppSidebarMetrics.lineHeight,
color: AppSidebarColors.of(context).secondary,
),
),
trailing: PopupMenuButton<String>(
tooltip: context.l10n.agentConversationActions,
onSelected: (value) {
if (value == 'restore') {
_restoreConversation(item);
}
if (value == 'delete') _deleteForever(item);
},
itemBuilder: (context) => [
PopupMenuItem(
height: AppMenuMetrics.rowHeight,
value: 'restore',
child: Text(context.l10n.agentRestore),
),
PopupMenuItem(
height: AppMenuMetrics.rowHeight,
value: 'delete',
child: Text(context.l10n.agentDeleteForever),
),
],
);
return _conversationError == null
? const SizedBox.shrink()
: Padding(
padding: const EdgeInsets.all(AppSpacing.small),
child: Text(
_conversationError!,
style: Theme.of(context).textTheme.bodySmall,
),
);
},
},
),
Consumer(
builder: (context, ref, _) {
ref.watch(
conversationSidebarProvider.select(
(value) => (value.value?.projectId, value.value?.trashed),
),
],
),
);
return widget.state.activeProject == null ||
(_trashed.isEmpty && !_showTrash)
? const SizedBox.shrink()
: ExpansionTile(
title: Text(
context.l10n.agentTrash,
style: AppSidebarTypography.style(
context,
color: AppSidebarColors.of(context).tertiary,
weight: FontWeight.w500,
),
),
initiallyExpanded: _showTrash,
onExpansionChanged: (value) =>
setState(() => _showTrash = value),
trailing: _trashed.isEmpty
? null
: TextButton(
onPressed: _emptyTrash,
child: Text(context.l10n.agentEmptyTrash),
),
children: [
ListView.builder(
primary: false,
shrinkWrap: true,
itemCount: _trashed.length,
itemBuilder: (context, index) {
final item = _trashed[index];
return ListTile(
dense: true,
title: Text(
item.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppSidebarTypography.style(
context,
fontSize: AppSidebarMetrics.fontSize,
height: AppSidebarMetrics.lineHeight,
color: AppSidebarColors.of(context).secondary,
),
),
trailing: PopupMenuButton<String>(
tooltip: context.l10n.agentConversationActions,
onSelected: (value) {
if (value == 'restore') {
_restoreConversation(item);
}
if (value == 'delete') _deleteForever(item);
},
itemBuilder: (context) => [
PopupMenuItem(
height: AppMenuMetrics.rowHeight,
value: 'restore',
child: Text(context.l10n.agentRestore),
),
PopupMenuItem(
height: AppMenuMetrics.rowHeight,
value: 'delete',
child: Text(
context.l10n.agentDeleteForever,
),
),
],
),
);
},
),
],
);
},
),
],
),
);
@@ -776,7 +879,28 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
modeHeader,
Expanded(child: projectList),
Expanded(
child: _touch
? projectList
: IndexedStack(
index: widget.resourcesSelected ? 1 : 0,
children: [
TickerMode(
enabled: !widget.resourcesSelected,
child: projectList,
),
TickerMode(
enabled: widget.resourcesSelected,
child: _resourcesVisited
? MediaPanel(
projectId: widget.state.activeProject?.id,
onSelectProject: widget.onSelectProject,
)
: Center(child: Text(context.l10n.projectsNone)),
),
],
),
),
],
),
);