Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface/interface_ops.c')
-rw-r--r--source/blender/editors/interface/interface_ops.c81
1 files changed, 77 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index f2b2a478ba9..f5a894d7620 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -65,6 +65,9 @@
#include "ED_object.h"
#include "ED_paint.h"
+/* for Copy As Driver */
+#include "ED_keyframing.h"
+
/* only for UI_OT_editsource */
#include "ED_screen.h"
#include "BKE_main.h"
@@ -153,23 +156,92 @@ static void UI_OT_copy_data_path_button(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-static bool copy_python_command_button_poll(bContext *C)
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Copy As Driver Operator
+ * \{ */
+
+static bool copy_as_driver_button_poll(bContext *C)
{
- uiBut *but = UI_context_active_but_get(C);
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ char *path;
+ int index;
- if (but && (but->optype != NULL)) {
- return 1;
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ if (ptr.id.data && ptr.data && prop &&
+ ELEM(RNA_property_type(prop), PROP_BOOLEAN, PROP_INT, PROP_FLOAT, PROP_ENUM)) {
+ path = RNA_path_from_ID_to_property(&ptr, prop);
+
+ if (path) {
+ MEM_freeN(path);
+ return 1;
+ }
}
return 0;
}
+static int copy_as_driver_button_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ /* try to create driver using property retrieved from UI */
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ if (ptr.id.data && ptr.data && prop) {
+ int dim = RNA_property_array_dimension(&ptr, prop, NULL);
+ char *path = RNA_path_from_ID_to_property_index(&ptr, prop, dim, index);
+
+ if (path) {
+ ANIM_copy_as_driver(ptr.id.data, path, RNA_property_identifier(prop));
+ MEM_freeN(path);
+ return OPERATOR_FINISHED;
+ }
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+static void UI_OT_copy_as_driver_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Copy As New Driver";
+ ot->idname = "UI_OT_copy_as_driver_button";
+ ot->description =
+ "Create a new driver with this property as input, and copy it to the "
+ "clipboard. Use Paste Driver to add it to the target property, or Paste "
+ "Driver Variables to extend an existing driver";
+
+ /* callbacks */
+ ot->exec = copy_as_driver_button_exec;
+ ot->poll = copy_as_driver_button_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
+}
+
/** \} */
/* -------------------------------------------------------------------- */
/** \name Copy Python Command Operator
* \{ */
+static bool copy_python_command_button_poll(bContext *C)
+{
+ uiBut *but = UI_context_active_but_get(C);
+
+ if (but && (but->optype != NULL)) {
+ return 1;
+ }
+
+ return 0;
+}
+
static int copy_python_command_button_exec(bContext *C, wmOperator *UNUSED(op))
{
uiBut *but = UI_context_active_but_get(C);
@@ -1668,6 +1740,7 @@ static void UI_OT_drop_color(wmOperatorType *ot)
void ED_operatortypes_ui(void)
{
WM_operatortype_append(UI_OT_copy_data_path_button);
+ WM_operatortype_append(UI_OT_copy_as_driver_button);
WM_operatortype_append(UI_OT_copy_python_command_button);
WM_operatortype_append(UI_OT_reset_default_button);
WM_operatortype_append(UI_OT_assign_default_button);