| 3013 | } |
| 3014 | |
| 3015 | void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const PackedStringArray &p_args) { |
| 3016 | ERR_FAIL_NULL(p_obj); |
| 3017 | Ref<Script> scr = p_obj->get_script(); |
| 3018 | ERR_FAIL_COND(scr.is_null()); |
| 3019 | |
| 3020 | if (!scr->get_language()->can_make_function()) { |
| 3021 | return; |
| 3022 | } |
| 3023 | |
| 3024 | EditorNode::get_singleton()->push_item(scr.ptr()); |
| 3025 | |
| 3026 | for (int i = 0; i < tab_container->get_tab_count(); i++) { |
| 3027 | ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i)); |
| 3028 | if (!se) { |
| 3029 | continue; |
| 3030 | } |
| 3031 | if (se->get_edited_resource() != scr) { |
| 3032 | continue; |
| 3033 | } |
| 3034 | |
| 3035 | se->add_callback(p_function, p_args); |
| 3036 | |
| 3037 | _go_to_tab(i); |
| 3038 | |
| 3039 | script_list->select(script_list->find_metadata(i)); |
| 3040 | |
| 3041 | // Save the current script so the changes can be picked up by an external editor. |
| 3042 | if (!scr.ptr()->is_built_in()) { // But only if it's not built-in script. |
| 3043 | save_current_script(); |
| 3044 | } |
| 3045 | |
| 3046 | break; |
| 3047 | } |
| 3048 | |
| 3049 | // Move back to the previously edited node to reselect it in the Inspector and the NodeDock. |
| 3050 | // We assume that the previous item is the node on which the callbacks were added. |
| 3051 | EditorNode::get_singleton()->edit_previous_item(); |
| 3052 | } |
| 3053 | |
| 3054 | void ScriptEditor::_save_editor_state(ScriptEditorBase *p_editor) { |
| 3055 | if (restoring_layout) { |
nothing calls this directly
no test coverage detected