| 873 | } |
| 874 | |
| 875 | void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { |
| 876 | int selected = p_idx; |
| 877 | if (selected < 0 || selected >= tab_container->get_tab_count()) { |
| 878 | return; |
| 879 | } |
| 880 | |
| 881 | Node *tselected = tab_container->get_tab_control(selected); |
| 882 | |
| 883 | ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tselected); |
| 884 | if (current) { |
| 885 | Ref<Resource> file = current->get_edited_resource(); |
| 886 | if (p_save && file.is_valid()) { |
| 887 | // Do not try to save internal scripts, but prompt to save in-memory |
| 888 | // scripts which are not saved to disk yet (have empty path). |
| 889 | if (!file->is_built_in()) { |
| 890 | save_current_script(); |
| 891 | } |
| 892 | } |
| 893 | if (file.is_valid()) { |
| 894 | if (!file->get_path().is_empty()) { |
| 895 | // Only saved scripts can be restored. |
| 896 | previous_scripts.push_back(file->get_path()); |
| 897 | } |
| 898 | |
| 899 | Ref<Script> scr = file; |
| 900 | if (scr.is_valid()) { |
| 901 | notify_script_close(scr); |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | // roll back to previous tab |
| 907 | if (p_history_back) { |
| 908 | _history_back(); |
| 909 | } |
| 910 | |
| 911 | //remove from history |
| 912 | history.resize(history_pos + 1); |
| 913 | |
| 914 | for (int i = 0; i < history.size(); i++) { |
| 915 | if (history[i].control == tselected) { |
| 916 | history.remove_at(i); |
| 917 | i--; |
| 918 | history_pos--; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | if (history_pos >= history.size()) { |
| 923 | history_pos = history.size() - 1; |
| 924 | } |
| 925 | |
| 926 | int idx = tab_container->get_current_tab(); |
| 927 | if (current) { |
| 928 | current->clear_edit_menu(); |
| 929 | _save_editor_state(current); |
| 930 | } |
| 931 | memdelete(tselected); |
| 932 |
nothing calls this directly
no test coverage detected