summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-07-19 09:54:02 +0200
committerGitHub <noreply@github.com>2017-07-19 09:54:02 +0200
commitd4c73ea2b379835e75e02b78073547960cf03a74 (patch)
tree1496863e3d9a7d9e0e6bf7a0683a9b49695a9f92 /editor/plugins
parent9cf72d0ae174badab07b1461f576955725375046 (diff)
parent708d8250011dad02fd7d3651eb057bdd9e52fb7f (diff)
Merge pull request #9565 from kubecz3k/tool-signals
Make more informations available for Tool Plugins about the editor
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/script_editor_plugin.cpp61
-rw-r--r--editor/plugins/script_editor_plugin.h7
2 files changed, 67 insertions, 1 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index d10831eea1..f7952e77f2 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -405,6 +405,8 @@ void ScriptEditor::_go_to_tab(int p_idx) {
script_icon->set_texture(c->cast_to<ScriptEditorBase>()->get_icon());
if (is_visible_in_tree())
c->cast_to<ScriptEditorBase>()->ensure_focus();
+
+ notify_script_changed(c->cast_to<ScriptEditorBase>()->get_edited_script());
}
if (c->cast_to<EditorHelp>()) {
@@ -510,7 +512,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) {
apply_scripts();
}
current->clear_edit_menu();
-
+ notify_script_close(current->get_edited_script());
} else {
EditorHelp *help = tab_container->get_child(selected)->cast_to<EditorHelp>();
_add_recent_script(help->get_class());
@@ -777,6 +779,31 @@ void ScriptEditor::_file_dialog_action(String p_file) {
file_dialog_option = -1;
}
+Ref<Script> ScriptEditor::_get_current_script() {
+
+ int selected = tab_container->get_current_tab();
+ if (selected < 0 || selected >= tab_container->get_child_count())
+ return NULL;
+
+ ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>();
+ if (current) {
+ return current->get_edited_script();
+ } else {
+ return NULL;
+ }
+}
+
+Array ScriptEditor::_get_opened_script_list() const {
+
+ Array ret;
+ Vector<Ref<Script> > scripts = get_opened_scripts();
+ int scrits_amount = scripts.size();
+ for (int idx_script = 0; idx_script < scrits_amount; idx_script++) {
+ ret.push_back(scripts[idx_script]);
+ }
+ return ret;
+}
+
void ScriptEditor::_menu_option(int p_option) {
switch (p_option) {
@@ -1127,6 +1154,14 @@ void ScriptEditor::edited_scene_changed() {
_update_modified_scripts_for_external_editor();
}
+void ScriptEditor::notify_script_close(const Ref<Script> &p_script) {
+ emit_signal("script_close", p_script);
+}
+
+void ScriptEditor::notify_script_changed(const Ref<Script> &p_script) {
+ emit_signal("script_changed", p_script);
+}
+
static const Node *_find_node_with_script(const Node *p_node, const RefPtr &p_script) {
if (p_node->get_script() == p_script)
@@ -1662,6 +1697,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
if (p_line >= 0)
se->goto_line(p_line - 1);
+ notify_script_changed(p_script);
return true;
}
@@ -2038,6 +2074,8 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
n->cast_to<ScriptEditorBase>()->set_edit_state(history[history_pos].state);
n->cast_to<ScriptEditorBase>()->ensure_focus();
+
+ notify_script_changed(n->cast_to<ScriptEditorBase>()->get_edited_script());
}
if (n->cast_to<EditorHelp>()) {
@@ -2065,6 +2103,21 @@ void ScriptEditor::_history_back() {
_update_history_pos(history_pos - 1);
}
}
+
+Vector<Ref<Script> > ScriptEditor::get_opened_scripts() const {
+
+ Vector<Ref<Script> > out_scripts = Vector<Ref<Script> >();
+
+ for (int i = 0; i < tab_container->get_child_count(); i++) {
+ ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ if (!se)
+ continue;
+ out_scripts.push_back(se->get_edited_script());
+ }
+
+ return out_scripts;
+}
+
void ScriptEditor::set_scene_root_script(Ref<Script> p_script) {
bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change");
@@ -2158,6 +2211,12 @@ void ScriptEditor::_bind_methods() {
ClassDB::bind_method("_history_back", &ScriptEditor::_history_back);
ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts);
ClassDB::bind_method("_unhandled_input", &ScriptEditor::_unhandled_input);
+
+ ClassDB::bind_method(D_METHOD("get_current_script"), &ScriptEditor::_get_current_script);
+ ClassDB::bind_method(D_METHOD("get_opened_scripts_list"), &ScriptEditor::_get_opened_script_list);
+
+ ADD_SIGNAL(MethodInfo("script_changed", PropertyInfo(Variant::OBJECT, "script:Script")));
+ ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::STRING, "script:String")));
}
ScriptEditor::ScriptEditor(EditorNode *p_editor) {
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 010a5604ec..3d03eb0f49 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -321,6 +321,9 @@ class ScriptEditor : public PanelContainer {
int file_dialog_option;
void _file_dialog_action(String p_file);
+ Ref<Script> _get_current_script();
+ Array _get_opened_script_list() const;
+
static void _open_script_request(const String &p_path);
static ScriptEditor *script_editor;
@@ -354,11 +357,15 @@ public:
void get_window_layout(Ref<ConfigFile> p_layout);
void set_scene_root_script(Ref<Script> p_script);
+ Vector<Ref<Script> > get_opened_scripts() const;
bool script_goto_method(Ref<Script> p_script, const String &p_method);
virtual void edited_scene_changed();
+ void notify_script_close(const Ref<Script> &p_script);
+ void notify_script_changed(const Ref<Script> &p_script);
+
void close_builtin_scripts_from_scene(const String &p_scene);
void goto_help(const String &p_desc) { _help_class_goto(p_desc); }