ronantakizawa/codereview-bench huggingface dataset:
Repository: godotengine/godot
File: editor/scene/texture/texture_editor_plugin.h (C/C++)

Code before:
private:
	struct ThemeCache {
		Color outline_color;
	} theme_cache;

	TextureRect *texture_display = nullptr;

	MarginContainer *margin_container = nullptr;
	Control *outline_overlay = nullptr;
	AspectRatioContainer *centering_container = nullptr;
	ColorRect *bg_rect = nullptr;
	TextureRect *checkerboard = nullptr;
	Label *metadata_label = nullptr;
	Ref<ShaderMaterial> material;

	ColorChannelSelector *channel_selector = nullptr;
	SpinBox *mipmap_spinbox = nullptr;

	void _draw_outline();
	void _update_metadata_label_text();

protected:
	void _notification(int p_what);
	void _update_texture_display_ratio();
	void on_selected_channels_changed();
	void on_selected_mipmap_changed(double);

public:
	TextureRect *get_texture_display();
	TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata);
};

class EditorInspectorPluginTexture : public EditorInspectorPlugin {
	GDCLASS(EditorInspectorPluginTexture, EditorInspectorPlugin);

private:
	Ref<Image> this_image;

public:
	virtual bool can_handle(Object *p_object) override;
	virtual void parse_begin(Object *p_object) override;
};

class TextureEditorPlugin : public EditorPlugin {
	GDCLASS(TextureEditorPlugin, EditorPlugin);

public:
	virtual String get_plugin_name() const override { return "Texture2D"; }

	TextureEditorPlugin();
};

Review comment (suggestion):
```suggestion
	void on_selected_mipmap_changed(double p_value);
```
Should be descriptive, even if unused 

Code after:
	struct ThemeCache {
		Color outline_color;
	} theme_cache;

	TextureRect *texture_display = nullptr;

	MarginContainer *margin_container = nullptr;
	Control *outline_overlay = nullptr;
	AspectRatioContainer *centering_container = nullptr;
	ColorRect *bg_rect = nullptr;
	TextureRect *checkerboard = nullptr;
	Label *metadata_label = nullptr;

	static inline Ref<ShaderMaterial> texture_material;

	ColorChannelSelector *channel_selector = nullptr;
	SpinBox *mipmap_spinbox = nullptr;

	void _draw_outline();
	void _update_metadata_label_text();

protected:
	void _notification(int p_what);
	void _update_texture_display_ratio();
	void on_selected_channels_changed();
	void on_selected_mipmap_changed(double p_value);

public:
	static void init_shaders();
	static void finish_shaders();

	TextureRect *get_texture_display();
	TexturePreview(Ref<Texture2D> p_texture, bool p_show_metadata);
};

class EditorInspectorPluginTexture : public EditorInspectorPlugin {
	GDCLASS(EditorInspectorPluginTexture, EditorInspectorPlugin);

	Ref<Image> this_image;

public:
	virtual bool can_handle(Object *p_object) override;
	virtual void parse_begin(Object *p_object) override;
};

class TextureEditorPlugin : public EditorPlugin {
	GDCLASS(TextureEditorPlugin, EditorPlugin);

public:
	virtual String get_plugin_name() const override { return "Texture2D"; }
Repository: godotengine/godot
File: editor/docks/filesystem_dock.h (C/C++)

Code before:
	PopupMenu *file_list_popup = nullptr;
	PopupMenu *tree_popup = nullptr;

	DependencyEditor *deps_editor = nullptr;
	DependencyEditorOwners *owners_editor = nullptr;
	DependencyRemoveDialog *remove_dialog = nullptr;

	EditorDirDialog *move_dialog = nullptr;
	DirectoryCreateDialog *make_dir_dialog = nullptr;

	ConfirmationDialog *overwrite_dialog = nullptr;
	ScrollContainer *overwrite_dialog_scroll = nullptr;
	Label *overwrite_dialog_header = nullptr;
	Label *overwrite_dialog_footer = nullptr;
	Label *overwrite_dialog_file_list = nullptr;

	ConfirmationDialog *conversion_dialog = nullptr;
	ConfirmationDialog *move_confirm_dialog = nullptr;

	SceneCreateDialog *make_scene_dialog = nullptr;
	ScriptCreateDialog *make_script_dialog = nullptr;
	ShaderCreateDialog *make_shader_dialog = nullptr;
	CreateDialog *new_resource_dialog = nullptr;

