summaryrefslogtreecommitdiff
path: root/editor/plugins/script_text_editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins/script_text_editor.cpp')
-rw-r--r--editor/plugins/script_text_editor.cpp59
1 files changed, 48 insertions, 11 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 9c57dd53f1..f705970d79 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -644,6 +644,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<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
Vector<Node *> nodes;
@@ -1092,7 +1129,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
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...
- // So this will be delegated to the ScriptEditor
+ // So this will be delegated to the ScriptEditor.
emit_signal("search_in_files_requested", selected_text);
} break;
@@ -1258,6 +1295,8 @@ void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
void ScriptTextEditor::_bind_methods() {
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("_breakpoint_toggled", &ScriptTextEditor::_breakpoint_toggled);
ClassDB::bind_method("_lookup_connections", &ScriptTextEditor::_lookup_connections);
@@ -1708,18 +1747,16 @@ ScriptTextEditor::ScriptTextEditor() {
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);
+ 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);
add_child(quick_open);
quick_open->connect("goto_line", this, "_goto_line");