This commit is contained in:
LZX committed 2026-09-11 16:03:47 +08:00
1 parent 8531403c33
commit b03ece33a2
37 files changed
+6388 -908

No files matched your search

+93 -27
View File
@@ -4,18 +4,20 @@ import 'package:path/path.dart' as p;
class CodeEditorAppBar extends StatelessWidget implements PreferredSizeWidget {
final String? filePath;
final VoidCallback? onUndo;
final VoidCallback? onRedo;
final String? rootPath;
final bool isModified;
final VoidCallback? onSave;
final VoidCallback? onSaveAll;
final VoidCallback? onRun;
final VoidCallback? onSettings;
const CodeEditorAppBar({
super.key,
required this.filePath,
this.onUndo,
this.onRedo,
this.rootPath,
this.isModified = false,
this.onSave,
this.onSaveAll,
this.onRun,
this.onSettings,
});
@@ -29,29 +31,59 @@ class CodeEditorAppBar extends StatelessWidget implements PreferredSizeWidget {
final l10n = AppLocalizations.of(context)!;
final path = filePath;
final String titleText;
final String? subtitleText;
if (path != null && path.isNotEmpty) {
final base = p.basename(path);
titleText = isModified ? '* $base' : base;
if (rootPath != null && rootPath!.trim().isNotEmpty) {
final cleanRoot = p.normalize(rootPath!.trim());
final cleanFile = p.normalize(path.trim());
final dirPath = p.dirname(cleanFile);
if (dirPath == cleanRoot || !p.isWithin(cleanRoot, cleanFile)) {
subtitleText = '/';
} else {
final rel = p.relative(dirPath, from: cleanRoot);
final formattedRel = rel.replaceAll(r'\', '/');
subtitleText = formattedRel.startsWith('/') ? formattedRel : '/$formattedRel';
}
} else {
subtitleText = '/';
}
} else {
titleText = '';
subtitleText = null;
}
return AppBar(
backgroundColor: theme.colorScheme.primaryContainer,
foregroundColor: theme.colorScheme.onPrimaryContainer,
title: Text(path != null && path.isNotEmpty ? p.basename(path) : ''),
foregroundColor: theme.colorScheme.onSurface,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
titleText,
style: const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
),
if (subtitleText != null)
Text(
subtitleText,
style: TextStyle(
fontSize: 11.0,
color: theme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
),
],
),
actions: [
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.undo),
tooltip: l10n.undo,
onPressed: onUndo ?? () {},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.redo),
tooltip: l10n.redo,
onPressed: onRedo ?? () {},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.save_outlined),
tooltip: l10n.save,
onPressed: onSave ?? () {},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.play_arrow),
@@ -60,9 +92,43 @@ class CodeEditorAppBar extends StatelessWidget implements PreferredSizeWidget {
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.settings),
tooltip: l10n.settings,
onPressed: onSettings ?? () {},
icon: const Icon(Icons.save_outlined),
tooltip: l10n.save,
onPressed: onSave ?? () {},
),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert),
tooltip: l10n.more,
position: PopupMenuPosition.under,
onSelected: (value) {
if (value == 'save_all') {
onSaveAll?.call();
} else if (value == 'settings') {
onSettings?.call();
}
},
itemBuilder: (context) => [
PopupMenuItem<String>(
value: 'save_all',
child: Row(
children: [
const Icon(Icons.save_as_outlined, size: 20),
const SizedBox(width: 10),
Text(l10n.saveAll),
],
),
),
PopupMenuItem<String>(
value: 'settings',
child: Row(
children: [
const Icon(Icons.settings, size: 20),
const SizedBox(width: 10),
Text(l10n.settings),
],
),
),
],
),
],
);