diff --git a/lib/ai/formula_list.dart b/lib/ai/formula_list.dart index 3c1f48f..a4fb90b 100644 --- a/lib/ai/formula_list.dart +++ b/lib/ai/formula_list.dart @@ -156,41 +156,7 @@ class _FormulaListState extends State { trailing: Row( mainAxisSize: MainAxisSize.min, children: [ - PopupMenuButton( - icon: const Icon(Icons.share), - tooltip: 'Share or copy to clipboard', - onSelected: (value) { - if (value == 'share') { - FormulaList.shareFormula(formula); - } else if (value == 'copy') { - FormulaList.copyFormula(context, formula); - } - }, - itemBuilder: (context) => [ - PopupMenuItem( - value: 'share', - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon(Icons.share, size: 20), - const SizedBox(width: 8), - Flexible(child: Text('Share', softWrap: false)), - ], - ), - ), - PopupMenuItem( - value: 'copy', - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon(Icons.copy, size: 20), - const SizedBox(width: 8), - Flexible(child: Text('Copy to clipboard', softWrap: false)), - ], - ), - ), - ], - ), + // TOTHINK: Add buttons here, but I don't know which ones ], ), onTap: () { diff --git a/lib/ai/formula_screen.dart b/lib/ai/formula_screen.dart index 442a163..ffcc368 100644 --- a/lib/ai/formula_screen.dart +++ b/lib/ai/formula_screen.dart @@ -1,4 +1,5 @@ // dart +import 'package:d4rt_formulas/database/database_service.dart'; import 'package:flutter/material.dart'; import 'package:flutter_markdown_plus_latex/flutter_markdown_plus_latex.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; @@ -7,6 +8,7 @@ import '../formula_models.dart'; import '../formula_evaluator.dart'; import '../corpus.dart'; import '../error_handler.dart'; +import '../service_locator.dart'; import '../value_formatter.dart'; import 'd4rt_editing_controller.dart'; import 'formula_list.dart'; @@ -194,28 +196,69 @@ class _FormulaScreenState extends State { ], ), + IconButton( + icon: const Icon(Icons.delete_forever), + onPressed: () { + print( "Borrando"); + showAlertDialog(BuildContext context) { + // set up the buttons + Widget cancelButton = TextButton( + child: Text("Cancel"), + onPressed: () { + Navigator.of(context).pop(); + }, + ); + Widget deleteButton = TextButton( + child: Text("Delete"), + onPressed: () { + widget.corpus.forgetFormula(formula.originalFormula); + getDatabase().deleteFormula(formula.originalFormula.uuid); + Navigator.of(context) + ..pop()..pop(); + }, + ); + + // set up the AlertDialog + AlertDialog alert = AlertDialog( + title: Text("Delete Formula"), + content: Text("Please confirm deletion of formula ${formula.name}"), + actions: [ + cancelButton, + deleteButton, + ], + ); + return alert; + } + // show the dialog + showDialog( + context: context, + builder: showAlertDialog + ); + }, + tooltip: "Delete formula" + ), IconButton( icon: const Icon(Icons.edit), onPressed: formula is DerivedFormula ? null : () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => - FormulaEditor( - formula: formula as Formula, - corpus: widget.corpus, - onSave: (updatedFormula) { - widget.onSave?.call(updatedFormula); - setState(() { - formula = updatedFormula; - }); - }, - ), + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + FormulaEditor( + formula: formula as Formula, + corpus: widget.corpus, + onSave: (updatedFormula) { + widget.onSave?.call(updatedFormula); + setState(() { + formula = updatedFormula; + }); + }, ), - ); - }, + ), + ); + }, tooltip: formula is DerivedFormula ? 'Cannot edit derived formula' : 'Edit Formula', diff --git a/lib/corpus.dart b/lib/corpus.dart index 4775801..568815c 100644 --- a/lib/corpus.dart +++ b/lib/corpus.dart @@ -275,4 +275,11 @@ class Corpus{ return result.toList(); } + void forgetFormula(Formula formula) { + for (final tag in formula.tags) { + _tags[tag]?.remove(formula); + } + _allFormulas.remove(formula.uuid); + } + } diff --git a/lib/value_formatter.dart b/lib/value_formatter.dart index e65f41f..1387bf2 100644 --- a/lib/value_formatter.dart +++ b/lib/value_formatter.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; String? formatOutput(dynamic result) { if (result == null) return null; + return result.toString(); // Try to parse as number to format with commas if (result is num) {