From 0b806ee0fc9097fa7bda7ac0109191c9c5e0a1ac Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 9 Feb 2014 22:10:30 -0300 Subject: GODOT IS OPEN SOURCE --- tools/editor/plugins/script_editor_plugin.cpp | 1519 +++++++++++++++++++++++++ 1 file changed, 1519 insertions(+) create mode 100644 tools/editor/plugins/script_editor_plugin.cpp (limited to 'tools/editor/plugins/script_editor_plugin.cpp') diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp new file mode 100644 index 000000000..1a1791639 --- /dev/null +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -0,0 +1,1519 @@ +/*************************************************************************/ +/* script_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "script_editor_plugin.h" +#include "tools/editor/editor_settings.h" +#include "io/resource_loader.h" +#include "io/resource_saver.h" +#include "os/keyboard.h" +#include "os/os.h" +#include "tools/editor/editor_node.h" +#include "tools/editor/script_editor_debugger.h" +#include "globals.h" +#include "os/file_access.h" +#include "scene/main/viewport.h" +#include "os/keyboard.h" +/*** SCRIPT EDITOR ****/ + + + + +void ScriptEditorQuickOpen::popup(const Vector& p_functions, bool p_dontclear) { + + popup_centered_ratio(0.6); + if (p_dontclear) + search_box->select_all(); + else + search_box->clear(); + search_box->grab_focus(); + functions=p_functions; + _update_search(); + + +} + + +void ScriptEditorQuickOpen::_text_changed(const String& p_newtext) { + + _update_search(); +} + +void ScriptEditorQuickOpen::_sbox_input(const InputEvent& p_ie) { + + if (p_ie.type==InputEvent::KEY && ( + p_ie.key.scancode == KEY_UP || + p_ie.key.scancode == KEY_DOWN || + p_ie.key.scancode == KEY_PAGEUP || + p_ie.key.scancode == KEY_PAGEDOWN ) ) { + + search_options->call("_input_event",p_ie); + search_box->accept_event(); + } + +} + + + +void ScriptEditorQuickOpen::_update_search() { + + + search_options->clear(); + TreeItem *root = search_options->create_item(); + + for(int i=0;iget_text()=="" || file.findn(search_box->get_text())!=-1)) { + + TreeItem *ti = search_options->create_item(root); + ti->set_text(0,file); + if (root->get_children()==ti) + ti->select(0); + + } + } + + get_ok()->set_disabled(root->get_children()==NULL); + +} + +void ScriptEditorQuickOpen::_confirmed() { + + TreeItem *ti = search_options->get_selected(); + if (!ti) + return; + int line = ti->get_text(0).get_slice(":",1).to_int(); + + emit_signal("goto_line",line-1); + hide(); +} + +void ScriptEditorQuickOpen::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_SCENE) { + + connect("confirmed",this,"_confirmed"); + } +} + + + + +void ScriptEditorQuickOpen::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_text_changed"),&ScriptEditorQuickOpen::_text_changed); + ObjectTypeDB::bind_method(_MD("_confirmed"),&ScriptEditorQuickOpen::_confirmed); + ObjectTypeDB::bind_method(_MD("_sbox_input"),&ScriptEditorQuickOpen::_sbox_input); + + ADD_SIGNAL(MethodInfo("goto_line",PropertyInfo(Variant::INT,"line"))); + +} + + +ScriptEditorQuickOpen::ScriptEditorQuickOpen() { + + + VBoxContainer *vbc = memnew( VBoxContainer ); + add_child(vbc); + set_child_rect(vbc); + search_box = memnew( LineEdit ); + vbc->add_margin_child("Search:",search_box); + search_box->connect("text_changed",this,"_text_changed"); + search_box->connect("input_event",this,"_sbox_input"); + search_options = memnew( Tree ); + vbc->add_margin_child("Matches:",search_options,true); + get_ok()->set_text("Open"); + get_ok()->set_disabled(true); + register_text_enter(search_box); + set_hide_on_ok(false); + search_options->connect("item_activated",this,"_confirmed"); + search_options->set_hide_root(true); +} + + +///////////////////////////////// + +ScriptEditor *ScriptEditor::script_editor=NULL; + +Vector ScriptTextEditor::get_functions() { + + + String errortxt; + int line=-1,col; + TextEdit *te=get_text_edit(); + String text = te->get_text(); + List fnc; + + if (script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) { + + //if valid rewrite functions to latest + functions.clear(); + for (List::Element *E=fnc.front();E;E=E->next()) { + + functions.push_back(E->get()); + } + + + } + + return functions; +} + +void ScriptTextEditor::apply_code() { + + if (script.is_null()) + return; + script->set_source_code(get_text_edit()->get_text()); +} + +Ref