- console drop handler for datablocks & filepaths.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 8 May 2010 07:25:26 +0000 (07:25 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 8 May 2010 07:25:26 +0000 (07:25 +0000)
- added BLO_idcode_to_name_plural() for names like meshes, scenes, libraries etc from and ID type.

source/blender/blenloader/BLO_readfile.h
source/blender/blenloader/intern/readblenentry.c
source/blender/editors/space_console/space_console.c
source/blender/makesrna/intern/rna_internal.h
source/blender/makesrna/intern/rna_main.c
source/blender/makesrna/intern/rna_main_api.c

index df7cd25a6dbd9c6ff2b5fa66f6cfe8c1b6212e03..d6418f426c87ab0774bda51065d1f35fc033760d 100644 (file)
@@ -122,6 +122,17 @@ BLO_blendfiledata_free(
        char*
 BLO_idcode_to_name(
        int code);
+       
+/**
+ * Convert an idcode into a name (plural).
+ * 
+ * @param code The code to convert.
+ * @return A static string representing the name of
+ * the code.
+ */
+       char*
+BLO_idcode_to_name_plural(
+       int code);
 
 /**
  * Convert a name into an idcode (ie. ID_SCE)
index 33827c801f17927c19a9a6227434d3ab439ad821..6424829c12a83578ebe483ea71d1e7ed4d1eb74c 100644 (file)
 
 typedef struct {
        unsigned short code;
-       char *name;
+       char *name, *plural;
        
        int flags;
 #define IDTYPE_FLAGS_ISLINKABLE        (1<<0)
 } IDType;
 
+/* plural need to match rna_main.c's MainCollectionDef */
 static IDType idtypes[]= {
-       { ID_AC,                "Action",       IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_AR,                "Armature", IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_BR,                "Brush",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_CA,                "Camera",       IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_CU,                "Curve",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_GD,                "GPencil",      IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_GR,                "Group",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_ID,                "ID",           0}, 
-       { ID_IM,                "Image",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_IP,                "Ipo",          IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_KE,                "Key",          0}, 
-       { ID_LA,                "Lamp",         IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_LI,                "Library",      0}, 
-       { ID_LT,                "Lattice",      IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_MA,                "Material", IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_MB,                "Metaball", IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_ME,                "Mesh",         IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_NT,                "NodeTree",     IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_OB,                "Object",       IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_SCE,               "Scene",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_SCR,               "Screen",       0}, 
-       { ID_SEQ,               "Sequence",     0}, 
-       { ID_SO,                "Sound",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_TE,                "Texture",      IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_TXT,               "Text",         IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_VF,                "VFont",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_WO,                "World",        IDTYPE_FLAGS_ISLINKABLE}, 
-       { ID_WV,                "Wave",         0}, 
+       { ID_AC,                "Action",       "actions",              IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_AR,                "Armature", "armatures",        IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_BR,                "Brush",        "brushes",              IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_CA,                "Camera",       "cameras",              IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_CU,                "Curve",        "curves",               IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_GD,                "GPencil",      "gpencil",              IDTYPE_FLAGS_ISLINKABLE},  /* rename gpencil */
+       { ID_GR,                "Group",        "groups",               IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_ID,                "ID",           "ids",                  0}, /* plural is fake */
+       { ID_IM,                "Image",        "images",               IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_IP,                "Ipo",          "ipos",                 IDTYPE_FLAGS_ISLINKABLE},  /* deprecated */
+       { ID_KE,                "Key",          "keys",                 0}, 
+       { ID_LA,                "Lamp",         "lamps",                IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_LI,                "Library",      "libraries",    0}, 
+       { ID_LT,                "Lattice",      "lattices",             IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_MA,                "Material", "materials",        IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_MB,                "Metaball", "metaballs",        IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_ME,                "Mesh",         "meshes",               IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_NT,                "NodeTree",     "node_groups",  IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_OB,                "Object",       "objects",              IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_PA,                "ParticleSettings",     "particles", 0},
+       { ID_SCE,               "Scene",        "scenes",               IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_SCR,               "Screen",       "screens",              0}, 
+       { ID_SEQ,               "Sequence",     "sequences",    0}, /* not actually ID data */
+       { ID_SO,                "Sound",        "sounds",               IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_TE,                "Texture",      "textures",             IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_TXT,               "Text",         "texts",                IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_VF,                "VFont",        "fonts",                IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_WO,                "World",        "worlds",               IDTYPE_FLAGS_ISLINKABLE}, 
+       { ID_WM,                "WindowManager", "window_managers",     0}, 
+       { ID_WV,                "Wave",         "waves",                0},  /* deprecated */
 };
 static int nidtypes= sizeof(idtypes)/sizeof(idtypes[0]);
 
@@ -156,7 +159,14 @@ int BLO_idcode_from_name(char *name)
        
        return idt?idt->code:0;
 }
+
+char *BLO_idcode_to_name_plural(int code) 
+{
+       IDType *idt= idtype_from_code(code);
        
+       return idt?idt->plural:NULL;
+}
+
        /* Access routines used by filesel. */
         
 BlendHandle *BLO_blendhandle_from_file(char *file) 
index 1b8191696f4b6b7816d5a32434032b2b70e09842..8a2f4e85f961f6476d73afbb0ab4a25d11662ec4 100644 (file)
  #include <string.h>
 #include <stdio.h>
 
+#ifdef WIN32
+#include "BLI_winstuff.h"
+#endif
 
 #include "MEM_guardedalloc.h"
 
+#include "BLO_readfile.h"
+               
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 
@@ -142,14 +147,71 @@ static SpaceLink *console_duplicate(SpaceLink *sl)
 static void console_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
        wmKeyMap *keymap;
+       ListBase *lb;
 
        UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
 
        /* own keymap */
        keymap= WM_keymap_find(wm->defaultconf, "Console", SPACE_CONSOLE, 0);
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+       
+       /* add drop boxes */
+       lb= WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
+       
+       WM_event_add_dropbox_handler(&ar->handlers, lb);
+}
+
+
+/* ************* dropboxes ************* */
+
+static int id_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+{
+    SpaceConsole *sc= CTX_wm_space_console(C);
+    if(sc->type==CONSOLE_TYPE_PYTHON)
+        if(drag->type==WM_DRAG_ID)
+            return 1;
+       return 0;
+}
+
+static void id_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+       char text[64];
+       ID *id= drag->poin;
+
+       snprintf(text, sizeof(text), "bpy.data.%s['%s']", BLO_idcode_to_name_plural(GS(id->name)), id->name+2); 
+
+       /* copy drag path to properties */
+       RNA_string_set(drop->ptr, "text", text);
 }
 
