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>2010-05-08 11:25:26 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-05-08 11:25:26 +0400
commitfcaca6c5bde7c580fa9c7d2445ec5c98418b7cbc (patch)
tree3f787c6c491c83a096650e2ef398ed29fd97df30 /source
parent68173d1dc0e4d1b8e205bd614e1dc43aaafd4442 (diff)
- console drop handler for datablocks & filepaths.
- added BLO_idcode_to_name_plural() for names like meshes, scenes, libraries etc from and ID type.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenloader/BLO_readfile.h11
-rw-r--r--source/blender/blenloader/intern/readblenentry.c68
-rw-r--r--source/blender/editors/space_console/space_console.c63
-rw-r--r--source/blender/makesrna/intern/rna_internal.h2
-rw-r--r--source/blender/makesrna/intern/rna_main.c5
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c2
6 files changed, 118 insertions, 33 deletions
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index df7cd25a6db..d6418f426c8 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -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)
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 33827c801f1..6424829c12a 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -70,41 +70,44 @@
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)
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index 1b8191696f4..8a2f4e85f96 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -29,9 +29,14 @@
#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 */
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 433d5ff2904..005efdb9bc4 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -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);
diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c
index 7688d92f2e1..b683f5dc4b1 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -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},
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index d70962568e5..186334f12a4 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -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)
{
}