Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
520 lines
19 KiB
Dart
520 lines
19 KiB
Dart
import 'package:cutdex/l10n/l10n.dart';
|
|
|
|
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/file_picker.dart';
|
|
|
|
import '../../workspace/persistence/project_location_directory.dart';
|
|
|
|
import 'package:cutdex_ui/theme.dart';
|
|
import 'package:cutdex_ui/widgets.dart';
|
|
|
|
import 'appearance_settings.dart';
|
|
import 'language_settings.dart';
|
|
import 'location_settings.dart';
|
|
import 'mcp_settings_panel.dart';
|
|
import 'settings_layout.dart';
|
|
import '../../settings/settings_operation.dart';
|
|
import 'update_settings.dart';
|
|
import 'diagnostic_settings.dart';
|
|
import 'agent_settings_panel.dart';
|
|
|
|
const _settingsContentPadding = EdgeInsets.fromLTRB(20, 48, 20, 20);
|
|
|
|
Future<void> showSettingsDialog(
|
|
BuildContext context, {
|
|
(String, String)? workspace,
|
|
int initialTab = 0,
|
|
}) => showAppDialog<void>(
|
|
context: Navigator.of(context, rootNavigator: true).context,
|
|
builder: (_) => SettingsDialog(workspace: workspace, initialTab: initialTab),
|
|
);
|
|
|
|
class SettingsDialog extends ConsumerStatefulWidget {
|
|
const SettingsDialog({super.key, this.workspace, this.initialTab = 0})
|
|
: assert(initialTab >= 0 && initialTab <= 2);
|
|
|
|
final int initialTab;
|
|
|
|
final (String, String)? workspace;
|
|
|
|
@override
|
|
ConsumerState<SettingsDialog> createState() => _SettingsDialogState();
|
|
}
|
|
|
|
class _SettingsDialogState extends ConsumerState<SettingsDialog> {
|
|
late int _tab = widget.initialTab;
|
|
|
|
Future<void> _setMode(AppAppearance appearance) async {
|
|
await ref
|
|
.read(settingsOperationProvider('appearance').notifier)
|
|
.run(
|
|
() =>
|
|
ref.read(appearanceSettingsProvider.notifier).setMode(appearance),
|
|
);
|
|
}
|
|
|
|
Future<void> _setLanguage(AppLanguage language) async {
|
|
await ref
|
|
.read(settingsOperationProvider('language').notifier)
|
|
.run(
|
|
() =>
|
|
ref.read(languageSettingsProvider.notifier).setLanguage(language),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Theme(
|
|
data: AppTheme.settingsContentTheme(Theme.of(context)),
|
|
child: Builder(builder: _buildDialog),
|
|
);
|
|
|
|
Widget _buildDialog(BuildContext context) {
|
|
final appearanceSave = ref.watch(settingsOperationProvider('appearance'));
|
|
final languageSave = ref.watch(settingsOperationProvider('language'));
|
|
final appearance = ref.watch(appearanceSettingsProvider);
|
|
final language = ref.watch(languageSettingsProvider);
|
|
final viewport = MediaQuery.sizeOf(context);
|
|
return AppDialog(
|
|
title: context.l10n.settings,
|
|
closeLabel: context.l10n.closeSettings,
|
|
width: math.min(1120, math.max(560, viewport.width * .9)),
|
|
height: math.min(704, math.max(520, viewport.height * .88)),
|
|
contentOnly: true,
|
|
scrollContent: false,
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) => Row(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
SizedBox(
|
|
width: constraints.maxWidth < 600 ? 96 : 220,
|
|
child: _SettingsNavigation(
|
|
value: _tab,
|
|
compact: constraints.maxWidth < 600,
|
|
onChanged: (value) => setState(() => _tab = value),
|
|
),
|
|
),
|
|
VerticalDivider(
|
|
key: const Key('settings-sidebar-divider'),
|
|
width: 1,
|
|
thickness: 1,
|
|
color: Theme.of(context).colorScheme.outlineVariant,
|
|
),
|
|
Expanded(
|
|
child: ColoredBox(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
child: IndexedStack(
|
|
index: _tab,
|
|
children: [
|
|
ExcludeFocus(
|
|
excluding: _tab != 0,
|
|
child: TickerMode(
|
|
enabled: _tab == 0,
|
|
child: SingleChildScrollView(
|
|
primary: false,
|
|
padding: _settingsContentPadding,
|
|
child: SettingsPageSection(
|
|
title: context.l10n.general,
|
|
icon: Icons.settings_outlined,
|
|
children: [
|
|
AppField(
|
|
label: context.l10n.appearance,
|
|
orientation: AppFieldOrientation.horizontal,
|
|
error:
|
|
(appearanceSave.hasError
|
|
? context.l10n.saveAppearanceFailed
|
|
: null) ??
|
|
(appearance.hasError
|
|
? context.l10n.loadAppearanceFailed
|
|
: null),
|
|
child: SizedBox(
|
|
width: AppSettingsMetrics.controlWidth,
|
|
child: AppSelect<AppAppearance>(
|
|
emptyLabel: context.l10n.noMatchingOptions,
|
|
controlHeight:
|
|
AppSettingsMetrics.controlHeight,
|
|
value:
|
|
appearance.asData?.value ??
|
|
AppAppearance.system,
|
|
label: context.l10n.theme,
|
|
options: [
|
|
AppSelectOption(
|
|
AppAppearance.system,
|
|
context.l10n.system,
|
|
),
|
|
AppSelectOption(
|
|
AppAppearance.penLight,
|
|
'Pen · ${context.l10n.light}',
|
|
),
|
|
AppSelectOption(
|
|
AppAppearance.penDark,
|
|
'Pen · ${context.l10n.dark}',
|
|
),
|
|
],
|
|
onChanged:
|
|
appearanceSave.isLoading ||
|
|
appearance.isLoading
|
|
? null
|
|
: _setMode,
|
|
),
|
|
),
|
|
),
|
|
AppField(
|
|
label: context.l10n.language,
|
|
orientation: AppFieldOrientation.horizontal,
|
|
error:
|
|
(languageSave.hasError
|
|
? context.l10n.saveLanguageFailed
|
|
: null) ??
|
|
(language.hasError
|
|
? context.l10n.loadLanguageFailed
|
|
: null),
|
|
child: SizedBox(
|
|
width: AppSettingsMetrics.controlWidth,
|
|
child: AppSelect<AppLanguage>(
|
|
emptyLabel: context.l10n.noMatchingOptions,
|
|
controlHeight:
|
|
AppSettingsMetrics.controlHeight,
|
|
value:
|
|
language.asData?.value ??
|
|
AppLanguage.system,
|
|
label: context.l10n.language,
|
|
options: [
|
|
for (final option in AppLanguage.values)
|
|
AppSelectOption(
|
|
option,
|
|
option == AppLanguage.system
|
|
? context.l10n.system
|
|
: option.nativeName,
|
|
),
|
|
],
|
|
onChanged:
|
|
languageSave.isLoading ||
|
|
language.isLoading
|
|
? null
|
|
: _setLanguage,
|
|
),
|
|
),
|
|
),
|
|
const _ProjectLocationField(),
|
|
const _ResourceLocationField(),
|
|
const UpdateSettings(),
|
|
const DiagnosticSettings(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
ExcludeFocus(
|
|
excluding: _tab != 1,
|
|
child: TickerMode(
|
|
enabled: _tab == 1,
|
|
child: const AgentSettingsPanel(
|
|
contentPadding: _settingsContentPadding,
|
|
),
|
|
),
|
|
),
|
|
ExcludeFocus(
|
|
excluding: _tab != 2,
|
|
child: TickerMode(
|
|
enabled: _tab == 2,
|
|
child: SingleChildScrollView(
|
|
primary: false,
|
|
padding: _settingsContentPadding,
|
|
child: McpSettingsPanel(workspace: widget.workspace),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _SettingsNavigation extends StatelessWidget {
|
|
const _SettingsNavigation({
|
|
required this.value,
|
|
required this.compact,
|
|
required this.onChanged,
|
|
});
|
|
|
|
final int value;
|
|
final bool compact;
|
|
final ValueChanged<int> onChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final entries = [
|
|
(context.l10n.general, Icons.settings_outlined),
|
|
(context.l10n.agentSettings, Icons.auto_awesome_outlined),
|
|
('MCP', Icons.terminal_outlined),
|
|
];
|
|
return ColoredBox(
|
|
key: const Key('settings-sidebar'),
|
|
color: AppTheme.settingsSidebarBackground(context),
|
|
child: ListView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 20),
|
|
child: Text(
|
|
context.l10n.settings,
|
|
style: theme.textTheme.titleSmall?.copyWith(fontSize: 16),
|
|
),
|
|
),
|
|
for (var index = 0; index < entries.length; index++)
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 1),
|
|
child: Semantics(
|
|
selected: value == index,
|
|
child: Tooltip(
|
|
message: entries[index].$1,
|
|
child: TextButton(
|
|
key: ValueKey('settings-navigation-$index'),
|
|
onPressed: () => onChanged(index),
|
|
style: TextButton.styleFrom(
|
|
minimumSize: const Size(0, 30),
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
foregroundColor: theme.colorScheme.onSurface,
|
|
backgroundColor: value == index
|
|
? theme.colorScheme.onSurface.withValues(alpha: .078)
|
|
: Colors.transparent,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
alignment: AlignmentDirectional.centerStart,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
if (!compact) ...[
|
|
Icon(entries[index].$2, size: 16),
|
|
const SizedBox(width: 8),
|
|
],
|
|
Expanded(
|
|
child: Text(
|
|
entries[index].$1,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ResourceLocationField extends ConsumerWidget {
|
|
const _ResourceLocationField();
|
|
|
|
Future<void> _choose(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
String? initialDirectory,
|
|
) async {
|
|
final directory = await ref
|
|
.read(filePickerProvider)
|
|
.pickDirectory(
|
|
initialDirectory: initialDirectory,
|
|
confirmButtonText: context.l10n.select,
|
|
);
|
|
if (directory == null || !context.mounted) return;
|
|
await ref.read(resourceLocationSettingsProvider.notifier).save(directory);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final settings = ref.watch(resourceLocationSettingsProvider);
|
|
final error = switch (settings.error) {
|
|
LocationSettingsError.load => context.l10n.loadResourceLocationFailed,
|
|
LocationSettingsError.save => context.l10n.saveResourceLocationFailed,
|
|
null => null,
|
|
};
|
|
return AppField(
|
|
label: context.l10n.resourceLocation,
|
|
orientation: AppFieldOrientation.horizontal,
|
|
error: error,
|
|
child: SizedBox(
|
|
width: 420,
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Tooltip(
|
|
message:
|
|
settings.directory ?? context.l10n.resourceLocationNotSet,
|
|
child: _MiddleEllipsisText(
|
|
settings.directory ?? context.l10n.resourceLocationNotSet,
|
|
key: const Key('resource-location-value'),
|
|
textAlign: TextAlign.right,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.compact),
|
|
OutlinedButton(
|
|
key: const Key('choose-resource-location'),
|
|
onPressed: settings.loading || settings.saving
|
|
? null
|
|
: () => _choose(context, ref, settings.directory),
|
|
child: Text(context.l10n.modify),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ProjectLocationField extends ConsumerWidget {
|
|
const _ProjectLocationField();
|
|
|
|
Future<void> _choose(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
String? initialDirectory,
|
|
) async {
|
|
final directory = await ref
|
|
.read(filePickerProvider)
|
|
.pickDirectory(
|
|
initialDirectory: initialDirectory,
|
|
confirmButtonText: context.l10n.select,
|
|
);
|
|
if (directory == null || !context.mounted) return;
|
|
await ref.read(projectLocationSettingsProvider.notifier).save(directory);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final settings = ref.watch(projectLocationSettingsProvider);
|
|
final error = switch (settings.error) {
|
|
LocationSettingsError.load => context.l10n.loadProjectLocationFailed,
|
|
LocationSettingsError.save => context.l10n.saveProjectLocationFailed,
|
|
null => null,
|
|
};
|
|
return AppField(
|
|
label: context.l10n.projectLocation,
|
|
orientation: AppFieldOrientation.horizontal,
|
|
description: settings.status == ProjectLocationStatus.missing
|
|
? context.l10n.projectLocationMissing
|
|
: null,
|
|
error:
|
|
error ??
|
|
switch (settings.status) {
|
|
ProjectLocationStatus.unavailable =>
|
|
context.l10n.projectLocationUnavailable,
|
|
ProjectLocationStatus.notWritable =>
|
|
context.l10n.projectLocationNotWritable,
|
|
_ => null,
|
|
},
|
|
child: SizedBox(
|
|
width: 420,
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Tooltip(
|
|
message:
|
|
settings.directory ?? context.l10n.projectLocationNotSet,
|
|
child: _MiddleEllipsisText(
|
|
settings.directory ?? context.l10n.projectLocationNotSet,
|
|
key: const Key('project-location-value'),
|
|
textAlign: TextAlign.right,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.compact),
|
|
if (error != null ||
|
|
settings.status == ProjectLocationStatus.unavailable ||
|
|
settings.status == ProjectLocationStatus.notWritable)
|
|
TextButton(
|
|
key: const Key('retry-project-location'),
|
|
onPressed: settings.loading || settings.saving
|
|
? null
|
|
: ref.read(projectLocationSettingsProvider.notifier).reload,
|
|
child: Text(context.l10n.retry),
|
|
),
|
|
OutlinedButton(
|
|
key: const Key('choose-project-location'),
|
|
onPressed: settings.loading || settings.saving
|
|
? null
|
|
: () => _choose(context, ref, settings.directory),
|
|
child: Text(context.l10n.modify),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _MiddleEllipsisText extends StatelessWidget {
|
|
const _MiddleEllipsisText(
|
|
this.text, {
|
|
super.key,
|
|
this.textAlign = TextAlign.start,
|
|
});
|
|
|
|
final String text;
|
|
final TextAlign textAlign;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final style = DefaultTextStyle.of(context).style;
|
|
final direction = Directionality.of(context);
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) => Text(
|
|
_ellipsize(text, constraints.maxWidth, style, direction),
|
|
maxLines: 1,
|
|
textAlign: textAlign,
|
|
),
|
|
);
|
|
}
|
|
|
|
static String _ellipsize(
|
|
String value,
|
|
double maxWidth,
|
|
TextStyle style,
|
|
TextDirection direction,
|
|
) {
|
|
bool fits(String candidate) {
|
|
final painter = TextPainter(
|
|
text: TextSpan(text: candidate, style: style),
|
|
maxLines: 1,
|
|
textDirection: direction,
|
|
)..layout(maxWidth: maxWidth);
|
|
return !painter.didExceedMaxLines && painter.width <= maxWidth;
|
|
}
|
|
|
|
if (!maxWidth.isFinite || fits(value)) return value;
|
|
var low = 0;
|
|
var high = value.length;
|
|
while (low < high) {
|
|
final keep = (low + high + 1) ~/ 2;
|
|
final leading = (keep + 1) ~/ 2;
|
|
final candidate =
|
|
'${value.substring(0, leading)}…'
|
|
'${value.substring(value.length - (keep - leading))}';
|
|
if (fits(candidate)) {
|
|
low = keep;
|
|
} else {
|
|
high = keep - 1;
|
|
}
|
|
}
|
|
final leading = (low + 1) ~/ 2;
|
|
return '${value.substring(0, leading)}…'
|
|
'${value.substring(value.length - (low - leading))}';
|
|
}
|
|
}
|