refactor(desktop): reorganize workspace panels and navigation
This commit is contained in:
1 parent
826745b407
commit
1f73765745
92 files changed
+5811
-2650
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -86,9 +87,9 @@ class _AgentSettingsPanelState extends ConsumerState<AgentSettingsPanel>
|
||||
}
|
||||
}
|
||||
|
||||
void _showSaveError() => ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(context.l10n.agentSaveSettingsFailed)));
|
||||
void _showSaveError() => ErrorNotificationHost.of(context).show(
|
||||
ErrorNotification(content: Text(context.l10n.agentSaveSettingsFailed)),
|
||||
);
|
||||
|
||||
Future<void> _setProviderEnabled(
|
||||
AgentProviderSettings provider,
|
||||
|
||||
@@ -0,0 +1,537 @@
|
||||
import 'package:cutdex/l10n/l10n.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../integrations/platform/file_picker.dart';
|
||||
import '../../shared/widgets/workspace_card.dart';
|
||||
import '../../shared/layout/workspace_layout_metrics.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);
|
||||
|
||||
class SettingsContent extends ConsumerStatefulWidget {
|
||||
const SettingsContent({
|
||||
super.key,
|
||||
this.workspace,
|
||||
this.initialTab = 0,
|
||||
this.navigationRequest = 0,
|
||||
this.cardLayout = false,
|
||||
}) : assert(initialTab >= 0 && initialTab <= 2);
|
||||
|
||||
final int initialTab;
|
||||
final int navigationRequest;
|
||||
final bool cardLayout;
|
||||
|
||||
final (String, String)? workspace;
|
||||
|
||||
@override
|
||||
ConsumerState<SettingsContent> createState() => _SettingsContentState();
|
||||
}
|
||||
|
||||
class _SettingsContentState extends ConsumerState<SettingsContent> {
|
||||
late int _tab = widget.initialTab;
|
||||
|
||||
Widget _surface(String name, Widget child) => widget.cardLayout
|
||||
? WorkspaceCard(key: Key('settings-$name-card'), child: child)
|
||||
: child;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant SettingsContent oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.initialTab != oldWidget.initialTab ||
|
||||
widget.navigationRequest != oldWidget.navigationRequest) {
|
||||
_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: _buildContent),
|
||||
);
|
||||
|
||||
Widget _buildContent(BuildContext context) {
|
||||
final appearanceSave = ref.watch(settingsOperationProvider('appearance'));
|
||||
final languageSave = ref.watch(settingsOperationProvider('language'));
|
||||
final appearance = ref.watch(appearanceSettingsProvider);
|
||||
final language = ref.watch(languageSettingsProvider);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) => Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: constraints.maxWidth < 600
|
||||
? 96
|
||||
: widget.cardLayout
|
||||
? WorkspaceLayoutMetrics.sidebarDefaultWidth
|
||||
: 220,
|
||||
child: _surface(
|
||||
'navigation',
|
||||
_SettingsNavigation(
|
||||
value: _tab,
|
||||
compact: constraints.maxWidth < 600,
|
||||
onChanged: (value) => setState(() => _tab = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.cardLayout)
|
||||
const SizedBox(
|
||||
key: Key('settings-card-gap'),
|
||||
width: WorkspaceLayoutMetrics.desktopSpacing,
|
||||
)
|
||||
else
|
||||
VerticalDivider(
|
||||
key: const Key('settings-sidebar-divider'),
|
||||
width: 1,
|
||||
thickness: 1,
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
),
|
||||
Expanded(
|
||||
child: _surface(
|
||||
'content',
|
||||
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))}';
|
||||
}
|
||||
}
|
||||
@@ -1,519 +1,31 @@
|
||||
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;
|
||||
import '../../l10n/l10n.dart';
|
||||
import 'settings_content.dart';
|
||||
|
||||
/// Dialog adapter for embedded settings hosts.
|
||||
class SettingsDialog extends StatelessWidget {
|
||||
const SettingsDialog({super.key, this.workspace, this.initialTab = 0});
|
||||
final (String, String)? workspace;
|
||||
|
||||
final int initialTab;
|
||||
@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);
|
||||
Widget build(BuildContext context) {
|
||||
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),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
return Theme(
|
||||
data: AppTheme.settingsContentTheme(Theme.of(context)),
|
||||
child: 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: SettingsContent(workspace: workspace, initialTab: initialTab),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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))}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import 'package:cutdex_native/cutdex_native.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../app/shells/desktop_window_frame.dart';
|
||||
import '../../app/adaptive/desktop_content_controller.dart';
|
||||
import '../../integrations/platform/device_experience.dart';
|
||||
import '../../integrations/platform/editor_window_chrome.dart';
|
||||
import '../../l10n/l10n.dart';
|
||||
import 'settings_content.dart';
|
||||
|
||||
Future<void> showSettingsPage(
|
||||
BuildContext context, {
|
||||
(String, String)? workspace,
|
||||
int? initialTab,
|
||||
}) {
|
||||
final container = ProviderScope.containerOf(context, listen: false);
|
||||
if (container.read(deviceExperienceProvider) == DeviceExperience.desktop) {
|
||||
container
|
||||
.read(desktopContentProvider.notifier)
|
||||
.showSettings(tab: initialTab, workspace: workspace);
|
||||
return Future<void>.value();
|
||||
}
|
||||
return context.push<void>(
|
||||
'/settings?tab=${initialTab ?? 0}',
|
||||
extra: workspace,
|
||||
);
|
||||
}
|
||||
|
||||
/// A pushed route keeps the editor and its session mounted underneath.
|
||||
class SettingsPage extends ConsumerWidget {
|
||||
const SettingsPage({super.key, this.workspace, this.initialTab = 0});
|
||||
final (String, String)? workspace;
|
||||
final int initialTab;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final desktop =
|
||||
ref.watch(deviceExperienceProvider) == DeviceExperience.desktop;
|
||||
void back() {
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go('/');
|
||||
}
|
||||
}
|
||||
|
||||
final content = SettingsContent(
|
||||
workspace: workspace,
|
||||
initialTab: initialTab,
|
||||
);
|
||||
if (!desktop) {
|
||||
return Scaffold(
|
||||
key: const Key('settings-page'),
|
||||
appBar: AppBar(
|
||||
leading: BackButton(
|
||||
key: const Key('settings-page-back'),
|
||||
onPressed: back,
|
||||
),
|
||||
title: Text(context.l10n.settings),
|
||||
),
|
||||
body: content,
|
||||
);
|
||||
}
|
||||
return EditorWindowChrome(
|
||||
headerHeight: DesktopWindowFrame.headerHeight,
|
||||
builder: (context, integrated) => Scaffold(
|
||||
key: const Key('settings-page'),
|
||||
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||
body: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: DesktopWindowFrame.headerHeight,
|
||||
child: WindowHeaderPadding(
|
||||
child: Row(
|
||||
children: [
|
||||
if (integrated)
|
||||
SizedBox(width: EditorWindowChrome.leadingWidth),
|
||||
HeaderControlRegion(
|
||||
child: BackButton(
|
||||
key: const Key('settings-page-back'),
|
||||
onPressed: back,
|
||||
),
|
||||
),
|
||||
Text(context.l10n.settings),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(child: content),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user