feat: create project folders from desktop app

This commit is contained in:
Hamza Ayed
2026-10-04 04:40:51 +03:00
parent ab34825faf
commit f6a2e8c3d3
7 changed files with 244 additions and 6 deletions
@@ -12,6 +12,7 @@ import '../../../audio/presentation/cubit/voice_cubit.dart';
import '../../../audio/presentation/cubit/voice_state.dart';
import '../../../../core/notifications/completion_notification_service.dart';
import '../../../../core/network/api_repository.dart';
import '../../../../core/projects/project_folder_service.dart';
import '../cubit/chat_cubit.dart';
import '../cubit/chat_state.dart';
@@ -149,6 +150,85 @@ class _ChatPageState extends State<ChatPage> {
}
}
Future<void> _createNewProject() async {
final cubit = context.read<ChatCubit>();
String? createdPath;
try {
final parent = await getDirectoryPath(
confirmButtonText: 'اختيار موقع المشروع',
);
if (!mounted || parent == null) return;
final nameController = TextEditingController();
final name = await showDialog<String>(
context: context,
builder:
(dialogContext) => AlertDialog(
title: const Text('إنشاء مشروع جديد'),
content: TextField(
controller: nameController,
autofocus: true,
maxLength: 80,
decoration: const InputDecoration(
labelText: 'اسم المشروع',
hintText: 'مثال: my-first-app',
),
onSubmitted:
(value) => Navigator.of(dialogContext).pop(value.trim()),
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(),
child: const Text('إلغاء'),
),
FilledButton(
onPressed:
() => Navigator.of(
dialogContext,
).pop(nameController.text.trim()),
child: const Text('إنشاء المجلد'),
),
],
),
);
nameController.dispose();
if (!mounted || name == null) return;
createdPath = await createProjectFolder(parent, name);
final files = await cubit.selectWorkspace(createdPath);
if (!mounted) return;
if (cubit.state.selectedWorkspacePath != createdPath) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'تم إنشاء المجلد لكنه لم يُسجّل للوكيل: ${cubit.state.error ?? createdPath}',
),
),
);
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'أنشأت مجلد المشروع وسجّلته: ${_workspaceName(createdPath)}. يمكنك الآن طلب إنشاء ملفات، وستراجع كل معاينة قبل حفظها.',
),
),
);
if (files.isNotEmpty) await _showWorkspaceFiles(files);
} catch (error) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
createdPath == null
? 'تعذر إنشاء مجلد المشروع: $error'
: 'تم إنشاء المجلد ولم يكتمل تسجيله: $createdPath · $error',
),
),
);
}
}
String _workspaceName(String path) {
final parts = path.split(RegExp(r'[/\\]')).where((part) => part.isNotEmpty);
return parts.isEmpty ? path : parts.last;
@@ -1844,11 +1924,26 @@ class _ChatPageState extends State<ChatPage> {
),
),
const SizedBox(height: 10),
FilledButton.icon(
onPressed:
chat.isSending ? null : _addWorkspaceProject,
icon: const Icon(Icons.folder_open_outlined),
label: const Text('اختيار مجلد مشروع موجود'),
Wrap(
spacing: 10,
runSpacing: 8,
children: [
FilledButton.icon(
onPressed:
chat.isSending ? null : _addWorkspaceProject,
icon: const Icon(Icons.folder_open_outlined),
label: const Text('فتح مجلد مشروع موجود'),
),
if (canCreateProjectFolders)
OutlinedButton.icon(
onPressed:
chat.isSending ? null : _createNewProject,
icon: const Icon(
Icons.create_new_folder_outlined,
),
label: const Text('إنشاء مشروع جديد'),
),
],
),
],
),