Fix broken 'search pointer' UI since this morning.
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 30 Oct 2018 18:52:06 +0000 (19:52 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 30 Oct 2018 18:55:02 +0000 (19:55 +0100)
Own rB4669c3692cc4f broke completely those searchbox pointers UI
widgets... This is a quick fix, better name handling is for tomorrow.

source/blender/makesrna/intern/rna_main.c

index 5e05d37dc8ce703b0d1b08ccb666941d1e393475..a807e3638427cb0a1e1aa3b4bee2089cbad33490 100644 (file)
@@ -31,6 +31,7 @@
 #include "BLI_path_util.h"
 
 #include "RNA_define.h"
+#include "RNA_access.h"
 
 #include "rna_internal.h"
 
@@ -305,6 +306,240 @@ static void rna_Main_lightprobes_begin(CollectionPropertyIterator *iter, Pointer
        rna_iterator_listbase_begin(iter, &bmain->lightprobe, NULL);
 }
 
+static int rna_ID_lookup_string(ListBase *lb, const char *key, PointerRNA *r_ptr)
+{
+       ID *id;
+       for (id = lb->first; id != NULL; id = id->next) {
+               printf("%s vs %s\n", id->name, key);
+               if (STREQ(id->name + 2, key)) {
+                       break;
+               }
+               else if (strstr(key, id->name + 2) != NULL) {
+                       char uiname[MAX_ID_NAME * 3];
+                       BKE_id_ui_prefix(uiname, id);
+                       printf("second chance: %s vs %s\n", uiname, key);
+                       if (STREQ(uiname, key)) {
+                               break;
+                       }
+               }
+       }
+       if (id != NULL) {
+               RNA_id_pointer_create(id, r_ptr);
+               return true;
+       }
+       return false;
+}
+
+int rna_Main_camera_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->camera, key, r_ptr);
+}
+
+int rna_Main_scene_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->scene, key, r_ptr);
+}
+
+int rna_Main_object_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->object, key, r_ptr);
+}
+
+int rna_Main_mat_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->mat, key, r_ptr);
+}
+
+int rna_Main_nodetree_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->nodetree, key, r_ptr);
+}
+
+int rna_Main_mesh_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->mesh, key, r_ptr);
+}
+
+int rna_Main_light_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->lamp, key, r_ptr);
+}
+
+int rna_Main_library_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->library, key, r_ptr);
+}
+
+int rna_Main_screen_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->screen, key, r_ptr);
+}
+
+int rna_Main_wm_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->wm, key, r_ptr);
+}
+
+int rna_Main_image_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->image, key, r_ptr);
+}
+
+int rna_Main_latt_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->latt, key, r_ptr);
+}
+
+int rna_Main_curve_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->curve, key, r_ptr);
+}
+
+int rna_Main_mball_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->mball, key, r_ptr);
+}
+
+int rna_Main_font_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->vfont, key, r_ptr);
+}
+
+int rna_Main_tex_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->tex, key, r_ptr);
+}
+
+int rna_Main_brush_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->brush, key, r_ptr);
+}
+
+int rna_Main_world_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->world, key, r_ptr);
+}
+
+int rna_Main_collection_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->collection, key, r_ptr);
+}
+
+int rna_Main_key_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->key, key, r_ptr);
+}
+
+int rna_Main_text_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->text, key, r_ptr);
+}
+
+int rna_Main_speaker_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->speaker, key, r_ptr);
+}
+
+int rna_Main_sound_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->sound, key, r_ptr);
+}
+
+int rna_Main_armature_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->armature, key, r_ptr);
+}
+
+int rna_Main_action_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->action, key, r_ptr);
+}
+
+int rna_Main_particle_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->particle, key, r_ptr);
+}
+
+int rna_Main_palette_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->palettes, key, r_ptr);
+}
+
+int rna_Main_gpencil_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->gpencil, key, r_ptr);
+}
+
+int rna_Main_movieclip_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->movieclip, key, r_ptr);
+}
+
+int rna_Main_mask_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->mask, key, r_ptr);
+}
+
+int rna_Main_linestyle_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->linestyle, key, r_ptr);
+}
+
+int rna_Main_cachefile_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->cachefiles, key, r_ptr);
+}
+
+int rna_Main_paintcurve_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->paintcurves, key, r_ptr);
+}
+
+int rna_Main_workspace_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->workspaces, key, r_ptr);
+}
+
+int rna_Main_lightprobe_lookup_string(PointerRNA *ptr, const char *key, struct PointerRNA *r_ptr)
+{
+       Main *bmain = ptr->data;
+       return rna_ID_lookup_string(&bmain->lightprobe, key, r_ptr);
+}
+
 static void rna_Main_version_get(PointerRNA *ptr, int *value)
 {
        Main *bmain = (Main *)ptr->data;
@@ -337,6 +572,7 @@ typedef struct MainCollectionDef {
        const char *name;
        const char *description;
        CollectionDefFunc *func;
+       const char *lookup_string;
 } MainCollectionDef;
 
 void RNA_def_main(BlenderRNA *brna)
@@ -347,41 +583,41 @@ void RNA_def_main(BlenderRNA *brna)
 
        /* plural must match idtypes in readblenentry.c */
        MainCollectionDef lists[] = {
-               {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera data-blocks", RNA_def_main_cameras},
-               {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene data-blocks", RNA_def_main_scenes},
-               {"objects", "Object", "rna_Main_object_begin", "Objects", "Object data-blocks", RNA_def_main_objects},
-               {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material data-blocks", RNA_def_main_materials},
-               {"node_groups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group data-blocks", RNA_def_main_node_groups},
-               {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh data-blocks", RNA_def_main_meshes},
-               {"lights", "Light", "rna_Main_light_begin", "Lights", "Light data-blocks", RNA_def_main_lights},
-               {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library data-blocks", RNA_def_main_libraries},
-               {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen data-blocks", RNA_def_main_screens},
-               {"window_managers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager data-blocks", RNA_def_main_window_managers},
-               {"images", "Image", "rna_Main_image_begin", "Images", "Image data-blocks", RNA_def_main_images},
-               {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice data-blocks", RNA_def_main_lattices},
-               {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve data-blocks", RNA_def_main_curves},
-               {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball data-blocks", RNA_def_main_metaballs},
-               {"fonts", "VectorFont", "rna_Main_font_begin", "Vector Fonts", "Vector font data-blocks", RNA_def_main_fonts},
-               {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture data-blocks", RNA_def_main_textures},
-               {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush data-blocks", RNA_def_main_brushes},
-               {"worlds", "World", "rna_Main_world_begin", "Worlds", "World data-blocks", RNA_def_main_worlds},
-               {"collections", "Collection", "rna_Main_collection_begin", "Collections", "Collection data-blocks", RNA_def_main_collections},
-               {"shape_keys", "Key", "rna_Main_key_begin", "Shape Keys", "Shape Key data-blocks", NULL},
-               {"texts", "Text", "rna_Main_text_begin", "Texts", "Text data-blocks", RNA_def_main_texts},
-               {"speakers", "Speaker", "rna_Main_speaker_begin", "Speakers", "Speaker data-blocks", RNA_def_main_speakers},
-               {"sounds", "Sound", "rna_Main_sound_begin", "Sounds", "Sound data-blocks", RNA_def_main_sounds},
-               {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature data-blocks", RNA_def_main_armatures},
-               {"actions", "Action", "rna_Main_action_begin", "Actions", "Action data-blocks", RNA_def_main_actions},
-               {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle data-blocks", RNA_def_main_particles},
-               {"palettes", "Palette", "rna_Main_palettes_begin", "Palettes", "Palette data-blocks", RNA_def_main_palettes},
-               {"grease_pencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil data-blocks", RNA_def_main_gpencil},
-               {"movieclips", "MovieClip", "rna_Main_movieclips_begin", "Movie Clips", "Movie Clip data-blocks", RNA_def_main_movieclips},
-               {"masks", "Mask", "rna_Main_masks_begin", "Masks", "Masks data-blocks", RNA_def_main_masks},
-               {"linestyles", "FreestyleLineStyle", "rna_Main_linestyle_begin", "Line Styles", "Line Style data-blocks", RNA_def_main_linestyles},
-               {"cache_files", "CacheFile", "rna_Main_cachefiles_begin", "Cache Files", "Cache Files data-blocks", RNA_def_main_cachefiles},
-               {"paint_curves", "PaintCurve", "rna_Main_paintcurves_begin", "Paint Curves", "Paint Curves data-blocks", RNA_def_main_paintcurves},
-               {"workspaces", "WorkSpace", "rna_Main_workspaces_begin", "Workspaces", "Workspace data-blocks", RNA_def_main_workspaces},
-               {"lightprobes", "LightProbe", "rna_Main_lightprobes_begin", "LightProbes", "LightProbe data-blocks", RNA_def_main_lightprobes},
+               {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera data-blocks", RNA_def_main_cameras, "rna_Main_camera_lookup_string"},
+               {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene data-blocks", RNA_def_main_scenes, "rna_Main_scene_lookup_string"},
+               {"objects", "Object", "rna_Main_object_begin", "Objects", "Object data-blocks", RNA_def_main_objects, "rna_Main_object_lookup_string"},
+               {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material data-blocks", RNA_def_main_materials, "rna_Main_mat_lookup_string"},
+               {"node_groups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group data-blocks", RNA_def_main_node_groups, "rna_Main_nodetree_lookup_string"},
+               {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh data-blocks", RNA_def_main_meshes, "rna_Main_mesh_lookup_string"},
+               {"lights", "Light", "rna_Main_light_begin", "Lights", "Light data-blocks", RNA_def_main_lights, "rna_Main_light_lookup_string"},
+               {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library data-blocks", RNA_def_main_libraries, "rna_Main_library_lookup_string"},
+               {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen data-blocks", RNA_def_main_screens, "rna_Main_screen_lookup_string"},
+               {"window_managers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager data-blocks", RNA_def_main_window_managers, "rna_Main_wm_lookup_string"},
+               {"images", "Image", "rna_Main_image_begin", "Images", "Image data-blocks", RNA_def_main_images, "rna_Main_image_lookup_string"},
+               {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice data-blocks", RNA_def_main_lattices, "rna_Main_latt_lookup_string"},
+               {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve data-blocks", RNA_def_main_curves, "rna_Main_curve_lookup_string"},
+               {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball data-blocks", RNA_def_main_metaballs, "rna_Main_mball_lookup_string"},
+               {"fonts", "VectorFont", "rna_Main_font_begin", "Vector Fonts", "Vector font data-blocks", RNA_def_main_fonts, "rna_Main_font_lookup_string"},
+               {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture data-blocks", RNA_def_main_textures, "rna_Main_tex_lookup_string"},
+               {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush data-blocks", RNA_def_main_brushes, "rna_Main_brush_lookup_string"},
+               {"worlds", "World", "rna_Main_world_begin", "Worlds", "World data-blocks", RNA_def_main_worlds, "rna_Main_world_lookup_string"},
+               {"collections", "Collection", "rna_Main_collection_begin", "Collections", "Collection data-blocks", RNA_def_main_collections, "rna_Main_collection_lookup_string"},
+               {"shape_keys", "Key", "rna_Main_key_begin", "Shape Keys", "Shape Key data-blocks", NULL, "rna_Main_key_lookup_string"},
+               {"texts", "Text", "rna_Main_text_begin", "Texts", "Text data-blocks", RNA_def_main_texts, "rna_Main_text_lookup_string"},
+               {"speakers", "Speaker", "rna_Main_speaker_begin", "Speakers", "Speaker data-blocks", RNA_def_main_speakers, "rna_Main_speaker_lookup_string"},
+               {"sounds", "Sound", "rna_Main_sound_begin", "Sounds", "Sound data-blocks", RNA_def_main_sounds, "rna_Main_sound_lookup_string"},
+               {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature data-blocks", RNA_def_main_armatures, "rna_Main_armature_lookup_string"},
+               {"actions", "Action", "rna_Main_action_begin", "Actions", "Action data-blocks", RNA_def_main_actions, "rna_Main_action_lookup_string"},
+               {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle data-blocks", RNA_def_main_particles, "rna_Main_particle_lookup_string"},
+               {"palettes", "Palette", "rna_Main_palettes_begin", "Palettes", "Palette data-blocks", RNA_def_main_palettes, "rna_Main_palette_lookup_string"},
+               {"grease_pencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil data-blocks", RNA_def_main_gpencil, "rna_Main_gpencil_lookup_string"},
+               {"movieclips", "MovieClip", "rna_Main_movieclips_begin", "Movie Clips", "Movie Clip data-blocks", RNA_def_main_movieclips, "rna_Main_movieclip_lookup_string"},
+               {"masks", "Mask", "rna_Main_masks_begin", "Masks", "Masks data-blocks", RNA_def_main_masks, "rna_Main_mask_lookup_string"},
+               {"linestyles", "FreestyleLineStyle", "rna_Main_linestyle_begin", "Line Styles", "Line Style data-blocks", RNA_def_main_linestyles, "rna_Main_linestyle_lookup_string"},
+               {"cache_files", "CacheFile", "rna_Main_cachefiles_begin", "Cache Files", "Cache Files data-blocks", RNA_def_main_cachefiles, "rna_Main_cachefile_lookup_string"},
+               {"paint_curves", "PaintCurve", "rna_Main_paintcurves_begin", "Paint Curves", "Paint Curves data-blocks", RNA_def_main_paintcurves, "rna_Main_paintcurve_lookup_string"},
+               {"workspaces", "WorkSpace", "rna_Main_workspaces_begin", "Workspaces", "Workspace data-blocks", RNA_def_main_workspaces, "rna_Main_workspace_lookup_string"},
+               {"lightprobes", "LightProbe", "rna_Main_lightprobes_begin", "LightProbes", "LightProbe data-blocks", RNA_def_main_lightprobes, "rna_Main_lightprobe_lookup_string"},
                {NULL, NULL, NULL, NULL, NULL, NULL}
        };
 
@@ -423,7 +659,7 @@ void RNA_def_main(BlenderRNA *brna)
                RNA_def_property_struct_type(prop, lists[i].type);
                RNA_def_property_collection_funcs(prop, lists[i].iter_begin, "rna_iterator_listbase_next",
                                                  "rna_iterator_listbase_end", "rna_iterator_listbase_get",
-                                                 NULL, NULL, NULL, NULL);
+                                                 NULL, NULL, lists[i].lookup_string, NULL);
                RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
 
                /* collection functions */