feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
@@ -0,0 +1,272 @@
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
/// Desktop conversation navigation, independent of project and agent state.
|
||||
class ChatHeader extends StatelessWidget {
|
||||
const ChatHeader({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.historyBuilder,
|
||||
required this.onNew,
|
||||
required this.actions,
|
||||
this.busy = false,
|
||||
this.panelActions = const [],
|
||||
});
|
||||
|
||||
final String title;
|
||||
final Widget Function(BuildContext context, VoidCallback close)
|
||||
historyBuilder;
|
||||
final VoidCallback? onNew;
|
||||
final List<Widget> actions;
|
||||
final bool busy;
|
||||
final List<Widget> panelActions;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final iconStyle = IconButton.styleFrom(
|
||||
fixedSize: const Size.square(26),
|
||||
minimumSize: const Size.square(26),
|
||||
maximumSize: const Size.square(26),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: 16,
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
);
|
||||
return SizedBox(
|
||||
key: const Key('project-chat-header'),
|
||||
height: AppDesktopMetrics.panelHeader,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: AppPopover(
|
||||
enabled: !busy,
|
||||
width: 300,
|
||||
surfaceKey: const Key('project-chat-history-menu'),
|
||||
child: Builder(
|
||||
builder: (menuContext) {
|
||||
final menu = MenuController.maybeOf(menuContext);
|
||||
return historyBuilder(menuContext, () {
|
||||
if (menu?.isOpen == true) menu!.close();
|
||||
});
|
||||
},
|
||||
),
|
||||
builder: (context, toggle) => Tooltip(
|
||||
message: '$title\n${l10n.agentConversations}',
|
||||
child: TextButton(
|
||||
key: const Key('project-chat-history'),
|
||||
onPressed: busy ? null : toggle,
|
||||
style: AppTheme.toolbarButtonStyle(context).copyWith(
|
||||
minimumSize: const WidgetStatePropertyAll(Size(0, 26)),
|
||||
maximumSize: const WidgetStatePropertyAll(
|
||||
Size(double.infinity, 26),
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 6),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
key: const Key('project-chat-title'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTheme.toolbarTextStyle(context)
|
||||
.copyWith(fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(AppIcons.expandMore, size: 14),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
IconButton(
|
||||
key: const Key('project-chat-new'),
|
||||
tooltip: l10n.agentNewConversation,
|
||||
style: iconStyle,
|
||||
onPressed: busy ? null : onNew,
|
||||
icon: const Icon(AppIcons.edit),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
AppDropdownMenu(
|
||||
enabled: (!busy && actions.isNotEmpty) || panelActions.isNotEmpty,
|
||||
items: [
|
||||
if (!busy) ...actions,
|
||||
if (!busy && actions.isNotEmpty && panelActions.isNotEmpty)
|
||||
const AppMenuSeparator(),
|
||||
...panelActions,
|
||||
],
|
||||
builder: (context, toggle, focus) => IconButton(
|
||||
key: const Key('project-chat-more'),
|
||||
tooltip: l10n.agentConversationActions,
|
||||
style: iconStyle,
|
||||
focusNode: focus,
|
||||
onPressed: toggle,
|
||||
icon: const Icon(AppIcons.more),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
typedef ChatHistoryEntry = ({String id, String title});
|
||||
|
||||
/// Search remains local to the currently open project's conversation list.
|
||||
class ChatHistoryMenu extends StatefulWidget {
|
||||
const ChatHistoryMenu({
|
||||
super.key,
|
||||
required this.entries,
|
||||
required this.onSelect,
|
||||
this.selectedId,
|
||||
this.itemBuilder,
|
||||
this.footer,
|
||||
this.error,
|
||||
});
|
||||
|
||||
static const contentInset = 8.0;
|
||||
static const sectionPadding = EdgeInsets.symmetric(
|
||||
horizontal: contentInset,
|
||||
vertical: 8,
|
||||
);
|
||||
|
||||
final List<ChatHistoryEntry> entries;
|
||||
final String? selectedId;
|
||||
final ValueChanged<String> onSelect;
|
||||
final Widget Function(BuildContext, String id, VoidCallback onSelect)?
|
||||
itemBuilder;
|
||||
final Widget? footer;
|
||||
final String? error;
|
||||
|
||||
@override
|
||||
State<ChatHistoryMenu> createState() => _ChatHistoryMenuState();
|
||||
}
|
||||
|
||||
class _ChatHistoryMenuState extends State<ChatHistoryMenu> {
|
||||
String _query = '';
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChatHistoryMenu oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.entries.isEmpty) _query = '';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final searchStyle = AppTheme.inputTextStyle(
|
||||
context,
|
||||
style: AppTheme.toolbarTextStyle(context),
|
||||
);
|
||||
final entries = widget.entries.where(
|
||||
(entry) =>
|
||||
entry.title.toLowerCase().contains(_query.trim().toLowerCase()),
|
||||
);
|
||||
return SizedBox(
|
||||
height:
|
||||
widget.entries.isEmpty &&
|
||||
widget.footer == null &&
|
||||
widget.error == null
|
||||
? 88
|
||||
: 360,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (widget.entries.isNotEmpty)
|
||||
TextField(
|
||||
key: const Key('project-chat-search'),
|
||||
autofocus: true,
|
||||
style: searchStyle,
|
||||
cursorHeight: AppTheme.inputCursorHeight(
|
||||
context,
|
||||
style: searchStyle,
|
||||
),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
constraints: const BoxConstraints(minHeight: 28),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 5,
|
||||
),
|
||||
hintText: l10n.searchOptions(l10n.agentConversations),
|
||||
hintStyle: AppTheme.inputHintStyle(
|
||||
context,
|
||||
style: searchStyle,
|
||||
),
|
||||
prefixIcon: const Icon(AppIcons.search, size: 14),
|
||||
prefixIconConstraints: const BoxConstraints(
|
||||
minWidth: 30,
|
||||
minHeight: 28,
|
||||
),
|
||||
),
|
||||
onChanged: (value) => setState(() => _query = value),
|
||||
),
|
||||
Padding(
|
||||
padding: ChatHistoryMenu.sectionPadding,
|
||||
child: Text(
|
||||
key: const Key('project-chat-group'),
|
||||
l10n.agentConversations,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
primary: false,
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
if (entries.isEmpty)
|
||||
Padding(
|
||||
padding: ChatHistoryMenu.sectionPadding,
|
||||
child: Text(
|
||||
_query.trim().isEmpty
|
||||
? l10n.agentNoConversations
|
||||
: l10n.noMatchingOptions,
|
||||
),
|
||||
),
|
||||
for (final entry in entries)
|
||||
widget.itemBuilder?.call(
|
||||
context,
|
||||
entry.id,
|
||||
() => widget.onSelect(entry.id),
|
||||
) ??
|
||||
AppMenuItem(
|
||||
key: ValueKey('chat-history-${entry.id}'),
|
||||
label: entry.title,
|
||||
selectOption: true,
|
||||
selected: entry.id == widget.selectedId,
|
||||
onPressed: () => widget.onSelect(entry.id),
|
||||
),
|
||||
if (widget.error != null)
|
||||
Padding(
|
||||
padding: ChatHistoryMenu.sectionPadding,
|
||||
child: Text(widget.error!),
|
||||
),
|
||||
if (widget.footer != null) widget.footer!,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import 'chat_header.dart';
|
||||
|
||||
@Preview(
|
||||
name: 'Chat header — dark',
|
||||
group: 'Desktop conversations',
|
||||
size: Size(320, 440),
|
||||
)
|
||||
Widget chatHeaderDarkPreview() => _preview(Brightness.dark);
|
||||
|
||||
@Preview(
|
||||
name: 'Chat header — light, narrow',
|
||||
group: 'Desktop conversations',
|
||||
size: Size(240, 440),
|
||||
)
|
||||
Widget chatHeaderLightPreview() => _preview(Brightness.light);
|
||||
|
||||
Widget _preview(Brightness brightness) {
|
||||
const entries = [
|
||||
(id: 'rough', title: '旅行短片粗剪'),
|
||||
(id: 'opening', title: '调整片头节奏与镜头衔接,让画面更自然'),
|
||||
(id: 'captions', title: '字幕与配乐'),
|
||||
];
|
||||
String? selected = 'opening';
|
||||
return MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, brightness),
|
||||
),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return Column(
|
||||
children: [
|
||||
ChatHeader(
|
||||
title:
|
||||
entries
|
||||
.where((entry) => entry.id == selected)
|
||||
.firstOrNull
|
||||
?.title ??
|
||||
l10n.agentUntitledConversation,
|
||||
onNew: () => setState(() => selected = null),
|
||||
actions: selected == null
|
||||
? const []
|
||||
: [
|
||||
AppMenuItem(label: l10n.rename, onPressed: () {}),
|
||||
AppMenuItem(
|
||||
label: l10n.agentMoveToTrash,
|
||||
onPressed: () => setState(() => selected = null),
|
||||
),
|
||||
],
|
||||
historyBuilder: (_, close) => ChatHistoryMenu(
|
||||
entries: entries,
|
||||
selectedId: selected,
|
||||
onSelect: (id) {
|
||||
close();
|
||||
setState(() => selected = id);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -60,8 +60,13 @@ class ConversationSelection extends _$ConversationSelection {
|
||||
ref.onDispose(() {
|
||||
if (_draftKey case final key?) composers.removeDraft(projectId, key);
|
||||
});
|
||||
ref.watch(
|
||||
ref.listen(
|
||||
projectsProvider.select((value) => value.value?.activeProject?.id),
|
||||
(_, next) {
|
||||
if (next == projectId && state.selectedId != null) {
|
||||
state = state.copyWith(initialized: false);
|
||||
}
|
||||
},
|
||||
);
|
||||
final saved = savedConversationSelectionProvider(projectId);
|
||||
ref.listen(saved, (_, next) {
|
||||
|
||||
@@ -135,7 +135,7 @@ final class ConversationSelectionProvider
|
||||
}
|
||||
|
||||
String _$conversationSelectionHash() =>
|
||||
r'eef3c6c95f86b017e73d3244adccc257f717699b';
|
||||
r'5b5036b69fd203ed7827d9f81d446786b7de373c';
|
||||
|
||||
/// Keeps a draft or explicit selection stable while the list refreshes.
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
import '../../integrations/platform/device_experience.dart';
|
||||
import '../editor/editor_page.dart';
|
||||
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
class EmptyEditor extends StatelessWidget {
|
||||
@@ -13,78 +16,92 @@ class EmptyEditor extends StatelessWidget {
|
||||
required this.headerLeading,
|
||||
required this.showProjectName,
|
||||
this.desktop = false,
|
||||
this.experience = DeviceExperience.desktop,
|
||||
});
|
||||
|
||||
final ProjectState state;
|
||||
final Widget headerLeading;
|
||||
final bool showProjectName;
|
||||
final bool desktop;
|
||||
final DeviceExperience experience;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: desktop
|
||||
? AppControlSize.panelToolbar
|
||||
: AppControlSize.panelHeader,
|
||||
child: Padding(
|
||||
padding: desktop
|
||||
? const EdgeInsets.symmetric(
|
||||
horizontal: AppSidebarMetrics.outerPadding,
|
||||
vertical: AppSpacing.gap,
|
||||
)
|
||||
: EdgeInsets.zero,
|
||||
child: WindowHeaderPadding(
|
||||
child: Row(
|
||||
children: [
|
||||
headerLeading,
|
||||
if (showProjectName)
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.activeProject?.name ?? '',
|
||||
key: const Key('workspace-project-title'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
Widget build(BuildContext context) => state.activeProject == null
|
||||
? EditorWorkspace(
|
||||
projectId: '',
|
||||
timelineId: '',
|
||||
projectName: '',
|
||||
integratedTitlebar: false,
|
||||
headerLeading: headerLeading,
|
||||
showProjectName: showProjectName,
|
||||
experience: experience,
|
||||
projectLoading: true,
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: desktop
|
||||
? AppControlSize.panelToolbar
|
||||
: AppControlSize.panelHeader,
|
||||
child: Padding(
|
||||
padding: desktop
|
||||
? const EdgeInsets.symmetric(
|
||||
horizontal: AppSidebarMetrics.outerPadding,
|
||||
vertical: AppSpacing.gap,
|
||||
)
|
||||
: EdgeInsets.zero,
|
||||
child: WindowHeaderPadding(
|
||||
child: Row(
|
||||
children: [
|
||||
headerLeading,
|
||||
if (!showProjectName) const Spacer(),
|
||||
if (showProjectName)
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.activeProject?.name ?? '',
|
||||
key: const Key('workspace-project-title'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppSpacing.page),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.movie_outlined,
|
||||
size: AppIconSize.project,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
Text(
|
||||
state.activeProject == null
|
||||
? context.l10n.projectsEmpty
|
||||
: context.l10n.projectNoTimelines,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
if (state.activeProject != null) ...[
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Text(
|
||||
context.l10n.createTimelineHint,
|
||||
textAlign: TextAlign.center,
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppSpacing.page),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
AppIcons.video,
|
||||
size: AppIconSize.project,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.medium),
|
||||
Text(
|
||||
state.activeProject == null
|
||||
? context.l10n.projectsEmpty
|
||||
: context.l10n.projectNoTimelines,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
if (state.activeProject != null) ...[
|
||||
const SizedBox(height: AppSpacing.small),
|
||||
Text(
|
||||
context.l10n.createTimelineHint,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import '../../integrations/platform/device_experience.dart';
|
||||
import 'touch_project_navigation.dart';
|
||||
import '../media/media_panel.dart';
|
||||
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
import 'dart:async';
|
||||
@@ -36,6 +37,9 @@ import '../../integrations/agent/agent_models.dart';
|
||||
|
||||
import 'widgets/name_dialog.dart';
|
||||
import 'conversation_sidebar.dart';
|
||||
import 'chat_header.dart';
|
||||
import 'sidebar_category_tabs.dart';
|
||||
import 'sidebar_navigation_controller.dart';
|
||||
|
||||
typedef ProjectRenamer = Future<bool> Function(RecentProject project);
|
||||
|
||||
@@ -44,7 +48,11 @@ class ProjectSidebar extends ConsumerStatefulWidget {
|
||||
super.key,
|
||||
required this.agent,
|
||||
this.navigationOnly = false,
|
||||
this.chatOnly = false,
|
||||
this.chatPanelActions = const [],
|
||||
this.resourcesSelected = false,
|
||||
this.onResourcesSelected,
|
||||
this.librarySelected = false,
|
||||
this.externalWindowFrame = false,
|
||||
this.experience = DeviceExperience.desktop,
|
||||
this.onNavigationComplete,
|
||||
@@ -66,7 +74,11 @@ class ProjectSidebar extends ConsumerStatefulWidget {
|
||||
|
||||
final Widget agent;
|
||||
final bool navigationOnly;
|
||||
final bool chatOnly;
|
||||
final List<Widget> chatPanelActions;
|
||||
final bool resourcesSelected;
|
||||
final ValueChanged<bool>? onResourcesSelected;
|
||||
final bool librarySelected;
|
||||
final bool externalWindowFrame;
|
||||
final DeviceExperience experience;
|
||||
final VoidCallback? onNavigationComplete;
|
||||
@@ -90,6 +102,13 @@ class ProjectSidebar extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
ProjectState get _projectState =>
|
||||
ref.read(projectsProvider).value ?? widget.state;
|
||||
SidebarNavigationContext _navigationContext(ProjectState state) =>
|
||||
(projectId: state.activeProject?.id, timelineId: state.visibleTimelineId);
|
||||
late final _navigation = SidebarNavigationController(
|
||||
_navigationContext(_projectState),
|
||||
);
|
||||
bool _resourcesVisited = false;
|
||||
bool get _touch => widget.experience != DeviceExperience.desktop;
|
||||
bool _projectHeaderHovered = false;
|
||||
@@ -115,10 +134,17 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
_projectSelection.value = widget.selectedProjectId;
|
||||
final ids = widget.state.recent.map((project) => project.id).toSet();
|
||||
_groupWidgets.removeWhere((id, _) => !ids.contains(id));
|
||||
_navigation.update(_navigationContext(_projectState));
|
||||
if (oldWidget.mode != widget.mode ||
|
||||
oldWidget.resourcesSelected != widget.resourcesSelected ||
|
||||
oldWidget.librarySelected != widget.librarySelected) {
|
||||
_navigation.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_navigation.dispose();
|
||||
_projectSelection.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -150,11 +176,15 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
}
|
||||
|
||||
void _selectProjectFromNavigation(RecentProject project) {
|
||||
_navigation.cancel();
|
||||
widget.onSelectProject?.call(project);
|
||||
if (widget.navigationOnly) _finishNavigation();
|
||||
}
|
||||
|
||||
void _newConversation() => _conversations.newConversation();
|
||||
void _newConversation() {
|
||||
_navigation.cancel();
|
||||
_conversations.newConversation();
|
||||
}
|
||||
|
||||
Future<void> _newConversationForProject(RecentProject project) async {
|
||||
_cutProjectsMenu.close();
|
||||
@@ -162,52 +192,75 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
!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;
|
||||
final navigation = _navigation.begin(project.id);
|
||||
bool isCurrent() => mounted && navigation();
|
||||
try {
|
||||
if (_projectState.activeProject?.id != project.id) {
|
||||
final opened = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.open(project.path, expectedId: project.id, isCurrent: isCurrent);
|
||||
if (!opened || !isCurrent()) return;
|
||||
}
|
||||
if (!isCurrent() || _projectState.activeProject?.id != project.id) return;
|
||||
_newConversation();
|
||||
widget.onModeChanged(WorkspaceMode.agent);
|
||||
_finishNavigation();
|
||||
} finally {
|
||||
_navigation.finish(navigation);
|
||||
}
|
||||
_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
|
||||
final navigation = _navigation.begin(
|
||||
item.projectId,
|
||||
timelineId: item.timelineId,
|
||||
);
|
||||
bool isCurrent() => mounted && navigation();
|
||||
try {
|
||||
await _conversations.rememberSelection(item);
|
||||
if (!isCurrent()) return;
|
||||
final currentProject = _projectState.activeProject?.id;
|
||||
if (currentProject != item.projectId) {
|
||||
final project = _projectState.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);
|
||||
.open(
|
||||
project.path,
|
||||
expectedId: project.id,
|
||||
timelineId: item.timelineId,
|
||||
isCurrent: isCurrent,
|
||||
);
|
||||
if (!isCurrent()) return;
|
||||
if (!opened) {
|
||||
_navigation.useProjectDefault(navigation);
|
||||
opened = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.open(project.path, expectedId: project.id, isCurrent: isCurrent);
|
||||
}
|
||||
if (!opened) return;
|
||||
} else if (_projectState.timeline?.id != item.timelineId &&
|
||||
_projectState.timelines.any(
|
||||
(timeline) => timeline.id == item.timelineId,
|
||||
)) {
|
||||
final opened = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.openTimeline(item.projectId, item.timelineId);
|
||||
if (!opened) return;
|
||||
}
|
||||
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 (!isCurrent() || _projectState.activeProject?.id != item.projectId) {
|
||||
return;
|
||||
}
|
||||
_conversations.activate(item);
|
||||
widget.onModeChanged(WorkspaceMode.agent);
|
||||
_finishNavigation();
|
||||
} finally {
|
||||
_navigation.finish(navigation);
|
||||
}
|
||||
if (!mounted || widget.state.activeProject?.id != item.projectId) return;
|
||||
_conversations.activate(item);
|
||||
widget.onModeChanged(WorkspaceMode.agent);
|
||||
_finishNavigation();
|
||||
}
|
||||
|
||||
Future<void> _renameConversation(ConversationMetadata item) async {
|
||||
@@ -254,7 +307,7 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
),
|
||||
),
|
||||
);
|
||||
if (selected == null) return;
|
||||
if (selected == null || !mounted) return;
|
||||
await _conversations.updateMetadata(item.copyWith(providerId: selected));
|
||||
}
|
||||
|
||||
@@ -266,16 +319,12 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
.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),
|
||||
),
|
||||
),
|
||||
ErrorNotificationHost.of(context).showMessage(
|
||||
content: Text(context.l10n.projectRemoved),
|
||||
actionLabel: context.l10n.undo,
|
||||
onAction: () => ref
|
||||
.read(projectsProvider.notifier)
|
||||
.restoreRecentProject(project, index),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -325,7 +374,32 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
) ==
|
||||
true;
|
||||
|
||||
Widget _conversationRow(ConversationMetadata item) => Consumer(
|
||||
List<Widget> _conversationActions(ConversationMetadata item) => [
|
||||
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),
|
||||
),
|
||||
];
|
||||
|
||||
Widget _conversationRow(
|
||||
ConversationMetadata item, {
|
||||
VoidCallback? onSelected,
|
||||
bool inMenu = false,
|
||||
}) => Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final active = ref.watch(
|
||||
projectsProvider.select(
|
||||
@@ -338,44 +412,40 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
.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 (inMenu) {
|
||||
return AppContextMenu(
|
||||
itemsBuilder: (_) => _conversationActions(item),
|
||||
child: AppMenuItem(
|
||||
key: ValueKey('sidebar-conversation-${item.id}'),
|
||||
label: item.title,
|
||||
selectOption: true,
|
||||
selected: selected,
|
||||
onPressed: onSelected ?? () => _selectConversation(item),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (_touch) {
|
||||
return TouchConversationTile(
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
selected: selected,
|
||||
onSelect: () => _selectConversation(item),
|
||||
actions: actions,
|
||||
onSelect: onSelected ?? () => _selectConversation(item),
|
||||
actions: (_) => _conversationActions(item),
|
||||
);
|
||||
}
|
||||
return Padding(
|
||||
padding: AppSidebarMetrics.rowPadding,
|
||||
child: AppContextMenu(
|
||||
itemsBuilder: actions,
|
||||
itemsBuilder: (_) => _conversationActions(item),
|
||||
child: Material(
|
||||
color: selected
|
||||
? AppSidebarColors.of(context).hover
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppSidebarMetrics.radius),
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppTheme.isDesktop(context)
|
||||
? AppRadius.large
|
||||
: AppSidebarMetrics.radius,
|
||||
),
|
||||
child: InkWell(
|
||||
key: ValueKey('sidebar-conversation-${item.id}'),
|
||||
hoverColor: selected
|
||||
@@ -383,28 +453,61 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
: AppSidebarColors.of(context).hover,
|
||||
splashColor: Colors.transparent,
|
||||
highlightColor: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppSidebarMetrics.radius),
|
||||
onTap: () => _selectConversation(item),
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppTheme.isDesktop(context)
|
||||
? AppRadius.large
|
||||
: AppSidebarMetrics.radius,
|
||||
),
|
||||
onTap: onSelected ?? () => _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,
|
||||
height: AppTheme.isDesktop(context)
|
||||
? AppDesktopMetrics.sidebarRow
|
||||
: AppSidebarMetrics.rowHeight,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
if (selected && AppTheme.isDesktop(context))
|
||||
PositionedDirectional(
|
||||
start: AppSidebarMetrics.cellPadding,
|
||||
top: 8,
|
||||
bottom: 8,
|
||||
width: 2,
|
||||
child: IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
key: ValueKey(
|
||||
'sidebar-conversation-selection-${item.id}',
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
borderRadius: BorderRadius.circular(1),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
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: AppTheme.isDesktop(context)
|
||||
? 13
|
||||
: AppSidebarMetrics.conversationFontSize,
|
||||
height: AppTheme.isDesktop(context)
|
||||
? 20 / 13
|
||||
: AppSidebarMetrics.conversationLineHeight,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -592,6 +695,130 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_navigation.update(_navigationContext(_projectState));
|
||||
ref.listen(
|
||||
projectsProvider.select(
|
||||
(value) =>
|
||||
value.value == null ? null : _navigationContext(value.requireValue),
|
||||
),
|
||||
(_, next) {
|
||||
if (next != null) _navigation.update(next);
|
||||
},
|
||||
);
|
||||
if (widget.chatOnly) {
|
||||
final snapshot = ref.watch(conversationSidebarProvider).value;
|
||||
final projectId = widget.state.activeProject?.id;
|
||||
final conversations =
|
||||
snapshot?.groups[projectId] ?? const <ConversationMetadata>[];
|
||||
final selectedId = ref.watch(
|
||||
conversationSelectionProvider(projectId)
|
||||
.select((value) => value.selectedId),
|
||||
);
|
||||
final selected = conversations
|
||||
.where((item) => item.id == selectedId)
|
||||
.firstOrNull;
|
||||
return Material(
|
||||
key: const Key('project-chat-sidebar'),
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: Column(
|
||||
children: [
|
||||
ChatHeader(
|
||||
key: ValueKey(('chat-header', projectId)),
|
||||
title: selected?.title ?? context.l10n.agentUntitledConversation,
|
||||
busy: widget.state.projectBusy,
|
||||
onNew: _newConversation,
|
||||
panelActions: widget.chatPanelActions,
|
||||
actions: selected == null
|
||||
? const []
|
||||
: _conversationActions(selected),
|
||||
historyBuilder: (menuContext, close) => ChatHistoryMenu(
|
||||
entries: [
|
||||
for (final item in conversations)
|
||||
(id: item.id, title: item.title),
|
||||
],
|
||||
selectedId: selectedId,
|
||||
error: _conversationError,
|
||||
onSelect: (id) {
|
||||
close();
|
||||
_selectConversation(
|
||||
conversations.firstWhere((item) => item.id == id),
|
||||
);
|
||||
},
|
||||
itemBuilder: (_, id, onSelect) => _conversationRow(
|
||||
conversations.firstWhere((item) => item.id == id),
|
||||
onSelected: onSelect,
|
||||
inMenu: true,
|
||||
),
|
||||
footer: _trashed.isEmpty
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Divider(),
|
||||
Padding(
|
||||
padding: ChatHistoryMenu.sectionPadding,
|
||||
child: Text(
|
||||
context.l10n.agentTrash,
|
||||
key: const Key('project-chat-trash-title'),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
for (final item in _trashed)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: ChatHistoryMenu.contentInset,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 28,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTheme.toolbarTextStyle(
|
||||
context,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final restore in [true, false])
|
||||
IconButton(
|
||||
tooltip: restore
|
||||
? context.l10n.agentRestore
|
||||
: context.l10n.agentDeleteForever,
|
||||
style: IconButton.styleFrom(
|
||||
fixedSize: const Size.square(24),
|
||||
minimumSize: const Size.square(24),
|
||||
maximumSize: const Size.square(24),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: 14,
|
||||
tapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
onPressed: () => restore
|
||||
? _restoreConversation(item)
|
||||
: _deleteForever(item),
|
||||
icon: Icon(
|
||||
restore
|
||||
? AppIcons.undo
|
||||
: AppIcons.delete,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Expanded(child: widget.agent),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
final compact = MediaQuery.sizeOf(context).height < 520;
|
||||
final headerHeight = widget.externalWindowFrame
|
||||
? 0.0
|
||||
@@ -601,8 +828,12 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
? AppControlSize.panelHeader
|
||||
: AppControlSize.headerButton;
|
||||
final modeTop = headerHeight;
|
||||
final modeHeader = SizedBox(
|
||||
key: const Key('project-content-header'),
|
||||
final legacyModeHeader = SizedBox(
|
||||
key: Key(
|
||||
!_touch && widget.navigationOnly
|
||||
? 'sidebar-window-header'
|
||||
: 'project-content-header',
|
||||
),
|
||||
height:
|
||||
modeTop +
|
||||
(_touch ? AppSidebarMetrics.modeHeight : 0) +
|
||||
@@ -713,7 +944,7 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_down,
|
||||
AppIcons.expandMore,
|
||||
size: AppSidebarMetrics.iconSize,
|
||||
),
|
||||
],
|
||||
@@ -725,13 +956,89 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
],
|
||||
),
|
||||
);
|
||||
final sectionHeader = !_touch && widget.externalWindowFrame
|
||||
? SizedBox(
|
||||
key: Key(
|
||||
widget.navigationOnly
|
||||
? 'sidebar-projects-header'
|
||||
: 'project-content-header',
|
||||
),
|
||||
height: AppDesktopMetrics.panelHeader,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
widget.resourcesSelected
|
||||
? AppIcons.mediaLibrary
|
||||
: AppIcons.folder,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
key: !widget.resourcesSelected && !widget.librarySelected
|
||||
? const Key('projects-heading')
|
||||
: null,
|
||||
widget.resourcesSelected
|
||||
? context.l10n.materials
|
||||
: widget.librarySelected
|
||||
? context.l10n.navigationLibrary
|
||||
: context.l10n.projects,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
if (!widget.resourcesSelected && !widget.librarySelected)
|
||||
IconButton(
|
||||
key: const Key('create-project'),
|
||||
tooltip: context.l10n.newProject,
|
||||
onPressed: widget.onCreateProject,
|
||||
icon: const Icon(AppIcons.add, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: legacyModeHeader;
|
||||
final modeHeader = !_touch && widget.navigationOnly
|
||||
? Column(
|
||||
key: const Key('project-content-header'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (!widget.externalWindowFrame) legacyModeHeader,
|
||||
if (widget.librarySelected)
|
||||
SizedBox(
|
||||
height: AppDesktopMetrics.panelHeader,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(context.l10n.navigationLibrary),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SidebarCategoryTabs(
|
||||
mediaSelected: widget.resourcesSelected,
|
||||
onSelected: widget.onResourcesSelected,
|
||||
),
|
||||
if (widget.externalWindowFrame &&
|
||||
!widget.resourcesSelected &&
|
||||
!widget.librarySelected)
|
||||
sectionHeader,
|
||||
],
|
||||
)
|
||||
: sectionHeader;
|
||||
final projectList = SingleChildScrollView(
|
||||
key: const Key('sidebar-projects-conversations'),
|
||||
primary: false,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (widget.mode == WorkspaceMode.agent || widget.navigationOnly)
|
||||
if ((widget.mode == WorkspaceMode.agent || widget.navigationOnly) &&
|
||||
(_touch || !widget.externalWindowFrame))
|
||||
MouseRegion(
|
||||
onEnter: (_) => setState(() => _projectHeaderHovered = true),
|
||||
onExit: (_) => setState(() => _projectHeaderHovered = false),
|
||||
@@ -813,7 +1120,11 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
onExpansionChanged: (value) =>
|
||||
setState(() => _showTrash = value),
|
||||
trailing: _trashed.isEmpty
|
||||
? null
|
||||
? Icon(
|
||||
_showTrash
|
||||
? AppIcons.expandLess
|
||||
: AppIcons.expandMore,
|
||||
)
|
||||
: TextButton(
|
||||
onPressed: _emptyTrash,
|
||||
child: Text(context.l10n.agentEmptyTrash),
|
||||
@@ -838,28 +1149,25 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
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),
|
||||
trailing: AppDropdownMenu(
|
||||
items: [
|
||||
AppMenuItem(
|
||||
label: context.l10n.agentRestore,
|
||||
onPressed: () => _restoreConversation(item),
|
||||
),
|
||||
PopupMenuItem(
|
||||
height: AppMenuMetrics.rowHeight,
|
||||
value: 'delete',
|
||||
child: Text(
|
||||
context.l10n.agentDeleteForever,
|
||||
),
|
||||
AppMenuItem(
|
||||
label: context.l10n.agentDeleteForever,
|
||||
destructive: true,
|
||||
onPressed: () => _deleteForever(item),
|
||||
),
|
||||
],
|
||||
builder: (context, toggle, focus) => IconButton(
|
||||
focusNode: focus,
|
||||
onPressed: toggle,
|
||||
icon: const Icon(AppIcons.more),
|
||||
tooltip:
|
||||
context.l10n.agentConversationActions,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -883,20 +1191,38 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
child: _touch
|
||||
? projectList
|
||||
: IndexedStack(
|
||||
index: widget.resourcesSelected ? 1 : 0,
|
||||
index: widget.librarySelected
|
||||
? 2
|
||||
: widget.resourcesSelected
|
||||
? 1
|
||||
: 0,
|
||||
children: [
|
||||
TickerMode(
|
||||
enabled: !widget.resourcesSelected,
|
||||
enabled:
|
||||
!widget.resourcesSelected &&
|
||||
!widget.librarySelected,
|
||||
child: projectList,
|
||||
),
|
||||
TickerMode(
|
||||
enabled: widget.resourcesSelected,
|
||||
child: _resourcesVisited
|
||||
? MediaPanel(
|
||||
projectId: widget.state.activeProject?.id,
|
||||
onSelectProject: widget.onSelectProject,
|
||||
)
|
||||
: Center(child: Text(context.l10n.projectsNone)),
|
||||
enabled:
|
||||
widget.resourcesSelected &&
|
||||
!widget.librarySelected,
|
||||
child: ExcludeFocus(
|
||||
excluding:
|
||||
!widget.resourcesSelected ||
|
||||
widget.librarySelected,
|
||||
child: _resourcesVisited
|
||||
? MediaPanel(
|
||||
projectId: widget.state.activeProject?.id,
|
||||
onSelectProject: widget.onSelectProject,
|
||||
)
|
||||
: Center(
|
||||
child: Text(context.l10n.projectsNone),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox.expand(
|
||||
key: Key('resource-library-empty'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -924,7 +1250,6 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
VerticalDivider(
|
||||
key: const Key('sidebar-chat-divider'),
|
||||
width: 1,
|
||||
thickness: 1,
|
||||
color: AppTheme.sidebarDividerColor(context),
|
||||
),
|
||||
Expanded(
|
||||
@@ -981,7 +1306,7 @@ class _ProjectSidebarState extends ConsumerState<ProjectSidebar> {
|
||||
onPressed: widget.onExpandEditor,
|
||||
padding: EdgeInsets.zero,
|
||||
icon: const Icon(
|
||||
Icons.vertical_split_outlined,
|
||||
AppIcons.splitVertical,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
@@ -1122,7 +1447,9 @@ class _ProjectsHeader extends StatelessWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppSidebarTypography.style(
|
||||
context,
|
||||
fontSize: AppSidebarMetrics.sectionFontSize,
|
||||
fontSize: AppTheme.isDesktop(context)
|
||||
? 13
|
||||
: AppSidebarMetrics.sectionFontSize,
|
||||
weight: FontWeight.w500,
|
||||
color: AppSidebarColors.of(context).section,
|
||||
),
|
||||
@@ -1131,7 +1458,7 @@ class _ProjectsHeader extends StatelessWidget {
|
||||
if (onPressed != null) ...[
|
||||
const SizedBox(width: AppSpacing.tiny),
|
||||
Icon(
|
||||
Icons.keyboard_arrow_down,
|
||||
AppIcons.expandMore,
|
||||
size: AppSidebarMetrics.iconSize,
|
||||
color: AppSidebarColors.of(context).secondary,
|
||||
),
|
||||
@@ -1152,7 +1479,7 @@ class _ProjectsHeader extends StatelessWidget {
|
||||
dimension: AppSidebarMetrics.actionSize,
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.more_horiz,
|
||||
AppIcons.more,
|
||||
size: AppSidebarMetrics.iconSize,
|
||||
color: AppSidebarColors.of(context).tertiary,
|
||||
),
|
||||
@@ -1172,7 +1499,7 @@ class _ProjectsHeader extends StatelessWidget {
|
||||
tooltip: context.l10n.newProject,
|
||||
onPressed: onCreateProject,
|
||||
padding: EdgeInsets.zero,
|
||||
icon: const Icon(Icons.add, size: AppSidebarMetrics.iconSize),
|
||||
icon: const Icon(AppIcons.add, size: AppSidebarMetrics.iconSize),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1187,6 +1514,38 @@ Color _sidebarItemHighlightColor(BuildContext context) =>
|
||||
ButtonStyle sidebarActionButtonStyle(BuildContext context) =>
|
||||
AppTheme.iconButtonStyle(context);
|
||||
|
||||
ButtonStyle _projectActionButtonStyle(BuildContext context) {
|
||||
if (!AppTheme.isDesktop(context)) return sidebarActionButtonStyle(context);
|
||||
final colors = AppSidebarColors.of(context);
|
||||
final accent = Theme.of(context).colorScheme.primary;
|
||||
return sidebarActionButtonStyle(context).copyWith(
|
||||
foregroundColor: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.disabled)) return colors.disabled;
|
||||
if (states.contains(WidgetState.hovered) ||
|
||||
states.contains(WidgetState.focused) ||
|
||||
states.contains(WidgetState.pressed)) {
|
||||
return accent;
|
||||
}
|
||||
return colors.secondary;
|
||||
}),
|
||||
backgroundColor: const WidgetStatePropertyAll(Colors.transparent),
|
||||
overlayColor: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.disabled)) return Colors.transparent;
|
||||
if (states.contains(WidgetState.pressed)) {
|
||||
return accent.withValues(alpha: .16);
|
||||
}
|
||||
if (states.contains(WidgetState.hovered) ||
|
||||
states.contains(WidgetState.focused)) {
|
||||
return accent.withValues(alpha: .10);
|
||||
}
|
||||
return Colors.transparent;
|
||||
}),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _availabilityLabel(
|
||||
BuildContext context,
|
||||
ProjectAvailability availability,
|
||||
@@ -1228,7 +1587,7 @@ class _ProjectTile extends StatelessWidget {
|
||||
List<Widget> _menuItems(BuildContext context) => [
|
||||
AppMenuItem(
|
||||
label: context.l10n.rename,
|
||||
icon: Icons.drive_file_rename_outline,
|
||||
icon: AppIcons.rename,
|
||||
onPressed: project.availability.canOpen ? onRename : null,
|
||||
),
|
||||
if (sidebarStyle) ...[
|
||||
@@ -1248,14 +1607,20 @@ class _ProjectTile extends StatelessWidget {
|
||||
'${sidebarStyle ? 'sidebar-project' : 'open-project'}-${project.id}',
|
||||
),
|
||||
minTileHeight: sidebarStyle
|
||||
? AppSidebarMetrics.rowHeight
|
||||
? (AppTheme.isDesktop(context)
|
||||
? AppDesktopMetrics.sidebarRow
|
||||
: AppSidebarMetrics.rowHeight)
|
||||
: project.availability.canOpen
|
||||
? 36
|
||||
: 48,
|
||||
minVerticalPadding: 0,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: sidebarStyle ? 0 : AppSpacing.small,
|
||||
),
|
||||
contentPadding: sidebarStyle
|
||||
? EdgeInsetsDirectional.only(
|
||||
end: AppTheme.isDesktop(context)
|
||||
? AppSidebarMetrics.cellPadding
|
||||
: 0,
|
||||
)
|
||||
: const EdgeInsets.symmetric(horizontal: AppSpacing.small),
|
||||
horizontalTitleGap: sidebarStyle
|
||||
? AppSidebarMetrics.iconGap
|
||||
: AppSpacing.small,
|
||||
@@ -1264,7 +1629,9 @@ class _ProjectTile extends StatelessWidget {
|
||||
titleAlignment: ListTileTitleAlignment.center,
|
||||
selected: active,
|
||||
selectedTileColor: sidebarStyle
|
||||
? Colors.transparent
|
||||
? AppTheme.isDesktop(context)
|
||||
? AppSidebarColors.of(context).hover
|
||||
: Colors.transparent
|
||||
: _sidebarItemHighlightColor(context),
|
||||
textColor: project.availability.canOpen
|
||||
? null
|
||||
@@ -1273,7 +1640,11 @@ class _ProjectTile extends StatelessWidget {
|
||||
? null
|
||||
: Theme.of(context).disabledColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.extraLarge),
|
||||
borderRadius: BorderRadius.circular(
|
||||
sidebarStyle && AppTheme.isDesktop(context)
|
||||
? AppRadius.large
|
||||
: AppRadius.extraLarge,
|
||||
),
|
||||
),
|
||||
hoverColor: sidebarStyle
|
||||
? AppSidebarColors.of(context).hover
|
||||
@@ -1283,7 +1654,9 @@ class _ProjectTile extends StatelessWidget {
|
||||
leading: sidebarStyle
|
||||
? SizedBox(
|
||||
width: AppSidebarMetrics.iconSlotWidth,
|
||||
height: AppSidebarMetrics.rowHeight,
|
||||
height: AppTheme.isDesktop(context)
|
||||
? AppDesktopMetrics.sidebarRow
|
||||
: AppSidebarMetrics.rowHeight,
|
||||
child: IconButton(
|
||||
key: ValueKey('sidebar-project-toggle-${project.id}'),
|
||||
tooltip: expanded
|
||||
@@ -1294,22 +1667,18 @@ class _ProjectTile extends StatelessWidget {
|
||||
onPressed: onToggleExpanded,
|
||||
icon: Icon(
|
||||
!project.availability.canOpen
|
||||
? Icons.folder_off_outlined
|
||||
? AppIcons.folderUnavailable
|
||||
: hovered
|
||||
? (expanded
|
||||
? Icons.keyboard_arrow_down
|
||||
: Icons.chevron_right)
|
||||
: (expanded
|
||||
? Icons.folder_open_outlined
|
||||
: Icons.folder_outlined),
|
||||
? (expanded ? AppIcons.expandMore : AppIcons.chevronRight)
|
||||
: (expanded ? AppIcons.folderOpen : AppIcons.folder),
|
||||
size: AppSidebarMetrics.iconSize,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
project.availability.canOpen
|
||||
? Icons.folder_outlined
|
||||
: Icons.folder_off_outlined,
|
||||
? AppIcons.folder
|
||||
: AppIcons.folderUnavailable,
|
||||
size: 18,
|
||||
),
|
||||
title: Text(
|
||||
@@ -1319,6 +1688,15 @@ class _ProjectTile extends StatelessWidget {
|
||||
style: sidebarStyle
|
||||
? AppSidebarTypography.style(
|
||||
context,
|
||||
fontSize: AppTheme.isDesktop(context)
|
||||
? 13
|
||||
: AppSidebarMetrics.fontSize,
|
||||
height: AppTheme.isDesktop(context)
|
||||
? 20 / 13
|
||||
: AppSidebarMetrics.lineHeight,
|
||||
weight: AppTheme.isDesktop(context)
|
||||
? FontWeight.w500
|
||||
: FontWeight.w400,
|
||||
color: project.availability.canOpen
|
||||
? AppSidebarColors.of(context).primary
|
||||
: AppSidebarColors.of(context).disabled,
|
||||
@@ -1364,11 +1742,13 @@ class _ProjectTile extends StatelessWidget {
|
||||
builder: (context, toggle) => IconButton(
|
||||
key: ValueKey('sidebar-project-more-${project.id}'),
|
||||
onPressed: toggle,
|
||||
style: sidebarActionButtonStyle(context),
|
||||
style: _projectActionButtonStyle(context),
|
||||
padding: EdgeInsets.zero,
|
||||
icon: const Icon(
|
||||
Icons.more_horiz,
|
||||
size: AppSidebarMetrics.iconSize,
|
||||
icon: Icon(
|
||||
AppIcons.more,
|
||||
size: AppTheme.isDesktop(context)
|
||||
? 14
|
||||
: AppSidebarMetrics.iconSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1380,11 +1760,13 @@ class _ProjectTile extends StatelessWidget {
|
||||
key: ValueKey('new-agent-conversation-${project.id}'),
|
||||
tooltip: context.l10n.agentNewConversation,
|
||||
onPressed: onNewConversation,
|
||||
style: sidebarActionButtonStyle(context),
|
||||
style: _projectActionButtonStyle(context),
|
||||
padding: EdgeInsets.zero,
|
||||
icon: const Icon(
|
||||
Icons.edit_square,
|
||||
size: AppSidebarMetrics.iconSize,
|
||||
icon: Icon(
|
||||
AppIcons.edit,
|
||||
size: AppTheme.isDesktop(context)
|
||||
? 14
|
||||
: AppSidebarMetrics.iconSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,60 +1,19 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Keeps the current content during short switches without delaying completion.
|
||||
class ProjectSwitchRegion extends StatefulWidget {
|
||||
/// Keeps prepared content mounted until the next project is published.
|
||||
class ProjectSwitchRegion extends StatelessWidget {
|
||||
const ProjectSwitchRegion({
|
||||
super.key,
|
||||
required this.pendingProjectId,
|
||||
required this.builder,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final String? pendingProjectId;
|
||||
final Widget Function(BuildContext context, bool showDefaults) builder;
|
||||
|
||||
@override
|
||||
State<ProjectSwitchRegion> createState() => _ProjectSwitchRegionState();
|
||||
}
|
||||
|
||||
class _ProjectSwitchRegionState extends State<ProjectSwitchRegion> {
|
||||
Timer? _timer;
|
||||
bool _showDefaults = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_reset();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ProjectSwitchRegion oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.pendingProjectId != widget.pendingProjectId) _reset();
|
||||
}
|
||||
|
||||
void _reset() {
|
||||
_timer?.cancel();
|
||||
_showDefaults = false;
|
||||
if (widget.pendingProjectId != null) {
|
||||
_timer = Timer(const Duration(milliseconds: 150), () {
|
||||
if (mounted) setState(() => _showDefaults = true);
|
||||
});
|
||||
}
|
||||
}
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ExcludeFocus(
|
||||
excluding: widget.pendingProjectId != null,
|
||||
child: IgnorePointer(
|
||||
ignoring: widget.pendingProjectId != null,
|
||||
child: widget.builder(context, _showDefaults),
|
||||
),
|
||||
excluding: pendingProjectId != null,
|
||||
child: IgnorePointer(ignoring: pendingProjectId != null, child: child),
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
|
||||
class ProjectTabsBar extends StatefulWidget {
|
||||
const ProjectTabsBar({
|
||||
super.key,
|
||||
required this.projects,
|
||||
required this.recent,
|
||||
required this.selectedId,
|
||||
required this.onSelect,
|
||||
required this.onClose,
|
||||
required this.onCreate,
|
||||
required this.onOpen,
|
||||
required this.onRename,
|
||||
this.onRemoveRecent,
|
||||
this.projectMenuActions = const [],
|
||||
this.leadingActions = const [],
|
||||
this.trailingActions = const [],
|
||||
});
|
||||
|
||||
final List<RecentProject> projects;
|
||||
final List<RecentProject> recent;
|
||||
final String? selectedId;
|
||||
final ValueChanged<RecentProject> onSelect;
|
||||
final ValueChanged<RecentProject> onClose;
|
||||
final VoidCallback onCreate;
|
||||
final VoidCallback onOpen;
|
||||
final ValueChanged<RecentProject> onRename;
|
||||
final ValueChanged<RecentProject>? onRemoveRecent;
|
||||
final List<Widget> projectMenuActions;
|
||||
final List<Widget> leadingActions;
|
||||
final List<Widget> trailingActions;
|
||||
|
||||
@override
|
||||
State<ProjectTabsBar> createState() => _ProjectTabsBarState();
|
||||
}
|
||||
|
||||
class _ProjectTabsBarState extends State<ProjectTabsBar> {
|
||||
final _tabKeys = <String, GlobalKey>{};
|
||||
final _addKey = GlobalKey();
|
||||
double? _availableWidth;
|
||||
bool _active = true;
|
||||
List<RecentProject> get projects => widget.projects;
|
||||
List<RecentProject> get recent => widget.recent;
|
||||
String? get selectedId => widget.selectedId;
|
||||
ValueChanged<RecentProject> get onSelect => widget.onSelect;
|
||||
ValueChanged<RecentProject> get onClose => widget.onClose;
|
||||
VoidCallback get onCreate => widget.onCreate;
|
||||
VoidCallback get onOpen => widget.onOpen;
|
||||
ValueChanged<RecentProject> get onRename => widget.onRename;
|
||||
|
||||
void _revealSelection() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || !_active) return;
|
||||
final context = projects.lastOrNull?.id == selectedId
|
||||
? _addKey.currentContext
|
||||
: _tabKeys[selectedId]?.currentContext;
|
||||
if (context != null) {
|
||||
Scrollable.ensureVisible(
|
||||
context,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_revealSelection();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ProjectTabsBar oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.selectedId != selectedId ||
|
||||
oldWidget.projects.length != projects.length ||
|
||||
oldWidget.projects.any(
|
||||
(project) =>
|
||||
projects.where((item) => item.id == project.id).firstOrNull !=
|
||||
project,
|
||||
)) {
|
||||
_revealSelection();
|
||||
}
|
||||
final ids = projects.map((project) => project.id).toSet();
|
||||
_tabKeys.removeWhere((id, _) => !ids.contains(id));
|
||||
}
|
||||
|
||||
@override
|
||||
void deactivate() {
|
||||
_active = false;
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
@override
|
||||
void activate() {
|
||||
super.activate();
|
||||
_active = true;
|
||||
_revealSelection();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (_availableWidth != constraints.maxWidth) {
|
||||
_availableWidth = constraints.maxWidth;
|
||||
_revealSelection();
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppProjectTabMetrics.gap,
|
||||
),
|
||||
child: Row(
|
||||
key: const Key('window-project-tabs'),
|
||||
children: [
|
||||
for (final action in widget.leadingActions) ...[
|
||||
HeaderControlRegion(
|
||||
child: SizedBox.square(
|
||||
dimension: AppProjectTabMetrics.height,
|
||||
child: action,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppProjectTabMetrics.gap),
|
||||
],
|
||||
AppDropdownMenu(
|
||||
maxHeight: 400,
|
||||
items: [
|
||||
AppMenuItem(
|
||||
label: context.l10n.newProject,
|
||||
icon: AppIcons.add,
|
||||
onPressed: onCreate,
|
||||
),
|
||||
AppMenuItem(
|
||||
label: context.l10n.openProjectMore,
|
||||
icon: AppIcons.folder,
|
||||
onPressed: onOpen,
|
||||
),
|
||||
if (recent.isNotEmpty) const AppMenuSeparator(),
|
||||
for (final project in recent)
|
||||
AppContextMenu(
|
||||
itemsBuilder: (_) => [
|
||||
AppMenuItem(
|
||||
label: context.l10n.rename,
|
||||
icon: AppIcons.rename,
|
||||
onPressed: !project.availability.canOpen
|
||||
? null
|
||||
: () => onRename(project),
|
||||
),
|
||||
if (widget.onRemoveRecent != null)
|
||||
AppMenuItem(
|
||||
label: context.l10n.removeProjectFromRecent,
|
||||
onPressed: () => widget.onRemoveRecent!(project),
|
||||
),
|
||||
],
|
||||
child: AppMenuItem(
|
||||
key: ValueKey('project-menu-${project.id}'),
|
||||
label: project.availability.canOpen
|
||||
? project.name
|
||||
: '${project.name} · ${context.l10n.projectAccessFailed}',
|
||||
icon: project.availability.canOpen
|
||||
? AppIcons.folder
|
||||
: AppIcons.folderUnavailable,
|
||||
selected: project.id == selectedId,
|
||||
onPressed: () => onSelect(project),
|
||||
),
|
||||
),
|
||||
if (widget.projectMenuActions.isNotEmpty) ...[
|
||||
const AppMenuSeparator(),
|
||||
...widget.projectMenuActions,
|
||||
],
|
||||
],
|
||||
builder: (context, toggle, focusNode) => HeaderControlRegion(
|
||||
child: IconButton(
|
||||
key: const Key('project-tabs-projects'),
|
||||
focusNode: focusNode,
|
||||
tooltip: context.l10n.projects,
|
||||
onPressed: toggle,
|
||||
constraints: const BoxConstraints.tightFor(
|
||||
width: AppProjectTabMetrics.height,
|
||||
height: AppProjectTabMetrics.height,
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: AppIconSize.small,
|
||||
style: AppTheme.projectTabActionStyle(context),
|
||||
icon: const Icon(AppIcons.home),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppProjectTabMetrics.gap),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (var index = 0; index < projects.length; index++) ...[
|
||||
if (index > 0)
|
||||
const SizedBox(width: AppProjectTabMetrics.gap),
|
||||
_ProjectTab(
|
||||
key: ValueKey(projects[index].id),
|
||||
anchorKey: _tabKeys.putIfAbsent(
|
||||
projects[index].id,
|
||||
GlobalKey.new,
|
||||
),
|
||||
project: projects[index],
|
||||
selected: projects[index].id == selectedId,
|
||||
maxWidth:
|
||||
(constraints.maxWidth -
|
||||
5 * AppProjectTabMetrics.gap -
|
||||
3 * AppProjectTabMetrics.height -
|
||||
(widget.leadingActions.length +
|
||||
widget.trailingActions.length) *
|
||||
(AppProjectTabMetrics.height +
|
||||
AppProjectTabMetrics.gap))
|
||||
.clamp(
|
||||
AppProjectTabMetrics.minWidth,
|
||||
AppProjectTabMetrics.maxWidth,
|
||||
),
|
||||
onSelect: () => onSelect(projects[index]),
|
||||
onClose: () => onClose(projects[index]),
|
||||
onRename: () => onRename(projects[index]),
|
||||
),
|
||||
],
|
||||
if (projects.isNotEmpty)
|
||||
const SizedBox(width: AppProjectTabMetrics.gap),
|
||||
HeaderControlRegion(
|
||||
key: _addKey,
|
||||
child: IconButton(
|
||||
key: const Key('project-tabs-add'),
|
||||
tooltip: context.l10n.newProject,
|
||||
onPressed: onCreate,
|
||||
iconSize: 16,
|
||||
style: AppTheme.projectTabActionStyle(context),
|
||||
icon: const Icon(AppIcons.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppProjectTabMetrics.gap),
|
||||
AppDropdownMenu(
|
||||
enabled: projects.isNotEmpty,
|
||||
maxHeight: 400,
|
||||
items: [
|
||||
for (final project in projects)
|
||||
AppMenuItem(
|
||||
key: ValueKey('project-tabs-menu-${project.id}'),
|
||||
label: project.name,
|
||||
icon: AppIcons.folder,
|
||||
selected: project.id == selectedId,
|
||||
onPressed: () => onSelect(project),
|
||||
),
|
||||
],
|
||||
builder: (context, toggle, focusNode) => HeaderControlRegion(
|
||||
child: IconButton(
|
||||
key: const Key('project-tabs-list'),
|
||||
focusNode: focusNode,
|
||||
tooltip: context.l10n.selectProject,
|
||||
onPressed: toggle,
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: 14,
|
||||
style: AppTheme.projectTabActionStyle(context),
|
||||
icon: const Icon(AppIcons.expandMore),
|
||||
),
|
||||
),
|
||||
),
|
||||
for (final action in widget.trailingActions) ...[
|
||||
const SizedBox(width: AppProjectTabMetrics.gap),
|
||||
HeaderControlRegion(
|
||||
child: SizedBox.square(
|
||||
dimension: AppProjectTabMetrics.height,
|
||||
child: action,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class _ProjectTab extends StatefulWidget {
|
||||
const _ProjectTab({
|
||||
super.key,
|
||||
required this.anchorKey,
|
||||
required this.project,
|
||||
required this.selected,
|
||||
required this.maxWidth,
|
||||
required this.onSelect,
|
||||
required this.onClose,
|
||||
required this.onRename,
|
||||
});
|
||||
final GlobalKey anchorKey;
|
||||
final RecentProject project;
|
||||
final bool selected;
|
||||
final double maxWidth;
|
||||
final VoidCallback onSelect, onClose, onRename;
|
||||
@override
|
||||
State<_ProjectTab> createState() => _ProjectTabState();
|
||||
}
|
||||
|
||||
class _ProjectTabState extends State<_ProjectTab> {
|
||||
bool _hovered = false;
|
||||
bool _focused = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final project = widget.project;
|
||||
final style = AppTheme.projectTabStyle(context, selected: widget.selected);
|
||||
final states = <WidgetState>{
|
||||
if (_hovered) WidgetState.hovered,
|
||||
if (_focused) WidgetState.focused,
|
||||
};
|
||||
final showClose = widget.selected || _hovered || _focused;
|
||||
return HeaderControlRegion(
|
||||
child: MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
onFocusChange: (value) => setState(() => _focused = value),
|
||||
child: AppContextMenu(
|
||||
itemsBuilder: (_) => [
|
||||
AppMenuItem(
|
||||
label: context.l10n.rename,
|
||||
onPressed: widget.onRename,
|
||||
),
|
||||
AppMenuItem(
|
||||
label: MaterialLocalizations.of(context).closeButtonTooltip,
|
||||
onPressed: widget.onClose,
|
||||
),
|
||||
],
|
||||
child: Semantics(
|
||||
selected: widget.selected,
|
||||
child: Material(
|
||||
key: widget.anchorKey,
|
||||
color: style.backgroundColor!.resolve(states),
|
||||
borderRadius: BorderRadius.circular(
|
||||
AppProjectTabMetrics.radius,
|
||||
),
|
||||
child: ConstrainedBox(
|
||||
key: ValueKey('project-tab-surface-${project.id}'),
|
||||
constraints: BoxConstraints(
|
||||
minWidth: AppProjectTabMetrics.minWidth,
|
||||
maxWidth: widget.maxWidth,
|
||||
),
|
||||
child: IntrinsicWidth(
|
||||
child: SizedBox(
|
||||
height: AppProjectTabMetrics.height,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Tooltip(
|
||||
message: '${project.name}\n${project.path}',
|
||||
child: TextButton(
|
||||
key: ValueKey('project-tab-${project.id}'),
|
||||
onPressed: widget.onSelect,
|
||||
style: style.copyWith(
|
||||
alignment: Alignment.centerLeft,
|
||||
backgroundColor: const WidgetStatePropertyAll(
|
||||
Colors.transparent,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(AppIcons.folder, size: 14),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
child: Text(
|
||||
project.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
ExcludeFocus(
|
||||
excluding: !showClose,
|
||||
child: IgnorePointer(
|
||||
ignoring: !showClose,
|
||||
child: ExcludeSemantics(
|
||||
excluding: !showClose,
|
||||
child: Opacity(
|
||||
opacity: showClose ? 1 : 0,
|
||||
child: IconButton(
|
||||
key: ValueKey(
|
||||
'project-tab-close-${project.id}',
|
||||
),
|
||||
tooltip: MaterialLocalizations.of(context)
|
||||
.closeButtonTooltip,
|
||||
onPressed: widget.onClose,
|
||||
constraints: const BoxConstraints.tightFor(
|
||||
width: AppProjectTabMetrics.close,
|
||||
height: AppProjectTabMetrics.close,
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
iconSize: 12,
|
||||
style: AppTheme.projectTabActionStyle(
|
||||
context,
|
||||
size: AppProjectTabMetrics.close,
|
||||
),
|
||||
icon: const Icon(AppIcons.close),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
import 'project_tabs_bar.dart';
|
||||
|
||||
@Preview(
|
||||
name: 'Rounded project tabs — dark',
|
||||
group: 'Desktop navigation',
|
||||
size: Size(720, 44),
|
||||
)
|
||||
Widget projectTabsDarkPreview() => _preview(Brightness.dark);
|
||||
|
||||
@Preview(
|
||||
name: 'Rounded project tabs — light, narrow',
|
||||
group: 'Desktop navigation',
|
||||
size: Size(320, 44),
|
||||
)
|
||||
Widget projectTabsLightPreview() => _preview(Brightness.light);
|
||||
|
||||
@Preview(
|
||||
name: 'Rounded project tabs — dark, compact',
|
||||
group: 'Desktop navigation',
|
||||
size: Size(240, 44),
|
||||
)
|
||||
Widget projectTabsCompactPreview() => _preview(Brightness.dark);
|
||||
|
||||
Widget _preview(Brightness brightness) {
|
||||
const projects = [
|
||||
RecentProject(id: 'travel', name: '旅行短片', path: '/Projects/Travel.cutdex'),
|
||||
RecentProject(
|
||||
id: 'product',
|
||||
name: '产品介绍',
|
||||
path: '/Projects/Product.cutdex',
|
||||
),
|
||||
RecentProject(id: 'city', name: '城市漫步', path: '/Projects/City.cutdex'),
|
||||
];
|
||||
var opened = projects.take(2).toList();
|
||||
var selected = 'travel';
|
||||
return MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, brightness),
|
||||
),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) => ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||
child: ProjectTabsBar(
|
||||
projects: opened,
|
||||
recent: projects,
|
||||
selectedId: selected,
|
||||
onSelect: (project) => setState(() {
|
||||
selected = project.id;
|
||||
if (!opened.contains(project)) {
|
||||
opened = [...opened, project];
|
||||
}
|
||||
}),
|
||||
onClose: (project) => setState(() {
|
||||
opened = opened.where((item) => item.id != project.id).toList();
|
||||
if (selected == project.id) {
|
||||
selected = opened.firstOrNull?.id ?? '';
|
||||
}
|
||||
}),
|
||||
onCreate: () {},
|
||||
onOpen: () {},
|
||||
onRename: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../shared/widgets/presentation_list.dart';
|
||||
import '../../workspace/project_state.dart';
|
||||
import '../../workspace/projects.dart';
|
||||
|
||||
final projectTabsProvider =
|
||||
NotifierProvider<ProjectTabsController, List<RecentProject>>(
|
||||
ProjectTabsController.new,
|
||||
);
|
||||
|
||||
/// Open tabs are separate from the recent-project history.
|
||||
class ProjectTabsController extends Notifier<List<RecentProject>> {
|
||||
@override
|
||||
List<RecentProject> build() {
|
||||
ref.listen(
|
||||
projectsProvider.select(
|
||||
(value) => (
|
||||
value.value?.activeProject,
|
||||
PresentationList(value.value?.recent ?? const <RecentProject>[]),
|
||||
),
|
||||
),
|
||||
(_, next) {
|
||||
final (active, recent) = next;
|
||||
final metadata = {for (final project in recent) project.id: project};
|
||||
if (active != null) metadata[active.id] = active;
|
||||
final updated = [
|
||||
for (final project in state) metadata[project.id] ?? project,
|
||||
if (active != null && !state.any((tab) => tab.id == active.id))
|
||||
active,
|
||||
];
|
||||
if (!listEquals(state, updated)) state = List.unmodifiable(updated);
|
||||
},
|
||||
);
|
||||
final active = ref.read(projectsProvider).value?.activeProject;
|
||||
return List.unmodifiable([?active]);
|
||||
}
|
||||
|
||||
void remove(String id) => state = List.unmodifiable([
|
||||
for (final tab in state)
|
||||
if (tab.id != id) tab,
|
||||
]);
|
||||
|
||||
void updateProject(RecentProject project) {
|
||||
final updated = [
|
||||
for (final tab in state)
|
||||
if (tab.id == project.id) project else tab,
|
||||
];
|
||||
if (!listEquals(state, updated)) state = List.unmodifiable(updated);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import '../../shared/widgets/presentation_list.dart';
|
||||
import '../assistant/agent_panel_presentation.dart';
|
||||
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
@@ -23,6 +26,8 @@ import 'package:cutdex_native/cutdex_native.dart';
|
||||
|
||||
import '../../persistence/app_settings_repositories.dart';
|
||||
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
|
||||
import '../../workspace/project_state.dart';
|
||||
@@ -38,6 +43,8 @@ import '../settings/settings_page.dart';
|
||||
import 'editor_loading_region.dart';
|
||||
import 'project_switch_region.dart';
|
||||
import 'project_sidebar.dart';
|
||||
import 'project_tabs_bar.dart';
|
||||
import 'project_tabs_controller.dart';
|
||||
import 'widgets/name_dialog.dart';
|
||||
|
||||
/// The single application surface: project navigation beside the editor.
|
||||
@@ -90,13 +97,26 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
WidgetRef ref, {
|
||||
required bool create,
|
||||
}) async {
|
||||
if (ref.read(projectsProvider).value?.projectBusy == true) return;
|
||||
if (_switchingProject ||
|
||||
ref.read(projectsProvider).value?.projectBusy == true) {
|
||||
return;
|
||||
}
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
try {
|
||||
if (create) {
|
||||
final name = await askName(
|
||||
context,
|
||||
title: context.l10n.newProject,
|
||||
label: context.l10n.projectName,
|
||||
validateName: (name) async {
|
||||
final failure = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.validateNewProjectName(name);
|
||||
if (!context.mounted) return null;
|
||||
return failure == null
|
||||
? null
|
||||
: context.l10n.failureMessage(failure);
|
||||
},
|
||||
);
|
||||
if (name == null || !context.mounted) return;
|
||||
final created = await ref
|
||||
@@ -130,15 +150,50 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openProject(WidgetRef ref, RecentProject project) =>
|
||||
ref.read(workspaceNavigationProvider.notifier).openProject(project);
|
||||
Future<void> _openProject(WidgetRef ref, RecentProject project) {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
return ref.read(workspaceNavigationProvider.notifier).openProject(project);
|
||||
}
|
||||
|
||||
Future<void> _closeProjectTab(RecentProject project) async {
|
||||
if (_switchingProject ||
|
||||
ref.read(projectsProvider).value?.projectBusy == true) {
|
||||
return;
|
||||
}
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
final tabs = ref.read(projectTabsProvider);
|
||||
if (ref.read(projectsProvider).value?.activeProject?.id == project.id) {
|
||||
final index = tabs.indexWhere((tab) => tab.id == project.id);
|
||||
final neighbors = [
|
||||
...tabs.skip(index + 1),
|
||||
...tabs.take(index).toList().reversed,
|
||||
];
|
||||
final next = neighbors.firstOrNull;
|
||||
if (next != null) {
|
||||
await _openProject(ref, next);
|
||||
if (!mounted ||
|
||||
ref.read(projectsProvider).value?.activeProject?.id != next.id) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
final closed = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.closeActiveProject();
|
||||
if (!closed || !mounted) return;
|
||||
}
|
||||
}
|
||||
if (mounted) ref.read(projectTabsProvider.notifier).remove(project.id);
|
||||
}
|
||||
|
||||
Future<bool> _renameProject(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
RecentProject project,
|
||||
) async {
|
||||
if (ref.read(projectsProvider).value?.projectBusy == true) return false;
|
||||
if (_switchingProject ||
|
||||
ref.read(projectsProvider).value?.projectBusy == true) {
|
||||
return false;
|
||||
}
|
||||
final name = await askName(
|
||||
context,
|
||||
title: context.l10n.rename,
|
||||
@@ -147,7 +202,35 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
submitLabel: context.l10n.rename,
|
||||
);
|
||||
if (name == null || !context.mounted || name == project.name) return false;
|
||||
return ref.read(projectsProvider.notifier).renameProject(project, name);
|
||||
final renamed = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.renameProject(project, name);
|
||||
if (renamed && mounted) {
|
||||
ref
|
||||
.read(projectTabsProvider.notifier)
|
||||
.updateProject(project.copyWith(name: name.trim()));
|
||||
}
|
||||
return renamed;
|
||||
}
|
||||
|
||||
Future<void> _removeRecentProject(RecentProject project) async {
|
||||
if (_switchingProject ||
|
||||
ref.read(projectsProvider).value?.projectBusy == true) {
|
||||
return;
|
||||
}
|
||||
final recent = ref.read(projectsProvider).value?.recent ?? const [];
|
||||
final index = recent.indexWhere((item) => item.id == project.id);
|
||||
final removed = await ref
|
||||
.read(projectsProvider.notifier)
|
||||
.removeRecentProject(project.id);
|
||||
if (!removed || !mounted) return;
|
||||
ErrorNotificationHost.of(context).showMessage(
|
||||
content: Text(context.l10n.projectRemoved),
|
||||
actionLabel: context.l10n.undo,
|
||||
onAction: () => ref
|
||||
.read(projectsProvider.notifier)
|
||||
.restoreRecentProject(project, index),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _relocateProject(
|
||||
@@ -155,7 +238,10 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
WidgetRef ref,
|
||||
RecentProject project,
|
||||
) async {
|
||||
if (ref.read(projectsProvider).value?.projectBusy == true) return;
|
||||
if (_switchingProject ||
|
||||
ref.read(projectsProvider).value?.projectBusy == true) {
|
||||
return;
|
||||
}
|
||||
final directory = await ref
|
||||
.read(filePickerProvider)
|
||||
.pickDirectory(confirmButtonText: context.l10n.openProject);
|
||||
@@ -183,7 +269,30 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
final experience = ref.watch(deviceExperienceProvider);
|
||||
final desktop = experience == DeviceExperience.desktop;
|
||||
final contentSelection = ref.watch(desktopContentProvider);
|
||||
final projects = ref.watch(projectsProvider);
|
||||
final openProjects = ref.watch(projectTabsProvider);
|
||||
// Window/navigation subscribe to chrome only. Content owns live values.
|
||||
ref.watch(
|
||||
projectsProvider.select((value) {
|
||||
final state = value.value;
|
||||
return (
|
||||
value.isLoading,
|
||||
value.error,
|
||||
state?.activeProject,
|
||||
PresentationList(state?.recent ?? const <RecentProject>[]),
|
||||
state?.timeline?.id,
|
||||
state?.projectBusy,
|
||||
state?.openingTimelineId,
|
||||
state?.error,
|
||||
PresentationList(
|
||||
state?.timelines.map(
|
||||
(timeline) => (timeline.id, timeline.name, timeline.pinned),
|
||||
) ??
|
||||
const <(String, String, bool)>[],
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
final projects = ref.read(projectsProvider);
|
||||
final state = projects.value ?? const ProjectState();
|
||||
return EditorWindowChrome(
|
||||
headerHeight: desktop ? DesktopWindowFrame.headerHeight : 48,
|
||||
@@ -210,6 +319,42 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
);
|
||||
final navigationCollapsed =
|
||||
_sidebarCollapsed || navigationHiddenBySpace;
|
||||
void toggleSidebar() {
|
||||
if (desktop && _desktopSplits.agentFloating) {
|
||||
_desktopSplits.setAgentFloating(false);
|
||||
_sidebarCollapsed = false;
|
||||
_saveViewState();
|
||||
if (navigationHiddenBySpace) {
|
||||
_desktopScaffoldKey.currentState
|
||||
?.openDrawer();
|
||||
}
|
||||
} else if (navigationHiddenBySpace) {
|
||||
final scaffold =
|
||||
_desktopScaffoldKey.currentState;
|
||||
if (scaffold?.isDrawerOpen == true) {
|
||||
scaffold?.closeDrawer();
|
||||
} else {
|
||||
scaffold?.openDrawer();
|
||||
}
|
||||
} else {
|
||||
_sidebarCollapsed = !_sidebarCollapsed;
|
||||
_saveViewState();
|
||||
}
|
||||
}
|
||||
|
||||
void toggleAgentFloating() {
|
||||
final floating = !_desktopSplits.agentFloating;
|
||||
if (floating) {
|
||||
_desktopScaffoldKey.currentState?.closeDrawer();
|
||||
_sidebarCollapsed = false;
|
||||
_saveViewState();
|
||||
}
|
||||
_desktopSplits.setAgentFloating(floating);
|
||||
if (!floating && navigationHiddenBySpace) {
|
||||
_desktopScaffoldKey.currentState?.openDrawer();
|
||||
}
|
||||
}
|
||||
|
||||
Widget controlSlot(Widget child) {
|
||||
if (!desktop) {
|
||||
return SizedBox.square(
|
||||
@@ -263,9 +408,7 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: desktop
|
||||
? (DesktopWindowFrame.railWidth -
|
||||
AppControlSize.headerButton) /
|
||||
2
|
||||
? DesktopWindowFrame.headerInset
|
||||
: 0,
|
||||
),
|
||||
child: Row(
|
||||
@@ -281,21 +424,12 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
tooltip: navigationCollapsed
|
||||
? context.l10n.expandSidebar
|
||||
: context.l10n.collapseSidebar,
|
||||
onPressed: () {
|
||||
if (navigationHiddenBySpace) {
|
||||
_desktopScaffoldKey.currentState
|
||||
?.openDrawer();
|
||||
} else {
|
||||
_sidebarCollapsed =
|
||||
!_sidebarCollapsed;
|
||||
_saveViewState();
|
||||
}
|
||||
},
|
||||
onPressed: toggleSidebar,
|
||||
style: sidebarActionButtonStyle(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.view_sidebar_outlined,
|
||||
AppIcons.sidebar,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
@@ -316,7 +450,7 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.settings_outlined,
|
||||
AppIcons.settings,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
@@ -349,6 +483,7 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
|
||||
final agent = WorkspaceAgentSurface(
|
||||
key: _agentKey,
|
||||
showProjectSelector: !desktop,
|
||||
state: state,
|
||||
onSelectProject: (project) =>
|
||||
project.availability.canOpen
|
||||
@@ -357,14 +492,10 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
onCreateProject: () =>
|
||||
_selectProject(context, ref, create: true),
|
||||
);
|
||||
void selectSidebar(bool resources) {
|
||||
void selectSidebar(DesktopContent surface) {
|
||||
ref
|
||||
.read(desktopContentProvider.notifier)
|
||||
.select(
|
||||
resources
|
||||
? DesktopContent.library
|
||||
: DesktopContent.workspace,
|
||||
);
|
||||
.select(surface);
|
||||
setState(() => _sidebarCollapsed = false);
|
||||
_saveViewState();
|
||||
if (navigationHiddenBySpace) {
|
||||
@@ -384,15 +515,23 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
VoidCallback? expandEditor,
|
||||
bool drawer = false,
|
||||
}) => ProjectSidebar(
|
||||
chatOnly: desktop,
|
||||
experience: experience,
|
||||
librarySelected:
|
||||
desktop && contentSelection.librarySelected,
|
||||
resourcesSelected:
|
||||
desktop && contentSelection.resourcesSelected,
|
||||
onResourcesSelected: desktop
|
||||
? (media) => selectSidebar(
|
||||
media
|
||||
? DesktopContent.library
|
||||
: DesktopContent.workspace,
|
||||
)
|
||||
: null,
|
||||
key: drawer
|
||||
? _drawerNavigationKey
|
||||
: _navigationKey,
|
||||
agent: desktop && !drawer
|
||||
? agent
|
||||
: const SizedBox.shrink(),
|
||||
agent: desktop ? agent : const SizedBox.shrink(),
|
||||
navigationOnly: true,
|
||||
onNavigationComplete: desktop && !drawer
|
||||
? null
|
||||
@@ -431,70 +570,66 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
onPressed: () =>
|
||||
Scaffold.of(context)
|
||||
.closeDrawer(),
|
||||
icon: const Icon(Icons.close),
|
||||
icon: const Icon(AppIcons.close),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
final pendingProject = _switchingProject
|
||||
? state.recent
|
||||
final selectedProjectId =
|
||||
_selectedProjectId ?? state.activeProject?.id;
|
||||
final pendingProject = _selectedProjectId == null
|
||||
? null
|
||||
: state.recent
|
||||
.where(
|
||||
(item) => item.id == _selectedProjectId,
|
||||
(item) => item.id == selectedProjectId,
|
||||
)
|
||||
.firstOrNull
|
||||
: null;
|
||||
final projectLoading =
|
||||
pendingProject != null &&
|
||||
pendingProject.id != state.activeProject?.id;
|
||||
.firstOrNull;
|
||||
final visibleProjects = [
|
||||
...openProjects,
|
||||
if (pendingProject != null &&
|
||||
!openProjects.any(
|
||||
(item) => item.id == pendingProject.id,
|
||||
))
|
||||
pendingProject,
|
||||
];
|
||||
final editor = ProjectSwitchRegion(
|
||||
pendingProjectId: projectLoading
|
||||
? pendingProject.id
|
||||
pendingProjectId:
|
||||
selectedProjectId != state.activeProject?.id
|
||||
? _selectedProjectId
|
||||
: null,
|
||||
builder: (context, showDefaults) {
|
||||
final displayDefaults =
|
||||
projectLoading && showDefaults;
|
||||
final visibleProject = displayDefaults
|
||||
? pendingProject
|
||||
: state.activeProject;
|
||||
return visibleProject != null &&
|
||||
(displayDefaults ||
|
||||
state.timeline != null)
|
||||
? EditorWorkspace(
|
||||
key: _editorKey,
|
||||
experience: experience,
|
||||
projectId: visibleProject.id,
|
||||
timelineId: displayDefaults
|
||||
? ''
|
||||
: state.visibleTimelineId!,
|
||||
projectName: visibleProject.name,
|
||||
projectLoading: displayDefaults,
|
||||
timelineLoading:
|
||||
state.openingTimelineId != null,
|
||||
showProjectName:
|
||||
desktop &&
|
||||
_mode == WorkspaceMode.cut,
|
||||
integratedTitlebar: false,
|
||||
headerLeading: desktop
|
||||
? const SizedBox.shrink()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
)
|
||||
: EmptyEditor(
|
||||
desktop: desktop,
|
||||
state: state,
|
||||
showProjectName:
|
||||
desktop &&
|
||||
_mode == WorkspaceMode.cut,
|
||||
headerLeading: desktop
|
||||
? const SizedBox.shrink()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
);
|
||||
},
|
||||
child:
|
||||
state.activeProject != null &&
|
||||
state.timeline != null
|
||||
? EditorWorkspace(
|
||||
key: _editorKey,
|
||||
experience: experience,
|
||||
projectId: state.activeProject!.id,
|
||||
timelineId: state.timeline!.id,
|
||||
projectName: state.activeProject!.name,
|
||||
timelineLoading:
|
||||
state.openingTimelineId != null,
|
||||
showProjectName: false,
|
||||
integratedTitlebar: false,
|
||||
headerLeading: desktop
|
||||
? const SizedBox.shrink()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
)
|
||||
: EmptyEditor(
|
||||
experience: experience,
|
||||
desktop: desktop,
|
||||
state: state,
|
||||
showProjectName:
|
||||
desktop && _mode == WorkspaceMode.cut,
|
||||
headerLeading: desktop
|
||||
? const SizedBox.shrink()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
),
|
||||
);
|
||||
Widget contentSurface(
|
||||
DesktopContent surface,
|
||||
@@ -534,6 +669,12 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
),
|
||||
child: SettingsContent(
|
||||
cardLayout: true,
|
||||
onBack: () => ref
|
||||
.read(
|
||||
desktopContentProvider
|
||||
.notifier,
|
||||
)
|
||||
.closeSettings(),
|
||||
initialTab:
|
||||
contentSelection.settingsTab,
|
||||
navigationRequest: contentSelection
|
||||
@@ -549,22 +690,105 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
return switch (experience) {
|
||||
DeviceExperience.desktop => DesktopWindowFrame(
|
||||
integratedTitlebar: integrated,
|
||||
headerControls: controls(),
|
||||
librarySelected:
|
||||
headerControls: const SizedBox.shrink(),
|
||||
projectTabs: ListenableBuilder(
|
||||
listenable: _desktopSplits,
|
||||
builder: (context, _) => ProjectTabsBar(
|
||||
projects: visibleProjects,
|
||||
recent: state.recent,
|
||||
selectedId: selectedProjectId,
|
||||
onSelect: (project) {
|
||||
ref
|
||||
.read(desktopContentProvider.notifier)
|
||||
.select(DesktopContent.workspace);
|
||||
selectProject(project);
|
||||
},
|
||||
onClose: _closeProjectTab,
|
||||
onCreate: () => _selectProject(
|
||||
context,
|
||||
ref,
|
||||
create: true,
|
||||
),
|
||||
onOpen: () => _selectProject(
|
||||
context,
|
||||
ref,
|
||||
create: false,
|
||||
),
|
||||
onRename: (project) =>
|
||||
_renameProject(context, ref, project),
|
||||
onRemoveRecent: _removeRecentProject,
|
||||
leadingActions: [
|
||||
IconButton(
|
||||
key: const Key(
|
||||
'project-sidebar-toggle',
|
||||
),
|
||||
tooltip:
|
||||
navigationCollapsed ||
|
||||
_desktopSplits.agentFloating
|
||||
? context.l10n.expandSidebar
|
||||
: context.l10n.collapseSidebar,
|
||||
onPressed: toggleSidebar,
|
||||
style: AppTheme.projectTabActionStyle(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
AppIcons.sidebar,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
],
|
||||
trailingActions: [
|
||||
IconButton(
|
||||
key: const Key('agent-minimize-button'),
|
||||
tooltip: _desktopSplits.agentFloating
|
||||
? context.l10n.agentDock
|
||||
: context.l10n.agentMinimize,
|
||||
onPressed: toggleAgentFloating,
|
||||
isSelected:
|
||||
_desktopSplits.agentFloating,
|
||||
style: AppTheme.projectTabActionStyle(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
AppIcons.fullscreen,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
const BackgroundTasksButton(
|
||||
iconSize: 16,
|
||||
alignment:
|
||||
AlignmentDirectional.bottomEnd,
|
||||
),
|
||||
],
|
||||
projectMenuActions: [
|
||||
AppMenuItem(
|
||||
key: const Key(
|
||||
'project-settings-button',
|
||||
),
|
||||
label: context.l10n.settings,
|
||||
icon: AppIcons.settings,
|
||||
onPressed: () =>
|
||||
showSettingsPage(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
resourceLibrarySelected:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.library,
|
||||
DesktopContent.resourceLibrary,
|
||||
onResourceLibraryPressed: () => selectSidebar(
|
||||
DesktopContent.resourceLibrary,
|
||||
),
|
||||
settingsSelected:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.settings,
|
||||
onModeChanged: (mode) {
|
||||
selectSidebar(false);
|
||||
_setMode(mode);
|
||||
},
|
||||
onLibraryPressed: () => selectSidebar(true),
|
||||
onHomePressed: () =>
|
||||
selectSidebar(DesktopContent.workspace),
|
||||
onSettingsPressed: () =>
|
||||
showSettingsPage(context),
|
||||
child: desktopContents(
|
||||
DesktopWorkspaceShell(
|
||||
projectTabsLayout: true,
|
||||
controller: _desktopSplits,
|
||||
scaffoldKey: _desktopScaffoldKey,
|
||||
navigationDrawer: navigation(drawer: true),
|
||||
@@ -584,63 +808,90 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
geometry: geometry,
|
||||
expandEditor: expand,
|
||||
),
|
||||
agentBuilder: (geometry, expand) => Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
key: const Key(
|
||||
'agent-content-header',
|
||||
),
|
||||
height: AppControlSize.panelToolbar,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(
|
||||
AppSpacing.gap,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Spacer(),
|
||||
HeaderControlRegion(
|
||||
child: SizedBox.square(
|
||||
dimension: AppControlSize
|
||||
.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key(
|
||||
'agent-fullscreen-button',
|
||||
agentBuilder: (geometry, expand) =>
|
||||
_desktopSplits.agentFloating
|
||||
? AgentPanelPresentation(
|
||||
compact: true,
|
||||
expanded: _desktopSplits
|
||||
.agentFloatingExpanded,
|
||||
onToggleExpanded: _desktopSplits
|
||||
.toggleFloatingConversation,
|
||||
onDock: () => _desktopSplits
|
||||
.setAgentFloating(false),
|
||||
child: agent,
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
key: const Key(
|
||||
'agent-content-header',
|
||||
),
|
||||
height: AppDesktopMetrics
|
||||
.panelHeader,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
),
|
||||
isSelected:
|
||||
geometry.editorHidden,
|
||||
tooltip:
|
||||
geometry.editorHidden
|
||||
? context
|
||||
.l10n
|
||||
.exitPreviewFullscreen
|
||||
: context
|
||||
.l10n
|
||||
.agentFullscreen,
|
||||
onPressed:
|
||||
geometry.editorHidden
|
||||
? expand
|
||||
: () => _desktopSplits
|
||||
.setAgentFullscreen(
|
||||
true,
|
||||
),
|
||||
icon: Icon(
|
||||
size:
|
||||
AppIconSize.header,
|
||||
geometry.editorHidden
|
||||
? Icons
|
||||
.fullscreen_exit
|
||||
: Icons.fullscreen,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
AppIcons.chat,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
context
|
||||
.l10n
|
||||
.workspaceAgent,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow
|
||||
.ellipsis,
|
||||
),
|
||||
),
|
||||
HeaderControlRegion(
|
||||
child: IconButton(
|
||||
key: const Key(
|
||||
'agent-fullscreen-button',
|
||||
),
|
||||
isSelected:
|
||||
_desktopSplits
|
||||
.agentFullscreen,
|
||||
tooltip:
|
||||
geometry
|
||||
.editorHidden
|
||||
? context
|
||||
.l10n
|
||||
.expandEditor
|
||||
: context
|
||||
.l10n
|
||||
.agentFullscreen,
|
||||
onPressed:
|
||||
geometry
|
||||
.editorHidden
|
||||
? expand
|
||||
: () => _desktopSplits
|
||||
.setAgentFullscreen(
|
||||
true,
|
||||
),
|
||||
icon: Icon(
|
||||
geometry.editorHidden
|
||||
? AppIcons
|
||||
.splitVertical
|
||||
: AppIcons
|
||||
.fullscreen,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: agent),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: agent),
|
||||
],
|
||||
),
|
||||
editor: editor,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
/// Desktop sidebar categories change navigation content, not workspace layout.
|
||||
class SidebarCategoryTabs extends StatelessWidget {
|
||||
const SidebarCategoryTabs({
|
||||
super.key,
|
||||
required this.mediaSelected,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final bool mediaSelected;
|
||||
final ValueChanged<bool>? onSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SizedBox(
|
||||
key: const Key('sidebar-category-header'),
|
||||
height: AppDesktopMetrics.panelHeader,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final media in [false, true]) ...[
|
||||
if (media) const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Semantics(
|
||||
selected: mediaSelected == media,
|
||||
child: Tooltip(
|
||||
message: media
|
||||
? context.l10n.materials
|
||||
: context.l10n.navigationChat,
|
||||
child: TextButton(
|
||||
key: Key(
|
||||
media ? 'sidebar-tab-resources' : 'sidebar-tab-chat',
|
||||
),
|
||||
onPressed: onSelected == null
|
||||
? null
|
||||
: () => onSelected!(media),
|
||||
style:
|
||||
AppTheme.panelTabStyle(
|
||||
context,
|
||||
selected: mediaSelected == media,
|
||||
).copyWith(
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 6),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
media
|
||||
? context.l10n.materials
|
||||
: context.l10n.navigationChat,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widget_previews.dart';
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import 'sidebar_category_tabs.dart';
|
||||
|
||||
@Preview(
|
||||
name: 'Sidebar categories — light',
|
||||
group: 'Desktop navigation',
|
||||
size: Size(280, 36),
|
||||
)
|
||||
Widget sidebarCategoriesLightPreview() => _preview(Brightness.light);
|
||||
|
||||
@Preview(
|
||||
name: 'Sidebar categories — dark',
|
||||
group: 'Desktop navigation',
|
||||
size: Size(180, 36),
|
||||
)
|
||||
Widget sidebarCategoriesDarkPreview() => _preview(Brightness.dark);
|
||||
|
||||
Widget _preview(Brightness brightness) {
|
||||
var media = false;
|
||||
return MaterialApp(
|
||||
theme: AppTheme.desktopWorkspaceTheme(
|
||||
AppTheme.forPalette(AppPalette.graphite, brightness),
|
||||
),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) => SidebarCategoryTabs(
|
||||
mediaSelected: media,
|
||||
onSelected: (value) => setState(() => media = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import '../../shared/state/operation_scope.dart';
|
||||
|
||||
typedef SidebarNavigationContext = ({String? projectId, String? timelineId});
|
||||
|
||||
/// Owns navigation intent while allowing the context changes it requested.
|
||||
class SidebarNavigationController {
|
||||
SidebarNavigationController(this._context);
|
||||
|
||||
SidebarNavigationContext _context;
|
||||
SidebarNavigationContext? _target;
|
||||
final _operations = OperationScope<void>(null);
|
||||
|
||||
bool Function() begin(String projectId, {String? timelineId}) {
|
||||
_target = (projectId: projectId, timelineId: timelineId);
|
||||
return _operations.begin();
|
||||
}
|
||||
|
||||
void update(SidebarNavigationContext context) {
|
||||
if (_context == context) return;
|
||||
_context = context;
|
||||
final target = _target;
|
||||
if (target == null ||
|
||||
context.projectId != target.projectId ||
|
||||
(target.timelineId != null &&
|
||||
context.timelineId != target.timelineId)) {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void finish(bool Function() isCurrent) {
|
||||
if (isCurrent()) _target = null;
|
||||
}
|
||||
|
||||
void useProjectDefault(bool Function() isCurrent) {
|
||||
if (!isCurrent() || _target == null) return;
|
||||
_target = (projectId: _target!.projectId, timelineId: null);
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
_target = null;
|
||||
_operations.invalidate();
|
||||
}
|
||||
|
||||
void dispose() => _operations.dispose();
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/l10n.dart';
|
||||
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import '../../workspace/project_state.dart';
|
||||
@@ -20,7 +21,7 @@ class TouchProjectsHeader extends StatelessWidget {
|
||||
key: const Key('create-project'),
|
||||
tooltip: context.l10n.newProject,
|
||||
onPressed: onCreate,
|
||||
icon: const Icon(Icons.add),
|
||||
icon: const Icon(AppIcons.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -64,7 +65,7 @@ class TouchProjectTile extends StatelessWidget {
|
||||
? context.l10n.collapseProject
|
||||
: context.l10n.expandProject,
|
||||
onPressed: onToggle,
|
||||
icon: Icon(expanded ? Icons.expand_more : Icons.chevron_right),
|
||||
icon: Icon(expanded ? AppIcons.expandMore : AppIcons.chevronRight),
|
||||
),
|
||||
title: Text(project.name, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
subtitle: project.availability.canOpen ? null : Text(availabilityLabel),
|
||||
@@ -76,7 +77,7 @@ class TouchProjectTile extends StatelessWidget {
|
||||
constraints: const BoxConstraints.tightFor(width: 48, height: 48),
|
||||
tooltip: context.l10n.agentNewConversation,
|
||||
onPressed: onNewConversation,
|
||||
icon: const Icon(Icons.edit_square),
|
||||
icon: const Icon(AppIcons.edit),
|
||||
),
|
||||
AppPopover(
|
||||
child: Column(
|
||||
@@ -93,7 +94,7 @@ class TouchProjectTile extends StatelessWidget {
|
||||
key: ValueKey('sidebar-project-more-${project.id}'),
|
||||
constraints: const BoxConstraints.tightFor(width: 48, height: 48),
|
||||
onPressed: toggle,
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
icon: const Icon(AppIcons.more),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -130,7 +131,7 @@ class TouchConversationTile extends StatelessWidget {
|
||||
key: ValueKey('sidebar-conversation-more-$id'),
|
||||
constraints: const BoxConstraints.tightFor(width: 48, height: 48),
|
||||
onPressed: toggle,
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
icon: const Icon(AppIcons.more),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -11,6 +11,7 @@ Future<String?> askName(
|
||||
String? description,
|
||||
String initialValue = '',
|
||||
String? submitLabel,
|
||||
Future<String?> Function(String name)? validateName,
|
||||
}) => showAppDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => _NameDialog(
|
||||
@@ -19,6 +20,7 @@ Future<String?> askName(
|
||||
description: description,
|
||||
initialValue: initialValue,
|
||||
submitLabel: submitLabel,
|
||||
validateName: validateName,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -29,12 +31,14 @@ class _NameDialog extends StatefulWidget {
|
||||
this.description,
|
||||
required this.initialValue,
|
||||
this.submitLabel,
|
||||
this.validateName,
|
||||
});
|
||||
final String title;
|
||||
final String label;
|
||||
final String? description;
|
||||
final String initialValue;
|
||||
final String? submitLabel;
|
||||
final Future<String?> Function(String name)? validateName;
|
||||
@override
|
||||
State<_NameDialog> createState() => _NameDialogState();
|
||||
}
|
||||
@@ -46,16 +50,39 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
extentOffset: widget.initialValue.length,
|
||||
);
|
||||
final _form = GlobalKey<FormState>();
|
||||
bool _validating = false;
|
||||
String? _validationError;
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
if (_form.currentState!.validate()) {
|
||||
Navigator.pop(context, _controller.text.trim());
|
||||
Future<void> _submit() async {
|
||||
if (_validating) return;
|
||||
_validationError = null;
|
||||
if (!_form.currentState!.validate()) return;
|
||||
final name = _controller.text.trim();
|
||||
if (widget.validateName != null) {
|
||||
setState(() => _validating = true);
|
||||
String? error;
|
||||
try {
|
||||
error = await widget.validateName!(name);
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
error = context.l10n.operationFailed;
|
||||
}
|
||||
if (!mounted || ModalRoute.of(context)?.isCurrent != true) return;
|
||||
setState(() {
|
||||
_validating = false;
|
||||
_validationError = error;
|
||||
});
|
||||
if (error != null) {
|
||||
_form.currentState!.validate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mounted) Navigator.pop(context, name);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -69,7 +96,7 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
child: Text(context.l10n.cancel),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _submit,
|
||||
onPressed: _validating ? null : _submit,
|
||||
child: Text(widget.submitLabel ?? context.l10n.create),
|
||||
),
|
||||
],
|
||||
@@ -78,8 +105,10 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
key: _form,
|
||||
child: TextFormField(
|
||||
controller: _controller,
|
||||
readOnly: _validating,
|
||||
style: AppTheme.inputTextStyle(dialogContext),
|
||||
cursorHeight: AppTheme.inputCursorHeight(dialogContext),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
autofocus: true,
|
||||
maxLength: 80,
|
||||
buildCounter: (
|
||||
@@ -88,13 +117,22 @@ class _NameDialogState extends State<_NameDialog> {
|
||||
required isFocused,
|
||||
maxLength,
|
||||
}) => null,
|
||||
decoration: InputDecoration(hintText: widget.label),
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.label,
|
||||
hintStyle: AppTheme.inputHintStyle(dialogContext),
|
||||
errorMaxLines: 3,
|
||||
),
|
||||
validator: (value) => value == null || value.trim().isEmpty
|
||||
? context.l10n.enterName
|
||||
: RegExp(r'[/\\\x00-\x1F]').hasMatch(value) ||
|
||||
['.', '..'].contains(value.trim())
|
||||
? context.l10n.invalidName
|
||||
: null,
|
||||
: _validationError,
|
||||
onChanged: (_) {
|
||||
if (_validationError == null) return;
|
||||
_validationError = null;
|
||||
_form.currentState!.validate();
|
||||
},
|
||||
onFieldSubmitted: (_) => _submit(),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user