Optimize SceneTree's `change_scene_to_file` autocompletion
This commit is contained in:
parent
8e951fd0a9
commit
7b3e1a5bde
|
@ -828,17 +828,21 @@ static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_functio
|
||||||
return arghint;
|
return arghint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _get_directory_contents(EditorFileSystemDirectory *p_dir, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_list) {
|
static void _get_directory_contents(EditorFileSystemDirectory *p_dir, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_list, const StringName &p_required_type = StringName()) {
|
||||||
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
|
const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
|
||||||
|
const bool requires_type = p_required_type;
|
||||||
|
|
||||||
for (int i = 0; i < p_dir->get_file_count(); i++) {
|
for (int i = 0; i < p_dir->get_file_count(); i++) {
|
||||||
|
if (requires_type && !ClassDB::is_parent_class(p_dir->get_file_type(i), p_required_type)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ScriptLanguage::CodeCompletionOption option(p_dir->get_file_path(i), ScriptLanguage::CODE_COMPLETION_KIND_FILE_PATH);
|
ScriptLanguage::CodeCompletionOption option(p_dir->get_file_path(i), ScriptLanguage::CODE_COMPLETION_KIND_FILE_PATH);
|
||||||
option.insert_text = option.display.quote(quote_style);
|
option.insert_text = option.display.quote(quote_style);
|
||||||
r_list.insert(option.display, option);
|
r_list.insert(option.display, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
|
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
|
||||||
_get_directory_contents(p_dir->get_subdir(i), r_list);
|
_get_directory_contents(p_dir->get_subdir(i), r_list, p_required_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2803,6 +2807,16 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||||
r_result.insert(option.display, option);
|
r_result.insert(option.display, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (EDITOR_GET("text_editor/completion/complete_file_paths")) {
|
||||||
|
if (p_argidx == 0 && p_method == SNAME("change_scene_to_file") && ClassDB::is_parent_class(class_name, SNAME("SceneTree"))) {
|
||||||
|
HashMap<String, ScriptLanguage::CodeCompletionOption> list;
|
||||||
|
_get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), list, SNAME("PackedScene"));
|
||||||
|
for (const KeyValue<String, ScriptLanguage::CodeCompletionOption> &key_value_pair : list) {
|
||||||
|
ScriptLanguage::CodeCompletionOption option = key_value_pair.value;
|
||||||
|
r_result.insert(option.display, option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
base_type.kind = GDScriptParser::DataType::UNRESOLVED;
|
base_type.kind = GDScriptParser::DataType::UNRESOLVED;
|
||||||
} break;
|
} break;
|
||||||
|
|
|
@ -1693,45 +1693,16 @@ void SceneTree::add_idle_callback(IdleCallback p_callback) {
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
void SceneTree::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
|
void SceneTree::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
|
||||||
const String pf = p_function;
|
const String pf = p_function;
|
||||||
if (pf == "change_scene_to_file") {
|
bool add_options = false;
|
||||||
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
if (p_idx == 0) {
|
||||||
List<String> directories;
|
add_options = pf == "get_nodes_in_group" || pf == "has_group" || pf == "get_first_node_in_group" || pf == "set_group" || pf == "notify_group" || pf == "call_group" || pf == "add_to_group";
|
||||||
directories.push_back(dir_access->get_current_dir());
|
} else if (p_idx == 1) {
|
||||||
|
add_options = pf == "set_group_flags" || pf == "call_group_flags" || pf == "notify_group_flags";
|
||||||
while (!directories.is_empty()) {
|
}
|
||||||
dir_access->change_dir(directories.back()->get());
|
if (add_options) {
|
||||||
directories.pop_back();
|
HashMap<StringName, String> global_groups = ProjectSettings::get_singleton()->get_global_groups_list();
|
||||||
|
for (const KeyValue<StringName, String> &E : global_groups) {
|
||||||
dir_access->list_dir_begin();
|
r_options->push_back(E.key.operator String().quote());
|
||||||
String filename = dir_access->get_next();
|
|
||||||
|
|
||||||
while (!filename.is_empty()) {
|
|
||||||
if (filename == "." || filename == "..") {
|
|
||||||
filename = dir_access->get_next();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dir_access->dir_exists(filename)) {
|
|
||||||
directories.push_back(dir_access->get_current_dir().path_join(filename));
|
|
||||||
} else if (filename.ends_with(".tscn") || filename.ends_with(".scn")) {
|
|
||||||
r_options->push_back("\"" + dir_access->get_current_dir().path_join(filename) + "\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
filename = dir_access->get_next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bool add_options = false;
|
|
||||||
if (p_idx == 0) {
|
|
||||||
add_options = pf == "get_nodes_in_group" || pf == "has_group" || pf == "get_first_node_in_group" || pf == "set_group" || pf == "notify_group" || pf == "call_group" || pf == "add_to_group";
|
|
||||||
} else if (p_idx == 1) {
|
|
||||||
add_options = pf == "set_group_flags" || pf == "call_group_flags" || pf == "notify_group_flags";
|
|
||||||
}
|
|
||||||
if (add_options) {
|
|
||||||
HashMap<StringName, String> global_groups = ProjectSettings::get_singleton()->get_global_groups_list();
|
|
||||||
for (const KeyValue<StringName, String> &E : global_groups) {
|
|
||||||
r_options->push_back(E.key.operator String().quote());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainLoop::get_argument_options(p_function, p_idx, r_options);
|
MainLoop::get_argument_options(p_function, p_idx, r_options);
|
||||||
|
|
Loading…
Reference in New Issue