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

Code before:
	undo_redo->add_undo_method(gradient.ptr(), "set_colors", gradient->get_colors());
	undo_redo->add_undo_method(gradient.ptr(), "set_interpolation_mode", gradient->get_interpolation_mode());
	undo_redo->commit_action();
	editing = false;
}

void GradientEditor::_bind_methods() {
}

void GradientEditor::set_gradient(const Ref<Gradient> &p_gradient) {
	gradient = p_gradient;
	connect("ramp_changed", callable_mp(this, &GradientEditor::_ramp_changed));
	gradient->connect("changed", callable_mp(this, &GradientEditor::_gradient_changed));
	set_points(gradient->get_points());
	set_interpolation_mode(gradient->get_interpolation_mode());
}

void GradientEditor::reverse_gradient() {
	gradient->reverse();
	set_points(gradient->get_points());
	emit_signal(SNAME("ramp_changed"));
	update();
}

GradientEditor::GradientEditor() {
	editing = false;
}

///////////////////////

void GradientReverseButton::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_DRAW: {
			Ref<Texture2D> icon = get_theme_icon(SNAME("ReverseGradient"), SNAME("EditorIcons"));
			if (is_pressed()) {
				draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height()), false, get_theme_color(SNAME("icon_pressed_color"), SNAME("Button")));
			} else {
				draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height()));
			}
		} break;
	}
}

Size2 GradientReverseButton::get_minimum_size() const {
	return (get_theme_icon(SNAME("ReverseGradient"), SNAME("EditorIcons"))->get_size() + Size2(margin * 2, margin * 2));
}

///////////////////////

bool EditorInspectorPluginGradient::can_handle(Object *p_object) {
	return Object::cast_to<Gradient>(p_object) != nullptr;

Review comment (suggestion):
```suggestion
	get_popup()->connect("about_to_popup", callable_mp(EditorNode::get_singleton(), &EditorNode::setup_color_picker), varray(GradientEdit::get_picker()));
```
Not necessary.

Code after:
	undo_redo->add_undo_method(gradient.ptr(), "set_colors", gradient->get_colors());
	undo_redo->add_undo_method(gradient.ptr(), "set_interpolation_mode", gradient->get_interpolation_mode());
	undo_redo->commit_action();
	editing = false;
}

void GradientEditor::_bind_methods() {
}

void GradientEditor::set_gradient(const Ref<Gradient> &p_gradient) {
	gradient = p_gradient;
	connect("ramp_changed", callable_mp(this, &GradientEditor::_ramp_changed));
	gradient->connect("changed", callable_mp(this, &GradientEditor::_gradient_changed));
	set_points(gradient->get_points());
	set_interpolation_mode(gradient->get_interpolation_mode());
}

void GradientEditor::reverse_gradient() {
	gradient->reverse();
	set_points(gradient->get_points());
	emit_signal(SNAME("ramp_changed"));
	update();
}

GradientEditor::GradientEditor() {
	GradientEdit::get_popup()->connect("about_to_popup", callable_mp(EditorNode::get_singleton(), &EditorNode::setup_color_picker), varray(GradientEdit::get_picker()));
	editing = false;
}

///////////////////////

void GradientReverseButton::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_DRAW: {
			Ref<Texture2D> icon = get_theme_icon(SNAME("ReverseGradient"), SNAME("EditorIcons"));
			if (is_pressed()) {
				draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height()), false, get_theme_color(SNAME("icon_pressed_color"), SNAME("Button")));
			} else {
				draw_texture_rect(icon, Rect2(margin, margin, icon->get_width(), icon->get_height()));
			}
		} break;
	}
}

Size2 GradientReverseButton::get_minimum_size() const {
	return (get_theme_icon(SNAME("ReverseGradient"), SNAME("EditorIcons"))->get_size() + Size2(margin * 2, margin * 2));
}

///////////////////////

bool EditorInspectorPluginGradient::can_handle(Object *p_object) {