diff options
author | Ton Roosendaal <ton@blender.org> | 2010-12-17 22:05:34 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2010-12-17 22:05:34 +0300 |
commit | a0ce28d7312adc31194e2ba34974dc5de754fced (patch) | |
tree | fc801b5d536e8d37207d04c068b7e1e456f470df /source/blender/editors | |
parent | fd90685a48f6fae30e6731bc4a805930e776f117 (diff) |
Drag & drop feature:
You now can drop a .blend inside blender window to open it.
Implementation notes:
- Added call to extract icon type for files. Code re-used from
space_file
- External files that get dropped set icon types too.
Drop box polls can check for this.
- Also enabled setting op-context for drop operators, this was
needed to prevent filewindow to open.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_fileselect.h | 2 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 24 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 137 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.h | 1 |
4 files changed, 112 insertions, 52 deletions
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h index 5001323cb61..a7d763ca4c8 100644 --- a/source/blender/editors/include/ED_fileselect.h +++ b/source/blender/editors/include/ED_fileselect.h @@ -93,5 +93,7 @@ void ED_fileselect_clear(struct bContext *C, struct SpaceFile *sfile); void ED_fileselect_exit(struct bContext *C, struct SpaceFile *sfile); +int ED_file_extension_icon(char *relname); + #endif /* ED_FILES_H */ diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index bcfddd0792c..0c49779cd84 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -64,6 +64,7 @@ #include "RNA_define.h" #include "UI_interface.h" +#include "UI_resources.h" #include "wm_window.h" @@ -3014,6 +3015,7 @@ void SCENE_OT_delete(wmOperatorType *ot) /* **************** Assigning operatortypes to global list, adding handlers **************** */ + /* called in spacetypes.c */ void ED_operatortypes_screen(void) { @@ -3087,9 +3089,27 @@ static void keymap_modal_set(wmKeyConfig *keyconf) } +static int open_file_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event)) +{ + if(drag->type==WM_DRAG_PATH) { + if(drag->icon==ICON_FILE_BLEND) + return 1; + } + return 0; +} + +static void open_file_drop_copy(wmDrag *drag, wmDropBox *drop) +{ + /* copy drag path to properties */ + RNA_string_set(drop->ptr, "filepath", drag->path); + drop->opcontext= WM_OP_EXEC_DEFAULT; +} + + /* called in spacetypes.c */ void ED_keymap_screen(wmKeyConfig *keyconf) { + ListBase *lb; wmKeyMap *keymap; //wmKeyMapItem *kmi; @@ -3203,6 +3223,10 @@ void ED_keymap_screen(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", DOWNARROWKEY, KM_PRESS, KM_ALT, 0); #endif + /* dropbox for entire window */ + lb= WM_dropboxmap_find("Window", 0, 0); + WM_dropbox_add(lb, "WM_OT_open_mainfile", open_file_drop_poll, open_file_drop_copy); + keymap_modal_set(keyconf); } diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 476a887ee87..ce4b5bdd4de 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -69,10 +69,11 @@ #include "PIL_time.h" - #include "WM_api.h" #include "WM_types.h" +#include "UI_resources.h" + #include "filelist.h" /* max length of library group name within filesel */ @@ -360,7 +361,7 @@ void filelist_filter(FileList* filelist) } } -void filelist_init_icons() +void filelist_init_icons(void) { short x, y, k; ImBuf *bbuf; @@ -383,7 +384,7 @@ void filelist_init_icons() } } -void filelist_free_icons() +void filelist_free_icons(void) { int i; for (i=0; i < SPECIAL_IMG_MAX; ++i) { @@ -720,6 +721,87 @@ void filelist_setfilter_types(struct FileList* filelist, const char *filter_glob BLI_strncpy(filelist->filter_glob, filter_glob, sizeof(filelist->filter_glob)); } +static int file_extension_type(char *relname) +{ + if(BLO_has_bfile_extension(relname)) { + return BLENDERFILE; + } else if(BLI_testextensie(relname, ".py")) { + return PYSCRIPTFILE; + } else if(BLI_testextensie(relname, ".txt") + || BLI_testextensie(relname, ".glsl") + || BLI_testextensie(relname, ".data")) { + return TEXTFILE; + } else if( BLI_testextensie(relname, ".ttf") + || BLI_testextensie(relname, ".ttc") + || BLI_testextensie(relname, ".pfb") + || BLI_testextensie(relname, ".otf") + || BLI_testextensie(relname, ".otc")) { + return FTFONTFILE; + } else if(BLI_testextensie(relname, ".btx")) { + return BTXFILE; + } else if(BLI_testextensie(relname, ".dae")) { + return COLLADAFILE; + } else if(BLI_testextensie_array(relname, imb_ext_image) + || (G.have_quicktime && BLI_testextensie_array(relname, imb_ext_image_qt))) { + return IMAGEFILE; + } else if(BLI_testextensie_array(relname, imb_ext_movie)) { + return MOVIEFILE; + } else if(BLI_testextensie_array(relname, imb_ext_audio)) { + return SOUNDFILE; + } + return 0; +} + +int ED_file_extension_icon(char *relname) +{ + int type= file_extension_type(relname); + + if (type == BLENDERFILE) + return ICON_FILE_BLEND; + else if (type == IMAGEFILE) + return ICON_FILE_IMAGE; + else if (type == MOVIEFILE) + return ICON_FILE_MOVIE; + else if (type == PYSCRIPTFILE) + return ICON_FILE_SCRIPT; + else if (type == PYSCRIPTFILE) + return ICON_FILE_SCRIPT; + else if (type == SOUNDFILE) + return ICON_FILE_SOUND; + else if (type == FTFONTFILE) + return ICON_FILE_FONT; + else if (type == BTXFILE) + return ICON_FILE_BLANK; + else if (type == COLLADAFILE) + return ICON_FILE_BLANK; + + return ICON_FILE_BLANK; +} + +void filelist_setfiletypes(struct FileList* filelist) +{ + struct direntry *file; + int num; + + file= filelist->filelist; + + for(num=0; num<filelist->numfiles; num++, file++) { + file->type= file->s.st_mode; /* restore the mess below */ + + /* Don't check extensions for directories */ + if (file->type & S_IFDIR) { + continue; + } + file->flags = file_extension_type(file->relname); + + if(filelist->filter_glob + && BLI_testextensie_glob(file->relname, filelist->filter_glob)) { + file->flags= OPERATORFILE; + } + + } +} + static void filelist_read_dir(struct FileList* filelist) { char wdir[FILE_MAX]; @@ -734,7 +816,7 @@ static void filelist_read_dir(struct FileList* filelist) filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist)); if(!chdir(wdir)) {} /* fix warning about not checking return value */ - filelist_setfiletypes(filelist, G.have_quicktime); + filelist_setfiletypes(filelist); filelist_filter(filelist); } @@ -790,53 +872,6 @@ void filelist_parent(struct FileList* filelist) filelist_readdir(filelist); } -void filelist_setfiletypes(struct FileList* filelist, short has_quicktime) -{ - struct direntry *file; - int num; - - file= filelist->filelist; - - for(num=0; num<filelist->numfiles; num++, file++) { - file->flags= 0; - file->type= file->s.st_mode; /* restore the mess below */ - - /* Don't check extensions for directories */ - if (file->type & S_IFDIR) { - continue; - } - - if(BLO_has_bfile_extension(file->relname)) { - file->flags |= BLENDERFILE; - } else if(BLI_testextensie(file->relname, ".py")) { - file->flags |= PYSCRIPTFILE; - } else if(BLI_testextensie(file->relname, ".txt") - || BLI_testextensie(file->relname, ".glsl") - || BLI_testextensie(file->relname, ".data")) { - file->flags |= TEXTFILE; - } else if( BLI_testextensie(file->relname, ".ttf") - || BLI_testextensie(file->relname, ".ttc") - || BLI_testextensie(file->relname, ".pfb") - || BLI_testextensie(file->relname, ".otf") - || BLI_testextensie(file->relname, ".otc")) { - file->flags |= FTFONTFILE; - } else if(BLI_testextensie(file->relname, ".btx")) { - file->flags |= BTXFILE; - } else if(BLI_testextensie(file->relname, ".dae")) { - file->flags |= COLLADAFILE; - } else if(BLI_testextensie_array(file->relname, imb_ext_image) - || (has_quicktime && BLI_testextensie_array(file->relname, imb_ext_image_qt))) { - file->flags |= IMAGEFILE; - } else if(BLI_testextensie_array(file->relname, imb_ext_movie)) { - file->flags |= MOVIEFILE; - } else if(BLI_testextensie_array(file->relname, imb_ext_audio)) { - file->flags |= SOUNDFILE; - } else if(filelist->filter_glob - && BLI_testextensie_glob(file->relname, filelist->filter_glob)) { - file->flags |= OPERATORFILE; - } - } -} void filelist_swapselect(struct FileList* filelist) { diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h index eb1c46d652e..6ea91746b85 100644 --- a/source/blender/editors/space_file/filelist.h +++ b/source/blender/editors/space_file/filelist.h @@ -69,7 +69,6 @@ void filelist_readdir(struct FileList* filelist); int filelist_empty(struct FileList* filelist); void filelist_parent(struct FileList* filelist); -void filelist_setfiletypes(struct FileList* filelist, short has_quicktime); int filelist_islibrary (struct FileList* filelist, char* dir, char* group); |