GPv3: send notifiers and undo push when changing the active layer #110378

Merged
Pratik Borhade merged 7 commits from PratikPB2123/blender:gpv3-rna-prop-active-layer-index into main 2023-07-27 11:37:53 +02:00
1 changed files with 13 additions and 2 deletions

View File

@ -18,6 +18,8 @@
#include "RNA_access.h"
#include "RNA_prototypes.h"
#include "ED_undo.h"
#include <fmt/format.h>
namespace blender::ui::greasepencil {
@ -180,9 +182,18 @@ class LayerViewItem : public AbstractTreeViewItem {
return {};
}
void on_activate(bContext & /*C*/) override
void on_activate(bContext &C) override
{
this->grease_pencil_.set_active_layer(&layer_);
PointerRNA grease_pencil_ptr, value_ptr;
RNA_pointer_create(&grease_pencil_.id, &RNA_GreasePencilv3Layers, nullptr, &grease_pencil_ptr);
RNA_pointer_create(&grease_pencil_.id, &RNA_GreasePencilLayer, &layer_, &value_ptr);

Passing a value to the reference parameter is usually only needed for specific cases, is there any reason your doing this? Otherwise I'd prefer keeping this null, so it's clear that it's not needed (making further refactors to remove the argument easier).

Passing a value to the `reference` parameter is usually only needed for specific cases, is there any reason your doing this? Otherwise I'd prefer keeping this null, so it's clear that it's not needed (making further refactors to remove the argument easier).

Also, thinking about this, I think it's better to use RNA here, so that the message bus also gets notified about the change. Call RNA_property_pointer_set() and RNA_property_update() for this.

Also, thinking about this, I think it's better to use RNA here, so that the message bus also gets notified about the change. Call `RNA_property_pointer_set()` and `RNA_property_update()` for this.
PropertyRNA *prop = RNA_struct_find_property(&grease_pencil_ptr, "active");
RNA_property_pointer_set(&grease_pencil_ptr, prop, value_ptr, nullptr);
RNA_property_update(&C, &grease_pencil_ptr, prop);

View item buttons are not designed to control RNA properties. It just happens to work in this case because they reuse ui_apply_but_ROW() (which applies the value of but->hardmax which you set to the layer index here). But this is not intentional design and can break easily.

View item buttons are not designed to control RNA properties. It just happens to work in this case because they reuse `ui_apply_but_ROW()` (which applies the value of `but->hardmax` which you set to the layer index here). But this is not intentional design and can break easily.
ED_undo_push(&C, "Active Grease Pencil Layer");
}
bool supports_renaming() const override