Repository: godotengine/godot
File: editor/plugins/sprite_2d_editor_plugin.cpp (C++)

Code before:
	dragging_mode_hint->add_theme_color_override("font_shadow_color", Color(0.2f, 0.2f, 0.2f, 1));
	dragging_mode_hint->add_theme_constant_override("shadow_outline_size", 1 * EDSCALE);
	dragging_mode_hint->add_theme_constant_override("line_spacing", 0);
}

void Sprite2DEditorPlugin::_update_dragging_mode_hint(bool p_region_enabled) {
	if (p_region_enabled) {
		dragging_mode_hint->show();
	} else {
		dragging_mode_hint->hide();
	}
	dragging_mode_hint->set_text(TTRC("Drag and hold Ctrl + left mouse button  change the region_rect and position (when region_enabled is true).\nDrag and hold left mouse button to drag to modify the scale of the sprite.\nNote: Multiple frames are not supported yet."));
}

void Sprite2DEditorPlugin::edit(Object *p_object) {
	Callable update_text = callable_mp(this, &Sprite2DEditorPlugin::_update_dragging_mode_hint);
	StringName update_signal = SNAME("_editor_region_rect_enabled");

	Sprite2D *spr = sprite_editor->node;
	if (spr != nullptr && spr->is_connected(update_signal, update_text)) {
		spr->disconnect(update_signal, update_text);
	}

	spr = Object::cast_to<Sprite2D>(p_object);
	if (spr != nullptr) {
		sprite_editor->edit(spr);
		_update_dragging_mode_hint(spr->is_region_enabled());
		if (!spr->is_connected(update_signal, update_text)) {
			spr->connect(update_signal, update_text);
		}
	}
}

bool Sprite2DEditorPlugin::handles(Object *p_object) const {
	return p_object->is_class("Sprite2D");
}

void Sprite2DEditorPlugin::make_visible(bool p_visible) {
	if (p_visible) {
		sprite_editor->options->show();
	} else {
		sprite_editor->options->hide();
		dragging_mode_hint->hide();
		sprite_editor->edit(nullptr);
	}
}

Sprite2DEditorPlugin::Sprite2DEditorPlugin() {
	sprite_editor = memnew(Sprite2DEditor);
	EditorNode::get_singleton()->get_gui_base()->add_child(sprite_editor);
	sprite_editor->connect("theme_changed", callable_mp(this, &Sprite2DEditorPlugin::_editor_theme_changed));

Review comment (suggestion):
This needs to be outside the condition (to allow `edit(null)`.

Code after:
	dragging_mode_hint->add_theme_color_override("font_shadow_color", Color(0.2f, 0.2f, 0.2f, 1));
	dragging_mode_hint->add_theme_constant_override("shadow_outline_size", 1 * EDSCALE);
	dragging_mode_hint->add_theme_constant_override("line_spacing", 0);
}

void Sprite2DEditorPlugin::_update_dragging_mode_hint(bool p_region_enabled) {
	if (p_region_enabled) {
		dragging_mode_hint->show();
	} else {
		dragging_mode_hint->hide();
	}
}

void Sprite2DEditorPlugin::edit(Object *p_object) {
	Callable update_text = callable_mp(this, &Sprite2DEditorPlugin::_update_dragging_mode_hint);
	StringName update_signal = SNAME("_editor_region_rect_enabled");

	Sprite2D *spr = sprite_editor->node;
	if (spr != nullptr && spr->is_connected(update_signal, update_text)) {
		spr->disconnect(update_signal, update_text);
	}

	spr = Object::cast_to<Sprite2D>(p_object);
	sprite_editor->edit(spr);
	if (spr != nullptr) {
		_update_dragging_mode_hint(spr->is_editor_region_rect_draggable());
		if (!spr->is_connected(update_signal, update_text)) {
			spr->connect(update_signal, update_text);
		}
	}
}

bool Sprite2DEditorPlugin::handles(Object *p_object) const {
	return p_object->is_class("Sprite2D");
}

void Sprite2DEditorPlugin::make_visible(bool p_visible) {
	if (p_visible) {
		sprite_editor->options->show();
	} else {
		sprite_editor->options->hide();
		dragging_mode_hint->hide();
		sprite_editor->edit(nullptr);
	}
}

Sprite2DEditorPlugin::Sprite2DEditorPlugin() {
	sprite_editor = memnew(Sprite2DEditor);
	sprite_editor->connect(SceneStringName(theme_changed), callable_mp(this, &Sprite2DEditorPlugin::_editor_theme_changed));
	EditorNode::get_singleton()->get_gui_base()->add_child(sprite_editor);