	String confirm_move_to_dir;
	bool confirm_to_copy;

	bool always_show_folders = false;
	int thumbnail_size_setting = 0;

	bool editor_is_dark_theme = false;

	class FileOrFolder {
	public:
		String path;
		bool is_file = false;

		FileOrFolder() {}
		FileOrFolder(const String &p_path, bool p_is_file) :
				path(p_path),
				is_file(p_is_file) {}
	};
	FileOrFolder to_rename;
	FileOrFolder to_duplicate;
	Vector<FileOrFolder> to_move;
	String to_move_path;
	bool to_move_or_copy = false;

	Vector<String> to_convert;
	int selected_conversion_id = 0;


Review comment (suggestion):
```suggestion
	bool confirm_to_copy = false;
```
Or some appropriate default

Code after:
	PopupMenu *file_list_popup = nullptr;
	PopupMenu *tree_popup = nullptr;

	DependencyEditor *deps_editor = nullptr;
	DependencyEditorOwners *owners_editor = nullptr;
	DependencyRemoveDialog *remove_dialog = nullptr;

	EditorDirDialog *move_dialog = nullptr;
	DirectoryCreateDialog *make_dir_dialog = nullptr;

	ConfirmationDialog *overwrite_dialog = nullptr;
	ScrollContainer *overwrite_dialog_scroll = nullptr;
	Label *overwrite_dialog_header = nullptr;
	Label *overwrite_dialog_footer = nullptr;
	Label *overwrite_dialog_file_list = nullptr;

	ConfirmationDialog *conversion_dialog = nullptr;
	ConfirmationDialog *move_confirm_dialog = nullptr;

	SceneCreateDialog *make_scene_dialog = nullptr;
	ScriptCreateDialog *make_script_dialog = nullptr;
	ShaderCreateDialog *make_shader_dialog = nullptr;
	CreateDialog *new_resource_dialog = nullptr;

	String confirm_move_to_dir;
	bool confirm_to_copy = false;

	bool always_show_folders = false;
	int thumbnail_size_setting = 0;

	bool editor_is_dark_theme = false;

	class FileOrFolder {
	public:
		String path;
		bool is_file = false;

		FileOrFolder() {}
		FileOrFolder(const String &p_path, bool p_is_file) :
				path(p_path),
				is_file(p_is_file) {}
	};
	FileOrFolder to_rename;
	FileOrFolder to_duplicate;
	Vector<FileOrFolder> to_move;
	String to_move_path;
	bool to_move_or_copy = false;

	Vector<String> to_convert;
	int selected_conversion_id = 0;
Repository: godotengine/godot
File: editor/docks/node_dock.cpp (C++)

Code before:
	mode_hb->add_child(connections_button);
	connections_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_connections));

	groups_button = memnew(Button);
	groups_button->set_theme_type_variation(SceneStringName(FlatButton));
	groups_button->set_text(TTRC("Groups"));
	groups_button->set_toggle_mode(true);
	groups_button->set_pressed(false);
	groups_button->set_h_size_flags(SIZE_EXPAND_FILL);
	groups_button->set_clip_text(true);
	mode_hb->add_child(groups_button);
	groups_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_groups));

	connections = memnew(ConnectionsDock);
	add_child(connections);
	connections->set_v_size_flags(SIZE_EXPAND_FILL);
	connections->hide();

	groups = memnew(GroupsEditor);
	add_child(groups);
	groups->set_v_size_flags(SIZE_EXPAND_FILL);
	groups->hide();

	select_a_node = memnew(Label);
	select_a_node->set_focus_mode(FOCUS_ACCESSIBILITY);
	select_a_node->set_text(TTRC("Select a single node to edit its signals and groups, or select an independent resource to edit its signals."));
	select_a_node->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
	select_a_node->set_v_size_flags(SIZE_EXPAND_FILL);
	select_a_node->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
	select_a_node->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
	select_a_node->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
	add_child(select_a_node);
}

NodeDock::~NodeDock() {
	singleton = nullptr;
}


Review comment (suggestion):
```suggestion
	select_a_node->set_text(TTRC("Select a single node to edit its signals and groups, or select an independent resource to show its signals."));
```

