@@ -139,6 +139,11 @@ void sexp_tree_view::ui_add_children_visual(int parent_node_index)
139139 }
140140}
141141
142+ void sexp_tree_view::ui_move_branch (int source_node, int parent_node)
143+ {
144+ move_branch (source_node, parent_node);
145+ }
146+
142147void sexp_tree_view::ui_expand_branch (void * handle)
143148{
144149 expand_branch ((HTREEITEM )handle);
@@ -752,9 +757,7 @@ void sexp_tree_view::end_operator_edit(bool confirm)
752757// now it also handles messages from the operator combo box
753758BOOL sexp_tree_view::OnCommand (WPARAM wParam, LPARAM lParam)
754759{
755- int i, z, id, data, node, op;
756- sexp_list_item *list, *ptr;
757- HTREEITEM h;
760+ int id, data, node, op;
758761
759762 if ((item_index >= 0 ) && (item_index < total_nodes) && !tree_nodes.empty ())
760763 item_handle = tree_item_handle (tree_nodes[item_index]);
@@ -946,38 +949,11 @@ BOOL sexp_tree_view::OnCommand(WPARAM wParam, LPARAM lParam)
946949 // check if REPLACE_VARIABLE_MENU
947950 if ( (id >= ID_VARIABLE_MENU ) && (id < ID_VARIABLE_MENU + 511 )) {
948951
949- Assertion (item_index >= 0 , " Invalid item index" );
950-
951- // get index into list of type valid variables
952952 int var_idx = id - ID_VARIABLE_MENU ;
953- Assertion ( (var_idx >= 0 ) && (var_idx < MAX_SEXP_VARIABLES ), " Invalid variable index" );
954-
955- int type = get_type (item_handle);
956- Assertion ( (type & SEXPT_NUMBER ) || (type & SEXPT_STRING ), " Invalid variable type" );
957-
958- // don't do type check for modify-variable or OPF_CONTAINER_VALUE (can be either type)
959- if (m_modify_variable || _model.query_node_argument_type (item_index) == OPF_CONTAINER_VALUE ) {
960- if (Sexp_variables[var_idx].type & SEXP_VARIABLE_NUMBER ) {
961- type = SEXPT_NUMBER ;
962- } else if (Sexp_variables[var_idx].type & SEXP_VARIABLE_STRING ) {
963- type = SEXPT_STRING ;
964- } else {
965- Int3 (); // unknown type
966- }
967-
968- } else {
969- // verify type in tree is same as type in Sexp_variables array
970- if (type & SEXPT_NUMBER ) {
971- Assertion (Sexp_variables[var_idx].type & SEXP_VARIABLE_NUMBER , " Invalid variable type" );
972- }
973-
974- if (type & SEXPT_STRING ) {
975- Assertion ((Sexp_variables[var_idx].type & SEXP_VARIABLE_STRING ), " Invalid variable type" );
976- }
977- }
978-
979- // Replace data
980- _actions.replace_variable_data (var_idx, (type | SEXPT_VARIABLE ));
953+ const int type = get_type (item_handle);
954+ const bool allow_type_coercion =
955+ (m_modify_variable != 0 ) || (_model.query_node_argument_type (item_index) == OPF_CONTAINER_VALUE );
956+ _actions.replace_variable_with_type_validation (var_idx, type, allow_type_coercion);
981957
982958 return 1 ;
983959 }
@@ -988,30 +964,12 @@ BOOL sexp_tree_view::OnCommand(WPARAM wParam, LPARAM lParam)
988964 Assertion (item_index >= 0 , " Invalid item index" );
989965
990966 int type = 0 ;
991-
992- if (tree_nodes[item_index].type & SEXPT_CONTAINER_DATA ) {
993- list = _model._opf .get_container_multidim_modifiers (item_index);
994- } else {
967+ if (!(tree_nodes[item_index].type & SEXPT_CONTAINER_DATA )) {
995968 op = get_operator_index (tree_nodes[item_index].text );
996969 Assertion (op >= 0 , " Invalid operator index" );
997-
998970 type = query_operator_argument_type (op, m_add_count);
999- list = _model._opf .get_listing_opf (type, item_index, m_add_count);
1000- }
1001- Assertion (list, " Invalid listing" );
1002-
1003- id -= ID_ADD_MENU ;
1004- ptr = list;
1005- while (id) {
1006- id--;
1007- ptr = ptr->next ;
1008- Assertion (ptr, " Invalid list pointer" );
1009971 }
1010-
1011- Assertion ((SEXPT_TYPE (ptr->type ) != SEXPT_OPERATOR ) && (ptr->op < 0 ), " Invalid list type" );
1012- _actions.expand_operator (item_index);
1013- node = _actions.add_data (ptr->text .c_str (), ptr->type );
1014- list->destroy ();
972+ node = _actions.add_or_replace_typed_data (id - ID_ADD_MENU , false , m_add_count, m_replace_count);
1015973
1016974 // bolted-on ugly hack
1017975 if (type == OPF_VARIABLE_NAME ) {
@@ -1037,32 +995,7 @@ BOOL sexp_tree_view::OnCommand(WPARAM wParam, LPARAM lParam)
1037995 }
1038996
1039997 if ((id >= ID_REPLACE_MENU ) && (id < ID_REPLACE_MENU + 511 )) {
1040- Assertion (item_index >= 0 , " Invalid item index" );
1041- Assertion (tree_nodes[item_index].parent >= 0 , " Invalid parent index" );
1042-
1043- if (tree_nodes[item_index].type & SEXPT_MODIFIER ) {
1044- list = _model._opf .get_container_modifiers (tree_nodes[item_index].parent );
1045- } else {
1046- op = get_operator_index (tree_nodes[tree_nodes[item_index].parent ].text );
1047- Assertion (op >= 0 , " Invalid operator index" );
1048-
1049- auto type = query_operator_argument_type (op, m_replace_count); // check argument type at this position
1050- list = _model._opf .get_listing_opf (type, tree_nodes[item_index].parent , m_replace_count);
1051- }
1052- Assertion (list, " Invalid listing" );
1053-
1054- id -= ID_REPLACE_MENU ;
1055- ptr = list;
1056- while (id) {
1057- id--;
1058- ptr = ptr->next ;
1059- Assertion (ptr, " Invalid list pointer" );
1060- }
1061-
1062- Assertion ((SEXPT_TYPE (ptr->type ) != SEXPT_OPERATOR ) && (ptr->op < 0 ), " Invalid list type" );
1063- _actions.expand_operator (item_index);
1064- _actions.replace_data (ptr->text .c_str (), ptr->type );
1065- list->destroy ();
998+ _actions.add_or_replace_typed_data (id - ID_REPLACE_MENU , true , m_add_count, m_replace_count);
1066999 return 1 ;
10671000 }
10681001
@@ -1119,37 +1052,12 @@ BOOL sexp_tree_view::OnCommand(WPARAM wParam, LPARAM lParam)
11191052 }
11201053
11211054 if (id == (Operators[op].value | OP_INSERT_FLAG )) {
1122- int flags;
1123-
1124- z = tree_nodes[item_index].parent ;
1125- flags = tree_nodes[item_index].flags ;
1126- node = _model.allocate_node (z, item_index);
1127- _model.set_node (node, (SEXPT_OPERATOR | SEXPT_VALID ), Operators[op].text .c_str ());
1128- tree_nodes[node].flags = flags;
1129- if (z >= 0 )
1130- h = tree_item_handle (tree_nodes[z]);
1131-
1132- else {
1133- h = GetParentItem (tree_item_handle (tree_nodes[item_index]));
1134- if (_model._interface && _model._interface ->getFlags ()[TreeFlags::LabeledRoot]) {
1135- _model._interface ->onRootInserted (item_index, node);
1136- SetItemData (h, node);
1137- } else {
1138- h = TVI_ROOT ;
1139- root_item = node;
1140- }
1055+ HTREEITEM root_parent = GetParentItem (tree_item_handle (tree_nodes[item_index]));
1056+ node = _actions.insert_operator (op, root_parent);
1057+ if (_model._interface && _model._interface ->getFlags ()[TreeFlags::LabeledRoot] && root_parent) {
1058+ SetItemData (root_parent, node);
11411059 }
1142-
1143- tree_nodes[node].handle = insert (Operators[op].text .c_str (), BITMAP_OPERATOR , BITMAP_OPERATOR , h, tree_item_handle (tree_nodes[item_index]));
1144- item_handle = tree_item_handle (tree_nodes[node]);
1145- move_branch (item_index, node);
1146-
11471060 item_index = node;
1148- for (i=1 ; i<Operators[op].min ; i++)
1149- _actions.add_default_operator (op, i);
1150-
1151- Expand (item_handle, TVE_EXPAND );
1152- *modified = 1 ;
11531061 return 1 ;
11541062 }
11551063 }
@@ -1939,4 +1847,3 @@ void sexp_tree_view::OnKeyDown(NMHDR *pNMHDR, LRESULT *pResult)
19391847
19401848 *pResult = 0 ;
19411849}
1942-
0 commit comments