From e12b482022b6b78fcc07b79ff3aec1007aa57c1a Mon Sep 17 00:00:00 2001 From: Michael Alexsander Silva Dias Date: Tue, 21 May 2019 05:07:48 -0300 Subject: Improve bookmarks --- editor/plugins/script_text_editor.cpp | 59 +++++++++++++++++++++++++++------ editor/plugins/script_text_editor.h | 6 ++-- editor/plugins/shader_editor_plugin.cpp | 57 ++++++++++++++++++++++++++----- editor/plugins/shader_editor_plugin.h | 4 +++ editor/plugins/text_editor.cpp | 58 +++++++++++++++++++++++++++----- editor/plugins/text_editor.h | 4 +++ 6 files changed, 157 insertions(+), 31 deletions(-) (limited to 'editor') diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index ff0959c8a1..5688994c24 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -630,6 +630,43 @@ void ScriptTextEditor::_validate_script() { 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 _find_all_node_for_script(Node *p_base, Node *p_current, const Ref