From 145b8c5e6fb755a2454312dc6f49ca50ff5175b2 Mon Sep 17 00:00:00 2001 From: marynate Date: Mon, 5 May 2014 21:59:18 +0800 Subject: Start working on script editor help --- tools/editor/editor_help.cpp | 13 +++++++++++-- tools/editor/plugins/script_editor_plugin.cpp | 11 +++++++++++ tools/editor/plugins/script_editor_plugin.h | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp index 19e65f3844..a77d27d699 100644 --- a/tools/editor/editor_help.cpp +++ b/tools/editor/editor_help.cpp @@ -43,9 +43,16 @@ void EditorHelpSearch::popup(const String& p_term) { if (p_term!="") { search_box->set_text(p_term); search_box->select_all(); - } else + _update_search(); + //TreeItem *ti = search_options->select_single_item(); + //if (!ti) + // return; + search_options->grab_focus(); + + } else { search_box->clear(); - search_box->grab_focus(); + search_box->grab_focus(); + } } @@ -863,6 +870,8 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs void EditorHelp::_request_help(const String& p_string) { _goto_desc(p_string); + class_search->popup(p_string); + //100 palabras diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index a01565a046..2d2e02f5c4 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -752,6 +752,11 @@ void ScriptEditor::_menu_option(int p_option) { debugger->show(); } } break; + case HELP_SELECTED: { + String selected = current->get_text_edit()->get_selection_text(); + editor->call("_editor_select", 3); + editor->emit_signal("request_help", selected); + } break; case WINDOW_CLOSE: { erase_tab_confirm->set_text("Close Tab?:\n\""+current->get_name()+"\""); @@ -1362,6 +1367,12 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { window_menu->get_popup()->add_separator(); window_menu->get_popup()->connect("item_pressed", this,"_menu_option"); + help_menu = memnew( MenuButton ); + menu_hb->add_child(help_menu); + help_menu->set_text("Help"); + help_menu->get_popup()->add_item("Selected", HELP_SELECTED, KEY_MASK_CTRL|KEY_MASK_SHIFT|KEY_D); + help_menu->get_popup()->connect("item_pressed", this,"_menu_option"); + tab_container->connect("tab_changed", this,"_tab_changed"); find_replace_dialog = memnew(FindReplaceDialog); diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h index e0cf3c1a49..af1fe1c6c3 100644 --- a/tools/editor/plugins/script_editor_plugin.h +++ b/tools/editor/plugins/script_editor_plugin.h @@ -133,6 +133,7 @@ class ScriptEditor : public VBoxContainer { DEBUG_BREAK, DEBUG_CONTINUE, DEBUG_SHOW, + HELP_SELECTED, WINDOW_CLOSE, WINDOW_MOVE_LEFT, WINDOW_MOVE_RIGHT, @@ -145,6 +146,7 @@ class ScriptEditor : public VBoxContainer { MenuButton *search_menu; MenuButton *window_menu; MenuButton *debug_menu; + MenuButton *help_menu; uint64_t idle; TabContainer *tab_container; -- cgit v1.2.3 From 212b8b2a0348eed9c7f2dd593fb103dc5d4af9d3 Mon Sep 17 00:00:00 2001 From: marynate Date: Tue, 6 May 2014 17:36:39 +0800 Subject: Add get_word_under_cursor() method to TextEdit --- scene/gui/text_edit.cpp | 22 ++++++++++++++++++++++ scene/gui/text_edit.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 87900306d4..bd15e14ccd 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2485,6 +2485,27 @@ String TextEdit::get_selection_text() const { } +String TextEdit::get_word_under_cursor() const { + + int prev_cc = cursor.column; + while(prev_cc >0) { + bool is_char = _is_text_char(text[cursor.line][prev_cc-1]); + if (!is_char) + break; + --prev_cc; + } + + int next_cc = cursor.column; + while(next_cc TextEdit::_search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const { @@ -3037,6 +3058,7 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_selection_to_line"),&TextEdit::get_selection_to_line); ObjectTypeDB::bind_method(_MD("get_selection_to_column"),&TextEdit::get_selection_to_column); ObjectTypeDB::bind_method(_MD("get_selection_text"),&TextEdit::get_selection_text); + ObjectTypeDB::bind_method(_MD("get_word_under_cursor"),&TextEdit::get_word_under_cursor); ObjectTypeDB::bind_method(_MD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind); ObjectTypeDB::bind_method(_MD("undo"),&TextEdit::undo); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 58d62dea48..7700bfd4d3 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -341,6 +341,8 @@ public: int get_selection_to_column() const; String get_selection_text() const; + String get_word_under_cursor() const; + bool search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const; void undo(); -- cgit v1.2.3 From d3b7f4b1a7f73f3ec69157d2f400ae24b4e02896 Mon Sep 17 00:00:00 2001 From: marynate Date: Tue, 6 May 2014 17:38:00 +0800 Subject: EditorNode consume F1 key only when Shift or Command key not pressed at the same time --- tools/editor/editor_node.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 3ea09fca47..3ef523a695 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -115,7 +115,10 @@ void EditorNode::_unhandled_input(const InputEvent& p_event) { switch(p_event.key.scancode) { - case KEY_F1: _editor_select(3); break; + case KEY_F1: + if (!p_event.key.mod.shift && !p_event.key.mod.command) + _editor_select(3); + break; case KEY_F2: _editor_select(0); break; case KEY_F3: _editor_select(1); break; case KEY_F4: _editor_select(2); break; -- cgit v1.2.3 From ab76f541961c9bf11ba51ea6aeeacab529e9e0b9 Mon Sep 17 00:00:00 2001 From: marynate Date: Tue, 6 May 2014 17:41:19 +0800 Subject: Update EditorHelp to response help request other than class; Make sure EditorHelpSearch dialog popup with search results --- tools/editor/editor_help.cpp | 41 +++++++++++++++++++++-------------------- tools/editor/editor_help.h | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp index a77d27d699..ddbc8ee479 100644 --- a/tools/editor/editor_help.cpp +++ b/tools/editor/editor_help.cpp @@ -44,15 +44,9 @@ void EditorHelpSearch::popup(const String& p_term) { search_box->set_text(p_term); search_box->select_all(); _update_search(); - //TreeItem *ti = search_options->select_single_item(); - //if (!ti) - // return; - search_options->grab_focus(); - - } else { + } else search_box->clear(); - search_box->grab_focus(); - } + search_box->grab_focus(); } @@ -77,7 +71,6 @@ void EditorHelpSearch::_sbox_input(const InputEvent& p_ie) { void EditorHelpSearch::_update_search() { - search_options->clear(); search_options->set_hide_root(true); @@ -256,6 +249,7 @@ void EditorHelpSearch::_confirmed() { String mdata=ti->get_metadata(0); emit_signal("go_to_help",mdata); + editor->call("_editor_select",3); // in case EditorHelpSearch beeen invoked on top of other editor window // go to that hide(); } @@ -325,10 +319,14 @@ DocData *EditorHelp::doc=NULL; void EditorHelp::_unhandled_key_input(const InputEvent& p_ev) { - if (is_visible() && p_ev.key.mod.control && p_ev.key.scancode==KEY_F) { + if (!is_visible()) + return; + if ( p_ev.key.mod.control && p_ev.key.scancode==KEY_F) { search->grab_focus(); search->select_all(); + } else if (p_ev.key.mod.shift && p_ev.key.scancode==KEY_F1) { + class_search->popup(); } } @@ -461,9 +459,11 @@ void EditorHelp::_scroll_changed(double p_scroll) { history[p].scroll=p_scroll; } -void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vscr) { +Error EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vscr) { - ERR_FAIL_COND(!doc->class_list.has(p_class)); + //ERR_FAIL_COND(!doc->class_list.has(p_class)); + if (!doc->class_list.has(p_class)) + return ERR_DOES_NOT_EXIST; if (tree_item_map.has(p_class)) { @@ -477,7 +477,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs description_line=0; if (p_class==edited_class->get_text()) - return; //already there + return OK; //already there scroll_locked=true; @@ -865,15 +865,16 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs scroll_locked=false; + return OK; } -void EditorHelp::_request_help(const String& p_string) { - - _goto_desc(p_string); - class_search->popup(p_string); - - - +void EditorHelp::_request_help(const String& p_string) { + Error err = _goto_desc(p_string); + if (err==OK) { + editor->call("_editor_select",3); + } else { + class_search->popup(p_string); + } //100 palabras } diff --git a/tools/editor/editor_help.h b/tools/editor/editor_help.h index eac33e5e16..94a31ce902 100644 --- a/tools/editor/editor_help.h +++ b/tools/editor/editor_help.h @@ -139,7 +139,7 @@ class EditorHelp : public VBoxContainer { void _class_list_select(const String& p_select); void _class_desc_select(const String& p_select); - void _goto_desc(const String& p_class,bool p_update_history=true,int p_vscr=-1); + Error _goto_desc(const String& p_class,bool p_update_history=true,int p_vscr=-1); void _update_history_buttons(); void _update_doc(); -- cgit v1.2.3 From 6c0f3f8d0ca9e30951f0e6e643af07ca7ed695a9 Mon Sep 17 00:00:00 2001 From: marynate Date: Tue, 6 May 2014 17:43:14 +0800 Subject: Implement Shift+F1 as contextual help hotkey for script editor; There's one bug that when jump to help tab first time, the scroll position is wrong. --- tools/editor/plugins/script_editor_plugin.cpp | 17 ++++++++--------- tools/editor/plugins/script_editor_plugin.h | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 2d2e02f5c4..83cf753692 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -394,7 +394,6 @@ ScriptTextEditor::ScriptTextEditor() { /*** SCRIPT EDITOR ******/ - String ScriptEditor::_get_debug_tooltip(const String&p_text,Node *_ste) { ScriptTextEditor *ste=_ste->cast_to(); @@ -752,10 +751,12 @@ void ScriptEditor::_menu_option(int p_option) { debugger->show(); } } break; - case HELP_SELECTED: { - String selected = current->get_text_edit()->get_selection_text(); - editor->call("_editor_select", 3); - editor->emit_signal("request_help", selected); + case HELP_CONTEXTUAL: { + String text = current->get_text_edit()->get_selection_text(); + if (text == "") + text = current->get_text_edit()->get_word_under_cursor(); + if (text != "") + editor->emit_signal("request_help", text); } break; case WINDOW_CLOSE: { @@ -1056,9 +1057,6 @@ void ScriptEditor::_bind_methods() { ObjectTypeDB::bind_method("_show_debugger",&ScriptEditor::_show_debugger); ObjectTypeDB::bind_method("_get_debug_tooltip",&ScriptEditor::_get_debug_tooltip); - - - } @@ -1370,7 +1368,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { help_menu = memnew( MenuButton ); menu_hb->add_child(help_menu); help_menu->set_text("Help"); - help_menu->get_popup()->add_item("Selected", HELP_SELECTED, KEY_MASK_CTRL|KEY_MASK_SHIFT|KEY_D); + help_menu->get_popup()->add_item("Contextual", HELP_CONTEXTUAL, KEY_MASK_SHIFT|KEY_F1); help_menu->get_popup()->connect("item_pressed", this,"_menu_option"); tab_container->connect("tab_changed", this,"_tab_changed"); @@ -1425,6 +1423,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { v_split->add_child(debugger); debugger->connect("breaked",this,"_breaked"); // debugger_gui->hide(); + } diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h index af1fe1c6c3..97f1702f8f 100644 --- a/tools/editor/plugins/script_editor_plugin.h +++ b/tools/editor/plugins/script_editor_plugin.h @@ -133,7 +133,7 @@ class ScriptEditor : public VBoxContainer { DEBUG_BREAK, DEBUG_CONTINUE, DEBUG_SHOW, - HELP_SELECTED, + HELP_CONTEXTUAL, WINDOW_CLOSE, WINDOW_MOVE_LEFT, WINDOW_MOVE_RIGHT, @@ -187,6 +187,7 @@ class ScriptEditor : public VBoxContainer { void _breaked(bool p_breaked,bool p_can_debug); void _show_debugger(bool p_show); void _update_window_menu(); + static ScriptEditor *script_editor; protected: void _notification(int p_what); -- cgit v1.2.3