+static int path_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
+{
+    SpaceConsole *sc= CTX_wm_space_console(C);
+    if(sc->type==CONSOLE_TYPE_PYTHON)
+        if(drag->type==WM_DRAG_PATH)
+            return 1;
+       return 0;
+}
+
+static void path_drop_copy(wmDrag *drag, wmDropBox *drop)
+{
+    char pathname[FILE_MAXDIR+FILE_MAXFILE+2];
+    snprintf(pathname, sizeof(pathname), "\"%s\"", drag->path);
+       RNA_string_set(drop->ptr, "text", pathname);
+}
+
+
+/* this region dropbox definition */
+static void console_dropboxes(void)
+{
+       ListBase *lb= WM_dropboxmap_find("Console", SPACE_CONSOLE, RGN_TYPE_WINDOW);
+       
+       WM_dropbox_add(lb, "CONSOLE_OT_insert", id_drop_poll, id_drop_copy);
+       WM_dropbox_add(lb, "CONSOLE_OT_insert", path_drop_poll, path_drop_copy);
+}
+
+/* ************* end drop *********** */
+
 static void console_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
@@ -344,6 +406,7 @@ void ED_spacetype_console(void)
        st->duplicate= console_duplicate;
        st->operatortypes= console_operatortypes;
        st->keymap= console_keymap;
+       st->dropboxes= console_dropboxes;
        st->listener= console_main_area_listener;
        
        /* regions: main window */
index 433d5ff29049b8da29765cfc659969f99701cc40..005efdb9bc420095aa6128a1530dbb653b3f0963 100644 (file)
@@ -249,7 +249,7 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop);
 void RNA_def_main_lattices(BlenderRNA *brna, PropertyRNA *cprop);
 void RNA_def_main_curves(BlenderRNA *brna, PropertyRNA *cprop);
 void RNA_def_main_metaballs(BlenderRNA *brna, PropertyRNA *cprop);
-void RNA_def_main_vfonts(BlenderRNA *brna, PropertyRNA *cprop);
+void RNA_def_main_fonts(BlenderRNA *brna, PropertyRNA *cprop);
 void RNA_def_main_textures(BlenderRNA *brna, PropertyRNA *cprop);
 void RNA_def_main_brushes(BlenderRNA *brna, PropertyRNA *cprop);
 void RNA_def_main_worlds(BlenderRNA *brna, PropertyRNA *cprop);
index 7688d92f2e13b783ec64c22ae6082b2f3d3effd0..b683f5dc4b15b0082d9779535660a9a7f0fae418 100644 (file)
@@ -173,7 +173,7 @@ static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *
        rna_iterator_listbase_begin(iter, &bmain->script, NULL);
 }
 
-static void rna_Main_vfont_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+static void rna_Main_font_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        Main *bmain= (Main*)ptr->data;
        rna_iterator_listbase_begin(iter, &bmain->vfont, NULL);
@@ -271,6 +271,7 @@ void RNA_def_main(BlenderRNA *brna)
        PropertyRNA *prop;
        CollectionDefFunc *func;
 
+       /* plural must match idtypes in readblenentry.c */
        MainCollectionDef lists[]= {
                {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks.", RNA_def_main_cameras},
                {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks.", RNA_def_main_scenes},
@@ -286,7 +287,7 @@ void RNA_def_main(BlenderRNA *brna)
                {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks.", RNA_def_main_lattices},
                {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks.", RNA_def_main_curves} ,
                {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks.", RNA_def_main_metaballs},
-               {"vfonts", "VectorFont", "rna_Main_vfont_begin", "Vector Fonts", "Vector font datablocks.", RNA_def_main_vfonts},
+               {"fonts", "VectorFont", "rna_Main_font_begin", "Vector Fonts", "Vector font datablocks.", RNA_def_main_fonts},
                {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks.", RNA_def_main_textures},
                {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks.", RNA_def_main_brushes},
                {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks.", RNA_def_main_worlds},
index d70962568e50cbbad95c47e05389651c033f4264..186334f12a46fbf0e62d09d5e37caa220c209bcd 100644 (file)
@@ -594,7 +594,7 @@ void RNA_def_main_metaballs(BlenderRNA *brna, PropertyRNA *cprop)
 {
 
 }
-void RNA_def_main_vfonts(BlenderRNA *brna, PropertyRNA *cprop)
+void RNA_def_main_fonts(BlenderRNA *brna, PropertyRNA *cprop)
 {
 
 }