static void file_panel_operator_header(const bContext *C, Panel *pa) { SpaceFile *sfile = CTX_wm_space_file(C); wmOperator *op = sfile->op; BLI_strncpy(pa->drawname, RNA_struct_ui_name(op->type->srna), sizeof(pa->drawname)); }
static void view3d_panel_operator_redo_header(const bContext *C, Panel *pa) { wmOperator *op = WM_operator_last_redo(C); if (op) BLI_strncpy(pa->drawname, RNA_struct_ui_name(op->type->srna), sizeof(pa->drawname)); else BLI_strncpy(pa->drawname, IFACE_("Operator"), sizeof(pa->drawname)); }
static void view3d_panel_operator_redo_operator(const bContext *C, Panel *pa, wmOperator *op) { if (op->type->flag & OPTYPE_MACRO) { for (op = op->macro.first; op; op = op->next) { uiItemL(pa->layout, RNA_struct_ui_name(op->type->srna), ICON_NONE); view3d_panel_operator_redo_operator(C, pa, op); } } else { view3d_panel_operator_redo_buts(C, pa, op); } }
static const char *dropbox_active(bContext *C, ListBase *handlers, wmDrag *drag, wmEvent *event) { wmEventHandler *handler = handlers->first; for (; handler; handler = handler->next) { if (handler->dropboxes) { wmDropBox *drop = handler->dropboxes->first; for (; drop; drop = drop->next) { if (drop->poll(C, drag, event)) /* XXX Doing translation here might not be ideal, but later we have no more * access to ot (and hence op context)... */ return RNA_struct_ui_name(drop->ot->srna); } } } return NULL; }
static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { int undosys, totitem = 0; undosys = get_undo_system(C); if (undosys) { EnumPropertyItem *item = rna_undo_itemf(C, undosys, &totitem); if (totitem > 0) { uiPopupMenu *pup = uiPupMenuBegin(C, RNA_struct_ui_name(op->type->srna), ICON_NONE); uiLayout *layout = uiPupMenuLayout(pup); uiLayout *split = uiLayoutSplit(layout, 0.0f, false); uiLayout *column = NULL; const int col_size = 20 + totitem / 12; int i, c; bool add_col = true; for (c = 0, i = totitem; i--;) { if (add_col && !(c % col_size)) { column = uiLayoutColumn(split, false); add_col = false; } if (item[i].identifier) { uiItemIntO(column, item[i].name, item[i].icon, op->type->idname, "item", item[i].value); ++c; add_col = true; } } MEM_freeN(item); uiPupMenuEnd(C, pup); } } return OPERATOR_CANCELLED; }
/** * \note RNA_struct_property_is_set_ex is used here because we want * the previously used settings to be used here rather then overriding them */ short ED_fileselect_set_params(SpaceFile *sfile) { FileSelectParams *params; wmOperator *op = sfile->op; /* create new parameters if necessary */ if (!sfile->params) { sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams"); /* set path to most recently opened .blend */ BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); sfile->params->filter_glob[0] = '\0'; /* set the default thumbnails size */ sfile->params->thumbnail_size = 128; } params = sfile->params; /* set the parameters from the operator, if it exists */ if (op) { PropertyRNA *prop; const bool is_files = (RNA_struct_find_property(op->ptr, "files") != NULL); const bool is_filepath = (RNA_struct_find_property(op->ptr, "filepath") != NULL); const bool is_filename = (RNA_struct_find_property(op->ptr, "filename") != NULL); const bool is_directory = (RNA_struct_find_property(op->ptr, "directory") != NULL); const bool is_relative_path = (RNA_struct_find_property(op->ptr, "relative_path") != NULL); BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title)); 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]; RNA_string_get(op->ptr, "filepath", name); if (params->type == FILE_LOADLIB) { BLI_strncpy(params->dir, name, sizeof(params->dir)); sfile->params->file[0] = '\0'; } else { BLI_split_dirfile(name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); } } else { if (is_directory && RNA_struct_property_is_set_ex(op->ptr, "directory", false)) { RNA_string_get(op->ptr, "directory", params->dir); sfile->params->file[0] = '\0'; } if (is_filename && RNA_struct_property_is_set_ex(op->ptr, "filename", false)) { RNA_string_get(op->ptr, "filename", params->file); } } if (params->dir[0]) { BLI_cleanup_dir(G.main->name, params->dir); BLI_path_abs(params->dir, G.main->name); } if (is_directory == true && is_filename == false && is_filepath == false && is_files == false) { params->flag |= FILE_DIRSEL_ONLY; } else { params->flag &= ~FILE_DIRSEL_ONLY; } params->filter = 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_blender"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_backup"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER_BACKUP : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_image"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_IMAGE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_movie"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_MOVIE : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_python"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_PYSCRIPT : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_font"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FTFONT : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_sound"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_SOUND : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_text"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_TEXT : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_folder"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FOLDER : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_btx"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BTX : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_collada"))) params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_COLLADA : 0; if ((prop = RNA_struct_find_property(op->ptr, "filter_glob"))) { RNA_property_string_get(op->ptr, prop, params->filter_glob); params->filter |= (FILE_TYPE_OPERATOR | FILE_TYPE_FOLDER); } else { params->filter_glob[0] = '\0'; } if (params->filter != 0) { if (U.uiflag & USER_FILTERFILEEXTS) { params->flag |= FILE_FILTER; } else { params->flag &= ~FILE_FILTER; } } if (U.uiflag & USER_HIDE_DOT) { params->flag |= FILE_HIDE_DOT; } else { params->flag &= ~FILE_HIDE_DOT; } if (params->type == FILE_LOADLIB) { params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0; params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0; params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0; } 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) { if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE)) params->display = FILE_IMGDISPLAY; else params->display = FILE_SHORTDISPLAY; } else { params->display = FILE_SHORTDISPLAY; } } if (is_relative_path) { 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) != 0); } } } } else { /* default values, if no operator */ params->type = FILE_UNIX; params->flag |= FILE_HIDE_DOT; params->flag &= ~FILE_DIRSEL_ONLY; params->display = FILE_SHORTDISPLAY; params->filter = 0; params->filter_glob[0] = '\0'; } /* operator has no setting for this */ params->sort = FILE_SORT_ALPHA; params->active_file = -1; /* initialize the list with previous folders */ if (!sfile->folders_prev) sfile->folders_prev = folderlist_new(); if (!sfile->params->dir[0]) { if (G.main->name[0]) { BLI_split_dir_part(G.main->name, sfile->params->dir, sizeof(sfile->params->dir)); } else { const char *doc_path = BKE_appdir_folder_default(); if (doc_path) { BLI_strncpy(sfile->params->dir, doc_path, sizeof(sfile->params->dir)); } } } folderlist_pushdir(sfile->folders_prev, sfile->params->dir); /* switching thumbnails needs to recalc layout [#28809] */ if (sfile->layout) { sfile->layout->dirty = true; } return 1; }
/* Write into "name" buffer, the name of the property (retrieved using RNA from the curve's settings), * and return the icon used for the struct that this property refers to * WARNING: name buffer we're writing to cannot exceed 256 chars (check anim_channels_defines.c for details) */ int getname_anim_fcurve(char *name, ID *id, FCurve *fcu) { int icon = 0; /* sanity checks */ if (name == NULL) return icon; else if (ELEM3(NULL, id, fcu, fcu->rna_path)) { if (fcu == NULL) strcpy(name, "<invalid>"); else if (fcu->rna_path == NULL) strcpy(name, "<no path>"); else /* id == NULL */ BLI_snprintf(name, 256, "%s[%d]", fcu->rna_path, fcu->array_index); } else { PointerRNA id_ptr, ptr; PropertyRNA *prop; /* get RNA pointer, and resolve the path */ RNA_id_pointer_create(id, &id_ptr); /* try to resolve the path */ if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) { const char *structname = NULL, *propname = NULL; char arrayindbuf[16]; const char *arrayname = NULL; short free_structname = 0; /* For now, name will consist of 3 parts: struct-name, property name, array index * There are several options possible: * 1) <struct-name>.<property-name>.<array-index> * i.e. Bone1.Location.X, or Object.Location.X * 2) <array-index> <property-name> (<struct name>) * i.e. X Location (Bone1), or X Location (Object) * * Currently, option 2 is in use, to try and make it easier to quickly identify F-Curves (it does have * problems with looking rather odd though). Option 1 is better in terms of revealing a consistent sense of * hierarchy though, which isn't so clear with option 2. */ /* for structname * - as base, we use a custom name from the structs if one is available * - however, if we're showing subdata of bones (probably there will be other exceptions later) * need to include that info too since it gets confusing otherwise * - if a pointer just refers to the ID-block, then don't repeat this info * since this just introduces clutter */ if (strstr(fcu->rna_path, "bones") && strstr(fcu->rna_path, "constraints")) { /* perform string 'chopping' to get "Bone Name : Constraint Name" */ char *pchanName = BLI_getQuotedStr(fcu->rna_path, "bones["); char *constName = BLI_getQuotedStr(fcu->rna_path, "constraints["); /* assemble the string to display in the UI... */ structname = BLI_sprintfN("%s : %s", pchanName, constName); free_structname = 1; /* free the temp names */ if (pchanName) MEM_freeN(pchanName); if (constName) MEM_freeN(constName); } else if (ptr.data != ptr.id.data) { PropertyRNA *nameprop = RNA_struct_name_property(ptr.type); if (nameprop) { /* this gets a string which will need to be freed */ structname = RNA_property_string_get_alloc(&ptr, nameprop, NULL, 0, NULL); free_structname = 1; } else structname = RNA_struct_ui_name(ptr.type); } /* Property Name is straightforward */ propname = RNA_property_ui_name(prop); /* Array Index - only if applicable */ if (RNA_property_array_length(&ptr, prop)) { char c = RNA_property_array_item_char(prop, fcu->array_index); /* we need to write the index to a temp buffer (in py syntax) */ if (c) BLI_snprintf(arrayindbuf, sizeof(arrayindbuf), "%c ", c); else BLI_snprintf(arrayindbuf, sizeof(arrayindbuf), "[%d]", fcu->array_index); arrayname = &arrayindbuf[0]; } else { /* no array index */ arrayname = ""; } /* putting this all together into the buffer */ // XXX we need to check for invalid names... // XXX the name length limit needs to be passed in or as some define if (structname) BLI_snprintf(name, 256, "%s%s (%s)", arrayname, propname, structname); else BLI_snprintf(name, 256, "%s%s", arrayname, propname); /* free temp name if nameprop is set */ if (free_structname) MEM_freeN((void *)structname); /* Icon for this property's owner: * use the struct's icon if it is set */ icon = RNA_struct_ui_icon(ptr.type); /* valid path - remove the invalid tag since we now know how to use it saving * users manual effort to reenable using "Revive Disabled FCurves" [#29629] */ fcu->flag &= ~FCURVE_DISABLED; } else { /* invalid path */ BLI_snprintf(name, 256, "\"%s[%d]\"", fcu->rna_path, fcu->array_index); /* icon for this should be the icon for the base ID */ // TODO: or should we just use the error icon? icon = RNA_struct_ui_icon(id_ptr.type); /* tag F-Curve as disabled - as not usable path */ fcu->flag |= FCURVE_DISABLED; } } /* return the icon that the active data had */ return icon; }