File Selector, support filepath dropping
This adds support for dropping a filepath on an open file-selector to set that path.
This commit is contained in:

committed by
Campbell Barton

parent
e43b6e2f97
commit
b566adec52
@@ -441,6 +441,7 @@ static void file_operatortypes(void)
|
||||
WM_operatortype_append(FILE_OT_delete);
|
||||
WM_operatortype_append(FILE_OT_rename);
|
||||
WM_operatortype_append(FILE_OT_smoothscroll);
|
||||
WM_operatortype_append(FILE_OT_filepath_drop);
|
||||
}
|
||||
|
||||
/* NOTE: do not add .blend file reading on this level */
|
||||
@@ -661,6 +662,30 @@ static void file_ui_area_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), AReg
|
||||
}
|
||||
}
|
||||
|
||||
static int filepath_drop_poll(bContext *C, wmDrag *drag, const wmEvent *UNUSED(event))
|
||||
{
|
||||
if (drag->type == WM_DRAG_PATH) {
|
||||
SpaceFile *sfile = CTX_wm_space_file(C);
|
||||
if (sfile) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void filepath_drop_copy(wmDrag *drag, wmDropBox *drop)
|
||||
{
|
||||
RNA_string_set(drop->ptr, "filepath", drag->path);
|
||||
}
|
||||
|
||||
/* region dropbox definition */
|
||||
static void file_dropboxes(void)
|
||||
{
|
||||
ListBase *lb = WM_dropboxmap_find("Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
|
||||
|
||||
WM_dropbox_add(lb, "FILE_OT_filepath_drop", filepath_drop_poll, filepath_drop_copy);
|
||||
}
|
||||
|
||||
/* only called once, from space/spacetypes.c */
|
||||
void ED_spacetype_file(void)
|
||||
{
|
||||
@@ -679,7 +704,8 @@ void ED_spacetype_file(void)
|
||||
st->listener = file_listener;
|
||||
st->operatortypes = file_operatortypes;
|
||||
st->keymap = file_keymap;
|
||||
|
||||
st->dropboxes = file_dropboxes;
|
||||
|
||||
/* regions: main window */
|
||||
art = MEM_callocN(sizeof(ARegionType), "spacetype file region");
|
||||
art->regionid = RGN_TYPE_WINDOW;
|
||||
|
Reference in New Issue
Block a user