Skip to content

Commit b876256

Browse files
authored
Merge pull request #981 from UC-Davis-molecular-computing/980-remove-smartdialog
closes #980: remove smart_dialog package dependency
2 parents 740d359 + 132f191 commit b876256

File tree

7 files changed

+65
-186
lines changed

7 files changed

+65
-186
lines changed

lib/src/state/dialog.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class DialogType extends EnumClass {
3737
static const DialogType edit_modification = _$edit_modification;
3838
static const DialogType set_color = _$set_color;
3939
static const DialogType set_loopout_name = _$set_loopout_name;
40+
static const DialogType set_loopout_length = _$set_loopout_length;
41+
static const DialogType set_insertion_length = _$set_insertion_length;
42+
static const DialogType set_extension_num_bases = _$set_extension_num_bases;
4043
static const DialogType set_helix_minimum_offset = _$set_helix_minimum_offset;
4144
static const DialogType set_helix_maximum_offset = _$set_helix_maximum_offset;
4245
static const DialogType set_helix_index = _$set_helix_index;

lib/src/view/design_main_strand_crossover.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:html';
22

33
import 'package:over_react/over_react.dart';
44
import 'package:built_collection/built_collection.dart';
5+
import 'package:scadnano/src/state/dialog.dart';
56
import '../state/geometry.dart';
67

78
import 'transform_by_helix_group.dart';
@@ -211,7 +212,12 @@ class DesignMainStrandCrossoverComponent
211212
}
212213

