This commit is contained in:
LZX committed 2026-09-17 19:45:53 +08:00
1 parent 6fd164fa6f
commit 27cdb00af2
7 files changed
+587 -187

No files matched your search

+405 -185
View File
@@ -19,9 +19,16 @@ enum _OpenProjectSource {
fromExternal,
}
class CodeEditorDrawer extends StatelessWidget {
class CodeEditorDrawer extends StatefulWidget {
const CodeEditorDrawer({super.key});
@override
State<CodeEditorDrawer> createState() => _CodeEditorDrawerState();
}
class _CodeEditorDrawerState extends State<CodeEditorDrawer> {
int _selectedIndex = 0;
static ProjectProvider _getProjectProvider(
BuildContext context, {
bool listen = false,
@@ -126,6 +133,393 @@ class CodeEditorDrawer extends StatelessWidget {
}
}
Widget _buildActivityBarItem({
required BuildContext context,
required int index,
required IconData icon,
required String label,
}) {
final theme = Theme.of(context);
final isSelected = _selectedIndex == index;
final colorScheme = theme.colorScheme;
return Tooltip(
message: label,
preferBelow: false,
child: InkWell(
onTap: () {
if (_selectedIndex != index) {
setState(() {
_selectedIndex = index;
});
}
},
child: SizedBox(
width: 48,
height: 48,
child: Stack(
alignment: Alignment.center,
children: [
if (isSelected)
Positioned(
left: 0,
top: 10,
bottom: 10,
width: 3,
child: Container(
decoration: BoxDecoration(
color: colorScheme.primary,
borderRadius: const BorderRadius.only(
topRight: Radius.circular(2),
bottomRight: Radius.circular(2),
),
),
),
),
Icon(
icon,
size: 22,
color: isSelected
? colorScheme.primary
: colorScheme.onSurfaceVariant.withValues(alpha: 0.7),
),
],
),
),
),
);
}
Widget _buildActivityBar(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
) {
return Container(
width: 48,
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerLow,
border: Border(
right: BorderSide(
color: theme.colorScheme.outlineVariant.withValues(alpha: 0.4),
width: 1,
),
),
),
child: SafeArea(
bottom: true,
right: false,
child: Column(
children: [
const SizedBox(height: 8),
_buildActivityBarItem(
context: context,
index: 0,
icon: Icons.folder_copy_outlined,
label: l10n.drawerTabExplorer,
),
const SizedBox(height: 4),
_buildActivityBarItem(
context: context,
index: 1,
icon: Icons.search,
label: l10n.drawerTabSearch,
),
const SizedBox(height: 4),
_buildActivityBarItem(
context: context,
index: 2,
icon: Icons.alt_route_rounded,
label: l10n.drawerTabGit,
),
],
),
),
);
}
Widget _buildExplorerPage(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
String? rootPath,
bool hasProject,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: SafeArea(
bottom: false,
left: false,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
l10n.fileDirectory,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.refresh),
tooltip: l10n.refreshDirectory,
onPressed: () {
_getProjectProvider(context).refreshTree();
final runProvider = context.read<RunProvider?>();
final root = _getProjectProvider(context).rootPath;
if (root != null && root.isNotEmpty) {
runProvider?.onProjectOpened(
root,
systemName: context.read<DistroProvider?>()?.selectedSystem,
);
}
},
),
PopupMenuButton<_OpenProjectSource>(
icon: const Icon(Icons.folder_open),
tooltip: l10n.openFileDirectory,
itemBuilder: (popupContext) => [
PopupMenuItem<_OpenProjectSource>(
value: _OpenProjectSource.fromApp,
child: Row(
children: [
const Icon(Icons.inventory_2_outlined, size: 20),
const SizedBox(width: 8),
Text(l10n.openFromApp),
],
),
),
PopupMenuItem<_OpenProjectSource>(
value: _OpenProjectSource.fromExternal,
child: Row(
children: [
const Icon(Icons.folder_open_outlined, size: 20),
const SizedBox(width: 8),
Text(l10n.openFromExternal),
],
),
),
],
onSelected: (source) async {
switch (source) {
case _OpenProjectSource.fromApp:
Navigator.of(context).pop();
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ProjectManagementView(),
),
);
break;
case _OpenProjectSource.fromExternal:
final hasPermission = await PermissionService
.instance
.ensureStoragePermission(context: context);
if (!hasPermission || !context.mounted) return;
final canProceed = await _getTabProvider(
context,
).checkUnsavedChanges(context);
if (!canProceed || !context.mounted) return;
_getProjectProvider(context).openDirectory();
break;
}
},
),
IconButton(
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.history),
tooltip: l10n.viewProjectHistory,
onPressed: () {
ProjectHistoryWidget.show(
context,
onSelectHistory: (selectedHistory) async {
final canProceed = await _getTabProvider(
context,
).checkUnsavedChanges(context);
if (!canProceed || !context.mounted) return;
_getProjectProvider(
context,
).switchProject(selectedHistory);
},
);
},
),
],
),
Row(
children: [
Expanded(
child: Text(
hasProject
? (InternalProjectService.instance
.isInternalProject(rootPath!)
? p.basename(rootPath)
: rootPath)
: '',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
if (hasProject) ...[
const SizedBox(width: 4),
IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: Size.zero,
padding: const EdgeInsets.all(3),
),
constraints: const BoxConstraints(
minWidth: 24,
minHeight: 24,
),
iconSize: 18,
icon: const Icon(Icons.note_add_outlined),
tooltip: l10n.newFile,
onPressed: () => _handleNewFile(context, rootPath!),
),
const SizedBox(width: 2),
IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: Size.zero,
padding: const EdgeInsets.all(3),
),
constraints: const BoxConstraints(
minWidth: 24,
minHeight: 24,
),
iconSize: 18,
icon: const Icon(Icons.create_new_folder_outlined),
tooltip: l10n.newFolder,
onPressed: () =>
_handleNewFolder(context, rootPath!),
),
const SizedBox(width: 2),
IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: Size.zero,
padding: const EdgeInsets.all(3),
),
constraints: const BoxConstraints(
minWidth: 24,
minHeight: 24,
),
iconSize: 18,
icon: const Icon(Icons.file_upload_outlined),
tooltip: l10n.importFromExternal,
onPressed: () =>
_handleImportFiles(context, rootPath!),
),
],
],
),
],
),
),
),
),
const Expanded(child: SafeArea(top: false, left: false, child: FileTreeWidget())),
],
);
}
Widget _buildSearchPlaceholder(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: SafeArea(
bottom: false,
left: false,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
child: Row(
children: [
Expanded(
child: Text(
l10n.drawerTabSearch,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
),
),
const Expanded(child: SizedBox.shrink()),
],
);
}
Widget _buildGitPlaceholder(
BuildContext context,
AppLocalizations l10n,
ThemeData theme,
) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: SafeArea(
bottom: false,
left: false,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 14.0),
child: Row(
children: [
Expanded(
child: Text(
l10n.drawerTabGit,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
],
),
),
),
),
const Expanded(child: SizedBox.shrink()),
],
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@@ -135,194 +529,20 @@ class CodeEditorDrawer extends StatelessWidget {
final hasProject = rootPath != null && rootPath.trim().isNotEmpty;
return Drawer(
child: Column(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
),
child: SafeArea(
bottom: false,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
l10n.fileDirectory,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const Spacer(),
IconButton(
icon: const Icon(Icons.refresh),
tooltip: l10n.refreshDirectory,
onPressed: () {
_getProjectProvider(context).refreshTree();
final runProvider = context.read<RunProvider?>();
final root = _getProjectProvider(context).rootPath;
if (root != null && root.isNotEmpty) {
// 传入当前真实选中的系统,无系统时不进行任何任务探测
runProvider?.onProjectOpened(
root,
systemName: context.read<DistroProvider?>()?.selectedSystem,
);
}
},
),
PopupMenuButton<_OpenProjectSource>(
icon: const Icon(Icons.folder_open),
tooltip: l10n.openFileDirectory,
itemBuilder: (popupContext) => [
PopupMenuItem<_OpenProjectSource>(
value: _OpenProjectSource.fromApp,
child: Row(
children: [
const Icon(Icons.inventory_2_outlined, size: 20),
const SizedBox(width: 8),
Text(l10n.openFromApp),
],
),
),
PopupMenuItem<_OpenProjectSource>(
value: _OpenProjectSource.fromExternal,
child: Row(
children: [
const Icon(Icons.folder_open_outlined, size: 20),
const SizedBox(width: 8),
Text(l10n.openFromExternal),
],
),
),
],
onSelected: (source) async {
switch (source) {
case _OpenProjectSource.fromApp:
Navigator.of(context).pop();
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ProjectManagementView(),
),
);
break;
case _OpenProjectSource.fromExternal:
final hasPermission = await PermissionService
.instance
.ensureStoragePermission(context: context);
if (!hasPermission || !context.mounted) return;
final canProceed = await _getTabProvider(
context,
).checkUnsavedChanges(context);
if (!canProceed || !context.mounted) return;
_getProjectProvider(context).openDirectory();
break;
}
},
),
IconButton(
icon: const Icon(Icons.history),
tooltip: l10n.viewProjectHistory,
onPressed: () {
ProjectHistoryWidget.show(
context,
onSelectHistory: (selectedHistory) async {
final canProceed = await _getTabProvider(
context,
).checkUnsavedChanges(context);
if (!canProceed || !context.mounted) return;
_getProjectProvider(
context,
).switchProject(selectedHistory);
},
);
},
),
],
),
Row(
children: [
Expanded(
child: Text(
hasProject
? (InternalProjectService.instance
.isInternalProject(rootPath)
? p.basename(rootPath)
: rootPath)
: '',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
),
if (hasProject) ...[
const SizedBox(width: 6),
IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: Size.zero,
padding: const EdgeInsets.all(3),
),
constraints: const BoxConstraints(
minWidth: 24,
minHeight: 24,
),
iconSize: 18,
icon: const Icon(Icons.note_add_outlined),
tooltip: l10n.newFile,
onPressed: () => _handleNewFile(context, rootPath),
),
const SizedBox(width: 2),
IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: Size.zero,
padding: const EdgeInsets.all(3),
),
constraints: const BoxConstraints(
minWidth: 24,
minHeight: 24,
),
iconSize: 18,
icon: const Icon(Icons.create_new_folder_outlined),
tooltip: l10n.newFolder,
onPressed: () =>
_handleNewFolder(context, rootPath),
),
const SizedBox(width: 2),
IconButton(
visualDensity: VisualDensity.compact,
style: IconButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: Size.zero,
padding: const EdgeInsets.all(3),
),
constraints: const BoxConstraints(
minWidth: 24,
minHeight: 24,
),
iconSize: 18,
icon: const Icon(Icons.file_upload_outlined),
tooltip: l10n.importFromExternal,
onPressed: () =>
_handleImportFiles(context, rootPath),
),
],
],
),
],
),
),
_buildActivityBar(context, l10n, theme),
Expanded(
child: IndexedStack(
index: _selectedIndex,
children: [
_buildExplorerPage(context, l10n, theme, rootPath, hasProject),
_buildSearchPlaceholder(context, l10n, theme),
_buildGitPlaceholder(context, l10n, theme),
],
),
),
const Expanded(child: SafeArea(top: false, child: FileTreeWidget())),
],
),
);