summaryrefslogtreecommitdiff
path: root/tools/editor/plugins/script_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/editor/plugins/script_editor_plugin.cpp')
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp556
1 files changed, 397 insertions, 159 deletions
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp
index 72b3025f2f..3ef240e74c 100644
--- a/tools/editor/plugins/script_editor_plugin.cpp
+++ b/tools/editor/plugins/script_editor_plugin.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2015 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 */
@@ -38,10 +38,89 @@
#include "os/file_access.h"
#include "scene/main/viewport.h"
#include "os/keyboard.h"
+#include "os/input.h"
+
/*** SCRIPT EDITOR ****/
+class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache {
+
+
+ struct Cache {
+ uint64_t time_loaded;
+ RES cache;
+ };
+
+ Map<String,Cache> cached;
+
+
+public:
+
+ uint64_t max_time_cache;
+ int max_cache_size;
+
+ void cleanup() {
+
+ List< Map<String,Cache>::Element * > to_clean;
+
+
+ Map<String,Cache>::Element *I=cached.front();
+ while(I) {
+ if ((OS::get_singleton()->get_ticks_msec()-I->get().time_loaded)>max_time_cache) {
+ to_clean.push_back(I);
+ }
+ I=I->next();
+ }
+
+ while(to_clean.front()) {
+ cached.erase(to_clean.front()->get());
+ to_clean.pop_front();
+ }
+ }
+
+ RES get_cached_resource(const String& p_path) {
+
+ Map<String,Cache>::Element *E=cached.find(p_path);
+ if (!E) {
+
+ Cache c;
+ c.cache=ResourceLoader::load(p_path);
+ E=cached.insert(p_path,c);
+ }
+
+ E->get().time_loaded=OS::get_singleton()->get_ticks_msec();
+
+ if (cached.size()>max_cache_size) {
+ uint64_t older;
+ Map<String,Cache>::Element *O=cached.front();
+ older=O->get().time_loaded;
+ Map<String,Cache>::Element *I=O;
+ while(I) {
+ if (I->get().time_loaded<older) {
+ older = I->get().time_loaded;
+ O=I;
+ }
+ I=I->next();
+ }
+
+ if (O!=E) {//should never heppane..
+ cached.erase(O);
+ }
+ }
+
+ return E->get().cache;
+ }
+
+
+ EditorScriptCodeCompletionCache() {
+
+ max_cache_size=128;
+ max_time_cache=5*60*1000; //minutes, five
+ }
+};
+
+#define SORT_SCRIPT_LIST
void ScriptEditorQuickOpen::popup(const Vector<String>& p_functions, bool p_dontclear) {
@@ -118,6 +197,8 @@ void ScriptEditorQuickOpen::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) {
connect("confirmed",this,"_confirmed");
+
+
}
}
@@ -130,6 +211,7 @@ void ScriptEditorQuickOpen::_bind_methods() {
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")));
}
@@ -239,10 +321,10 @@ void ScriptTextEditor::_load_theme_settings() {
//colorize engine types
Color type_color= EDITOR_DEF("text_editor/engine_type_color",Color(0.0,0.2,0.4));
- List<String> types;
+ List<StringName> types;
ObjectTypeDB::get_type_list(&types);
- for(List<String>::Element *E=types.front();E;E=E->next()) {
+ for(List<StringName>::Element *E=types.front();E;E=E->next()) {
get_text_edit()->add_keyword_color(E->get(),type_color);
}
@@ -285,8 +367,19 @@ void ScriptTextEditor::reload_text() {
ERR_FAIL_COND(script.is_null()) ;
- get_text_edit()->set_text(script->get_source_code());
- get_text_edit()->clear_undo_history();
+ TextEdit *te = get_text_edit();
+ int column = te->cursor_get_column();
+ int row = te->cursor_get_line();
+ int h = te->get_h_scroll();
+ int v = te->get_v_scroll();
+
+ te->set_text(script->get_source_code());
+ te->clear_undo_history();
+ te->cursor_set_line(row);
+ te->cursor_set_column(column);
+ te->set_h_scroll(h);
+ te->set_v_scroll(v);
+
_line_col_changed();
}
@@ -295,12 +388,11 @@ void ScriptTextEditor::_notification(int p_what) {
if (p_what==NOTIFICATION_READY) {
- _update_name();
+ //emit_signal("name_changed");
}
}
-void ScriptTextEditor::_update_name() {
-
+String ScriptTextEditor::get_name() {
String name;
if (script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
@@ -313,21 +405,20 @@ void ScriptTextEditor::_update_name() {
else
name=script->get_type()+"("+itos(script->get_instance_ID())+")";
+ return name;
- if (name!=String(get_name())) {
+}
- set_name(name);
+Ref<Texture> ScriptTextEditor::get_icon() {
+ if (get_parent_control() && get_parent_control()->has_icon(script->get_type(),"EditorIcons")) {
+ return get_parent_control()->get_icon(script->get_type(),"EditorIcons");
}
- if (!has_meta("_tab_icon")) {
- if (get_parent_control() && get_parent_control()->has_icon(script->get_type(),"EditorIcons")) {
- set_meta("_tab_icon",get_parent_control()->get_icon(script->get_type(),"EditorIcons"));
- }
- }
+ return Ref<Texture>();
+}
-}
void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) {
@@ -343,8 +434,7 @@ void ScriptTextEditor::set_edited_script(const Ref<Script>& p_script) {
get_text_edit()->tag_saved_version();
- _update_name();
-
+ emit_signal("name_changed");
_line_col_changed();
}
@@ -383,7 +473,7 @@ void ScriptTextEditor::_validate_script() {
te->set_line_as_marked(i,line==i);
}
- _update_name();
+ emit_signal("name_changed");
}
@@ -417,6 +507,10 @@ void ScriptTextEditor::_code_complete_script(const String& p_code, List<String>*
}
}
+void ScriptTextEditor::_bind_methods() {
+
+ ADD_SIGNAL(MethodInfo("name_changed"));
+}
ScriptTextEditor::ScriptTextEditor() {
@@ -491,11 +585,15 @@ void ScriptEditor::_close_current_tab() {
memdelete(current);
if (idx>=tab_container->get_child_count())
idx=tab_container->get_child_count()-1;
- if (idx>=0)
+ if (idx>=0) {
tab_container->set_current_tab(idx);
+ //script_list->select(idx);
+ }
+
- _update_window_menu();
- _save_files_state();
+
+ _update_script_names();
+ EditorNode::get_singleton()->save_layout();
}
@@ -586,10 +684,10 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource>& p_res) {
ste->get_text_edit()->tag_saved_version();
}
- ste->_update_name();
-
}
+ _update_script_names();
+
}
bool ScriptEditor::_test_script_times_on_disk() {
@@ -705,25 +803,31 @@ void ScriptEditor::_menu_option(int p_option) {
} break;
case EDIT_UNDO: {
current->get_text_edit()->undo();
+ current->get_text_edit()->call_deferred("grab_focus");
} break;
case EDIT_REDO: {
current->get_text_edit()->redo();
+ current->get_text_edit()->call_deferred("grab_focus");
} break;
case EDIT_CUT: {
current->get_text_edit()->cut();
+ current->get_text_edit()->call_deferred("grab_focus");
} break;
case EDIT_COPY: {
current->get_text_edit()->copy();
+ current->get_text_edit()->call_deferred("grab_focus");
} break;
case EDIT_PASTE: {
current->get_text_edit()->paste();
+ current->get_text_edit()->call_deferred("grab_focus");
} break;
case EDIT_SELECT_ALL: {
current->get_text_edit()->select_all();
+ current->get_text_edit()->call_deferred("grab_focus");
} break;
case EDIT_MOVE_LINE_UP: {
@@ -815,11 +919,11 @@ void ScriptEditor::_menu_option(int p_option) {
if (scr.is_null())
return;
- int begin, end;
- begin = tx->get_selection_from_line();
+
if (tx->is_selection_active())
{
- end = tx->get_selection_to_line();
+ int begin = tx->get_selection_from_line();
+ int end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
@@ -839,7 +943,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
else
{
- begin = tx->cursor_get_line();
+ int begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
// begins with tab
if (line_text.begins_with("\t"))
@@ -865,11 +969,10 @@ void ScriptEditor::_menu_option(int p_option) {
if (scr.is_null())
return;
- int begin, end;
- begin = tx->get_selection_from_line();
if (tx->is_selection_active())
{
- end = tx->get_selection_to_line();
+ int begin = tx->get_selection_from_line();
+ int end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
@@ -879,7 +982,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
else
{
- begin = tx->cursor_get_line();
+ int begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
line_text = '\t' + line_text;
tx->set_line(begin, line_text);
@@ -912,11 +1015,12 @@ void ScriptEditor::_menu_option(int p_option) {
if (scr.is_null())
return;
- int begin, end;
- begin = tx->get_selection_from_line();
+
+
if (tx->is_selection_active())
{
- end = tx->get_selection_to_line();
+ int begin = tx->get_selection_from_line();
+ int end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
@@ -930,7 +1034,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
else
{
- begin = tx->cursor_get_line();
+ int begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
if (line_text.begins_with("#"))
@@ -1038,10 +1142,10 @@ void ScriptEditor::_menu_option(int p_option) {
if (text != "")
editor->emit_signal("request_help", text);
} break;
- case WINDOW_CLOSE: {
+ case FILE_CLOSE: {
if (current->get_text_edit()->get_version()!=current->get_text_edit()->get_saved_version()) {
erase_tab_confirm->set_text("Close and save changes?\n\""+current->get_name()+"\"");
- erase_tab_confirm->popup_centered(Point2(250,80));
+ erase_tab_confirm->popup_centered_minsize();
} else {
_close_current_tab();
}
@@ -1050,16 +1154,18 @@ void ScriptEditor::_menu_option(int p_option) {
if (tab_container->get_current_tab()>0) {
tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()-1);
+ script_list->call_deferred("select",tab_container->get_current_tab()-1);
tab_container->move_child(current,tab_container->get_current_tab()-1);
- _update_window_menu();
+ _update_script_names();
}
} break;
case WINDOW_MOVE_RIGHT: {
if (tab_container->get_current_tab()<tab_container->get_child_count()-1) {
tab_container->call_deferred("set_current_tab",tab_container->get_current_tab()+1);
+ script_list->call_deferred("select",tab_container->get_current_tab()+1);
tab_container->move_child(current,tab_container->get_current_tab()+1);
- _update_window_menu();
+ _update_script_names();
}
@@ -1069,6 +1175,8 @@ void ScriptEditor::_menu_option(int p_option) {
if (p_option>=WINDOW_SELECT_BASE) {
tab_container->set_current_tab(p_option-WINDOW_SELECT_BASE);
+ script_list->select(p_option-WINDOW_SELECT_BASE);
+
}
}
}
@@ -1089,12 +1197,27 @@ void ScriptEditor::_notification(int p_what) {
editor->connect("stop_pressed",this,"_editor_stop");
editor->connect("script_add_function_request",this,"_add_callback");
editor->connect("resource_saved",this,"_res_saved_callback");
+ script_list->connect("item_selected",this,"_script_selected");
+ script_split->connect("dragged",this,"_script_split_dragged");
+ autosave_timer->connect("timeout",this,"_autosave_scripts");
+ {
+ float autosave_time = EditorSettings::get_singleton()->get("text_editor/autosave_interval_secs");
+ if (autosave_time>0) {
+ autosave_timer->set_wait_time(autosave_time);
+ autosave_timer->start();
+ } else {
+ autosave_timer->stop();
+ }
+ }
+
+ EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
}
if (p_what==NOTIFICATION_READY) {
- _update_window_menu();
+
+ get_tree()->connect("tree_changed",this,"_tree_changed");
}
if (p_what==NOTIFICATION_EXIT_TREE) {
@@ -1134,10 +1257,11 @@ static const Node * _find_node_with_script(const Node* p_node, const RefPtr & p_
Dictionary ScriptEditor::get_state() const {
- apply_scripts();
- Dictionary state;
+// apply_scripts();
+ Dictionary state;
+#if 0
Array paths;
int open=-1;
@@ -1170,12 +1294,12 @@ Dictionary ScriptEditor::get_state() const {
if (open!=-1)
state["current"]=open;
-
+#endif
return state;
}
void ScriptEditor::set_state(const Dictionary& p_state) {
-
+#if 0
print_line("attempt set state: "+String(Variant(p_state)));
if (!p_state.has("sources"))
@@ -1212,6 +1336,7 @@ void ScriptEditor::set_state(const Dictionary& p_state) {
if (p_state.has("current")) {
tab_container->set_current_tab(p_state["current"]);
}
+#endif
}
void ScriptEditor::clear() {
@@ -1235,68 +1360,17 @@ void ScriptEditor::clear() {
int idx = tab_container->get_current_tab();
if (idx>=tab_container->get_child_count())
idx=tab_container->get_child_count()-1;
- if (idx>=0)
+ if (idx>=0) {
tab_container->set_current_tab(idx);
-
- _update_window_menu();
-
-
-}
-
-void ScriptEditor::_save_files_state() {
-
- return; //no thank you
-
- String rpath="_open_scripts_"+Globals::get_singleton()->get_resource_path();
- rpath=rpath.replace("\\","_-_");
- rpath=rpath.replace("/","_-_");
- rpath=rpath.replace(":","_");
-
- Vector<String> scripts;
-
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!ste)
- continue;
-
-
- Ref<Script> script = ste->get_edited_script();
- if (script->get_path()!="" && script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
-
-
- scripts.push_back(script->get_path());
- }
+ script_list->select( script_list->find_metadata(idx) );
}
- EditorSettings::get_singleton()->set(rpath,scripts);
- EditorSettings::get_singleton()->save();
-
-}
-void ScriptEditor::_load_files_state() {
- return;
-
- String rpath="_open_scripts_"+Globals::get_singleton()->get_resource_path();
- rpath=rpath.replace("\\","_-_");
- rpath=rpath.replace("/","_-_");
- rpath=rpath.replace(":","_");
-
- if (EditorSettings::get_singleton()->has(rpath)) {
-
- Vector<String> open_files=EditorSettings::get_singleton()->get("rpath");
- for(int i=0;i<open_files.size();i++) {
- Ref<Script> scr = ResourceLoader::load(open_files[i]);
- if (!scr.is_valid())
- continue;
-
- editor->edit_resource(scr);
- }
- }
}
+
void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
for(int i=0;i<tab_container->get_child_count();i++) {
@@ -1339,12 +1413,20 @@ void ScriptEditor::_bind_methods() {
ObjectTypeDB::bind_method("_breaked",&ScriptEditor::_breaked);
ObjectTypeDB::bind_method("_show_debugger",&ScriptEditor::_show_debugger);
ObjectTypeDB::bind_method("_get_debug_tooltip",&ScriptEditor::_get_debug_tooltip);
-
+ ObjectTypeDB::bind_method("_autosave_scripts",&ScriptEditor::_autosave_scripts);
+ ObjectTypeDB::bind_method("_editor_settings_changed",&ScriptEditor::_editor_settings_changed);
+ ObjectTypeDB::bind_method("_update_script_names",&ScriptEditor::_update_script_names);
+ ObjectTypeDB::bind_method("_tree_changed",&ScriptEditor::_tree_changed);
+ ObjectTypeDB::bind_method("_script_selected",&ScriptEditor::_script_selected);
+ ObjectTypeDB::bind_method("_script_split_dragged",&ScriptEditor::_script_split_dragged);
}
void ScriptEditor::ensure_focus_current() {
+ if (!is_inside_tree())
+ return;
+
int cidx = tab_container->get_current_tab();
if (cidx<0 || cidx>=tab_container->get_tab_count());
Control *c = tab_container->get_child(cidx)->cast_to<Control>();
@@ -1356,6 +1438,13 @@ void ScriptEditor::ensure_focus_current() {
ste->get_text_edit()->grab_focus();
}
+void ScriptEditor::_script_selected(int p_idx) {
+
+ grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing
+ tab_container->set_current_tab(script_list->get_item_metadata(p_idx));
+ grab_focus_block=false;
+}
+
void ScriptEditor::ensure_select_current() {
@@ -1366,8 +1455,66 @@ void ScriptEditor::ensure_select_current() {
return;
Ref<Script> script = ste->get_edited_script();
- ste->get_text_edit()->grab_focus();
+ if (!grab_focus_block && is_inside_tree())
+ ste->get_text_edit()->grab_focus();
+ }
+
+
+}
+
+void ScriptEditor::_find_scripts(Node* p_base, Node* p_current, Set<Ref<Script> > &used) {
+ if (p_current!=p_base && p_current->get_owner()!=p_base)
+ return;
+
+ if (p_current->get_script_instance()) {
+ Ref<Script> scr = p_current->get_script();
+ if (scr.is_valid())
+ used.insert(scr);
}
+
+ for(int i=0;i<p_current->get_child_count();i++) {
+ _find_scripts(p_base,p_current->get_child(i),used);
+ }
+
+}
+
+
+void ScriptEditor::_update_script_names() {
+
+ waiting_update_names=false;
+ Set<Ref<Script> > used;
+ Node* edited = EditorNode::get_singleton()->get_edited_scene();
+ if (edited) {
+ _find_scripts(edited,edited,used);
+ }
+
+ script_list->clear();
+ for(int i=0;i<tab_container->get_child_count();i++) {
+
+ ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
+ if (!ste)
+ continue;
+
+ String script = ste->get_name();
+ Ref<Texture> icon = ste->get_icon();
+ String path = ste->get_edited_script()->get_path();
+ script_list->add_item(script,icon);
+
+ int index = script_list->get_item_count()-1;
+
+ script_list->set_item_tooltip(index,path);
+ script_list->set_item_metadata(index,i);
+ if (used.has(ste->get_edited_script())) {
+
+ script_list->set_item_custom_bg_color(index,Color(88/255.0,88/255.0,60/255.0));
+ }
+ if (tab_container->get_current_tab()==index) {
+ script_list->select(index);
+ }
+ }
+
+ script_list->sort_items_by_text();
+
}
void ScriptEditor::edit(const Ref<Script>& p_script) {
@@ -1405,9 +1552,13 @@ void ScriptEditor::edit(const Ref<Script>& p_script) {
if (ste->get_edited_script()==p_script) {
- if (tab_container->get_current_tab()!=i)
- tab_container->set_current_tab(i);
- ste->get_text_edit()->grab_focus();
+ if (!EditorNode::get_singleton()->is_changing_scene()) {
+ if (tab_container->get_current_tab()!=i) {
+ tab_container->set_current_tab(i);
+ script_list->select( script_list->find_metadata(i) );
+ }
+ ste->get_text_edit()->grab_focus();
+ }
return;
}
}
@@ -1420,9 +1571,13 @@ void ScriptEditor::edit(const Ref<Script>& p_script) {
tab_container->add_child(ste);
tab_container->set_current_tab(tab_container->get_tab_count()-1);
- _update_window_menu();
- _save_files_state();
+
+ _update_script_names();
+ ste->connect("name_changed",this,"_update_script_names");
+ if (!restoring_layout) {
+ EditorNode::get_singleton()->save_layout();
+ }
}
void ScriptEditor::save_external_data() {
@@ -1482,51 +1637,6 @@ void ScriptEditor::_editor_stop() {
debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true );
}
-void ScriptEditor::_update_window_menu() {
-
- int idx=0;
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!ste)
- continue;
- idx++;
- }
-
- if (idx==0) {
- window_menu->set_disabled(true);
- edit_menu->set_disabled(true);
- search_menu->set_disabled(true);
- return;
- } else {
-
- window_menu->set_disabled(false);
- edit_menu->set_disabled(false);
- search_menu->set_disabled(false);
- }
-
- window_menu->get_popup()->clear();
- window_menu->get_popup()->add_item("Close",WINDOW_CLOSE,KEY_MASK_CMD|KEY_W);
- window_menu->get_popup()->add_separator();
- window_menu->get_popup()->add_item("Move Left",WINDOW_MOVE_LEFT,KEY_MASK_CMD|KEY_LEFT);
- window_menu->get_popup()->add_item("Move Right",WINDOW_MOVE_RIGHT,KEY_MASK_CMD|KEY_RIGHT);
- window_menu->get_popup()->add_separator();
-
- idx=0;
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!ste)
- continue;
- String n = ste->get_name();
- uint32_t accel=0;
- if (idx<9) {
- accel=KEY_MASK_ALT|(KEY_1+idx);
- }
- window_menu->get_popup()->add_item(n,WINDOW_SELECT_BASE+idx,accel);
- idx++;
- }
-}
void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const StringArray& p_args) {
@@ -1562,14 +1672,108 @@ void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const
ste->get_text_edit()->cursor_set_line(pos);
ste->get_text_edit()->cursor_set_column(1);
+ script_list->select( script_list->find_metadata(i) );
+
break;
}
}
+void ScriptEditor::_editor_settings_changed() {
+
+ print_line("settings changed");
+ float autosave_time = EditorSettings::get_singleton()->get("text_editor/autosave_interval_secs");
+ if (autosave_time>0) {
+ autosave_timer->set_wait_time(autosave_time);
+ autosave_timer->start();
+ } else {
+ autosave_timer->stop();
+ }
+
+}
+
+void ScriptEditor::_autosave_scripts() {
+
+ print_line("autosaving");
+ save_external_data();
+}
+
+void ScriptEditor::_tree_changed() {
+
+ if (waiting_update_names)
+ return;
+
+ waiting_update_names=true;
+ call_deferred("_update_script_names");
+}
+
+void ScriptEditor::_script_split_dragged(float) {
+
+ EditorNode::get_singleton()->save_layout();
+}
+
+void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
+
+ if (!bool(EDITOR_DEF("text_editor/restore_scripts_on_load",true))) {
+ return;
+ }
+
+ if (!p_layout->has_section_key("ScriptEditor","open_scripts"))
+ return;
+
+ Array scripts = p_layout->get_value("ScriptEditor","open_scripts");
+
+ restoring_layout=true;
+
+ for(int i=0;i<scripts.size();i++) {
+
+ String path = scripts[i];
+ Ref<Script> scr = ResourceLoader::load(path);
+ if (scr.is_valid()) {
+ edit(scr);
+ }
+ }
+
+ if (p_layout->has_section_key("ScriptEditor","split_offset")) {
+ script_split->set_split_offset(p_layout->get_value("ScriptEditor","split_offset"));
+ }
+
+
+ restoring_layout=false;
+
+}
+
+void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
+
+ Array scripts;
+
+ for(int i=0;i<tab_container->get_child_count();i++) {
+
+ ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
+ if (!ste)
+ continue;
+
+ String path = ste->get_edited_script()->get_path();
+ if (!path.is_resource_file())
+ continue;
+
+ scripts.push_back(path);
+
+ }
+
+ p_layout->set_value("ScriptEditor","open_scripts",scripts);
+ p_layout->set_value("ScriptEditor","split_offset",script_split->get_split_offset());
+
+}
+
+
+
ScriptEditor::ScriptEditor(EditorNode *p_editor) {
+ completion_cache = memnew( EditorScriptCodeCompletionCache );
+ restoring_layout=false;
+ waiting_update_names=false;
editor=p_editor;
menu_hb = memnew( HBoxContainer );
@@ -1579,17 +1783,32 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
add_child(v_split);
v_split->set_v_size_flags(SIZE_EXPAND_FILL);
+ script_split = memnew( HSplitContainer );
+ v_split->add_child(script_split);
+ script_split->set_v_size_flags(SIZE_EXPAND_FILL);
+
+ script_list = memnew( ItemList );
+ script_split->add_child(script_list);
+ script_list->set_custom_minimum_size(Size2(70,0));
+ script_split->set_split_offset(70);
+
tab_container = memnew( TabContainer );
- v_split->add_child(tab_container);
- tab_container->set_v_size_flags(SIZE_EXPAND_FILL);
+ tab_container->set_tabs_visible(false);
+ script_split->add_child(tab_container);
+
+
+ tab_container->set_h_size_flags(SIZE_EXPAND_FILL);
file_menu = memnew( MenuButton );
menu_hb->add_child(file_menu);
file_menu->set_text("File");
file_menu->get_popup()->add_item("Open",FILE_OPEN);
+ file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_MASK_CMD|KEY_S);
file_menu->get_popup()->add_item("Save As..",FILE_SAVE_AS);
file_menu->get_popup()->add_item("Save All",FILE_SAVE_ALL,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_S);
+ file_menu->get_popup()->add_separator();
+ file_menu->get_popup()->add_item("Close",FILE_CLOSE,KEY_MASK_CMD|KEY_W);
file_menu->get_popup()->connect("item_pressed", this,"_menu_option");
edit_menu = memnew( MenuButton );
@@ -1651,6 +1870,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
debug_menu->get_popup()->set_item_disabled( debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true );
+#if 0
window_menu = memnew( MenuButton );
menu_hb->add_child(window_menu);
window_menu->set_text("Window");
@@ -1661,6 +1881,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
window_menu->get_popup()->add_separator();
window_menu->get_popup()->connect("item_pressed", this,"_menu_option");
+#endif
+
help_menu = memnew( MenuButton );
menu_hb->add_child(help_menu);
help_menu->set_text("Help");
@@ -1718,11 +1940,23 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
v_split->add_child(debugger);
debugger->connect("breaked",this,"_breaked");
+
+ autosave_timer = memnew( Timer );
+ autosave_timer->set_one_shot(false);
+ add_child(autosave_timer);
+
+ grab_focus_block=false;
+
// debugger_gui->hide();
}
+ScriptEditor::~ScriptEditor() {
+
+ memdelete(completion_cache);
+}
+
void ScriptEditorPlugin::edit(Object *p_object) {
if (!p_object->cast_to<Script>())
@@ -1782,20 +2016,24 @@ void ScriptEditorPlugin::apply_changes() {
void ScriptEditorPlugin::restore_global_state() {
- if (bool(EDITOR_DEF("text_editor/restore_scripts_on_load",true))) {
- script_editor->_load_files_state();
- }
}
void ScriptEditorPlugin::save_global_state() {
- if (bool(EDITOR_DEF("text_editor/restore_scripts_on_load",true))) {
- script_editor->_save_files_state();
- }
+}
+void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
+
+ script_editor->set_window_layout(p_layout);
}
+void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout){
+
+ script_editor->get_window_layout(p_layout);
+}
+
+
void ScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) {