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:
authorHans Goudey <h.goudey@me.com>2020-07-16 21:07:47 +0300
committerHans Goudey <h.goudey@me.com>2020-07-16 21:07:47 +0300
commit608d9b5aa1f199683a2e9fdd3b66b480779cb7ca (patch)
tree0252e7fae7154498fdb71ae67ce6219ebb823609 /source/blender/editors/object/object_constraint.c
parentb13bbb22e4cb7b4cd21b33d1f1b165abcde5fe6e (diff)
UI: Add shortcuts for constraint panels
Only the delete shortcut applies here, although the move up and down operators can optionally be assigned in the keymap. See rB1fa40c9f8a81 for more details and rB5d2005cbb54b for the grease pencil modifier panel implementation, which is the same. Some refactoring of the constraint delete operator was necessary, including adding an invoke function. Differential Revision: https://developer.blender.org/D8238
Diffstat (limited to 'source/blender/editors/object/object_constraint.c')
-rw-r--r--source/blender/editors/object/object_constraint.c109
1 files changed, 79 insertions, 30 deletions
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index 90ea71ae5c5..bcb1b8afbdd 100644
--- a/source/blender/editors/object/object_constraint.c
+++ b/source/blender/editors/object/object_constraint.c
@@ -702,7 +702,17 @@ static void edit_constraint_properties(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN);
}
-static bool edit_constraint_invoke_properties(bContext *C, wmOperator *op)
+static void edit_constraint_report_property(wmOperatorType *ot)
+{
+ PropertyRNA *prop = RNA_def_boolean(
+ ot->srna, "report", false, "Report", "Create a notification after the operation");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+}
+
+static bool edit_constraint_invoke_properties(bContext *C,
+ wmOperator *op,
+ const wmEvent *event,
+ int *r_retval)
{
PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : ED_object_active_context(C);
@@ -730,6 +740,31 @@ static bool edit_constraint_invoke_properties(bContext *C, wmOperator *op)
return true;
}
+ /* Check the custom data of panels under the mouse for a modifier. */
+ if (event != NULL) {
+ PointerRNA *panel_ptr = UI_region_panel_custom_data_under_cursor(C, event);
+
+ if (!(panel_ptr == NULL || RNA_pointer_is_null(panel_ptr))) {
+ if (RNA_struct_is_a(panel_ptr->type, &RNA_Constraint)) {
+ con = panel_ptr->data;
+ RNA_string_set(op->ptr, "constraint", con->name);
+ list = ED_object_constraint_list_from_constraint(ob, con, NULL);
+ RNA_enum_set(op->ptr,
+ "owner",
+ (&ob->constraints == list) ? EDIT_CONSTRAINT_OWNER_OBJECT :
+ EDIT_CONSTRAINT_OWNER_BONE);
+
+ return true;
+ }
+
+ BLI_assert(r_retval != NULL); /* We need the return value in this case. */
+ if (r_retval != NULL) {
+ *r_retval = (OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED);
+ }
+ return false;
+ }
+ }
+
return false;
}
@@ -813,7 +848,7 @@ static int stretchto_reset_exec(bContext *C, wmOperator *op)
static int stretchto_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op)) {
+ if (edit_constraint_invoke_properties(C, op, NULL, NULL)) {
return stretchto_reset_exec(C, op);
}
return OPERATOR_CANCELLED;
@@ -868,7 +903,7 @@ static int limitdistance_reset_exec(bContext *C, wmOperator *op)
static int limitdistance_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op)) {
+ if (edit_constraint_invoke_properties(C, op, NULL, NULL)) {
return limitdistance_reset_exec(C, op);
}
return OPERATOR_CANCELLED;
@@ -946,7 +981,7 @@ static int childof_set_inverse_exec(bContext *C, wmOperator *op)
static int childof_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op)) {
+ if (edit_constraint_invoke_properties(C, op, NULL, NULL)) {
return childof_set_inverse_exec(C, op);
}
return OPERATOR_CANCELLED;
@@ -995,7 +1030,7 @@ static int childof_clear_inverse_exec(bContext *C, wmOperator *op)
static int childof_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op)) {
+ if (edit_constraint_invoke_properties(C, op, NULL, NULL)) {
return childof_clear_inverse_exec(C, op);
}
return OPERATOR_CANCELLED;
@@ -1120,7 +1155,7 @@ static int followpath_path_animate_invoke(bContext *C,
const wmEvent *UNUSED(event))
{
/* hook up invoke properties for figuring out which constraint we're dealing with */
- if (edit_constraint_invoke_properties(C, op)) {
+ if (edit_constraint_invoke_properties(C, op, NULL, NULL)) {
return followpath_path_animate_exec(C, op);
}
return OPERATOR_CANCELLED;
@@ -1201,7 +1236,7 @@ static int objectsolver_set_inverse_invoke(bContext *C,
wmOperator *op,
const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op)) {
+ if (edit_constraint_invoke_properties(C, op, NULL, NULL)) {
return objectsolver_set_inverse_exec(C, op);
}
return OPERATOR_CANCELLED;
@@ -1257,7 +1292,7 @@ static int objectsolver_clear_inverse_invoke(bContext *C,
wmOperator *op,
const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op)) {
+ if (edit_constraint_invoke_properties(C, op, NULL, NULL)) {
return objectsolver_clear_inverse_exec(C, op);
}
return OPERATOR_CANCELLED;
@@ -1374,26 +1409,23 @@ void ED_object_constraint_dependency_tag_update(Main *bmain, Object *ob, bConstr
DEG_relations_tag_update(bmain);
}
-static bool constraint_poll(bContext *C)
-{
- PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
- return (ptr.owner_id && ptr.data);
-}
-
/** \} */
/* ------------------------------------------------------------------- */
/** \name Delete Constraint Operator
* \{ */
-static int constraint_delete_exec(bContext *C, wmOperator *UNUSED(op))
+static int constraint_delete_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- PointerRNA ptr = CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
- Object *ob = (Object *)ptr.owner_id;
- bConstraint *con = ptr.data;
+ Object *ob = ED_object_active_context(C);
+ bConstraint *con = edit_constraint_property_get(op, ob, 0);
ListBase *lb = ED_object_constraint_list_from_constraint(ob, con, NULL);
+ /* Store name temporarily for report. */
+ char name[MAX_NAME];
+ strcpy(name, con->name);
+
/* free the constraint */
if (BKE_constraint_remove_ex(lb, ob, con, true)) {
/* there's no active constraint now, so make sure this is the case */
@@ -1407,12 +1439,25 @@ static int constraint_delete_exec(bContext *C, wmOperator *UNUSED(op))
/* notifiers */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
+ if (RNA_boolean_get(op->ptr, "report")) {
+ BKE_reportf(op->reports, RPT_INFO, "Removed constraint: %s", name);
+ }
+
return OPERATOR_FINISHED;
}
/* couldn't remove due to some invalid data */
return OPERATOR_CANCELLED;
}
+static int constraint_delete_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ int retval;
+ if (edit_constraint_invoke_properties(C, op, event, &retval)) {
+ return constraint_delete_exec(C, op);
+ }
+ return OPERATOR_CANCELLED;
+}
+
void CONSTRAINT_OT_delete(wmOperatorType *ot)
{
/* identifiers */
@@ -1421,11 +1466,14 @@ void CONSTRAINT_OT_delete(wmOperatorType *ot)
ot->description = "Remove constraint from constraint stack";
/* callbacks */
+ ot->invoke = constraint_delete_invoke;
ot->exec = constraint_delete_exec;
- ot->poll = constraint_poll;
+ ot->poll = edit_constraint_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ edit_constraint_properties(ot);
+ edit_constraint_report_property(ot);
}
/** \} */
@@ -1455,12 +1503,13 @@ static int constraint_move_down_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
-static int constraint_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int constraint_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (edit_constraint_invoke_properties(C, op)) {
+ int retval;
+ if (edit_constraint_invoke_properties(C, op, event, &retval)) {
return constraint_move_down_exec(C, op);
}
- return OPERATOR_CANCELLED;
+ return retval;
}
void CONSTRAINT_OT_move_down(wmOperatorType *ot)
@@ -1509,12 +1558,13 @@ static int constraint_move_up_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
-static int constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (edit_constraint_invoke_properties(C, op)) {
+ int retval;
+ if (edit_constraint_invoke_properties(C, op, event, &retval)) {
return constraint_move_up_exec(C, op);
}
- return OPERATOR_CANCELLED;
+ return retval;
}
void CONSTRAINT_OT_move_up(wmOperatorType *ot)
@@ -1565,14 +1615,13 @@ static int constraint_move_to_index_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
-static int constraint_move_to_index_invoke(bContext *C,
- wmOperator *op,
- const wmEvent *UNUSED(event))
+static int constraint_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- if (edit_constraint_invoke_properties(C, op)) {
+ int retval;
+ if (edit_constraint_invoke_properties(C, op, event, &retval)) {
return constraint_move_to_index_exec(C, op);
}
- return OPERATOR_CANCELLED;
+ return retval;
}
void CONSTRAINT_OT_move_to_index(wmOperatorType *ot)