diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-05-24 01:35:47 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-05-24 01:35:47 -0300 |
commit | 1cad087969efefa401a11051343cd0689f660770 (patch) | |
tree | 1595dd049bdb7289752012dca4398b2251fb08fa /modules/gdscript/gd_editor.cpp | |
parent | f9ff086235cd4ff406b136f62fff77b85c0873f9 (diff) | |
download | redot-engine-1cad087969efefa401a11051343cd0689f660770.tar.gz |
Making Godot Easier to Use..
-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-Auto indenter in code editor, this makes it much easier to paste external code.
-Zoom in 2D viewport now uses the mouse pointer as reference.
-Obscure hack to see where code/line of GDScript in C++ backtrace.
-Fixed a bug where keys would get stuck on X11 if pressed simultaneously
-Added Api on IP singleton to request local IPs.
-Premultiplied alpha support when importing texture, editing PNGs and as a blend mode.
Diffstat (limited to 'modules/gdscript/gd_editor.cpp')
-rw-r--r-- | modules/gdscript/gd_editor.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index f8717c292f..5f5de8b5db 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -787,3 +787,67 @@ Error GDScriptLanguage::complete_keyword(const String& p_code, int p_line, const return OK; } +void GDScriptLanguage::auto_indent_code(String& p_code,int p_from_line,int p_to_line) const { + + + Vector<String> lines = p_code.split("\n"); + List<int> indent_stack; + + for(int i=0;i<lines.size();i++) { + + String l = lines[i]; + int tc=0; + for(int j=0;j<l.length();j++) { + if (l[j]==' ' || l[j]=='\t') { + + tc++; + } else { + break; + } + } + + + String st = l.substr(tc,l.length()).strip_edges(); + if (st=="" || st.begins_with("#")) + continue; //ignore! + + int ilevel=0; + if (indent_stack.size()) { + ilevel=indent_stack.back()->get(); + } + + if (tc>ilevel) { + indent_stack.push_back(tc); + } else if (tc<ilevel) { + while(indent_stack.size() && indent_stack.back()->get()>tc) { + indent_stack.pop_back(); + } + + if (indent_stack.size() && indent_stack.back()->get()!=tc) + indent_stack.push_back(tc); //this is not right but gets the job done + } + + if (i>=p_from_line) { + + l=""; + for(int j=0;j<indent_stack.size();j++) + l+="\t"; + l+=st; + + + } else if (i>p_to_line) { + break; + } + + //print_line(itos(indent_stack.size())+","+itos(tc)+": "+l); + lines[i]=l; + } + + p_code=""; + for(int i=0;i<lines.size();i++) { + if (i>0) + p_code+="\n"; + p_code+=lines[i]; + } + +} |