Skip to content

Commit

Permalink
fixes #953
Browse files Browse the repository at this point in the history
  • Loading branch information
rayzhuca committed Oct 24, 2023
1 parent e487457 commit abcecd2
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions lib/src/view/design_main_strand.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,13 @@ class DesignMainStrandComponent extends UiComponent2<DesignMainStrandProps>
set_strand_label() => app.disable_keyboard_shortcuts_while(
() => ask_for_label(props.strand, null, app.state.ui_state.selectables_store.selected_strands));

set_substrand_name(Substrand substrand) =>
app.disable_keyboard_shortcuts_while(() => ask_for_substrand_name(substrand));
set_domain_names(BuiltSet<Domain> domains) =>
app.disable_keyboard_shortcuts_while(() => ask_for_domain_names(domains));

set_substrand_label(Substrand substrand) => app.disable_keyboard_shortcuts_while(
() => ask_for_label(props.strand, substrand, app.state.ui_state.selectables_store.selected_substrands));
set_domain_labels(Substrand substrand, BuiltSet<Domain> domains) {
return app.disable_keyboard_shortcuts_while(
() => ask_for_label(props.strand, substrand, get_selected_domains()));
}

ReactElement _insertions() {
List<ReactElement> paths = [];
Expand Down Expand Up @@ -482,7 +484,7 @@ assigned, assign the complementary DNA sequence to this strand.
'remove strand label'))),
ContextMenuItem(
title: 'set domain name',
on_click: () => set_substrand_name(substrand),
on_click: () => set_domain_names(get_selected_domains()),
),
ContextMenuItem(
title: 'assign domain name complement from bound strands',
Expand All @@ -496,7 +498,9 @@ feature for individual domains, set select mode to domain.
if (substrand.name != null)
ContextMenuItem(
title: 'remove domain name',
on_click: () => app.dispatch(actions.SubstrandNameSet(name: null, substrand: substrand))),
on_click: () => app.dispatch(actions.BatchAction(
get_selected_domains().map((d) => actions.SubstrandNameSet(name: null, substrand: d)),
'remove domain names'))),
].build()),
ContextMenuItem(
title: 'edit label',
Expand All @@ -515,12 +519,14 @@ feature for individual domains, set select mode to domain.
'remove strand label'))),
ContextMenuItem(
title: 'set domain label',
on_click: () => set_substrand_label(substrand),
on_click: () => set_domain_labels(substrand, get_selected_domains()),
),
if (substrand.label != null)
ContextMenuItem(
title: 'remove domain label',
on_click: () => app.dispatch(actions.SubstrandLabelSet(label: null, substrand: substrand))),
on_click: () => app.dispatch(actions.BatchAction(
get_selected_domains().map((d) => actions.SubstrandLabelSet(label: null, substrand: d)),
'remove domain labels'))),
].build()),
ContextMenuItem(
title: 'reflect',
Expand Down Expand Up @@ -926,13 +932,12 @@ PAGEHPLC : Dual PAGE & HPLC
app.dispatch(action);
}

Future<void> ask_for_substrand_name(Substrand substrand) async {
Future<void> ask_for_domain_names(BuiltSet<Domain> domains) async {
int name_idx = 0;
var items = List<DialogItem>.filled(1, null);

items[name_idx] = DialogText(label: 'name', value: substrand.name ?? '');
items[name_idx] = DialogText(label: 'name', value: "");
var dialog = Dialog(
title: 'set ${substrand.type_description()} name',
title: 'set ${domains.first.type_description()} name',
items: items,
type: DialogType.set_domain_name,
use_saved_response: false);
Expand All @@ -941,12 +946,14 @@ PAGEHPLC : Dual PAGE & HPLC
if (results == null) return;

String name = (results[name_idx] as DialogText).value;
actions.UndoableAction action = actions.SubstrandNameSet(name: name, substrand: substrand);
app.dispatch(action);
return app.dispatch(actions.BatchAction(
domains.map((d) => actions.SubstrandNameSet(name: name, substrand: d)), "set domain names"));
}
}

Future<void> ask_for_label(Strand strand, Substrand substrand, BuiltSet<Strand> selected_strands) async {
Future<void> ask_for_label<T extends SelectableMixin>(
Strand strand, Substrand substrand, BuiltSet<T> selected_strands) async {
// T is expected to be Strand or Domain
String part_name = 'strand';
if (substrand != null) {
part_name = substrand.type_description();
Expand Down Expand Up @@ -982,12 +989,12 @@ Future<void> ask_for_label(Strand strand, Substrand substrand, BuiltSet<Strand>

actions.UndoableAction action;
if (substrand == null) {
action = batch_if_multiple_selected(
label_set_strand_action_creator(label), strand, selected_strands, "set strand label");
action = batch_if_multiple_selected(label_set_strand_action_creator(label), strand,
selected_strands as BuiltSet<Strand>, "set strand label");
} else {
action = actions.SubstrandLabelSet(label: label, substrand: substrand);
// action = batch_if_multiple_selected(
// label_set_strand_action_creator(label), props.strand, selected_strands, "set domain label");
action = actions.BatchAction(
selected_strands.map((s) => actions.SubstrandLabelSet(label: label, substrand: (s as Substrand))),
"set domain labels");
}

app.dispatch(action);
Expand All @@ -1010,6 +1017,16 @@ actions.UndoableAction batch_if_multiple_selected(StrandActionCreator action_cre
return action;
}

// this is so if user selects with the domain select tool, it still returns the selected domains
// as opposed to just using "selected_strands"
BuiltSet<Domain> get_selected_domains() {
return BuiltSet<Domain>(app.state.ui_state.selectables_store.selected_strands
.map((s) => s.substrands)
.expand((l) => l)
.toBuiltSet())
.union(app.state.ui_state.selectables_store.selected_domains);
}

typedef StrandActionCreator = actions.UndoableAction Function(Strand strand);

StrandActionCreator scaffold_set_strand_action_creator(bool is_scaffold) =>
Expand Down

0 comments on commit abcecd2

Please sign in to comment.