Code after:
	groups_button->set_toggle_mode(true);
	groups_button->set_pressed(false);
	groups_button->set_h_size_flags(SIZE_EXPAND_FILL);
	groups_button->set_clip_text(true);
	mode_hb->add_child(groups_button);
	groups_button->connect(SceneStringName(pressed), callable_mp(this, &NodeDock::show_groups));

	connections = memnew(ConnectionsDock);
	add_child(connections);
	connections->set_v_size_flags(SIZE_EXPAND_FILL);
	connections->hide();

	groups = memnew(GroupsEditor);
	add_child(groups);
	groups->set_v_size_flags(SIZE_EXPAND_FILL);
	groups->hide();

	select_a_node = memnew(Label);
	select_a_node->set_focus_mode(FOCUS_ACCESSIBILITY);
	select_a_node->set_text(TTRC("Select a single node to edit its signals and groups, or select an independent resource to view its signals."));
	select_a_node->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
	select_a_node->set_v_size_flags(SIZE_EXPAND_FILL);
	select_a_node->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
	select_a_node->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
	select_a_node->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
	add_child(select_a_node);
}

NodeDock::~NodeDock() {
	singleton = nullptr;
}
Repository: godotengine/godot
File: editor/docks/node_dock.cpp (C++)

Code before:
			groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
		} break;
	}
}

void NodeDock::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
	ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
}

void NodeDock::update_lists() {
	connections->update_tree();
}

void NodeDock::set_object(Object *p_object) {
	connections->set_object(p_object);
	groups->set_current(cast_to<Node>(p_object));

	if (p_object) {
		if (connections_button->is_pressed()) {
			connections->show();
		} else {
			groups->show();
		}

		if (p_object->is_class("Resource")) {
			show_connections();
			connections_button->hide();
			groups_button->hide();
			set_name("Resource");
		} else {
			connections_button->show();
			groups_button->show();
			set_name("Node");
		}

		mode_hb->show();
		select_a_node->hide();
	} else {
		connections_button->show();
		groups_button->show();
		connections->hide();
		groups->hide();
		mode_hb->hide();
		select_a_node->show();
	}
}

NodeDock::NodeDock() {
	singleton = this;


Review comment (suggestion):
```suggestion
		if (Object::cast_to<Resource>(p_object)) {
```

Code after:
			groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
		} break;
	}
}

void NodeDock::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
	ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
}

void NodeDock::update_lists() {
	connections->update_tree();
}

void NodeDock::set_object(Object *p_object) {
	connections->set_object(p_object);
	groups->set_current(Object::cast_to<Node>(p_object));

	if (p_object) {
		if (connections_button->is_pressed()) {
			connections->show();
		} else {
			groups->show();
		}

		if (Object::cast_to<Resource>(p_object)) {
			show_connections();
			groups_button->set_disabled(true);
		} else {
			groups_button->set_disabled(false);
		}

		mode_hb->show();
		select_a_node->hide();
	} else {
		connections->hide();
		groups->hide();
		mode_hb->hide();
		select_a_node->show();
	}
}

NodeDock::NodeDock() {
	singleton = this;

	set_name("Node");
	mode_hb = memnew(HBoxContainer);
	add_child(mode_hb);
	mode_hb->hide();

	connections_button = memnew(Button);
Repository: godotengine/godot
File: editor/docks/node_dock.cpp (C++)

Code before:

void NodeDock::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
	ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
}

void NodeDock::update_lists() {
	connections->update_tree();
}

void NodeDock::set_object(Object *p_object) {
	connections->set_object(p_object);
	groups->set_current(cast_to<Node>(p_object));

	if (p_object) {
		if (connections_button->is_pressed()) {
			connections->show();
		} else {
			groups->show();
		}

		if (p_object->is_class("Resource")) {
			show_connections();
			connections_button->hide();
			groups_button->hide();
			set_name("Resource");
		} else {
			connections_button->show();
			groups_button->show();
			set_name("Node");
		}

		mode_hb->show();
		select_a_node->hide();
	} else {
		connections_button->show();
		groups_button->show();
		connections->hide();
		groups->hide();
		mode_hb->hide();
		select_a_node->show();
	}
}

NodeDock::NodeDock() {
	singleton = this;

	set_name("Node");
	mode_hb = memnew(HBoxContainer);
	add_child(mode_hb);
	mode_hb->hide();

Review comment (suggestion):
```suggestion
			set_name(TTRC("Resource"));
```
Same below.

Code after:

void NodeDock::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
	ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
}

void NodeDock::update_lists() {
	connections->update_tree();
}

