MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _close_tab

Method _close_tab

editor/script/script_editor_plugin.cpp:875–952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

873}
874
875void 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

Callers

nothing calls this directly

Calls 15

memdeleteFunction · 0.85
get_tab_controlMethod · 0.80
is_built_inMethod · 0.80
sizeMethod · 0.65
get_tab_countMethod · 0.45
get_edited_resourceMethod · 0.45
is_validMethod · 0.45
is_emptyMethod · 0.45
get_pathMethod · 0.45
push_backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected