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:
authorColin Basnett <cmbasnett@gmail.com>2022-09-13 04:11:00 +0300
committerColin Basnett <cmbasnett@gmail.com>2022-09-13 04:11:00 +0300
commitddfce277e0cbf0997c1366d366416dd43f997b7c (patch)
tree8bd78c2e44db8c5e79d5bd0ab1b8ee737592973f
parentb3e9ef1924783f3684f6e0c1b4cd588191340adf (diff)
NLA: actionclip_add now fails on invoke if no NLA track is selected
This makes the NLA_OT_actionclip_add operation (Shift+A while mousing over the NLA strips area) fail on invocation if no tracks are active. This stops the annoyance of using the Shift+A menu to select an action to add, but only getting the error after you select an action. Differential Revision: https://developer.blender.org/D15737
-rw-r--r--source/blender/editors/space_nla/nla_edit.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c
index 801d032a861..bcdbbb00d1c 100644
--- a/source/blender/editors/space_nla/nla_edit.c
+++ b/source/blender/editors/space_nla/nla_edit.c
@@ -606,6 +606,36 @@ void NLA_OT_view_frame(wmOperatorType *ot)
* (or the active block if no space in the track).
* \{ */
+/* Get a list of the editable tracks being shown in the NLA. */
+static int nlaedit_get_editable_tracks(bAnimContext *ac, ListBase *anim_data)
+{
+ const int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT |
+ ANIMFILTER_FCURVESONLY);
+ return ANIM_animdata_filter(ac, anim_data, filter, ac->data, ac->datatype);
+}
+
+static int nlaedit_add_actionclip_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ /* Get editor data. */
+ bAnimContext ac;
+ if (ANIM_animdata_get_context(C, &ac) == 0) {
+ return OPERATOR_CANCELLED;
+ }
+
+ ListBase anim_data = {NULL, NULL};
+ const size_t items = nlaedit_get_editable_tracks(&ac, &anim_data);
+
+ if (items == 0) {
+ BKE_report(op->reports,
+ RPT_ERROR,
+ "No active track(s) to add strip to, select an existing track or add one before "
+ "trying again");
+ return OPERATOR_CANCELLED;
+ }
+
+ return WM_enum_search_invoke(C, op, event);
+}
+
/* add the specified action as new strip */
static int nlaedit_add_actionclip_exec(bContext *C, wmOperator *op)
{
@@ -615,8 +645,6 @@ static int nlaedit_add_actionclip_exec(bContext *C, wmOperator *op)
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
- size_t items;
- int filter;
bAction *act;
@@ -654,20 +682,7 @@ static int nlaedit_add_actionclip_exec(bContext *C, wmOperator *op)
*/
nlaedit_add_tracks_empty(&ac);
- /* get a list of the editable tracks being shown in the NLA
- * - this is limited to active ones for now, but could be expanded to
- */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT |
- ANIMFILTER_FCURVESONLY);
- items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
- if (items == 0) {
- BKE_report(op->reports,
- RPT_ERROR,
- "No active track(s) to add strip to, select an existing track or add one before "
- "trying again");
- return OPERATOR_CANCELLED;
- }
+ nlaedit_get_editable_tracks(&ac, &anim_data);
/* for every active track,
* try to add strip to free space in track or to the top of the stack if no space */
@@ -736,7 +751,7 @@ void NLA_OT_actionclip_add(wmOperatorType *ot)
"Add an Action-Clip strip (i.e. an NLA Strip referencing an Action) to the active track";
/* api callbacks */
- ot->invoke = WM_enum_search_invoke;
+ ot->invoke = nlaedit_add_actionclip_invoke;
ot->exec = nlaedit_add_actionclip_exec;
ot->poll = nlaop_poll_tweakmode_off;