diff --git a/lib/src/state/dialog.dart b/lib/src/state/dialog.dart index ca37e13c4..3297aba91 100644 --- a/lib/src/state/dialog.dart +++ b/lib/src/state/dialog.dart @@ -37,6 +37,9 @@ class DialogType extends EnumClass { static const DialogType edit_modification = _$edit_modification; static const DialogType set_color = _$set_color; static const DialogType set_loopout_name = _$set_loopout_name; + static const DialogType set_loopout_length = _$set_loopout_length; + static const DialogType set_insertion_length = _$set_insertion_length; + static const DialogType set_extension_num_bases = _$set_extension_num_bases; static const DialogType set_helix_minimum_offset = _$set_helix_minimum_offset; static const DialogType set_helix_maximum_offset = _$set_helix_maximum_offset; static const DialogType set_helix_index = _$set_helix_index; diff --git a/lib/src/view/design_main_strand_crossover.dart b/lib/src/view/design_main_strand_crossover.dart index 29489ec7d..942199017 100644 --- a/lib/src/view/design_main_strand_crossover.dart +++ b/lib/src/view/design_main_strand_crossover.dart @@ -2,6 +2,7 @@ import 'dart:html'; import 'package:over_react/over_react.dart'; import 'package:built_collection/built_collection.dart'; +import 'package:scadnano/src/state/dialog.dart'; import '../state/geometry.dart'; import 'transform_by_helix_group.dart'; @@ -211,7 +212,12 @@ class DesignMainStrandCrossoverComponent } convert_crossover_to_loopout() async { - int new_length = await ask_for_length('change loopout length', current_length: 1, lower_bound: 1); + int new_length = await ask_for_length( + 'set loopout length', + current_length: 1, + lower_bound: 1, + dialog_type: DialogType.set_loopout_length, + ); if (new_length == null || new_length == 0) { return; } diff --git a/lib/src/view/design_main_strand_extension.dart b/lib/src/view/design_main_strand_extension.dart index 47894e680..58c12d5df 100644 --- a/lib/src/view/design_main_strand_extension.dart +++ b/lib/src/view/design_main_strand_extension.dart @@ -6,7 +6,6 @@ import 'package:built_collection/built_collection.dart'; import 'package:color/color.dart'; import 'package:over_react/over_react.dart'; import 'package:react/react.dart' as react; -import 'package:smart_dialogs/smart_dialogs.dart'; import 'package:scadnano/src/state/modification_type.dart'; import 'package:scadnano/src/view/transform_by_helix_group.dart'; @@ -307,33 +306,24 @@ tooltip_text(Extension ext) => (ext.label == null ? "" : "\n label=${ext.label.toString()}"); Future ask_for_num_bases(String title, {int current_num_bases, int lower_bound}) async { - // https://pub.dev/documentation/smart_dialogs/latest/smart_dialogs/Info/get.html - String buttontype = DiaAttr.CHECKBOX; - String htmlTitleText = title; - List textLabels = ['new number of bases:']; - List> comboInfo = null; - List defaultInputTexts = ['${current_num_bases}']; - List widths = [1]; - List isChecked = null; - bool alternateRowColor = false; - List buttonLabels = ['OK', 'Cancel']; - - UserInput result = await Info.get(buttontype, htmlTitleText, textLabels, comboInfo, defaultInputTexts, - widths, isChecked, alternateRowColor, buttonLabels); - - if (result.buttonCode != 'DIA_ACT_OK') { - return null; + int num_bases_idx = 0; + var items = List.filled(1, null); + items[num_bases_idx] = DialogInteger(label: 'number of bases:', value: current_num_bases); + var dialog = Dialog( + title: title, + type: DialogType.set_extension_num_bases, + items: items, + use_saved_response: false, + ); + + List results = await util.dialog(dialog); + if (results == null) return current_num_bases; + + int num_bases = (results[num_bases_idx] as DialogInteger).value; + if (num_bases < lower_bound) { + window.alert('number of bases must be at least ${lower_bound}, but you entered $num_bases'); + return current_num_bases; } - String length_str = result.getUserInput(0)[0]; - int length = int.tryParse(length_str); - if (length == null) { - Info.show('"$length_str" is not a valid integer'); - return null; - } else if (length < lower_bound) { - Info.show('number of bases must be at least ${lower_bound}, but it is $length_str'); - return null; - } - - return length; + return num_bases; } diff --git a/lib/src/view/design_main_strand_insertion.dart b/lib/src/view/design_main_strand_insertion.dart index 4f181086f..9a68e5e70 100644 --- a/lib/src/view/design_main_strand_insertion.dart +++ b/lib/src/view/design_main_strand_insertion.dart @@ -6,6 +6,7 @@ import 'package:over_react/over_react.dart'; import 'package:built_collection/built_collection.dart'; import 'package:platform_detect/platform_detect.dart'; import 'package:scadnano/src/state/context_menu.dart'; +import 'package:scadnano/src/state/dialog.dart'; import 'package:scadnano/src/state/geometry.dart'; import 'package:tuple/tuple.dart'; @@ -240,8 +241,17 @@ class DesignMainStrandInsertionComponent extends UiComponent2 ask_for_length( 'change loopout length (0 to convert to crossover)', current_length: props.loopout.loopout_num_bases, - lower_bound: 0)); + lower_bound: 0, + dialog_type: DialogType.set_loopout_length)); if (new_length == null || new_length == props.loopout.loopout_num_bases) { return; } @@ -435,122 +435,29 @@ String loopout_path_description_same_helix_same_direction(Loopout loopout, Helix return path; } -// String loopout_path_description_within_group_new(Helix prev_helix, Helix next_helix, Domain prev_domain, -// Domain next_domain, Loopout loopout, bool include_start_M) { -// Helix top_helix = prev_helix; -// Helix bot_helix = next_helix; -// Geometry geometry = prev_helix.geometry; -// Domain top_domain = prev_domain; -// Domain bot_domain = next_domain; -// if (top_helix.idx == bot_helix.idx) { -// top_helix = bot_helix = next_helix; -// if (!prev_domain.forward) { -// top_domain = next_domain; -// bot_domain = prev_domain; -// } -// } else if (top_helix.svg_position.y > bot_helix.svg_position.y) { -// top_helix = next_helix; -// bot_helix = prev_helix; -// top_domain = next_domain; -// bot_domain = prev_domain; -// } -// bool top_dom_is_prev = top_domain == prev_domain; -// -// int top_offset = top_dom_is_prev ? top_domain.offset_3p : top_domain.offset_5p; -// int bot_offset = top_dom_is_prev ? bot_domain.offset_5p : bot_domain.offset_3p; -// int prev_offset = top_dom_is_prev ? top_offset : bot_offset; -// int next_offset = top_dom_is_prev ? bot_offset : top_offset; -// -// var prev_svg = prev_helix.svg_base_pos(prev_offset, prev_domain.forward); -// var next_svg = next_helix.svg_base_pos(next_offset, next_domain.forward); -// -// var top_svg = prev_svg; -// var bot_svg = next_svg; -// if (top_helix.idx == bot_helix.idx) { -// if (!prev_domain.forward) { -// top_svg = next_svg; -// bot_svg = prev_svg; -// } -// } else if (top_helix.svg_position.y > bot_helix.svg_position.y) { -// top_svg = next_svg; -// bot_svg = prev_svg; -// } -// -// var w, h; -// -// if (top_helix.idx == bot_helix.idx) { -// w = 1.5 * util.sigmoid(loopout.loopout_length - 1) * geometry.base_width_svg; -// // h = 5 * util.sigmoid(loopout.loopout_length - 5) * geometry.base_height_svg; -// h = 5 * util.sigmoid(loopout.loopout_length - 1) * geometry.base_height_svg; -// print('h = $h'); -// } else { -// w = 2 * util.sigmoid(loopout.loopout_length) * geometry.base_width_svg; -// h = 5 * util.sigmoid(loopout.loopout_length - 3) * geometry.base_height_svg; -// } -// -// var y_offset_bot = bot_svg.y; -// var y_offset_top = top_svg.y; -// var x_offset_bot = bot_svg.x; -// var x_offset_top = top_svg.x; -// if (top_offset == top_domain.start) { -// x_offset_top -= w; -// } else { -// x_offset_top += w; -// } -// if (bot_offset == bot_domain.start) { -// x_offset_bot -= w; -// } else { -// x_offset_bot += w; -// } -// y_offset_top += h; -// y_offset_bot -= h; -// -// var c_bot = Point(x_offset_bot, y_offset_bot); -// var c_top = Point(x_offset_top, y_offset_top); -// -// var vector = bot_svg - top_svg; -// num angle_radians_from_x_axis = -atan2(vector.y, vector.x); -// num angle_degrees_from_x_axis = util.to_degrees(angle_radians_from_x_axis); -// num angle_degrees_from_y_axis = 90 - angle_degrees_from_x_axis; -// var c_bot_rot = util.rotate(c_bot, angle_degrees_from_y_axis, origin: prev_svg); -// var c_top_rot = util.rotate(c_top, angle_degrees_from_y_axis, origin: next_svg); -// print('top offset = ${top_offset}'); -// print(' angle = ${angle_degrees_from_y_axis}'); -// -// var path = (include_start_M ? 'M ${prev_svg.x} ${prev_svg.y} ' : '') + -// 'C ${c_bot_rot.x} ${c_bot_rot.y} ${c_top_rot.x} ${c_top_rot.y} ' -// '${next_svg.x} ${next_svg.y}'; -// -// return path; -// } - -Future ask_for_length(String title, {int current_length, int lower_bound}) async { - // https://pub.dev/documentation/smart_dialogs/latest/smart_dialogs/Info/get.html - String buttontype = DiaAttr.CHECKBOX; - String htmlTitleText = title; - List textLabels = ['new length:']; - List> comboInfo = null; - List defaultInputTexts = ['${current_length}']; - List widths = [1]; - List isChecked = null; - bool alternateRowColor = false; - List buttonLabels = ['OK', 'Cancel']; - - UserInput result = await Info.get(buttontype, htmlTitleText, textLabels, comboInfo, defaultInputTexts, - widths, isChecked, alternateRowColor, buttonLabels); - - if (result.buttonCode != 'DIA_ACT_OK') { - return null; - } - - String length_str = result.getUserInput(0)[0]; - int length = int.tryParse(length_str); - if (length == null) { - Info.show('"$length_str" is not a valid integer'); - return null; - } else if (length < lower_bound) { - Info.show('length must be at least ${lower_bound}, but it is $length_str'); - return null; +Future ask_for_length(String title, + {int current_length, int lower_bound, DialogType dialog_type, String tooltip = ""}) async { + int length_idx = 0; + var items = List.filled(1, null); + items[length_idx] = DialogInteger( + label: 'new length:', + value: current_length, + tooltip: tooltip, + ); + var dialog = Dialog( + title: title, + type: dialog_type, + items: items, + use_saved_response: false, + ); + + List results = await util.dialog(dialog); + if (results == null) return current_length; + + int length = (results[length_idx] as DialogInteger).value; + if (length < lower_bound) { + window.alert('length must be at least ${lower_bound}, but you entered $length'); + return current_length; } return length; diff --git a/pubspec.lock b/pubspec.lock index 7203032d7..f2bc63461 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -540,13 +540,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.4+1" - smart_dialogs: - dependency: "direct main" - description: - name: smart_dialogs - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.2" source_gen: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5a3ef48d2..a4bdd3a44 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,10 +8,7 @@ environment: dependencies: analyzer: '>=0.39.0 <0.42.0' - # analyzer: '^1.0.0' spreadsheet_decoder: ^2.0.0 - # spreadsheet_decoder: ^2.0.0 - smart_dialogs: ^2.1.2 dialog: ^0.8.0 meta: ^1.1.7 js: ^0.6.1+1 @@ -23,16 +20,11 @@ dependencies: path: ^1.6.4 platform_detect: ^1.0.0 dnd: ^2.0.1 - # dnd: ^2.0.0 - # redux_thunk: ^0.2.1 built_value: ^8.1.3 built_collection: ^5.1.1 reselect: ^0.4.0 redux: ^4.0.0 - # redux: ^5.0.0 - # react: ^5.1.0 react: ^6.0.0 - # over_react: ^3.11.0 over_react: ^4.0.0 http: ^0.12.2 @@ -48,25 +40,3 @@ dev_dependencies: analyzer: plugins: - over_react - -# Fix analyzer issue: https://github.com/flutter/flutter/issues/62240 -# dependency_overrides: -# analyzer: '0.39.14' - -#dependency_overrides: -# built_value: -# path: ../built_value.dart/built_value -# built_collection: -# path: ../built_collection.dart -# built_value_generator: -# path: ../built_value.dart/built_value_generator/ -# react: -# git: -# url: https://github.com/cleandart/react-dart -# ref: 5.1.0-wip -# over_react: -# git: -# url: https://github.com/Workiva/over_react -# ref: master -# ref: 4d6bab5b30c3354d34260ef0c9250209f5da3764 -