diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 5f2a4d22693..1b4f77419b5 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -558,6 +558,8 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { set("text_editor/completion/auto_brace_complete", false); set("text_editor/files/restore_scripts_on_load", true); set("text_editor/completion/complete_file_paths", true); + set("text_editor/files/maximum_recent_files", 20); + hints["text_editor/files/maximum_recent_files"] = PropertyInfo(Variant::INT, "text_editor/files/maximum_recent_files", PROPERTY_HINT_RANGE, "1, 200, 0"); //set("docks/scene_tree/display_old_action_buttons",false); set("docks/scene_tree/start_create_dialog_fully_expanded", false); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 91e3170e321..fc2bcfa22b8 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -411,6 +411,80 @@ void ScriptEditor::_go_to_tab(int p_idx) { _update_selected_editor_menu(); } +void ScriptEditor::_add_recent_script(String p_path) { + + if (p_path.empty()) { + return; + } + + // remove if already stored + int already_recent = previous_scripts.find(p_path); + if (already_recent >= 0) { + previous_scripts.remove(already_recent); + } + + // add to list + previous_scripts.insert(0, p_path); + + _update_recent_scripts(); +} + +void ScriptEditor::_update_recent_scripts() { + + // make sure we don't exceed max size + const int max_history = EDITOR_DEF("text_editor/files/maximum_recent_files", 20); + if (previous_scripts.size() > max_history) { + previous_scripts.resize(max_history); + } + + recent_scripts->clear(); + + recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T)); + recent_scripts->add_separator(); + + const int max_shown = 8; + for (int i = 0; i < previous_scripts.size() && i <= max_shown; i++) { + String path = previous_scripts.get(i); + // just show script name and last dir + recent_scripts->add_item(path.get_slice("/", path.get_slice_count("/") - 2) + "/" + path.get_file()); + } + + recent_scripts->add_separator(); + recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Files"))); +} + +void ScriptEditor::_open_recent_script(int p_idx) { + + // clear button + if (p_idx == recent_scripts->get_item_count() - 1) { + previous_scripts.clear(); + _update_recent_scripts(); + return; + } + + // take two for the open recent button + if (p_idx > 0) { + p_idx -= 2; + } + + if (p_idx < previous_scripts.size() && p_idx >= 0) { + + String path = previous_scripts.get(p_idx); + // if its not on disk its a help file or deleted + if (FileAccess::exists(path)) { + Ref