custom directory
This commit is contained in:
parent
185a1c62e9
commit
7e82ddcbb7
12 changed files with 396 additions and 56 deletions
|
|
@ -7,18 +7,21 @@ import 'themes/day.dart';
|
|||
import 'themes/night.dart';
|
||||
import 'themes/markdown.dart';
|
||||
import 'dart:io';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
class NoteEditorScreen extends StatefulWidget {
|
||||
final File note;
|
||||
final String? notesDirectoryPath; // ✅ Add this
|
||||
bool isDarkMode;
|
||||
|
||||
NoteEditorScreen({required this.note, required this.isDarkMode});
|
||||
NoteEditorScreen({required this.note, required this.isDarkMode, required this.notesDirectoryPath});
|
||||
|
||||
@override
|
||||
_NoteEditorScreenState createState() => _NoteEditorScreenState();
|
||||
}
|
||||
|
||||
class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
||||
bool isLoading = true;
|
||||
bool _isPreviewMode = false; // Default: Editing mode
|
||||
late CodeController _controller;
|
||||
double _fontSize = 16.0; // Default font size
|
||||
|
|
@ -37,7 +40,13 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
|||
}
|
||||
|
||||
Future<void> _loadNoteContent() async {
|
||||
final content = await widget.note.readAsString();
|
||||
String content = "";
|
||||
try {
|
||||
content = await widget.note.readAsString();
|
||||
} catch (e) {
|
||||
print("❌ Failed to read file: ${widget.note.path}");
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_controller = CodeController(
|
||||
text: content,
|
||||
|
|
@ -45,11 +54,26 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
|||
);
|
||||
_controller.addListener(_saveNote);
|
||||
_controller.popupController.enabled = false;
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Future<void> _saveNote() async {
|
||||
await widget.note.writeAsString(_controller.text);
|
||||
try {
|
||||
final notesDirectory = widget.notesDirectoryPath ?? widget.note.parent.path; // ✅ Use correct directory
|
||||
final newFilePath = path.join(notesDirectory, widget.note.uri.pathSegments.last);
|
||||
|
||||
print("📝 Attempting to save note at: $newFilePath");
|
||||
final newFile = File(newFilePath);
|
||||
await newFile.writeAsString(_controller.text);
|
||||
|
||||
print("✅ Successfully saved note at: $newFilePath");
|
||||
} catch (e, stackTrace) {
|
||||
print("❌ Error saving note: ${widget.note.path}");
|
||||
print("⚠️ Exception: $e");
|
||||
print("🛠 Stack trace: $stackTrace");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -118,10 +142,12 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
|
|||
),
|
||||
],
|
||||
),
|
||||
body: _controller == null
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: _isPreviewMode
|
||||
? Padding(
|
||||
body: isLoading
|
||||
? Center(child: CircularProgressIndicator()) // Show loader while initializing
|
||||
: _controller == null
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: _isPreviewMode
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SingleChildScrollView(
|
||||
child: MarkdownBody(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue