1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Improve bookmarks

This commit is contained in:
Michael Alexsander Silva Dias
2019-05-21 05:07:48 -03:00
parent da617b7943
commit e12b482022
6 changed files with 157 additions and 31 deletions

View File

@@ -630,6 +630,43 @@ void ScriptTextEditor::_validate_script() {
emit_signal("edited_script_changed"); emit_signal("edited_script_changed");
} }
void ScriptTextEditor::_update_bookmark_list() {
bookmarks_menu->get_popup()->clear();
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array();
if (bookmark_list.size() == 0) {
return;
}
bookmarks_menu->get_popup()->add_separator();
for (int i = 0; i < bookmark_list.size(); i++) {
String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges();
// Limit the size of the line if too big.
if (line.length() > 50) {
line = line.substr(0, 50);
}
bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\"");
bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]);
}
}
void ScriptTextEditor::_bookmark_item_pressed(int p_idx) {
if (p_idx < 4) { // Any item before the separator.
_edit_option(bookmarks_menu->get_popup()->get_item_id(p_idx));
} else {
code_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx));
}
}
static Vector<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) { static Vector<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
Vector<Node *> nodes; Vector<Node *> nodes;
@@ -1054,7 +1091,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
String selected_text = code_editor->get_text_edit()->get_selection_text(); String selected_text = code_editor->get_text_edit()->get_selection_text();
// Yep, because it doesn't make sense to instance this dialog for every single script open... // Yep, because it doesn't make sense to instance this dialog for every single script open...
// So this will be delegated to the ScriptEditor // So this will be delegated to the ScriptEditor.
emit_signal("search_in_files_requested", selected_text); emit_signal("search_in_files_requested", selected_text);
} break; } break;
@@ -1220,6 +1257,8 @@ void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
void ScriptTextEditor::_bind_methods() { void ScriptTextEditor::_bind_methods() {
ClassDB::bind_method("_validate_script", &ScriptTextEditor::_validate_script); ClassDB::bind_method("_validate_script", &ScriptTextEditor::_validate_script);
ClassDB::bind_method("_update_bookmark_list", &ScriptTextEditor::_update_bookmark_list);
ClassDB::bind_method("_bookmark_item_pressed", &ScriptTextEditor::_bookmark_item_pressed);
ClassDB::bind_method("_load_theme_settings", &ScriptTextEditor::_load_theme_settings); ClassDB::bind_method("_load_theme_settings", &ScriptTextEditor::_load_theme_settings);
ClassDB::bind_method("_breakpoint_toggled", &ScriptTextEditor::_breakpoint_toggled); ClassDB::bind_method("_breakpoint_toggled", &ScriptTextEditor::_breakpoint_toggled);
ClassDB::bind_method("_lookup_connections", &ScriptTextEditor::_lookup_connections); ClassDB::bind_method("_lookup_connections", &ScriptTextEditor::_lookup_connections);
@@ -1670,18 +1709,16 @@ ScriptTextEditor::ScriptTextEditor() {
search_menu->get_popup()->connect("id_pressed", this, "_edit_option"); search_menu->get_popup()->connect("id_pressed", this, "_edit_option");
PopupMenu *bookmarks = memnew(PopupMenu);
bookmarks->set_name("bookmarks");
edit_menu->get_popup()->add_child(bookmarks);
edit_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "bookmarks");
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
bookmarks->connect("id_pressed", this, "_edit_option");
edit_hb->add_child(edit_menu); edit_hb->add_child(edit_menu);
bookmarks_menu = memnew(MenuButton);
edit_hb->add_child(bookmarks_menu);
bookmarks_menu->set_text(TTR("Bookmarks"));
bookmarks_menu->set_switch_on_hover(true);
_update_bookmark_list();
bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list");
bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed");
quick_open = memnew(ScriptEditorQuickOpen); quick_open = memnew(ScriptEditorQuickOpen);
add_child(quick_open); add_child(quick_open);
quick_open->connect("goto_line", this, "_goto_line"); quick_open->connect("goto_line", this, "_goto_line");

View File

@@ -70,6 +70,7 @@ class ScriptTextEditor : public ScriptEditorBase {
MenuButton *edit_menu; MenuButton *edit_menu;
MenuButton *search_menu; MenuButton *search_menu;
MenuButton *bookmarks_menu;
PopupMenu *highlighter_menu; PopupMenu *highlighter_menu;
PopupMenu *context_menu; PopupMenu *context_menu;
@@ -144,8 +145,9 @@ protected:
static void _code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options, bool &r_force); static void _code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options, bool &r_force);
void _breakpoint_toggled(int p_row); void _breakpoint_toggled(int p_row);
//no longer virtual void _validate_script(); // No longer virtual.
void _validate_script(); void _update_bookmark_list();
void _bookmark_item_pressed(int p_idx);
void _code_complete_script(const String &p_code, List<String> *r_options, bool &r_force); void _code_complete_script(const String &p_code, List<String> *r_options, bool &r_force);
void _load_theme_settings(); void _load_theme_settings();
void _set_theme_for_script(); void _set_theme_for_script();

View File

@@ -366,6 +366,9 @@ void ShaderEditor::_bind_methods() {
ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed); ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed);
ClassDB::bind_method("_text_edit_gui_input", &ShaderEditor::_text_edit_gui_input); ClassDB::bind_method("_text_edit_gui_input", &ShaderEditor::_text_edit_gui_input);
ClassDB::bind_method("_update_bookmark_list", &ShaderEditor::_update_bookmark_list);
ClassDB::bind_method("_bookmark_item_pressed", &ShaderEditor::_bookmark_item_pressed);
ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option); ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option);
ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed); ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed);
ClassDB::bind_method("apply_shaders", &ShaderEditor::apply_shaders); ClassDB::bind_method("apply_shaders", &ShaderEditor::apply_shaders);
@@ -465,6 +468,43 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
} }
} }
void ShaderEditor::_update_bookmark_list() {
bookmarks_menu->get_popup()->clear();
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
Array bookmark_list = shader_editor->get_text_edit()->get_bookmarks_array();
if (bookmark_list.size() == 0) {
return;
}
bookmarks_menu->get_popup()->add_separator();
for (int i = 0; i < bookmark_list.size(); i++) {
String line = shader_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges();
// Limit the size of the line if too big.
if (line.length() > 50) {
line = line.substr(0, 50);
}
bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\"");
bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]);
}
}
void ShaderEditor::_bookmark_item_pressed(int p_idx) {
if (p_idx < 4) { // Any item before the separator.
_menu_option(bookmarks_menu->get_popup()->get_item_id(p_idx));
} else {
shader_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx));
}
}
void ShaderEditor::_make_context_menu(bool p_selection) { void ShaderEditor::_make_context_menu(bool p_selection) {
context_menu->clear(); context_menu->clear();
@@ -483,6 +523,7 @@ void ShaderEditor::_make_context_menu(bool p_selection) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
context_menu->set_position(get_global_transform().xform(get_local_mouse_position())); context_menu->set_position(get_global_transform().xform(get_local_mouse_position()));
context_menu->set_size(Vector2(1, 1)); context_menu->set_size(Vector2(1, 1));
@@ -553,20 +594,18 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) {
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE);
search_menu->get_popup()->connect("id_pressed", this, "_menu_option"); search_menu->get_popup()->connect("id_pressed", this, "_menu_option");
PopupMenu *bookmarks = memnew(PopupMenu); bookmarks_menu = memnew(MenuButton);
bookmarks->set_name("bookmarks"); bookmarks_menu->set_text(TTR("Bookmarks"));
edit_menu->get_popup()->add_child(bookmarks); bookmarks_menu->set_switch_on_hover(true);
edit_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "bookmarks"); _update_bookmark_list();
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list");
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed");
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
bookmarks->connect("id_pressed", this, "_edit_option");
add_child(main_container); add_child(main_container);
main_container->add_child(hbc); main_container->add_child(hbc);
hbc->add_child(search_menu); hbc->add_child(search_menu);
hbc->add_child(edit_menu); hbc->add_child(edit_menu);
hbc->add_child(bookmarks_menu);
hbc->add_style_override("panel", p_node->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles")); hbc->add_style_override("panel", p_node->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles"));
main_container->add_child(shader_editor); main_container->add_child(shader_editor);

View File

@@ -97,6 +97,7 @@ class ShaderEditor : public PanelContainer {
MenuButton *edit_menu; MenuButton *edit_menu;
MenuButton *search_menu; MenuButton *search_menu;
MenuButton *bookmarks_menu;
MenuButton *settings_menu; MenuButton *settings_menu;
PopupMenu *context_menu; PopupMenu *context_menu;
uint64_t idle; uint64_t idle;
@@ -118,6 +119,9 @@ protected:
void _make_context_menu(bool p_selection); void _make_context_menu(bool p_selection);
void _text_edit_gui_input(const Ref<InputEvent> &ev); void _text_edit_gui_input(const Ref<InputEvent> &ev);
void _update_bookmark_list();
void _bookmark_item_pressed(int p_idx);
public: public:
void apply_shaders(); void apply_shaders();

View File

@@ -219,6 +219,43 @@ void TextEditor::_validate_script() {
emit_signal("edited_script_changed"); emit_signal("edited_script_changed");
} }
void TextEditor::_update_bookmark_list() {
bookmarks_menu->get_popup()->clear();
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT);
bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array();
if (bookmark_list.size() == 0) {
return;
}
bookmarks_menu->get_popup()->add_separator();
for (int i = 0; i < bookmark_list.size(); i++) {
String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges();
// Limit the size of the line if too big.
if (line.length() > 50) {
line = line.substr(0, 50);
}
bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\"");
bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]);
}
}
void TextEditor::_bookmark_item_pressed(int p_idx) {
if (p_idx < 4) { // Any item before the separator.
_edit_option(bookmarks_menu->get_popup()->get_item_id(p_idx));
} else {
code_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx));
}
}
void TextEditor::apply_code() { void TextEditor::apply_code() {
text_file->set_text(code_editor->get_text_edit()->get_text()); text_file->set_text(code_editor->get_text_edit()->get_text());
} }
@@ -466,6 +503,8 @@ void TextEditor::_convert_case(CodeTextEditor::CaseStyle p_case) {
void TextEditor::_bind_methods() { void TextEditor::_bind_methods() {
ClassDB::bind_method("_validate_script", &TextEditor::_validate_script); ClassDB::bind_method("_validate_script", &TextEditor::_validate_script);
ClassDB::bind_method("_update_bookmark_list", &TextEditor::_update_bookmark_list);
ClassDB::bind_method("_bookmark_item_pressed", &TextEditor::_bookmark_item_pressed);
ClassDB::bind_method("_load_theme_settings", &TextEditor::_load_theme_settings); ClassDB::bind_method("_load_theme_settings", &TextEditor::_load_theme_settings);
ClassDB::bind_method("_edit_option", &TextEditor::_edit_option); ClassDB::bind_method("_edit_option", &TextEditor::_edit_option);
ClassDB::bind_method("_change_syntax_highlighter", &TextEditor::_change_syntax_highlighter); ClassDB::bind_method("_change_syntax_highlighter", &TextEditor::_change_syntax_highlighter);
@@ -542,6 +581,7 @@ void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is
context_menu->add_separator(); context_menu->add_separator();
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);
if (p_selection) { if (p_selection) {
context_menu->add_separator(); context_menu->add_separator();
@@ -579,6 +619,7 @@ TextEditor::TextEditor() {
search_menu = memnew(MenuButton); search_menu = memnew(MenuButton);
edit_hb->add_child(search_menu); edit_hb->add_child(search_menu);
search_menu->set_text(TTR("Search")); search_menu->set_text(TTR("Search"));
search_menu->set_switch_on_hover(true);
search_menu->get_popup()->connect("id_pressed", this, "_edit_option"); search_menu->get_popup()->connect("id_pressed", this, "_edit_option");
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND);
@@ -593,6 +634,7 @@ TextEditor::TextEditor() {
edit_menu = memnew(MenuButton); edit_menu = memnew(MenuButton);
edit_menu->set_text(TTR("Edit")); edit_menu->set_text(TTR("Edit"));
edit_menu->set_switch_on_hover(true);
edit_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_menu->get_popup()->connect("id_pressed", this, "_edit_option");
edit_hb->add_child(edit_menu); edit_hb->add_child(edit_menu);
@@ -637,15 +679,13 @@ TextEditor::TextEditor() {
highlighter_menu->add_radio_check_item(TTR("Standard")); highlighter_menu->add_radio_check_item(TTR("Standard"));
highlighter_menu->connect("id_pressed", this, "_change_syntax_highlighter"); highlighter_menu->connect("id_pressed", this, "_change_syntax_highlighter");
PopupMenu *bookmarks = memnew(PopupMenu); bookmarks_menu = memnew(MenuButton);
bookmarks->set_name("bookmarks"); edit_hb->add_child(bookmarks_menu);
edit_menu->get_popup()->add_child(bookmarks); bookmarks_menu->set_text(TTR("Bookmarks"));
edit_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "bookmarks"); bookmarks_menu->set_switch_on_hover(true);
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); _update_bookmark_list();
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list");
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed");
bookmarks->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV);
bookmarks->connect("id_pressed", this, "_edit_option");
code_editor->get_text_edit()->set_drag_forwarding(this); code_editor->get_text_edit()->set_drag_forwarding(this);
} }

View File

@@ -46,6 +46,7 @@ private:
MenuButton *edit_menu; MenuButton *edit_menu;
PopupMenu *highlighter_menu; PopupMenu *highlighter_menu;
MenuButton *search_menu; MenuButton *search_menu;
MenuButton *bookmarks_menu;
PopupMenu *context_menu; PopupMenu *context_menu;
GotoLineDialog *goto_line_dialog; GotoLineDialog *goto_line_dialog;
@@ -110,6 +111,9 @@ protected:
void _validate_script(); void _validate_script();
void _update_bookmark_list();
void _bookmark_item_pressed(int p_idx);
public: public:
virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter); virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter);
virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter); virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter);