Skip to content

Commit

Permalink
Merge pull request #981 from UC-Davis-molecular-computing/980-remove-…
Browse files Browse the repository at this point in the history
…smartdialog

closes #980: remove smart_dialog package dependency
  • Loading branch information
dave-doty authored Sep 6, 2024
2 parents 740d359 + 132f191 commit b876256
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 186 deletions.
3 changes: 3 additions & 0 deletions lib/src/state/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion lib/src/view/design_main_strand_crossover.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
46 changes: 18 additions & 28 deletions lib/src/view/design_main_strand_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -307,33 +306,24 @@ tooltip_text(Extension ext) =>
(ext.label == null ? "" : "\n label=${ext.label.toString()}");

Future<int> 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<String> textLabels = ['new number of bases:'];
List<List<String>> comboInfo = null;
List<String> defaultInputTexts = ['${current_num_bases}'];
List<int> widths = [1];
List<String> isChecked = null;
bool alternateRowColor = false;
List<String> 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<DialogItem>.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<DialogItem> 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;
}
14 changes: 12 additions & 2 deletions lib/src/view/design_main_strand_insertion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -240,8 +241,17 @@ class DesignMainStrandInsertionComponent extends UiComponent2<DesignMainStrandIn

change_insertion_length() async {
int new_length = await ask_for_length('change insertion length',
current_length: props.insertion.length, lower_bound: 1);
if (new_length == null || new_length == props.insertion.length) {
current_length: props.insertion.length,
lower_bound: 1,
dialog_type: DialogType.set_insertion_length,
tooltip: """\
Changes the insertion length.
Keep in mind that the insertion length is the number of *extra* bases.
So for example an insertion length of 1 would represent at that offset
2 total bases: the original base and the 1 extra base from the insertion.
""");
if (new_length == props.insertion.length) {
return;
}

Expand Down
143 changes: 25 additions & 118 deletions lib/src/view/design_main_strand_loopout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:built_collection/built_collection.dart';
import 'package:color/color.dart';
import 'package:over_react/over_react.dart';
import 'package:scadnano/src/state/dialog.dart';
import 'package:smart_dialogs/smart_dialogs.dart';

import 'transform_by_helix_group.dart';
import '../state/geometry.dart';
Expand Down Expand Up @@ -216,7 +215,8 @@ class DesignMainLoopoutComponent extends UiStatefulComponent2<DesignMainLoopoutP
int new_length = await app.disable_keyboard_shortcuts_while(() => 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;
}
Expand Down Expand Up @@ -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<num>(x_offset_bot, y_offset_bot);
// var c_top = Point<num>(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<int> 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<String> textLabels = ['new length:'];
List<List<String>> comboInfo = null;
List<String> defaultInputTexts = ['${current_length}'];
List<int> widths = [1];
List<String> isChecked = null;
bool alternateRowColor = false;
List<String> 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<int> ask_for_length(String title,
{int current_length, int lower_bound, DialogType dialog_type, String tooltip = ""}) async {
int length_idx = 0;
var items = List<DialogItem>.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<DialogItem> 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;
Expand Down
7 changes: 0 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 0 additions & 30 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

0 comments on commit b876256

Please sign in to comment.