forked from bartvdbraak/blender
poll functions to stop crashing when running operators in an invalid context.
This commit is contained in:
parent
15ef88b902
commit
6ed49857a4
@ -465,6 +465,12 @@ void object_test_constraints (Object *owner)
|
||||
/* ---------- Distance-Dependent Constraints ---------- */
|
||||
/* StretchTo, Limit Distance */
|
||||
|
||||
static int stretchto_poll(bContext *C)
|
||||
{
|
||||
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_StretchToConstraint);
|
||||
return (ptr.id.data && ptr.data);
|
||||
}
|
||||
|
||||
static int stretchto_reset_exec (bContext *C, wmOperator *op)
|
||||
{
|
||||
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_StretchToConstraint);
|
||||
@ -484,6 +490,7 @@ void CONSTRAINT_OT_stretchto_reset (wmOperatorType *ot)
|
||||
ot->description= "Reset original length of bone for Stretch To Constraint.";
|
||||
|
||||
ot->exec= stretchto_reset_exec;
|
||||
ot->poll= stretchto_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -501,6 +508,12 @@ static int limitdistance_reset_exec (bContext *C, wmOperator *op)
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static int limitdistance_poll(bContext *C)
|
||||
{
|
||||
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_LimitDistanceConstraint);
|
||||
return (ptr.id.data && ptr.data);
|
||||
}
|
||||
|
||||
void CONSTRAINT_OT_limitdistance_reset (wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
@ -509,6 +522,7 @@ void CONSTRAINT_OT_limitdistance_reset (wmOperatorType *ot)
|
||||
ot->description= "Reset limiting distance for Limit Distance Constraint.";
|
||||
|
||||
ot->exec= limitdistance_reset_exec;
|
||||
ot->poll= limitdistance_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -516,6 +530,12 @@ void CONSTRAINT_OT_limitdistance_reset (wmOperatorType *ot)
|
||||
|
||||
/* ------------- Child-Of Constraint ------------------ */
|
||||
|
||||
static int childof_poll(bContext *C)
|
||||
{
|
||||
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_ChildOfConstraint);
|
||||
return (ptr.id.data && ptr.data);
|
||||
}
|
||||
|
||||
/* ChildOf Constraint - set inverse callback */
|
||||
static int childof_set_inverse_exec (bContext *C, wmOperator *op)
|
||||
{
|
||||
@ -582,12 +602,12 @@ void CONSTRAINT_OT_childof_set_inverse (wmOperatorType *ot)
|
||||
ot->description= "Set inverse correction for ChildOf constraint.";
|
||||
|
||||
ot->exec= childof_set_inverse_exec;
|
||||
ot->poll= childof_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
|
||||
/* ChildOf Constraint - clear inverse callback */
|
||||
static int childof_clear_inverse_exec (bContext *C, wmOperator *op)
|
||||
{
|
||||
@ -612,6 +632,7 @@ void CONSTRAINT_OT_childof_clear_inverse (wmOperatorType *ot)
|
||||
ot->description= "Clear inverse correction for ChildOf constraint.";
|
||||
|
||||
ot->exec= childof_clear_inverse_exec;
|
||||
ot->poll= childof_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -684,6 +705,12 @@ void ED_object_constraint_set_active(Object *ob, bConstraint *con)
|
||||
}
|
||||
}
|
||||
|
||||
static int constraint_poll(bContext *C)
|
||||
{
|
||||
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
|
||||
return (ptr.id.data && ptr.data);
|
||||
}
|
||||
|
||||
static int constraint_delete_exec (bContext *C, wmOperator *op)
|
||||
{
|
||||
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_Constraint);
|
||||
@ -711,6 +738,7 @@ void CONSTRAINT_OT_delete (wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec= constraint_delete_exec;
|
||||
ot->poll= constraint_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -747,6 +775,7 @@ void CONSTRAINT_OT_move_down (wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec= constraint_move_down_exec;
|
||||
ot->poll= constraint_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -784,6 +813,7 @@ void CONSTRAINT_OT_move_up (wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec= constraint_move_up_exec;
|
||||
ot->poll= constraint_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
|
@ -72,6 +72,12 @@ static int ptcache_bake_all_poll(bContext *C)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ptcache_poll(bContext *C)
|
||||
{
|
||||
PointerRNA ptr= CTX_data_pointer_get_type(C, "PointCache", &RNA_PointCache);
|
||||
return (ptr.data && ptr.id.data);
|
||||
}
|
||||
|
||||
static int ptcache_bake_all_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Scene *scene= CTX_data_scene(C);
|
||||
@ -215,7 +221,7 @@ void PTCACHE_OT_bake(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= ptcache_bake_exec;
|
||||
ot->poll= ptcache_bake_all_poll;
|
||||
ot->poll= ptcache_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -230,7 +236,7 @@ void PTCACHE_OT_free_bake(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= ptcache_free_bake_exec;
|
||||
ot->poll= ptcache_bake_all_poll;
|
||||
ot->poll= ptcache_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -243,7 +249,7 @@ void PTCACHE_OT_bake_from_cache(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= ptcache_bake_from_cache_exec;
|
||||
ot->poll= ptcache_bake_all_poll;
|
||||
ot->poll= ptcache_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -308,7 +314,7 @@ void PTCACHE_OT_add_new(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= ptcache_add_new_exec;
|
||||
ot->poll= ptcache_bake_all_poll;
|
||||
ot->poll= ptcache_poll; // ptcache_bake_all_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -321,7 +327,7 @@ void PTCACHE_OT_remove(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= ptcache_remove_exec;
|
||||
ot->poll= ptcache_bake_all_poll;
|
||||
ot->poll= ptcache_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
|
@ -613,6 +613,12 @@ void OBJECT_OT_particle_system_remove(wmOperatorType *ot)
|
||||
|
||||
/********************** new particle settings operator *********************/
|
||||
|
||||
static int psys_poll(bContext *C)
|
||||
{
|
||||
PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem);
|
||||
return (ptr.data != NULL);
|
||||
}
|
||||
|
||||
static int new_particle_settings_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
@ -657,6 +663,7 @@ void PARTICLE_OT_new(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= new_particle_settings_exec;
|
||||
ot->poll= psys_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
||||
@ -948,6 +955,9 @@ static int file_browse_exec(bContext *C, wmOperator *op)
|
||||
FileBrowseOp *fbo= op->customdata;
|
||||
char *str;
|
||||
|
||||
if (RNA_property_is_set(op->ptr, "filename")==0 || fbo==NULL)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
str= RNA_string_get_alloc(op->ptr, "filename", 0, 0);
|
||||
RNA_property_string_set(&fbo->ptr, fbo->prop, str);
|
||||
RNA_property_update(C, &fbo->ptr, fbo->prop);
|
||||
|
@ -234,6 +234,11 @@ static int console_edit_poll(bContext *C)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int console_poll(bContext *C)
|
||||
{
|
||||
return (CTX_wm_space_console(C) != NULL);
|
||||
}
|
||||
|
||||
|
||||
/* static funcs for text editing */
|
||||
|
||||
@ -695,6 +700,7 @@ void CONSOLE_OT_zoom(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= zoom_exec;
|
||||
ot->poll= console_poll;
|
||||
|
||||
/* flags */
|
||||
/* ot->flag= OPTYPE_REGISTER; */ /* super annoying */
|
||||
|
@ -1478,7 +1478,7 @@ static int move_cursor(bContext *C, int type, int select)
|
||||
ARegion *ar= CTX_wm_region(C);
|
||||
|
||||
/* ensure we have the right region, it's optional */
|
||||
if(ar->regiontype != RGN_TYPE_WINDOW)
|
||||
if(ar && ar->regiontype != RGN_TYPE_WINDOW)
|
||||
ar= NULL;
|
||||
|
||||
switch(type) {
|
||||
|
Loading…
Reference in New Issue
Block a user