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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-09-04 12:49:11 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-09-04 12:49:11 +0400
commit6ed49857a4408bf413f4bf626229aa00d6c8cad7 (patch)
treefe28f1a9577172536f7ef33bfbaf0e84bf55ef1c /source
parent15ef88b90239af30b08e798cc57cea317f1d56c9 (diff)
poll functions to stop crashing when running operators in an invalid context.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/object/editconstraint.c32
-rw-r--r--source/blender/editors/physics/ed_pointcache.c16
-rw-r--r--source/blender/editors/space_buttons/buttons_ops.c10
-rw-r--r--source/blender/editors/space_console/console_ops.c6
-rw-r--r--source/blender/editors/space_text/text_ops.c2
5 files changed, 59 insertions, 7 deletions
diff --git a/source/blender/editors/object/editconstraint.c b/source/blender/editors/object/editconstraint.c
index 23b3caf8e26..dc0442a5af9 100644
--- a/source/blender/editors/object/editconstraint.c
+++ b/source/blender/editors/object/editconstraint.c
@@ -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;
diff --git a/source/blender/editors/physics/ed_pointcache.c b/source/blender/editors/physics/ed_pointcache.c
index 68e0c28e9c1..22316290c7b 100644
--- a/source/blender/editors/physics/ed_pointcache.c
+++ b/source/blender/editors/physics/ed_pointcache.c
@@ -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;
diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c
index 057f35a2487..954a52c54aa 100644
--- a/source/blender/editors/space_buttons/buttons_ops.c
+++ b/source/blender/editors/space_buttons/buttons_ops.c
@@ -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);
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index f8dbe0c3dd4..3d0d284b501 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -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 */
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 7e514ea723a..14b72e13856 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -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) {