From 5ac76ef60b806f6f7a6a63ec610b2e293561734a Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Wed, 29 Dec 2021 21:58:08 -0800 Subject: [PATCH] Fixes #697; fix JSON encoding warning on startup --- lib/src/actions/actions.dart | 1 + lib/src/dna_file_type.dart | 23 +++++++++++++++++++++ lib/src/reducers/load_dna_file_reducer.dart | 5 +++-- lib/src/serializers.dart | 2 ++ lib/src/util.dart | 2 -- lib/src/view/menu.dart | 3 ++- 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 lib/src/dna_file_type.dart diff --git a/lib/src/actions/actions.dart b/lib/src/actions/actions.dart index 412c783f9..246130de1 100644 --- a/lib/src/actions/actions.dart +++ b/lib/src/actions/actions.dart @@ -8,6 +8,7 @@ import 'package:built_value/serializer.dart'; import 'package:color/color.dart'; import 'package:js/js.dart'; import 'package:built_collection/built_collection.dart'; +import 'package:scadnano/src/dna_file_type.dart'; import 'package:scadnano/src/state/domains_move.dart'; import 'package:scadnano/src/state/export_dna_format_strand_order.dart'; import 'package:scadnano/src/state/geometry.dart'; diff --git a/lib/src/dna_file_type.dart b/lib/src/dna_file_type.dart new file mode 100644 index 000000000..ff1d002c3 --- /dev/null +++ b/lib/src/dna_file_type.dart @@ -0,0 +1,23 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/serializer.dart'; + +part 'dna_file_type.g.dart'; + +class DNAFileType extends EnumClass { + const DNAFileType._(String name) : super(name); + + @memoized + int get hashCode; + + static Serializer get serializer => _$dNAFileTypeSerializer; + + /******************** end BuiltValue boilerplate *********************/ + + static const DNAFileType scadnano_file = _$scadnano_file; + static const DNAFileType cadnano_file = _$cadnano_file; + + static BuiltSet get values => _$values; + static DNAFileType valueOf(String name) => _$valueOf(name); +} + diff --git a/lib/src/reducers/load_dna_file_reducer.dart b/lib/src/reducers/load_dna_file_reducer.dart index 1302b9d41..1f7afb3cf 100644 --- a/lib/src/reducers/load_dna_file_reducer.dart +++ b/lib/src/reducers/load_dna_file_reducer.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:built_collection/built_collection.dart'; +import 'package:scadnano/src/dna_file_type.dart'; import '../state/selectable.dart'; import '../state/design.dart'; @@ -19,10 +20,10 @@ AppState load_dna_file_reducer(AppState state, actions.LoadDNAFile action) { try { switch (action.dna_file_type) { - case util.DNAFileType.scadnano_file: + case DNAFileType.scadnano_file: design_new = Design.from_json_str(action.content, state.ui_state.invert_xy); break; - case util.DNAFileType.cadnano_file: + case DNAFileType.cadnano_file: design_new = Design.from_cadnano_v2_json_str(action.content, state.ui_state.invert_xy); break; } diff --git a/lib/src/serializers.dart b/lib/src/serializers.dart index 426643870..35bcfa74a 100644 --- a/lib/src/serializers.dart +++ b/lib/src/serializers.dart @@ -5,6 +5,7 @@ import 'package:built_value/serializer.dart'; import 'package:built_collection/built_collection.dart'; import 'package:built_value/standard_json_plugin.dart'; import 'package:color/color.dart'; +import 'package:scadnano/src/dna_file_type.dart'; import 'package:tuple/tuple.dart'; import 'state/domains_move.dart'; @@ -105,6 +106,7 @@ part 'serializers.g.dart'; SetShowEditor, SaveDNAFile, LoadDNAFile, + DNAFileType, ExportCadnanoFile, ExportCodenanoFile, MouseoverDataClear, diff --git a/lib/src/util.dart b/lib/src/util.dart index f7f86327f..51faeeb22 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -1624,5 +1624,3 @@ Map invert_helices_view_order(Iterable helices_view_order) { } return view_order_inverse; } - -enum DNAFileType { scadnano_file, cadnano_file } diff --git a/lib/src/view/menu.dart b/lib/src/view/menu.dart index 972331fb6..23a2c62bb 100644 --- a/lib/src/view/menu.dart +++ b/lib/src/view/menu.dart @@ -6,6 +6,7 @@ import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; import 'package:over_react/over_react.dart'; import 'package:over_react/over_react_redux.dart'; +import 'package:scadnano/src/dna_file_type.dart'; import 'package:scadnano/src/json_serializable.dart'; import 'package:scadnano/src/state/design.dart'; import 'package:scadnano/src/state/dna_end.dart'; @@ -1167,7 +1168,7 @@ cadnano_file_loaded(FileReader file_reader, String filename) async { try { var json_cadnano_text = file_reader.result; filename = path.setExtension(filename, '.${constants.default_scadnano_file_extension}'); - app.dispatch(actions.LoadDNAFile(content: json_cadnano_text, filename: filename, dna_file_type: util.DNAFileType.cadnano_file)); + app.dispatch(actions.LoadDNAFile(content: json_cadnano_text, filename: filename, dna_file_type: DNAFileType.cadnano_file)); } on Exception catch (e) { window.alert('Error importing file: ${e}'); }