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.
1276 lines
47 KiB
Dart
1276 lines
47 KiB
Dart
import '../../integrations/platform/device_experience.dart';
|
|
import 'touch_project_navigation.dart';
|
|
|
|
import 'package:cutdex_ui/theme.dart';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:cutdex/l10n/l10n.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/editor_window_chrome.dart';
|
|
|
|
import 'package:cutdex_native/cutdex_native.dart';
|
|
|
|
import '../../shared/layout/workspace_layout_metrics.dart';
|
|
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
|
|
import '../../workspace/projects.dart';
|
|
import '../../workspace/workspace_mode.dart';
|
|
|
|
import '../../workspace/project_state.dart';
|
|
|
|
import '../../integrations/agent/conversation_repository.dart'
|
|
show ConversationMetadata;
|
|
import '../../integrations/agent/agent_settings.dart';
|
|
import '../../integrations/agent/agent_models.dart';
|
|
|
|
import 'widgets/name_dialog.dart';
|
|
import 'conversation_sidebar.dart';
|
|
|
|
typedef ProjectRenamer = Future<bool> Function(RecentProject project);
|
|
|
|
class ProjectSidebar extends ConsumerStatefulWidget {
|
|
const ProjectSidebar({
|
|
super.key,
|
|
required this.agent,
|
|
this.navigationOnly = false,
|
|
this.experience = DeviceExperience.desktop,
|
|
this.onNavigationComplete,
|
|
required this.mode,
|
|
required this.onModeChanged,
|
|
required this.navigationWidth,
|
|
required this.navigationCollapsed,
|
|
required this.agentHeaderLeading,
|
|
required this.editorHidden,
|
|
required this.onExpandEditor,
|
|
required this.state,
|
|
required this.selectedProjectId,
|
|
required this.integratedTitlebar,
|
|
required this.onCreateProject,
|
|
required this.onSelectProject,
|
|
required this.onRenameProject,
|
|
required this.headerControls,
|
|
});
|
|
|
|
final Widget agent;
|
|
final bool navigationOnly;
|
|
final DeviceExperience experience;
|
|
final VoidCallback? onNavigationComplete;
|
|
final ProjectState state;
|
|
final String? selectedProjectId;
|
|
final WorkspaceMode mode;
|
|
final ValueChanged<WorkspaceMode> onModeChanged;
|
|
final double navigationWidth;
|
|
final bool navigationCollapsed;
|
|
final Widget agentHeaderLeading;
|
|
final bool editorHidden;
|
|
final VoidCallback? onExpandEditor;
|
|
final bool integratedTitlebar;
|
|
final VoidCallback? onCreateProject;
|
|
final ValueChanged<RecentProject>? onSelectProject;
|
|
final ProjectRenamer onRenameProject;
|
|
final Widget headerControls;
|
|
|
|
@override
|
|
ConsumerState<ProjectSidebar> createState() => _ProjectSidebarState();
|
|
}
|
|
|
|
class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
|
bool get _touch => widget.experience != DeviceExperience.desktop;
|
|
bool _projectHeaderHovered = false;
|
|
String? _hoveredProjectId;
|
|
final _cutProjectsMenu = MenuController();
|
|
final Set<String> _expandedConversationProjects = {};
|
|
final Set<String> _collapsedProjects = {};
|
|
bool _showTrash = false;
|
|
|
|
ConversationSidebar get _conversations =>
|
|
ref.read(conversationSidebarProvider.notifier);
|
|
ConversationSnapshot get _snapshot {
|
|
final snapshot = ref.read(conversationSidebarProvider).value;
|
|
return snapshot?.projectId == widget.state.activeProject?.id
|
|
? snapshot ?? const ConversationSnapshot()
|
|
: const ConversationSnapshot();
|
|
}
|
|
|
|
Map<String, List<ConversationMetadata>> get _conversationsByProject =>
|
|
_snapshot.groups;
|
|
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
|
|
: null;
|
|
|
|
void _finishNavigation() {
|
|
final scaffold = Scaffold.maybeOf(context);
|
|
if (scaffold?.isDrawerOpen ?? false) {
|
|
scaffold!.closeDrawer();
|
|
} else {
|
|
widget.onNavigationComplete?.call();
|
|
}
|
|
}
|
|
|
|
void _selectProjectFromNavigation(RecentProject project) {
|
|
widget.onSelectProject?.call(project);
|
|
if (widget.navigationOnly) _finishNavigation();
|
|
}
|
|
|
|
void _newConversation() => _conversations.newConversation();
|
|
|
|
Future<void> _newConversationForProject(RecentProject project) async {
|
|
_cutProjectsMenu.close();
|
|
if (ref.read(projectsProvider).value?.projectBusy == true ||
|
|
!project.availability.canOpen) {
|
|
return;
|
|
}
|
|
if (widget.state.activeProject?.id != project.id) {
|
|
final opened = await ref
|
|
.read(projectsProvider.notifier)
|
|
.open(project.path, expectedId: project.id);
|
|
if (!opened || !mounted) return;
|
|
}
|
|
_newConversation();
|
|
widget.onModeChanged(WorkspaceMode.agent);
|
|
_finishNavigation();
|
|
}
|
|
|
|
Future<void> _selectConversation(ConversationMetadata item) async {
|
|
_cutProjectsMenu.close();
|
|
if (ref.read(projectsProvider).value?.projectBusy == true) return;
|
|
await _conversations.rememberSelection(item);
|
|
final currentProject = widget.state.activeProject?.id;
|
|
if (currentProject != item.projectId) {
|
|
final project = widget.state.recent
|
|
.where((entry) => entry.id == item.projectId)
|
|
.firstOrNull;
|
|
if (project == null || !project.availability.canOpen) return;
|
|
var opened = await ref
|
|
.read(projectsProvider.notifier)
|
|
.open(
|
|
project.path,
|
|
expectedId: project.id,
|
|
timelineId: item.timelineId,
|
|
);
|
|
if (!opened) {
|
|
opened = await ref
|
|
.read(projectsProvider.notifier)
|
|
.open(project.path, expectedId: project.id);
|
|
}
|
|
if (!opened) return;
|
|
} else if (widget.state.timeline?.id != item.timelineId &&
|
|
widget.state.timelines.any(
|
|
(timeline) => timeline.id == item.timelineId,
|
|
)) {
|
|
await ref
|
|
.read(projectsProvider.notifier)
|
|
.openTimeline(item.projectId, item.timelineId);
|
|
}
|
|
if (!mounted || widget.state.activeProject?.id != item.projectId) return;
|
|
_conversations.activate(item);
|
|
widget.onModeChanged(WorkspaceMode.agent);
|
|
_finishNavigation();
|
|
}
|
|
|
|
Future<void> _renameConversation(ConversationMetadata item) async {
|
|
final name = await askName(
|
|
context,
|
|
title: context.l10n.renameConversationTitle,
|
|
label: context.l10n.name,
|
|
description: context.l10n.renameConversationDescription,
|
|
initialValue: item.title,
|
|
submitLabel: context.l10n.save,
|
|
);
|
|
if (name == null || !mounted) return;
|
|
await _conversations.rename(item, name);
|
|
}
|
|
|
|
Future<void> _trashConversation(ConversationMetadata item) =>
|
|
_conversations.trash(item);
|
|
Future<void> _restoreConversation(ConversationMetadata item) =>
|
|
_conversations.restore(item);
|
|
|
|
Future<void> _relinkProvider(ConversationMetadata item) async {
|
|
final settings = await ref.read(agentSettingsProvider.future);
|
|
if (!mounted) return;
|
|
final candidates = settings.providers.where(
|
|
(provider) =>
|
|
provider.enabled &&
|
|
AgentApiType.values.any((type) => type.name == provider.apiType) &&
|
|
provider.models.any((model) => model.id == item.modelId),
|
|
);
|
|
final selected = await showAppDialog<String>(
|
|
context: context,
|
|
builder: (dialogContext) => AppDialog(
|
|
title: context.l10n.agentRelinkProvider,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (candidates.isEmpty) Text(context.l10n.agentProviderRequired),
|
|
for (final provider in candidates)
|
|
AppDialogOption(
|
|
label: provider.name,
|
|
onPressed: () => Navigator.pop(dialogContext, provider.id),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
if (selected == null) return;
|
|
await _conversations.updateMetadata(item.copyWith(providerId: selected));
|
|
}
|
|
|
|
Future<void> _removeProject(RecentProject project) async {
|
|
final index = widget.state.recent.indexWhere(
|
|
(item) => item.id == project.id,
|
|
);
|
|
final removed = await ref
|
|
.read(projectsProvider.notifier)
|
|
.removeRecentProject(project.id);
|
|
if (!removed || !mounted) return;
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(context.l10n.projectRemoved),
|
|
action: SnackBarAction(
|
|
label: context.l10n.undo,
|
|
onPressed: () => ref
|
|
.read(projectsProvider.notifier)
|
|
.restoreRecentProject(project, index),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _deleteForever(ConversationMetadata item) async {
|
|
if (!await _confirmDelete(item: item) || !mounted) return;
|
|
try {
|
|
await _conversations.delete(item);
|
|
} catch (_) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(context.l10n.operationFailed)));
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _emptyTrash() async {
|
|
if (!await _confirmDelete() || !mounted) return;
|
|
await _conversations.emptyTrash();
|
|
}
|
|
|
|
Future<bool> _confirmDelete({ConversationMetadata? item}) async =>
|
|
await showAppDialog<bool>(
|
|
context: context,
|
|
builder: (dialogContext) => AppDialog(
|
|
title: context.l10n.agentDeleteForever,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(dialogContext, false),
|
|
child: Text(context.l10n.cancel),
|
|
),
|
|
FilledButton(
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: Theme.of(context).colorScheme.error,
|
|
foregroundColor: Theme.of(context).colorScheme.onError,
|
|
),
|
|
onPressed: () => Navigator.pop(dialogContext, true),
|
|
child: Text(context.l10n.agentDeleteForever),
|
|
),
|
|
],
|
|
child: Text(
|
|
item == null
|
|
? context.l10n.agentEmptyTrashConfirmation
|
|
: context.l10n.agentDeleteConfirmation(item.title),
|
|
),
|
|
),
|
|
) ==
|
|
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,
|
|
);
|
|
}
|
|
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,
|
|
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,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _projectGroup(RecentProject project) {
|
|
final conversations = _conversationsByProject[project.id] ?? const [];
|
|
final expanded = _expandedConversationProjects.contains(project.id);
|
|
final collapsed = _collapsedProjects.contains(project.id);
|
|
final visible = collapsed
|
|
? const <ConversationMetadata>[]
|
|
: expanded
|
|
? conversations
|
|
: conversations.take(5);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
MouseRegion(
|
|
onEnter: (_) => setState(() => _hoveredProjectId = project.id),
|
|
onExit: (_) {
|
|
if (_hoveredProjectId == project.id) {
|
|
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(
|
|
project: project,
|
|
active: widget.selectedProjectId == project.id,
|
|
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),
|
|
_conversationRow(item),
|
|
],
|
|
if (!collapsed &&
|
|
_conversationsByProject.containsKey(project.id) &&
|
|
conversations.isEmpty)
|
|
Padding(
|
|
key: ValueKey('sidebar-project-empty-${project.id}'),
|
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
|
AppSidebarMetrics.outerPadding + AppSidebarMetrics.textInset,
|
|
4,
|
|
AppSidebarMetrics.outerPadding + AppSidebarMetrics.cellPadding,
|
|
4,
|
|
),
|
|
child: Text(
|
|
context.l10n.agentNoConversations,
|
|
style: AppSidebarTypography.style(
|
|
context,
|
|
fontSize: AppSidebarMetrics.hintFontSize,
|
|
height: AppSidebarMetrics.lineHeight,
|
|
color: AppSidebarColors.of(context).tertiary,
|
|
),
|
|
),
|
|
),
|
|
if (!collapsed && conversations.length > 5)
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.only(
|
|
start:
|
|
AppSidebarMetrics.outerPadding +
|
|
AppSidebarMetrics.textInset -
|
|
AppSidebarMetrics.cellPadding,
|
|
),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: TextButton(
|
|
style: TextButton.styleFrom(
|
|
minimumSize: const Size(0, AppSidebarMetrics.rowHeight),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: AppSidebarMetrics.cellPadding,
|
|
),
|
|
),
|
|
onPressed: () => setState(() {
|
|
if (expanded) {
|
|
_expandedConversationProjects.remove(project.id);
|
|
} else {
|
|
_expandedConversationProjects.add(project.id);
|
|
}
|
|
}),
|
|
child: Text(
|
|
expanded
|
|
? context.l10n.showFewerConversations
|
|
: context.l10n.showMoreConversations,
|
|
style: Theme.of(context).textTheme.bodySmall
|
|
?.copyWith(color: AppSidebarColors.of(context).secondary),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
@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
|
|
? 48.0
|
|
: widget.integratedTitlebar
|
|
? AppControlSize.panelHeader
|
|
: AppControlSize.headerButton;
|
|
final modeTop = headerHeight;
|
|
final modeHeader = SizedBox(
|
|
height:
|
|
modeTop + AppSidebarMetrics.modeHeight + AppSidebarMetrics.sectionGap,
|
|
child: Stack(
|
|
children: [
|
|
Positioned(
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
height: headerHeight,
|
|
child: SizedBox(
|
|
key: const Key('projects-window-header'),
|
|
child: WindowHeaderPadding(
|
|
child: Row(
|
|
children: [
|
|
if (widget.integratedTitlebar)
|
|
SizedBox(
|
|
key: const Key('native-window-controls-space'),
|
|
width: EditorWindowChrome.leadingWidth,
|
|
height: AppControlSize.panelHeader,
|
|
)
|
|
else
|
|
const SizedBox(width: AppSpacing.small),
|
|
widget.headerControls,
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
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(
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final projectList = SingleChildScrollView(
|
|
key: const Key('sidebar-projects-conversations'),
|
|
primary: false,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
if (widget.mode == WorkspaceMode.agent || widget.navigationOnly)
|
|
MouseRegion(
|
|
onEnter: (_) => setState(() => _projectHeaderHovered = true),
|
|
onExit: (_) => setState(() => _projectHeaderHovered = false),
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(
|
|
AppSidebarMetrics.outerPadding,
|
|
0,
|
|
AppSidebarMetrics.outerPadding,
|
|
AppSidebarMetrics.sectionGap,
|
|
),
|
|
child: _touch
|
|
? TouchProjectsHeader(onCreate: widget.onCreateProject)
|
|
: _ProjectsHeader(
|
|
onCreateProject: widget.onCreateProject,
|
|
hovered: _projectHeaderHovered,
|
|
),
|
|
),
|
|
),
|
|
if (widget.state.recent.isEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal:
|
|
AppSidebarMetrics.outerPadding +
|
|
AppSidebarMetrics.cellPadding,
|
|
vertical: AppSpacing.small,
|
|
),
|
|
child: Text(
|
|
context.l10n.projectsNone,
|
|
style: AppSidebarTypography.style(
|
|
context,
|
|
fontSize: AppSidebarMetrics.hintFontSize,
|
|
height: AppSidebarMetrics.lineHeight,
|
|
color: AppSidebarColors.of(context).tertiary,
|
|
),
|
|
),
|
|
),
|
|
for (var index = 0; index < widget.state.recent.length; index++) ...[
|
|
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,
|
|
),
|
|
),
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final chatPanel = widget.agent;
|
|
if (widget.navigationOnly) {
|
|
return Material(
|
|
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
modeHeader,
|
|
Expanded(child: projectList),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
final content = widget.mode == WorkspaceMode.agent
|
|
? Row(
|
|
key: const Key('agent-mode-layout'),
|
|
children: [
|
|
if (!widget.navigationCollapsed)
|
|
SizedBox(
|
|
width: widget.navigationWidth,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
modeHeader,
|
|
Expanded(child: projectList),
|
|
],
|
|
),
|
|
),
|
|
if (!widget.navigationCollapsed)
|
|
VerticalDivider(
|
|
key: const Key('sidebar-chat-divider'),
|
|
width: 1,
|
|
thickness: 1,
|
|
color: AppTheme.sidebarDividerColor(context),
|
|
),
|
|
Expanded(
|
|
child: Material(
|
|
key: const Key('agent-panel-surface'),
|
|
color: Theme.of(context).colorScheme.surface,
|
|
child: WindowHeaderPane(
|
|
offset: Offset(
|
|
widget.navigationCollapsed
|
|
? 0
|
|
: widget.navigationWidth + 1,
|
|
0,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
key: const Key('agent-content-header'),
|
|
height: AppControlSize.panelHeader,
|
|
child: WindowHeaderPadding(
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final header = Row(
|
|
children: [
|
|
widget.agentHeaderLeading,
|
|
Expanded(
|
|
child: Text(
|
|
widget.state.activeProject?.name ?? '',
|
|
key: const Key(
|
|
'workspace-project-title',
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.titleSmall,
|
|
),
|
|
),
|
|
if (widget.editorHidden)
|
|
HeaderControlRegion(
|
|
child: Padding(
|
|
padding:
|
|
const EdgeInsetsDirectional.only(
|
|
end: AppSpacing.small,
|
|
),
|
|
child: SizedBox.square(
|
|
dimension:
|
|
AppControlSize.headerButton,
|
|
child: IconButton(
|
|
key: const Key(
|
|
'expand-editor-button',
|
|
),
|
|
tooltip:
|
|
context.l10n.expandEditor,
|
|
onPressed: widget.onExpandEditor,
|
|
padding: EdgeInsets.zero,
|
|
icon: const Icon(
|
|
Icons.vertical_split_outlined,
|
|
size: AppIconSize.header,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
if (constraints.maxWidth >=
|
|
WorkspaceLayoutMetrics
|
|
.contentMinimumWidth) {
|
|
return header;
|
|
}
|
|
return SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: SizedBox(
|
|
width: WorkspaceLayoutMetrics
|
|
.contentMinimumWidth,
|
|
child: header,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Expanded(child: chatPanel),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: Column(
|
|
key: const Key('cut-mode-layout'),
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
modeHeader,
|
|
MouseRegion(
|
|
onEnter: (_) => setState(() => _projectHeaderHovered = true),
|
|
onExit: (_) => setState(() => _projectHeaderHovered = false),
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(
|
|
AppSidebarMetrics.outerPadding,
|
|
4,
|
|
AppSidebarMetrics.outerPadding,
|
|
0,
|
|
),
|
|
child: MenuAnchor(
|
|
controller: _cutProjectsMenu,
|
|
consumeOutsideTap: false,
|
|
alignmentOffset: const Offset(0, 4),
|
|
style: AppMenuStyle.panel(context, minWidth: 300),
|
|
menuChildren: [
|
|
SizedBox(
|
|
width: 320,
|
|
height: (MediaQuery.sizeOf(context).height - 180).clamp(
|
|
160.0,
|
|
440.0,
|
|
),
|
|
child: projectList,
|
|
),
|
|
],
|
|
builder: (context, controller, _) => _ProjectsHeader(
|
|
hovered: _projectHeaderHovered,
|
|
onPressed: () => controller.isOpen
|
|
? controller.close()
|
|
: controller.open(),
|
|
onCreateProject: widget.onCreateProject == null
|
|
? null
|
|
: () {
|
|
controller.close();
|
|
widget.onCreateProject!();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Expanded(child: chatPanel),
|
|
],
|
|
);
|
|
return Material(
|
|
color: Theme.of(context).colorScheme.surfaceContainerLow,
|
|
child: compact
|
|
? LayoutBuilder(
|
|
builder: (context, constraints) => SingleChildScrollView(
|
|
child: SizedBox(
|
|
height: constraints.maxHeight < 650
|
|
? 650
|
|
: constraints.maxHeight,
|
|
child: content,
|
|
),
|
|
),
|
|
)
|
|
: content,
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ProjectsHeader extends StatelessWidget {
|
|
const _ProjectsHeader({
|
|
required this.onCreateProject,
|
|
required this.hovered,
|
|
this.onPressed,
|
|
});
|
|
|
|
final VoidCallback? onCreateProject;
|
|
final bool hovered;
|
|
final VoidCallback? onPressed;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Row(
|
|
children: [
|
|
Expanded(
|
|
child: SizedBox(
|
|
key: const Key('projects-heading'),
|
|
height: AppSidebarMetrics.sectionHeight,
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
key: onPressed == null ? null : const Key('cut-projects-trigger'),
|
|
onTap: onPressed,
|
|
hoverColor: AppSidebarColors.of(context).hover,
|
|
focusColor: AppSidebarColors.of(context).hover,
|
|
highlightColor: Colors.transparent,
|
|
splashColor: Colors.transparent,
|
|
borderRadius: BorderRadius.circular(AppSidebarMetrics.radius),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.small,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Flexible(
|
|
child: Text(
|
|
context.l10n.projects,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: AppSidebarTypography.style(
|
|
context,
|
|
fontSize: AppSidebarMetrics.sectionFontSize,
|
|
weight: FontWeight.w500,
|
|
color: AppSidebarColors.of(context).section,
|
|
),
|
|
),
|
|
),
|
|
if (onPressed != null) ...[
|
|
const SizedBox(width: AppSpacing.tiny),
|
|
Icon(
|
|
Icons.keyboard_arrow_down,
|
|
size: AppSidebarMetrics.iconSize,
|
|
color: AppSidebarColors.of(context).secondary,
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.tiny),
|
|
AnimatedOpacity(
|
|
opacity: hovered ? 1 : 0,
|
|
duration: const Duration(milliseconds: 120),
|
|
child: SizedBox.square(
|
|
key: const Key('projects-more'),
|
|
dimension: AppSidebarMetrics.actionSize,
|
|
child: Center(
|
|
child: Icon(
|
|
Icons.more_horiz,
|
|
size: AppSidebarMetrics.iconSize,
|
|
color: AppSidebarColors.of(context).tertiary,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
IgnorePointer(
|
|
ignoring: !hovered,
|
|
child: AnimatedOpacity(
|
|
opacity: hovered ? 1 : 0,
|
|
duration: const Duration(milliseconds: 120),
|
|
child: SizedBox.square(
|
|
dimension: AppSidebarMetrics.actionSize,
|
|
child: IconButton(
|
|
key: const Key('create-project'),
|
|
style: sidebarActionButtonStyle(context),
|
|
tooltip: context.l10n.newProject,
|
|
onPressed: onCreateProject,
|
|
padding: EdgeInsets.zero,
|
|
icon: const Icon(Icons.add, size: AppSidebarMetrics.iconSize),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Color _sidebarItemHighlightColor(BuildContext context) =>
|
|
Theme.of(context).colorScheme.secondaryContainer;
|
|
|
|
ButtonStyle sidebarActionButtonStyle(BuildContext context) =>
|
|
AppTheme.iconButtonStyle(context);
|
|
|
|
String _availabilityLabel(
|
|
BuildContext context,
|
|
ProjectAvailability availability,
|
|
) => switch (availability) {
|
|
ProjectAvailability.available => '',
|
|
ProjectAvailability.missing ||
|
|
ProjectAvailability.volumeOffline ||
|
|
ProjectAvailability.invalid ||
|
|
ProjectAvailability.unavailable => context.l10n.projectAccessFailed,
|
|
};
|
|
|
|
class _ProjectTile extends StatelessWidget {
|
|
const _ProjectTile({
|
|
required this.project,
|
|
required this.active,
|
|
required this.availabilityLabel,
|
|
required this.onSelect,
|
|
required this.onRename,
|
|
this.sidebarStyle = false,
|
|
this.hovered = false,
|
|
this.onNewConversation,
|
|
this.onRemove,
|
|
this.onToggleExpanded,
|
|
this.expanded = true,
|
|
});
|
|
|
|
final RecentProject project;
|
|
final bool active;
|
|
final String availabilityLabel;
|
|
final VoidCallback onSelect;
|
|
final VoidCallback onRename;
|
|
final bool sidebarStyle;
|
|
final bool hovered;
|
|
final VoidCallback? onNewConversation;
|
|
final VoidCallback? onRemove;
|
|
final VoidCallback? onToggleExpanded;
|
|
final bool expanded;
|
|
|
|
List<Widget> _menuItems(BuildContext context) => [
|
|
AppMenuItem(
|
|
label: context.l10n.rename,
|
|
icon: Icons.drive_file_rename_outline,
|
|
onPressed: project.availability.canOpen ? onRename : null,
|
|
),
|
|
if (sidebarStyle) ...[
|
|
const AppMenuSeparator(),
|
|
AppMenuItem(
|
|
label: context.l10n.removeProjectFromSidebar,
|
|
onPressed: onRemove,
|
|
),
|
|
],
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) => AppContextMenu(
|
|
itemsBuilder: _menuItems,
|
|
child: ListTile(
|
|
key: ValueKey(
|
|
'${sidebarStyle ? 'sidebar-project' : 'open-project'}-${project.id}',
|
|
),
|
|
minTileHeight: sidebarStyle
|
|
? AppSidebarMetrics.rowHeight
|
|
: project.availability.canOpen
|
|
? 36
|
|
: 48,
|
|
minVerticalPadding: 0,
|
|
contentPadding: EdgeInsets.symmetric(
|
|
horizontal: sidebarStyle ? 0 : AppSpacing.small,
|
|
),
|
|
horizontalTitleGap: sidebarStyle
|
|
? AppSidebarMetrics.iconGap
|
|
: AppSpacing.small,
|
|
minLeadingWidth: sidebarStyle ? AppSidebarMetrics.iconSlotWidth : null,
|
|
visualDensity: VisualDensity.standard,
|
|
titleAlignment: ListTileTitleAlignment.center,
|
|
selected: active,
|
|
selectedTileColor: sidebarStyle
|
|
? Colors.transparent
|
|
: _sidebarItemHighlightColor(context),
|
|
textColor: project.availability.canOpen
|
|
? null
|
|
: Theme.of(context).disabledColor,
|
|
iconColor: project.availability.canOpen
|
|
? null
|
|
: Theme.of(context).disabledColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(AppRadius.extraLarge),
|
|
),
|
|
hoverColor: sidebarStyle
|
|
? AppSidebarColors.of(context).hover
|
|
: _sidebarItemHighlightColor(context),
|
|
focusColor: sidebarStyle ? AppSidebarColors.of(context).hover : null,
|
|
splashColor: Colors.transparent,
|
|
leading: sidebarStyle
|
|
? SizedBox(
|
|
width: AppSidebarMetrics.iconSlotWidth,
|
|
height: AppSidebarMetrics.rowHeight,
|
|
child: IconButton(
|
|
key: ValueKey('sidebar-project-toggle-${project.id}'),
|
|
tooltip: expanded
|
|
? context.l10n.collapseProject
|
|
: context.l10n.expandProject,
|
|
padding: EdgeInsets.zero,
|
|
style: sidebarActionButtonStyle(context),
|
|
onPressed: onToggleExpanded,
|
|
icon: Icon(
|
|
!project.availability.canOpen
|
|
? Icons.folder_off_outlined
|
|
: hovered
|
|
? (expanded
|
|
? Icons.keyboard_arrow_down
|
|
: Icons.chevron_right)
|
|
: (expanded
|
|
? Icons.folder_open_outlined
|
|
: Icons.folder_outlined),
|
|
size: AppSidebarMetrics.iconSize,
|
|
),
|
|
),
|
|
)
|
|
: Icon(
|
|
project.availability.canOpen
|
|
? Icons.folder_outlined
|
|
: Icons.folder_off_outlined,
|
|
size: 18,
|
|
),
|
|
title: Text(
|
|
project.name,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: sidebarStyle
|
|
? AppSidebarTypography.style(
|
|
context,
|
|
color: project.availability.canOpen
|
|
? AppSidebarColors.of(context).primary
|
|
: AppSidebarColors.of(context).disabled,
|
|
)
|
|
: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: project.availability.canOpen
|
|
? null
|
|
: Theme.of(context).disabledColor,
|
|
),
|
|
),
|
|
subtitle: project.availability.canOpen
|
|
? null
|
|
: Text(
|
|
availabilityLabel,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: sidebarStyle
|
|
? AppSidebarTypography.style(
|
|
context,
|
|
fontSize: AppSidebarMetrics.hintFontSize,
|
|
height: AppSidebarMetrics.lineHeight,
|
|
color: AppSidebarColors.of(context).tertiary,
|
|
)
|
|
: null,
|
|
),
|
|
trailing: sidebarStyle
|
|
? IgnorePointer(
|
|
ignoring: !hovered,
|
|
child: AnimatedOpacity(
|
|
opacity: hovered ? 1 : 0,
|
|
duration: const Duration(milliseconds: 120),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox.square(
|
|
dimension: AppSidebarMetrics.actionSize,
|
|
child: AppPopover(
|
|
width: 160,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: _menuItems(context),
|
|
),
|
|
builder: (context, toggle) => IconButton(
|
|
key: ValueKey('sidebar-project-more-${project.id}'),
|
|
onPressed: toggle,
|
|
style: sidebarActionButtonStyle(context),
|
|
padding: EdgeInsets.zero,
|
|
icon: const Icon(
|
|
Icons.more_horiz,
|
|
size: AppSidebarMetrics.iconSize,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
SizedBox.square(
|
|
dimension: AppSidebarMetrics.actionSize,
|
|
child: IconButton(
|
|
key: ValueKey('new-agent-conversation-${project.id}'),
|
|
tooltip: context.l10n.agentNewConversation,
|
|
onPressed: onNewConversation,
|
|
style: sidebarActionButtonStyle(context),
|
|
padding: EdgeInsets.zero,
|
|
icon: const Icon(
|
|
Icons.edit_square,
|
|
size: AppSidebarMetrics.iconSize,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: null,
|
|
onTap: onSelect,
|
|
),
|
|
);
|
|
}
|