Repository: godotengine/godot
File: editor/file_system/dependency_editor.cpp (C++)

Code before:
#include "scene/gui/margin_container.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/tree.h"

static void _setup_search_file_dialog(EditorFileDialog *p_dialog, const String &p_file, const String &p_type) {
	p_dialog->set_title(vformat(TTR("Search Replacement For: %s"), p_file.get_file()));

	// Set directory to closest existing directory.
	p_dialog->set_current_dir(p_file.get_base_dir());

	p_dialog->clear_filters();
	List<String> ext;
	ResourceLoader::get_recognized_extensions_for_type(p_type, &ext);
	for (const String &E : ext) {
		p_dialog->add_filter("*." + E);
	}
}

struct DependencyEditorSortByType {
	bool operator()(const String &p_a, const String &p_b) const {
		return DependencyEditor::sort_by_type(p_a, p_b, false);
	}
};

struct DependencyEditorSortByTypeReverse {
	bool operator()(const String &p_a, const String &p_b) const {
		return DependencyEditor::sort_by_type(p_a, p_b, true);
	}
};

struct DependencyEditorSortByPath {
	bool operator()(const String &p_a, const String &p_b) const {
		return DependencyEditor::sort_by_path(p_a, p_b, false);
	}
};

struct DependencyEditorSortByPathReverse {
	bool operator()(const String &p_a, const String &p_b) const {
		return DependencyEditor::sort_by_path(p_a, p_b, true);
	}
};

struct DependencyEditorSortByFile {
	bool operator()(const String &p_a, const String &p_b) const {
		return DependencyEditor::sort_by_file(p_a, p_b, false);
	}
};

struct DependencyEditorSortByFileReverse {
	bool operator()(const String &p_a, const String &p_b) const {

Review comment (suggestion):
I don't think you need separate structs for reverse sorting. Just sort normally and reverse the result, it should be the same (see how it's done in `file_info.cpp`).

Consequently, the static methods can be part of the structs.

Code after:
#include "scene/gui/margin_container.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/tree.h"

static void _setup_search_file_dialog(EditorFileDialog *p_dialog, const String &p_file, const String &p_type) {
	p_dialog->set_title(vformat(TTR("Search Replacement For: %s"), p_file.get_file()));

	// Set directory to closest existing directory.
	p_dialog->set_current_dir(p_file.get_base_dir());

	p_dialog->clear_filters();
	List<String> ext;
	ResourceLoader::get_recognized_extensions_for_type(p_type, &ext);
	for (const String &E : ext) {
		p_dialog->add_filter("*." + E);
	}
}

struct DependencyEditorSortByType {
	bool operator()(const String &p_a, const String &p_b) const {
		const String a_type = p_a.contains("::") ? p_a.get_slice("::", 1) : "Resource";
		const String b_type = p_b.contains("::") ? p_b.get_slice("::", 1) : "Resource";
		const String a_path = p_a.contains("::") ? p_a.get_slice("::", 2) : p_a;
		const String b_path = p_b.contains("::") ? p_b.get_slice("::", 2) : p_b;
		return a_type == b_type ? a_path < b_path : a_type < b_type;
	}
};

struct DependencyEditorSortByPath {
	bool operator()(const String &p_a, const String &p_b) const {
		const String a_path = p_a.contains("::") ? p_a.get_slice("::", 2) : p_a;
		const String b_path = p_b.contains("::") ? p_b.get_slice("::", 2) : p_b;
		return a_path < b_path;
	}
};

struct DependencyEditorSortByFile {
	bool operator()(const String &p_a, const String &p_b) const {
		const String a_path = p_a.contains("::") ? p_a.get_slice("::", 2) : p_a;
		const String b_path = p_b.contains("::") ? p_b.get_slice("::", 2) : p_b;
		const String a_file = a_path.get_file();
		const String b_file = b_path.get_file();
		return a_file == b_file ? a_path < b_path : a_file < b_file;
	}
};

void DependencyEditor::_searched(const String &p_path) {
	HashMap<String, String> dep_rename;
	dep_rename[replacing] = p_path;