diff options
Diffstat (limited to 'editor/plugins/script_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 316c76e4b2..fc11f561c7 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -965,7 +965,33 @@ void ScriptEditor::_menu_option(int p_option) { current->reload(p_option == FILE_TOOL_RELOAD_SOFT); } break; + case FILE_RUN: { + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) { + EditorNode::get_singleton()->show_warning("Can't obtain the script for running"); + break; + } + if (!scr->is_tool()) { + + EditorNode::get_singleton()->show_warning("Script is not in tool mode, will not be able to run"); + return; + } + + if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) { + + EditorNode::get_singleton()->show_warning("To run this script, it must inherit EditorScript and be set to tool mode"); + return; + } + + Ref<EditorScript> es = memnew(EditorScript); + es->set_script(scr.get_ref_ptr()); + es->set_editor(EditorNode::get_singleton()); + + es->_run(); + + EditorNode::get_undo_redo()->clear_history(); + } break; case FILE_CLOSE: { if (current->is_unsaved()) { _ask_close_current_unsaved_tab(current); @@ -2134,8 +2160,8 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("get_current_script"), &ScriptEditor::_get_current_script); ClassDB::bind_method(D_METHOD("get_open_scripts"), &ScriptEditor::_get_open_scripts); - ADD_SIGNAL(MethodInfo("editor_script_changed", PropertyInfo(Variant::OBJECT, "script:Script"))); - ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script:Script"))); + ADD_SIGNAL(MethodInfo("editor_script_changed", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script"))); + ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script"))); } ScriptEditor::ScriptEditor(EditorNode *p_editor) { @@ -2220,6 +2246,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL); file_menu->get_popup()->add_separator(); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/run_file", TTR("Run"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_X), FILE_RUN); + file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/toggle_scripts_panel", TTR("Toggle Scripts Panel"), KEY_MASK_CMD | KEY_BACKSLASH), TOGGLE_SCRIPTS_PANEL); file_menu->get_popup()->connect("id_pressed", this, "_menu_option"); |