void NodeDock::set_object(Object *p_object) {
	connections->set_object(p_object);
	groups->set_current(Object::cast_to<Node>(p_object));

	if (p_object) {
		if (connections_button->is_pressed()) {
			connections->show();
		} else {
			groups->show();
		}

		if (Object::cast_to<Resource>(p_object)) {
			show_connections();
			groups_button->set_disabled(true);
		} else {
			groups_button->set_disabled(false);
		}

		mode_hb->show();
		select_a_node->hide();
	} else {
		connections->hide();
		groups->hide();
		mode_hb->hide();
		select_a_node->show();
	}
}

NodeDock::NodeDock() {
	singleton = this;

	set_name("Node");
	mode_hb = memnew(HBoxContainer);
	add_child(mode_hb);
	mode_hb->hide();

	connections_button = memnew(Button);
	connections_button->set_theme_type_variation(SceneStringName(FlatButton));
	connections_button->set_text(TTRC("Signals"));
	connections_button->set_toggle_mode(true);
	connections_button->set_pressed(true);
Repository: godotengine/godot
File: editor/docks/node_dock.cpp (C++)

Code before:
	} else if (current_tab == 1) {
		show_groups();
	}
}

void NodeDock::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED: {
			connections_button->set_button_icon(get_editor_theme_icon(SNAME("Signals")));
			groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
		} break;
	}
}

void NodeDock::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
	ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
}

void NodeDock::update_lists() {
	connections->update_tree();
}

void NodeDock::set_object(Object *p_object) {
	connections->set_object(p_object);
	groups->set_current(cast_to<Node>(p_object));

	if (p_object) {
		if (connections_button->is_pressed()) {
			connections->show();
		} else {
			groups->show();
		}

		if (Object::cast_to<Resource>(p_object)) {
			show_connections();
			groups_button->set_disabled(true);
		} else {
			groups_button->set_disabled(false);
		}

		mode_hb->show();
		select_a_node->hide();
	} else {
		connections->hide();
		groups->hide();
		mode_hb->hide();
		select_a_node->show();
	}
}


Review comment (suggestion):
```suggestion
	groups->set_current(Object::cast_to<Node>(p_object));
```
Please call this static method as a static method

Code after:
	} else if (current_tab == 1) {
		show_groups();
	}
}

void NodeDock::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED: {
			connections_button->set_button_icon(get_editor_theme_icon(SNAME("Signals")));
			groups_button->set_button_icon(get_editor_theme_icon(SNAME("Groups")));
		} break;
	}
}

void NodeDock::_bind_methods() {
	ClassDB::bind_method(D_METHOD("_save_layout_to_config"), &NodeDock::_save_layout_to_config);
	ClassDB::bind_method(D_METHOD("_load_layout_from_config"), &NodeDock::_load_layout_from_config);
}

void NodeDock::update_lists() {
	connections->update_tree();
}

void NodeDock::set_object(Object *p_object) {
	connections->set_object(p_object);
	groups->set_current(Object::cast_to<Node>(p_object));

	if (p_object) {
		if (connections_button->is_pressed()) {
			connections->show();
		} else {
			groups->show();
		}

		if (Object::cast_to<Resource>(p_object)) {
			show_connections();
			groups_button->set_disabled(true);
		} else {
			groups_button->set_disabled(false);
		}

		mode_hb->show();
		select_a_node->hide();
	} else {
		connections->hide();
		groups->hide();
		mode_hb->hide();
		select_a_node->show();
	}
}
Repository: godotengine/godot
File: editor/scene/connections_dialog.cpp (C++)

Code before:
		}
	}
	emit_signal(SNAME("connected"));
	hide();
}

void ConnectDialog::_cancel_pressed() {
	hide();
}

void ConnectDialog::_item_activated() {
	_ok_pressed(); // From AcceptDialog.
}

/*
 * Called each time a target node is selected within the target node tree.
 */
void ConnectDialog::_tree_node_selected() {
	Node *current = tree->get_selected();

	if (!current) {
		return;
	}

	if (!source->is_class("Resource")) {
		dst_path = Object::cast_to<Node>(source)->get_path_to(current);
	}

	if (!edit_mode) {
		set_dst_method(generate_method_callback_name(source, signal, current));
	}

	cdbinds->update_base_node_relative(current);

	_update_method_tree();
	_update_warning_label();
	_update_ok_enabled();
}

