diff --git a/lib/src/view/design_main_strand.dart b/lib/src/view/design_main_strand.dart index 8730b0a2..ea373ce5 100644 --- a/lib/src/view/design_main_strand.dart +++ b/lib/src/view/design_main_strand.dart @@ -279,11 +279,13 @@ class DesignMainStrandComponent extends UiComponent2 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 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 domains) { + return app.disable_keyboard_shortcuts_while( + () => ask_for_label(props.strand, substrand, get_selected_domains())); + } ReactElement _insertions() { List paths = []; @@ -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', @@ -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', @@ -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', @@ -926,13 +932,12 @@ PAGEHPLC : Dual PAGE & HPLC app.dispatch(action); } - Future ask_for_substrand_name(Substrand substrand) async { + Future ask_for_domain_names(BuiltSet domains) async { int name_idx = 0; var items = List.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); @@ -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 ask_for_label(Strand strand, Substrand substrand, BuiltSet selected_strands) async { +Future ask_for_label( + Strand strand, Substrand substrand, BuiltSet selected_strands) async { + // T is expected to be Strand or Domain String part_name = 'strand'; if (substrand != null) { part_name = substrand.type_description(); @@ -982,12 +989,12 @@ Future ask_for_label(Strand strand, Substrand substrand, BuiltSet 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, "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); @@ -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 get_selected_domains() { + return BuiltSet(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) =>