diff options
Diffstat (limited to 'tools/editor/plugins')
-rw-r--r-- | tools/editor/plugins/polygon_2d_editor_plugin.cpp | 9 | ||||
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.cpp | 126 | ||||
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.h | 2 | ||||
-rw-r--r-- | tools/editor/plugins/shader_editor_plugin.cpp | 5 |
4 files changed, 112 insertions, 30 deletions
diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.cpp b/tools/editor/plugins/polygon_2d_editor_plugin.cpp index 7dd8dd3035..27e539d50b 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/tools/editor/plugins/polygon_2d_editor_plugin.cpp @@ -187,6 +187,8 @@ void Polygon2DEditor::_wip_close() { bool Polygon2DEditor::forward_input_event(const InputEvent& p_event) { + if (node==NULL) + return false; switch(p_event.type) { @@ -701,11 +703,16 @@ void Polygon2DEditor::edit(Node *p_collision_polygon) { node=p_collision_polygon->cast_to<Polygon2D>(); if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw"); + node->connect("exit_tree",this,"_node_removed",varray(),CONNECT_ONESHOT); wip.clear(); wip_active=false; edited_point=-1; } else { + + if (node) + node->disconnect("exit_tree",this,"_node_removed"); + node=NULL; if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) @@ -723,12 +730,14 @@ void Polygon2DEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_uv_draw"),&Polygon2DEditor::_uv_draw); ObjectTypeDB::bind_method(_MD("_uv_input"),&Polygon2DEditor::_uv_input); ObjectTypeDB::bind_method(_MD("_uv_scroll_changed"),&Polygon2DEditor::_uv_scroll_changed); + ObjectTypeDB::bind_method(_MD("_node_removed"),&Polygon2DEditor::_node_removed); } Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { + node=NULL; canvas_item_editor=NULL; editor=p_editor; undo_redo = editor->get_undo_redo(); diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index c0d773309c..c5fb574c71 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -608,6 +608,16 @@ bool ScriptEditor::_test_script_times_on_disk() { return all_ok; } +void ScriptEditor::swap_lines(TextEdit *tx, int line1, int line2) +{ + String tmp = tx->get_line(line1); + String tmp2 = tx->get_line(line2); + tx->set_line(line2, tmp); + tx->set_line(line1, tmp2); + + tx->cursor_set_line(line2); +} + void ScriptEditor::_menu_option(int p_option) { @@ -690,18 +700,38 @@ void ScriptEditor::_menu_option(int p_option) { if (scr.is_null()) return; - int line_id = tx->cursor_get_line(); - int next_id = line_id - 1; + if (tx->is_selection_active()) + { + int from_line = tx->get_selection_from_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); + int to_column = tx->get_selection_to_column(); + + for (int i = from_line; i <= to_line; i++) + { + int line_id = i; + int next_id = i - 1; - if (line_id == 0 || next_id < 0) - return; + if (line_id == 0 || next_id < 0) + return; - String tmp = tx->get_line(line_id); - String tmp2 = tx->get_line(next_id); - tx->set_line(next_id, tmp); - tx->set_line(line_id, tmp2); + swap_lines(tx, line_id, next_id); + } + int from_line_up = from_line > 0 ? from_line-1 : from_line; + int to_line_up = to_line > 0 ? to_line-1 : to_line; + tx->select(from_line_up, from_col, to_line_up, to_column); + } + else + { + int line_id = tx->cursor_get_line(); + int next_id = line_id - 1; + + if (line_id == 0 || next_id < 0) + return; + + swap_lines(tx, line_id, next_id); + } tx->update(); - tx->cursor_set_line(next_id); } break; case EDIT_MOVE_LINE_DOWN: { @@ -711,18 +741,38 @@ void ScriptEditor::_menu_option(int p_option) { if (scr.is_null()) return; - int line_id = tx->cursor_get_line(); - int next_id = line_id + 1; + if (tx->is_selection_active()) + { + int from_line = tx->get_selection_from_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); + int to_column = tx->get_selection_to_column(); - if (line_id == tx->get_line_count() || next_id > tx->get_line_count()) - return; + for (int i = to_line; i >= from_line; i--) + { + int line_id = i; + int next_id = i + 1; + + if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) + return; - String tmp = tx->get_line(line_id); - String tmp2 = tx->get_line(next_id); - tx->set_line(next_id, tmp); - tx->set_line(line_id, tmp2); + swap_lines(tx, line_id, next_id); + } + int from_line_down = from_line < tx->get_line_count() ? from_line+1 : from_line; + int to_line_down = to_line < tx->get_line_count() ? to_line+1 : to_line; + tx->select(from_line_down, from_col, to_line_down, to_column); + } + else + { + int line_id = tx->cursor_get_line(); + int next_id = line_id + 1; + + if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) + return; + + swap_lines(tx, line_id, next_id); + } tx->update(); - tx->cursor_set_line(next_id); } break; case EDIT_INDENT_LEFT: { @@ -740,19 +790,39 @@ void ScriptEditor::_menu_option(int p_option) { for (int i = begin; i <= end; i++) { String line_text = tx->get_line(i); - line_text = line_text.substr(1, line_text.length()); - tx->set_line(i, line_text); + // begins with tab + if (line_text.begins_with("\t")) + { + line_text = line_text.substr(1, line_text.length()); + tx->set_line(i, line_text); + } + // begins with 4 spaces + else if (line_text.begins_with(" ")) + { + line_text = line_text.substr(4, line_text.length()); + tx->set_line(i, line_text); + } } } else { begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); - line_text = line_text.substr(1, line_text.length()); - tx->set_line(begin, line_text); + // begins with tab + if (line_text.begins_with("\t")) + { + line_text = line_text.substr(1, line_text.length()); + tx->set_line(begin, line_text); + } + // begins with 4 spaces + else if (line_text.begins_with(" ")) + { + line_text = line_text.substr(4, line_text.length()); + tx->set_line(begin, line_text); + } } tx->update(); - tx->deselect(); + //tx->deselect(); } break; case EDIT_INDENT_RIGHT: { @@ -782,7 +852,7 @@ void ScriptEditor::_menu_option(int p_option) { tx->set_line(begin, line_text); } tx->update(); - tx->deselect(); + //tx->deselect(); } break; case EDIT_CLONE_DOWN: { @@ -837,7 +907,7 @@ void ScriptEditor::_menu_option(int p_option) { tx->set_line(begin, line_text); } tx->update(); - tx->deselect(); + //tx->deselect(); } break; case EDIT_COMPLETE: { @@ -1443,7 +1513,7 @@ void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const int pos = script->get_language()->find_function(p_function,code); if (pos==-1) { //does not exist - + ste->get_text_edit()->deselect(); pos=ste->get_text_edit()->get_line_count()+2; String func = script->get_language()->make_function("",p_function,p_args); //code=code+func; @@ -1498,8 +1568,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_item("Select All",EDIT_SELECT_ALL,KEY_MASK_CMD|KEY_A); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_item("Move Line Up",EDIT_MOVE_LINE_UP,KEY_MASK_ALT|KEY_UP); - edit_menu->get_popup()->add_item("Move Line Down",EDIT_MOVE_LINE_DOWN,KEY_MASK_ALT|KEY_DOWN); + edit_menu->get_popup()->add_item("Move Up",EDIT_MOVE_LINE_UP,KEY_MASK_ALT|KEY_UP); + edit_menu->get_popup()->add_item("Move Down",EDIT_MOVE_LINE_DOWN,KEY_MASK_ALT|KEY_DOWN); edit_menu->get_popup()->add_item("Indent Left",EDIT_INDENT_LEFT,KEY_MASK_ALT|KEY_LEFT); edit_menu->get_popup()->add_item("Indent Right",EDIT_INDENT_RIGHT,KEY_MASK_ALT|KEY_RIGHT); edit_menu->get_popup()->add_item("Toggle Comment",EDIT_TOGGLE_COMMENT,KEY_MASK_CMD|KEY_SLASH); diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h index 62508253e3..01942fab2a 100644 --- a/tools/editor/plugins/script_editor_plugin.h +++ b/tools/editor/plugins/script_editor_plugin.h @@ -218,7 +218,7 @@ public: void get_breakpoints(List<String> *p_breakpoints); - + void swap_lines(TextEdit *tx, int line1, int line2); void save_external_data(); diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp index d9bf4b6fa5..a6172ee098 100644 --- a/tools/editor/plugins/shader_editor_plugin.cpp +++ b/tools/editor/plugins/shader_editor_plugin.cpp @@ -144,10 +144,13 @@ void ShaderTextEditor::_validate_script() { Error err = ShaderLanguage::compile(code,type,NULL,NULL,&errortxt,&line,&col); if (err!=OK) { - String error_text="error("+itos(line)+","+itos(col)+"): "+errortxt; + String error_text="error("+itos(line+1)+","+itos(col)+"): "+errortxt; set_error(error_text); + get_text_edit()->set_line_as_marked(line,true); } else { + for(int i=0;i<get_text_edit()->get_line_count();i++) + get_text_edit()->set_line_as_marked(i,false); set_error(""); } |