213214
convert_crossover_to_loopout() async {
214-
int new_length = await ask_for_length('change loopout length', current_length: 1, lower_bound: 1);
215+
int new_length = await ask_for_length(
216+
'set loopout length',
217+
current_length: 1,
218+
lower_bound: 1,
219+
dialog_type: DialogType.set_loopout_length,
220+
);
215221
if (new_length == null || new_length == 0) {
216222
return;
217223
}

lib/src/view/design_main_strand_extension.dart

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:built_collection/built_collection.dart';
66
import 'package:color/color.dart';
77
import 'package:over_react/over_react.dart';
88
import 'package:react/react.dart' as react;
9-
import 'package:smart_dialogs/smart_dialogs.dart';
109

1110
import 'package:scadnano/src/state/modification_type.dart';
1211
import 'package:scadnano/src/view/transform_by_helix_group.dart';
@@ -307,33 +306,24 @@ tooltip_text(Extension ext) =>
307306
(ext.label == null ? "" : "\n label=${ext.label.toString()}");
308307

309308
Future<int> ask_for_num_bases(String title, {int current_num_bases, int lower_bound}) async {
310-
// https://pub.dev/documentation/smart_dialogs/latest/smart_dialogs/Info/get.html
311-
String buttontype = DiaAttr.CHECKBOX;
312-
String htmlTitleText = title;
313-
List<String> textLabels = ['new number of bases:'];
314-
List<List<String>> comboInfo = null;
315-
List<String> defaultInputTexts = ['${current_num_bases}'];
316-
List<int> widths = [1];
317-
List<String> isChecked = null;
318-
bool alternateRowColor = false;
319-
List<String> buttonLabels = ['OK', 'Cancel'];
320-
321-
UserInput result = await Info.get(buttontype, htmlTitleText, textLabels, comboInfo, defaultInputTexts,
322-
widths, isChecked, alternateRowColor, buttonLabels);
323-
324-
if (result.buttonCode != 'DIA_ACT_OK') {
325-
return null;
309+
int num_bases_idx = 0;
310+
var items = List<DialogItem>.filled(1, null);
311+
items[num_bases_idx] = DialogInteger(label: 'number of bases:', value: current_num_bases);
312+
var dialog = Dialog(
313+
title: title,
314+
type: DialogType.set_extension_num_bases,
315+
items: items,
316+
use_saved_response: false,
317+
);
318+
319+
List<DialogItem> results = await util.dialog(dialog);
320+
if (results == null) return current_num_bases;
321+
322+
int num_bases = (results[num_bases_idx] as DialogInteger).value;
323+
if (num_bases < lower_bound) {
324+
window.alert('number of bases must be at least ${lower_bound}, but you entered $num_bases');
325+
return current_num_bases;
326326
}
327327

328-
String length_str = result.getUserInput(0)[0];
329-
int length = int.tryParse(length_str);
330-
if (length == null) {
331-
Info.show('"$length_str" is not a valid integer');
332-
return null;
333-
} else if (length < lower_bound) {
334-
Info.show('number of bases must be at least ${lower_bound}, but it is $length_str');
335-
return null;
336-
}
337-
338-
return length;
328+
return num_bases;
339329
}

lib/src/view/design_main_strand_insertion.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:over_react/over_react.dart';
66
import 'package:built_collection/built_collection.dart';
77
import 'package:platform_detect/platform_detect.dart';
88
import 'package:scadnano/src/state/context_menu.dart';
9+
import 'package:scadnano/src/state/dialog.dart';
910
import 'package:scadnano/src/state/geometry.dart';
1011
import 'package:tuple/tuple.dart';
1112

@@ -240,8 +241,17 @@ class DesignMainStrandInsertionComponent extends UiComponent2<DesignMainStrandIn
240241

241242
change_insertion_length() async {
242243
int new_length = await ask_for_length('change insertion length',
243-
current_length: props.insertion.length, lower_bound: 1);
244-
if (new_length == null || new_length == props.insertion.length) {
244+
current_length: props.insertion.length,
245+
lower_bound: 1,
246+
dialog_type: DialogType.set_insertion_length,
247+
tooltip: """\
248+
Changes the insertion length.
249+
250+
Keep in mind that the insertion length is the number of *extra* bases.
251+
So for example an insertion length of 1 would represent at that offset
252+
2 total bases: the original base and the 1 extra base from the insertion.
253+
""");
254+
if (new_length == props.insertion.length) {
245255
return;
246256
}
247257

lib/src/view/design_main_strand_loopout.dart

Lines changed: 25 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:built_collection/built_collection.dart';
55
import 'package:color/color.dart';
66
import 'package:over_react/over_react.dart';
77
import 'package:scadnano/src/state/dialog.dart';
8-
import 'package:smart_dialogs/smart_dialogs.dart';
98

109
import 'transform_by_helix_group.dart';
1110
import '../state/geometry.dart';
@@ -216,7 +215,8 @@ class DesignMainLoopoutComponent extends UiStatefulComponent2<DesignMainLoopoutP
216215
int new_length = await app.disable_keyboard_shortcuts_while(() => ask_for_length(
217216
'change loopout length (0 to convert to crossover)',
218217
current_length: props.loopout.loopout_num_bases,
219-
lower_bound: 0));
218+
lower_bound: 0,
219+
dialog_type: DialogType.set_loopout_length));
220220
if (new_length == null || new_length == props.loopout.loopout_num_bases) {
221221
return;
222222
}
@@ -435,122 +435,29 @@ String loopout_path_description_same_helix_same_direction(Loopout loopout, Helix
435435
return path;
436436
}
437437

438-
// String loopout_path_description_within_group_new(Helix prev_helix, Helix next_helix, Domain prev_domain,
439-
// Domain next_domain, Loopout loopout, bool include_start_M) {
440-
// Helix top_helix = prev_helix;
441-
// Helix bot_helix = next_helix;
442-
// Geometry geometry = prev_helix.geometry;
443-
// Domain top_domain = prev_domain;
444-
// Domain bot_domain = next_domain;
445-
// if (top_helix.idx == bot_helix.idx) {
446-
// top_helix = bot_helix = next_helix;
447-
// if (!prev_domain.forward) {
448-
// top_domain = next_domain;
449-
// bot_domain = prev_domain;
450-
// }
451-
// } else if (top_helix.svg_position.y > bot_helix.svg_position.y) {
452-
// top_helix = next_helix;
453-
// bot_helix = prev_helix;
454-
// top_domain = next_domain;
455-
// bot_domain = prev_domain;
456-
// }
457-
// bool top_dom_is_prev = top_domain == prev_domain;
458-
//
459-
// int top_offset = top_dom_is_prev ? top_domain.offset_3p : top_domain.offset_5p;
460-
// int bot_offset = top_dom_is_prev ? bot_domain.offset_5p : bot_domain.offset_3p;
461-
// int prev_offset = top_dom_is_prev ? top_offset : bot_offset;
462-
// int next_offset = top_dom_is_prev ? bot_offset : top_offset;
463-
//
464-
// var prev_svg = prev_helix.svg_base_pos(prev_offset, prev_domain.forward);
465-
// var next_svg = next_helix.svg_base_pos(next_offset, next_domain.forward);
466-
//
467-
// var top_svg = prev_svg;
468-
// var bot_svg = next_svg;
469-
// if (top_helix.idx == bot_helix.idx) {
470-
// if (!prev_domain.forward) {
471-
// top_svg = next_svg;
472-
// bot_svg = prev_svg;
473-
// }
474-
// } else if (top_helix.svg_position.y > bot_helix.svg_position.y) {
475-
// top_svg = next_svg;
476-
// bot_svg = prev_svg;
477-
// }
478-
//
479-
// var w, h;
480-
//
481-
// if (top_helix.idx == bot_helix.idx) {
482-
// w = 1.5 * util.sigmoid(loopout.loopout_length - 1) * geometry.base_width_svg;
483-
// // h = 5 * util.sigmoid(loopout.loopout_length - 5) * geometry.base_height_svg;
484-
// h = 5 * util.sigmoid(loopout.loopout_length - 1) * geometry.base_height_svg;
485-
// print('h = $h');
486-
// } else {
487-
// w = 2 * util.sigmoid(loopout.loopout_length) * geometry.base_width_svg;
488-
// h = 5 * util.sigmoid(loopout.loopout_length - 3) * geometry.base_height_svg;
489-
// }
490-
//
491-
// var y_offset_bot = bot_svg.y;
492-
// var y_offset_top = top_svg.y;
493-
// var x_offset_bot = bot_svg.x;
494-
// var x_offset_top = top_svg.x;
495-
// if (top_offset == top_domain.start) {
496-
// x_offset_top -= w;
497-
// } else {
498-
// x_offset_top += w;
499-
// }
500-
// if (bot_offset == bot_domain.start) {
501-
// x_offset_bot -= w;
502-
// } else {
503-
// x_offset_bot += w;
504-
// }
505-
// y_offset_top += h;
506-
// y_offset_bot -= h;
507-
//
508-
// var c_bot = Point<num>(x_offset_bot, y_offset_bot);
509-
// var c_top = Point<num>(x_offset_top, y_offset_top);
510-
//
511-
// var vector = bot_svg - top_svg;
512-
// num angle_radians_from_x_axis = -atan2(vector.y, vector.x);
513-
// num angle_degrees_from_x_axis = util.to_degrees(angle_radians_from_x_axis);
514-
// num angle_degrees_from_y_axis = 90 - angle_degrees_from_x_axis;
515-
// var c_bot_rot = util.rotate(c_bot, angle_degrees_from_y_axis, origin: prev_svg);
516-
// var c_top_rot = util.rotate(c_top, angle_degrees_from_y_axis, origin: next_svg);
517-
// print('top offset = ${top_offset}');
518-
// print(' angle = ${angle_degrees_from_y_axis}');
519-
//
520-
// var path = (include_start_M ? 'M ${prev_svg.x} ${prev_svg.y} ' : '') +
521-
// 'C ${c_bot_rot.x} ${c_bot_rot.y} ${c_top_rot.x} ${c_top_rot.y} '
522-
// '${next_svg.x} ${next_svg.y}';
523-
//
524-
// return path;
525-
// }
526-
527-
Future<int> ask_for_length(String title, {int current_length, int lower_bound}) async {
528-
// https://pub.dev/documentation/smart_dialogs/latest/smart_dialogs/Info/get.html
529-
String buttontype = DiaAttr.CHECKBOX;
530-
String htmlTitleText = title;
531-
List<String> textLabels = ['new length:'];
532-
List<List<String>> comboInfo = null;
533-
List<String> defaultInputTexts = ['${current_length}'];
534-
List<int> widths = [1];
535-
List<String> isChecked = null;
536-
bool alternateRowColor = false;
537-
List<String> buttonLabels = ['OK', 'Cancel'];
538-
539-
UserInput result = await Info.get(buttontype, htmlTitleText, textLabels, comboInfo, defaultInputTexts,
540-
widths, isChecked, alternateRowColor, buttonLabels);
541-
542-
if (result.buttonCode != 'DIA_ACT_OK') {
543-
return null;
544-
}
545-
546-
String length_str = result.getUserInput(0)[0];
547-
int length = int.tryParse(length_str);
548-
if (length == null) {
549-
Info.show('"$length_str" is not a valid integer');
550-
return null;
551-
} else if (length < lower_bound) {
552-
Info.show('length must be at least ${lower_bound}, but it is $length_str');
553-
return null;
438+
Future<int> ask_for_length(String title,
439+
{int current_length, int lower_bound, DialogType dialog_type, String tooltip = ""}) async {
440+
int length_idx = 0;
441+
var items = List<DialogItem>.filled(1, null);
442+
items[length_idx] = DialogInteger(
443+
label: 'new length:',
444+
value: current_length,
445+
tooltip: tooltip,
446+
);
447+
var dialog = Dialog(
448+
title: title,
449+
type: dialog_type,
450+
items: items,
451+
use_saved_response: false,
452+
);
453+
454+
List<DialogItem> results = await util.dialog(dialog);
455+
if (results == null) return current_length;
456+
457+
int length = (results[length_idx] as DialogInteger).value;
458+
if (length < lower_bound) {
459+
window.alert('length must be at least ${lower_bound}, but you entered $length');
460+
return current_length;
554461
}
555462

556463
return length;

pubspec.lock

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,6 @@ packages:
540540
url: "https://pub.dartlang.org"
541541
source: hosted
542542
version: "0.2.4+1"
543-
smart_dialogs:
544-
dependency: "direct main"
545-
description:
546-
name: smart_dialogs
547-
url: "https://pub.dartlang.org"
548-
source: hosted
549-
version: "2.1.2"
550543
source_gen:
551544
dependency: transitive
552545
description:

pubspec.yaml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ environment:
88

99
dependencies:
1010
analyzer: '>=0.39.0 <0.42.0'
11-
# analyzer: '^1.0.0'
1211
spreadsheet_decoder: ^2.0.0
13-
# spreadsheet_decoder: ^2.0.0
14-
smart_dialogs: ^2.1.2
1512
dialog: ^0.8.0
1613
meta: ^1.1.7
1714
js: ^0.6.1+1
@@ -23,16 +20,11 @@ dependencies:
2320
path: ^1.6.4
2421
platform_detect: ^1.0.0
2522
dnd: ^2.0.1
26-
# dnd: ^2.0.0
27-
# redux_thunk: ^0.2.1
2823
built_value: ^8.1.3
2924
built_collection: ^5.1.1
3025
reselect: ^0.4.0
3126
redux: ^4.0.0
32-
# redux: ^5.0.0
33-
# react: ^5.1.0
3427
react: ^6.0.0
35-
# over_react: ^3.11.0
3628
over_react: ^4.0.0
3729
http: ^0.12.2
3830

@@ -48,25 +40,3 @@ dev_dependencies:
4840
analyzer:
4941
plugins:
5042
- over_react
51-
52-
# Fix analyzer issue: https://github.com/flutter/flutter/issues/62240
53-
# dependency_overrides:
54-
# analyzer: '0.39.14'
55-
56-
#dependency_overrides:
57-
# built_value:
58-
# path: ../built_value.dart/built_value
59-
# built_collection:
60-
# path: ../built_collection.dart
61-
# built_value_generator:
62-
# path: ../built_value.dart/built_value_generator/
63-
# react:
64-
# git:
65-
# url: https://github.com/cleandart/react-dart
66-
# ref: 5.1.0-wip
67-
# over_react:
68-
# git:
69-
# url: https://github.com/Workiva/over_react
70-
# ref: master
71-
# ref: 4d6bab5b30c3354d34260ef0c9250209f5da3764
72-

0 commit comments

Comments
 (0)