RNA API: reuse property lookups
This commit is contained in:
@@ -297,18 +297,19 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
|
||||
{
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
unsigned int _layer;
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* Switch to Edit mode? */
|
||||
if (RNA_struct_find_property(op->ptr, "enter_editmode")) { /* optional */
|
||||
/* Switch to Edit mode? optional prop */
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "enter_editmode"))) {
|
||||
bool _enter_editmode;
|
||||
if (!enter_editmode)
|
||||
enter_editmode = &_enter_editmode;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "enter_editmode") && enter_editmode)
|
||||
*enter_editmode = RNA_boolean_get(op->ptr, "enter_editmode");
|
||||
if (RNA_property_is_set(op->ptr, prop) && enter_editmode)
|
||||
*enter_editmode = RNA_property_boolean_get(op->ptr, prop);
|
||||
else {
|
||||
*enter_editmode = (U.flag & USER_ADD_EDITMODE) != 0;
|
||||
RNA_boolean_set(op->ptr, "enter_editmode", *enter_editmode);
|
||||
RNA_property_boolean_set(op->ptr, prop, *enter_editmode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,8 +319,9 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
|
||||
if (!layer)
|
||||
layer = &_layer;
|
||||
|
||||
if (RNA_struct_property_is_set(op->ptr, "layers")) {
|
||||
RNA_boolean_get_array(op->ptr, "layers", layer_values);
|
||||
prop = RNA_struct_find_property(op->ptr, "layers");
|
||||
if (RNA_property_is_set(op->ptr, prop)) {
|
||||
RNA_property_boolean_get_array(op->ptr, prop, layer_values);
|
||||
*layer = 0;
|
||||
for (a = 0; a < 20; a++) {
|
||||
if (layer_values[a])
|
||||
@@ -332,7 +334,7 @@ bool ED_object_add_generic_get_opts(bContext *C, wmOperator *op, const char view
|
||||
for (a = 0; a < 20; a++) {
|
||||
layer_values[a] = *layer & (1 << a);
|
||||
}
|
||||
RNA_boolean_set_array(op->ptr, "layers", layer_values);
|
||||
RNA_property_boolean_set_array(op->ptr, prop, layer_values);
|
||||
}
|
||||
|
||||
/* in local view we additionally add local view layers,
|
||||
|
||||
@@ -1386,11 +1386,15 @@ void TEXTURE_OT_slot_move(wmOperatorType *ot)
|
||||
|
||||
static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, const char imtype)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
float layout[12];
|
||||
if (RNA_struct_find_property(op->ptr, "layout") )
|
||||
RNA_float_get_array(op->ptr, "layout", layout);
|
||||
else
|
||||
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "layout"))) {
|
||||
RNA_property_float_get_array(op->ptr, prop, layout);
|
||||
}
|
||||
else {
|
||||
memcpy(layout, default_envmap_layout, sizeof(layout));
|
||||
}
|
||||
|
||||
if (RE_WriteEnvmapResult(op->reports, scene, env, path, imtype, layout)) {
|
||||
return OPERATOR_FINISHED;
|
||||
|
||||
@@ -205,6 +205,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
else {
|
||||
PropertyRNA *prop_relpath;
|
||||
const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
|
||||
fbo = MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
|
||||
fbo->ptr = ptr;
|
||||
@@ -216,10 +217,10 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
/* normally ED_fileselect_get_params would handle this but we need to because of stupid
|
||||
* user-prefs exception - campbell */
|
||||
if (RNA_struct_find_property(op->ptr, "relative_path")) {
|
||||
if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
|
||||
if ((prop_relpath = RNA_struct_find_property(op->ptr, "relative_path"))) {
|
||||
if (!RNA_property_is_set(op->ptr, prop_relpath)) {
|
||||
/* annoying exception!, if were dealing with the user prefs, default relative to be off */
|
||||
RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS && (ptr.data != &U));
|
||||
RNA_property_boolean_set(op->ptr, prop_relpath, U.flag & USER_RELPATHS && (ptr.data != &U));
|
||||
}
|
||||
}
|
||||
WM_event_add_fileselect(C, op);
|
||||
|
||||
@@ -461,12 +461,13 @@ void FILE_OT_select_all_toggle(wmOperatorType *ot)
|
||||
static int bookmark_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
SpaceFile *sfile = CTX_wm_space_file(C);
|
||||
PropertyRNA *prop;
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "dir")) {
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "dir"))) {
|
||||
char entry[256];
|
||||
FileSelectParams *params = sfile->params;
|
||||
|
||||
RNA_string_get(op->ptr, "dir", entry);
|
||||
RNA_property_string_get(op->ptr, prop, entry);
|
||||
BLI_strncpy(params->dir, entry, sizeof(params->dir));
|
||||
BLI_cleanup_dir(G.main->name, params->dir);
|
||||
ED_file_change_dir(C, true);
|
||||
@@ -830,57 +831,59 @@ void FILE_OT_cancel(struct wmOperatorType *ot)
|
||||
|
||||
void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
BLI_join_dirfile(filepath, FILE_MAX, sfile->params->dir, sfile->params->file); /* XXX, not real length */
|
||||
if (RNA_struct_find_property(op->ptr, "relative_path")) {
|
||||
if (RNA_boolean_get(op->ptr, "relative_path")) {
|
||||
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
|
||||
if (RNA_property_boolean_get(op->ptr, prop)) {
|
||||
BLI_path_rel(filepath, G.main->name);
|
||||
}
|
||||
}
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "filename")) {
|
||||
RNA_string_set(op->ptr, "filename", sfile->params->file);
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
|
||||
RNA_property_string_set(op->ptr, prop, sfile->params->file);
|
||||
}
|
||||
if (RNA_struct_find_property(op->ptr, "directory")) {
|
||||
RNA_string_set(op->ptr, "directory", sfile->params->dir);
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
|
||||
RNA_property_string_set(op->ptr, prop, sfile->params->dir);
|
||||
}
|
||||
if (RNA_struct_find_property(op->ptr, "filepath")) {
|
||||
RNA_string_set(op->ptr, "filepath", filepath);
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
|
||||
RNA_property_string_set(op->ptr, prop, filepath);
|
||||
}
|
||||
|
||||
/* some ops have multiple files to select */
|
||||
/* this is called on operators check() so clear collections first since
|
||||
* they may be already set. */
|
||||
{
|
||||
PointerRNA itemptr;
|
||||
PropertyRNA *prop_files = RNA_struct_find_property(op->ptr, "files");
|
||||
PropertyRNA *prop_dirs = RNA_struct_find_property(op->ptr, "dirs");
|
||||
int i, numfiles = filelist_numfiles(sfile->files);
|
||||
|
||||
if (prop_files) {
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
|
||||
PointerRNA itemptr;
|
||||
int num_files = 0;
|
||||
RNA_property_collection_clear(op->ptr, prop_files);
|
||||
RNA_property_collection_clear(op->ptr, prop);
|
||||
for (i = 0; i < numfiles; i++) {
|
||||
if (filelist_is_selected(sfile->files, i, CHECK_FILES)) {
|
||||
struct direntry *file = filelist_file(sfile->files, i);
|
||||
RNA_property_collection_add(op->ptr, prop_files, &itemptr);
|
||||
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
||||
RNA_string_set(&itemptr, "name", file->relname);
|
||||
num_files++;
|
||||
}
|
||||
}
|
||||
/* make sure the file specified in the filename button is added even if no files selected */
|
||||
if (0 == num_files) {
|
||||
RNA_property_collection_add(op->ptr, prop_files, &itemptr);
|
||||
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
||||
RNA_string_set(&itemptr, "name", sfile->params->file);
|
||||
}
|
||||
}
|
||||
|
||||
if (prop_dirs) {
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "dirs"))) {
|
||||
PointerRNA itemptr;
|
||||
int num_dirs = 0;
|
||||
RNA_property_collection_clear(op->ptr, prop_dirs);
|
||||
RNA_property_collection_clear(op->ptr, prop);
|
||||
for (i = 0; i < numfiles; i++) {
|
||||
if (filelist_is_selected(sfile->files, i, CHECK_DIRS)) {
|
||||
struct direntry *file = filelist_file(sfile->files, i);
|
||||
RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
|
||||
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
||||
RNA_string_set(&itemptr, "name", file->relname);
|
||||
num_dirs++;
|
||||
}
|
||||
@@ -888,7 +891,7 @@ void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char *filepath)
|
||||
|
||||
/* make sure the directory specified in the button is added even if no directory selected */
|
||||
if (0 == num_dirs) {
|
||||
RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
|
||||
RNA_property_collection_add(op->ptr, prop, &itemptr);
|
||||
RNA_string_set(&itemptr, "name", sfile->params->dir);
|
||||
}
|
||||
}
|
||||
@@ -952,8 +955,9 @@ void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2))
|
||||
bool file_draw_check_exists(SpaceFile *sfile)
|
||||
{
|
||||
if (sfile->op) { /* fails on reload */
|
||||
if (RNA_struct_find_property(sfile->op->ptr, "check_existing")) {
|
||||
if (RNA_boolean_get(sfile->op->ptr, "check_existing")) {
|
||||
PropertyRNA *prop;
|
||||
if ((prop = RNA_struct_find_property(sfile->op->ptr, "check_existing"))) {
|
||||
if (RNA_property_boolean_get(sfile->op->ptr, prop)) {
|
||||
char filepath[FILE_MAX];
|
||||
BLI_join_dirfile(filepath, sizeof(filepath), sfile->params->dir, sfile->params->file);
|
||||
if (BLI_is_file(filepath)) {
|
||||
@@ -1291,6 +1295,7 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
|
||||
char name[FILE_MAXFILE];
|
||||
char path[FILE_MAX];
|
||||
int generate_name = 1;
|
||||
PropertyRNA *prop;
|
||||
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
SpaceFile *sfile = CTX_wm_space_file(C);
|
||||
@@ -1302,8 +1307,8 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
|
||||
|
||||
path[0] = '\0';
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "directory")) {
|
||||
RNA_string_get(op->ptr, "directory", path);
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
|
||||
RNA_property_string_get(op->ptr, prop, path);
|
||||
if (path[0] != '\0') generate_name = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,10 +117,12 @@ short ED_fileselect_set_params(SpaceFile *sfile)
|
||||
|
||||
BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title));
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "filemode"))
|
||||
params->type = RNA_int_get(op->ptr, "filemode");
|
||||
else
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "filemode"))) {
|
||||
params->type = RNA_property_int_get(op->ptr, prop);
|
||||
}
|
||||
else {
|
||||
params->type = FILE_SPECIAL;
|
||||
}
|
||||
|
||||
if (is_filepath && RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
|
||||
char name[FILE_MAX];
|
||||
@@ -210,8 +212,9 @@ short ED_fileselect_set_params(SpaceFile *sfile)
|
||||
params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0;
|
||||
}
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "display_type"))
|
||||
params->display = RNA_enum_get(op->ptr, "display_type");
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "display_type"))) {
|
||||
params->display = RNA_property_enum_get(op->ptr, prop);
|
||||
}
|
||||
|
||||
if (params->display == FILE_DEFAULTDISPLAY) {
|
||||
if (U.uiflag & USER_SHOW_THUMBNAILS) {
|
||||
@@ -226,8 +229,10 @@ short ED_fileselect_set_params(SpaceFile *sfile)
|
||||
}
|
||||
|
||||
if (is_relative_path) {
|
||||
if (!RNA_struct_property_is_set_ex(op->ptr, "relative_path", false)) {
|
||||
RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
|
||||
if (!RNA_property_is_set_ex(op->ptr, prop, false)) {
|
||||
RNA_property_boolean_set(op->ptr, prop, U.flag & USER_RELPATHS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1974,8 +1974,8 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
|
||||
}
|
||||
}
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "proportional")) {
|
||||
RNA_enum_set(op->ptr, "proportional", proportional);
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "proportional"))) {
|
||||
RNA_property_enum_set(op->ptr, prop, proportional);
|
||||
RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
|
||||
RNA_float_set(op->ptr, "proportional_size", t->prop_size);
|
||||
}
|
||||
|
||||
@@ -4740,8 +4740,9 @@ char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
|
||||
/* this may not be an ID at all, check for simple when pointer owns property.
|
||||
* TODO, more complex nested case */
|
||||
if (!RNA_struct_is_ID(ptr->type)) {
|
||||
if (RNA_struct_find_property(ptr, RNA_property_identifier(prop)) == prop) {
|
||||
data_path = BLI_strdup(RNA_property_identifier(prop));
|
||||
const char *prop_identifier = RNA_property_identifier(prop);
|
||||
if (RNA_struct_find_property(ptr, prop_identifier) == prop) {
|
||||
data_path = BLI_strdup(prop_identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3171,14 +3171,16 @@ static int border_apply_rect(wmOperator *op)
|
||||
|
||||
static int border_apply(bContext *C, wmOperator *op, int gesture_mode)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
int retval;
|
||||
|
||||
if (!border_apply_rect(op))
|
||||
return 0;
|
||||
|
||||
/* XXX weak; border should be configured for this without reading event types */
|
||||
if (RNA_struct_find_property(op->ptr, "gesture_mode")) {
|
||||
RNA_int_set(op->ptr, "gesture_mode", gesture_mode);
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "gesture_mode"))) {
|
||||
RNA_property_int_set(op->ptr, prop, gesture_mode);
|
||||
}
|
||||
|
||||
retval = op->type->exec(C, op);
|
||||
@@ -3498,6 +3500,8 @@ void wm_tweakevent_test(bContext *C, wmEvent *event, int action)
|
||||
|
||||
int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
op->customdata = WM_gesture_new(C, event, WM_GESTURE_LASSO);
|
||||
|
||||
/* add modal handler */
|
||||
@@ -3505,8 +3509,8 @@ int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
wm_gesture_tag_redraw(C);
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "cursor")) {
|
||||
WM_cursor_modal_set(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "cursor"))) {
|
||||
WM_cursor_modal_set(CTX_wm_window(C), RNA_property_int_get(op->ptr, prop));
|
||||
}
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
@@ -3514,6 +3518,8 @@ int WM_gesture_lasso_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
int WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
op->customdata = WM_gesture_new(C, event, WM_GESTURE_LINES);
|
||||
|
||||
/* add modal handler */
|
||||
@@ -3521,8 +3527,8 @@ int WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
|
||||
wm_gesture_tag_redraw(C);
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "cursor")) {
|
||||
WM_cursor_modal_set(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "cursor"))) {
|
||||
WM_cursor_modal_set(CTX_wm_window(C), RNA_property_int_get(op->ptr, prop));
|
||||
}
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
@@ -3728,6 +3734,8 @@ static int straightline_apply(bContext *C, wmOperator *op)
|
||||
|
||||
int WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
op->customdata = WM_gesture_new(C, event, WM_GESTURE_STRAIGHTLINE);
|
||||
|
||||
/* add modal handler */
|
||||
@@ -3735,8 +3743,8 @@ int WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *e
|
||||
|
||||
wm_gesture_tag_redraw(C);
|
||||
|
||||
if (RNA_struct_find_property(op->ptr, "cursor")) {
|
||||
WM_cursor_modal_set(CTX_wm_window(C), RNA_int_get(op->ptr, "cursor"));
|
||||
if ((prop = RNA_struct_find_property(op->ptr, "cursor"))) {
|
||||
WM_cursor_modal_set(CTX_wm_window(C), RNA_property_int_get(op->ptr, prop));
|
||||
}
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
|
||||
Reference in New Issue
Block a user