diff --git a/.gitignore b/.gitignore index d64610c..ff38daa 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ .aider* .build-container-cache /coverage/ +/.agent-shell/ diff --git a/TODO.md b/TODO.md index 1d86856..df8dbb0 100644 --- a/TODO.md +++ b/TODO.md @@ -67,15 +67,15 @@ - [R] When a formula is derived in FormulaScreen, the new FormulaScreen is not pushed in navigator, it replacles the current FormulaScreen - [R] In FormulaScreen, a Formula cant be derived if DerivedFormula.isDerivable() returns false - [R] The algorithm of formulaSolver should be https://en.wikipedia.org/wiki/Newton%27s_method -- [ ] Use receive_sharing_intent package to implement import of files in linux and android. +- [R] Use receive_sharing_intent package to implement import of files in linux and android. - The application will accept *.d4rtf files with the same format of files in ./assets . - The application will accept also shared text, with same format as files in ./assets. - - The loaded formulaelemets will be added to the GetIt.instance.get() +- [R] Preview of imported formulalements - The screen will receive a list of FormulaElements to import - The formulas will have a "edit" button to show a FormulaEditor with the formula - The screen will have an "import all" button to import all the FormulaElements in the list. This will call Corpus.addFormulaElement() for each element, and then pop the screen. -- [ ] In FormulaList, add a button next to "export" to import FormulaElements. +- [R] In FormulaList, add a button next to "export" to import FormulaElements. - It will show a screen with a text editor with dart syntax and a button "paste". - The "paste" button will copy the clipboard into the text editor. - A second button "import" will use the import preview screen diff --git a/lib/ai/formula_list.dart b/lib/ai/formula_list.dart index 0974078..bfd4caf 100644 --- a/lib/ai/formula_list.dart +++ b/lib/ai/formula_list.dart @@ -7,13 +7,17 @@ import 'formula_screen.dart'; import 'package:share_plus/share_plus.dart' as share_plus; import 'formula_editor.dart'; import 'package:share_plus/share_plus.dart'; +import 'import_preview_screen.dart'; +import '../services/import_service.dart'; class FormulaList extends StatefulWidget { final Corpus corpus; + final VoidCallback? onImport; const FormulaList({ super.key, required this.corpus, + this.onImport, }); @override @@ -133,6 +137,23 @@ class _FormulaListState extends State { ); } + void _importFromText() { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ImportFromTextScreen( + corpus: widget.corpus, + ), + ), + ).then((result) { + if (result == true) { + setState(() { + // Refresh the list when returning from import + }); + } + }); + } + @override Widget build(BuildContext context) { return Column( diff --git a/lib/main.dart b/lib/main.dart index 38b389e..549b962 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,6 +8,7 @@ import 'ai/formula_list.dart'; import 'corpus.dart'; import 'defaults/default_corpus.dart'; import 'formula_models.dart' as models; +import 'ai/import_preview_screen.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -43,6 +44,23 @@ class _CorpusLoaderState extends State { _corpusFuture = loadCorpusFromDatabaseOrAssets(); } + void _handleImport() { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ImportFromTextScreen( + corpus: _corpusFuture.then((c) => c).value as Corpus? ?? Corpus(), + ), + ), + ).then((result) { + if( result ) { + setState(() { + // Refresh the list when returning from import + }); + } + }); + } + @override Widget build(BuildContext context) { return FutureBuilder( @@ -59,9 +77,19 @@ class _CorpusLoaderState extends State { // If the corpus is empty (user chose not to load default), we could handle that here // For now, just display the formula list return Scaffold( - appBar: AppBar(title: const Text('Formulas')), + appBar: AppBar( + title: const Text('Formulas'), + actions: [ + IconButton( + icon: const Icon(Icons.import_export), + tooltip: 'Import formulas', + onPressed: _handleImport, + ), + ], + ), body: FormulaList( corpus: snapshot.data!, + onImport: _handleImport, ), ); }