void ConnectDialog::_focus_currently_connected() {
	tree->set_selected(Object::cast_to<Node>(source));
}

void ConnectDialog::_unbind_count_changed(double p_count) {
	for (Control *control : bind_controls) {
		BaseButton *b = Object::cast_to<BaseButton>(control);
		if (b) {
			b->set_disabled(p_count > 0);
		}

		EditorInspector *e = Object::cast_to<EditorInspector>(control);

Review comment (suggestion):
```suggestion
	Node *source_node = Object::cast_to<Node>(source);
	if (source_node) {
		dst_path = source_node->get_path_to(current);
```
`is_class()` should be avoided.

Code after:
		}
	}
	emit_signal(SNAME("connected"));
	hide();
}

void ConnectDialog::_cancel_pressed() {
	hide();
}

void ConnectDialog::_item_activated() {
	_ok_pressed(); // From AcceptDialog.
}

/*
 * Called each time a target node is selected within the target node tree.
 */
void ConnectDialog::_tree_node_selected() {
	Node *current = tree->get_selected();

	if (!current) {
		return;
	}

	Node *source_node = Object::cast_to<Node>(source);
	if (source_node) {
		dst_path = source_node->get_path_to(current);
	}

	if (!edit_mode) {
		set_dst_method(generate_method_callback_name(source, signal, current));
	}

	cdbinds->update_base_node_relative(current);

	_update_method_tree();
	_update_warning_label();
	_update_ok_enabled();
}

void ConnectDialog::_focus_currently_connected() {
	tree->set_selected(Object::cast_to<Node>(source));
}

void ConnectDialog::_unbind_count_changed(double p_count) {
	for (Control *control : bind_controls) {
		BaseButton *b = Object::cast_to<BaseButton>(control);
		if (b) {
			b->set_disabled(p_count > 0);
		}
Repository: godotengine/godot
File: scene/resources/resource_format_text.cpp (C++)

Code before:
	loader.get_classes_used(r_classes);
}

String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
	if (p_path.has_extension("tscn")) {
		return "PackedScene";
	} else if (!p_path.has_extension("tres")) {
		return String();
	}

	// ...for anything else must test...

	Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
	if (f.is_null()) {
		return ""; //could not read
	}

	ResourceLoaderText loader;
	loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
	loader.res_path = loader.local_path;
	String r = loader.recognize(f);
	return ClassDB::get_compatibility_remapped_class(r);
}

String ResourceFormatLoaderText::get_resource_script_class(const String &p_path) const {
	if (p_path.has_extension("tres")) {
		return String();
	}

	// ...for anything else must test...

	Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
	if (f.is_null()) {
		return ""; //could not read
	}

	ResourceLoaderText loader;
	loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
	loader.res_path = loader.local_path;
	return loader.recognize_script_class(f);
}

ResourceUID::ID ResourceFormatLoaderText::get_resource_uid(const String &p_path) const {
	if (p_path.has_extension("tscn") && !p_path.has_extension("tres")) {
		return ResourceUID::INVALID_ID;
	}

	Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
	if (f.is_null()) {
		return ResourceUID::INVALID_ID; //could not read
	}

Review comment (suggestion):
```suggestion
	if (!p_path.has_extension("tres")) {
```
Typo

Code after:
	loader.get_classes_used(r_classes);
}

String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
	const String ext = p_path.get_extension().to_lower();
	if (ext == "tscn") {
		return "PackedScene";
	} else if (ext != "tres") {
		return String();
	}

	// ...for anything else must test...

	Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
	if (f.is_null()) {
		return ""; //could not read
	}

	ResourceLoaderText loader;
	loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
	loader.res_path = loader.local_path;
	String r = loader.recognize(f);
	return ClassDB::get_compatibility_remapped_class(r);
}

String ResourceFormatLoaderText::get_resource_script_class(const String &p_path) const {
	if (!p_path.has_extension("tres")) {
		return String();
	}

	// ...for anything else must test...

	Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
	if (f.is_null()) {
		return ""; //could not read
	}

	ResourceLoaderText loader;
	loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path);
	loader.res_path = loader.local_path;
	return loader.recognize_script_class(f);
}

ResourceUID::ID ResourceFormatLoaderText::get_resource_uid(const String &p_path) const {
	const String ext = p_path.get_extension().to_lower();
	if (ext != "tscn" && ext != "tres") {
		return ResourceUID::INVALID_ID;
	}

	Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
	if (f.is_null()) {