WIP: UI: Add Drag & Drop Feedback on Windows #107056
|
@ -26,6 +26,7 @@ set(INC_SYS
|
|||
)
|
||||
|
||||
set(SRC
|
||||
io_utils.c
|
||||
io_alembic.c
|
||||
io_cache.c
|
||||
io_collada.c
|
||||
|
@ -38,6 +39,7 @@ set(SRC
|
|||
io_stl_ops.c
|
||||
io_usd.c
|
||||
|
||||
io_utils.h
|
||||
io_alembic.h
|
||||
io_cache.h
|
||||
io_collada.h
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
# include "IO_path_util_types.h"
|
||||
# include "IO_wavefront_obj.h"
|
||||
# include "io_obj.h"
|
||||
# include "io_utils.h"
|
||||
|
||||
static const EnumPropertyItem io_obj_export_evaluation_mode[] = {
|
||||
{DAG_EVAL_RENDER, "DAG_EVAL_RENDER", 0, "Render", "Export objects as they appear in render"},
|
||||
|
@ -370,12 +371,6 @@ void WM_OT_obj_export(struct wmOperatorType *ot)
|
|||
RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
}
|
||||
|
||||
static int wm_obj_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
{
|
||||
WM_event_add_fileselect(C, op);
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
static int wm_obj_import_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
struct OBJImportParams import_params;
|
||||
|
@ -457,6 +452,7 @@ static void wm_obj_import_draw(bContext *C, wmOperator *op)
|
|||
PointerRNA ptr;
|
||||
wmWindowManager *wm = CTX_wm_manager(C);
|
||||
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
|
||||
files_drop_info_draw(C, op, ICON_FILE_3D);
|
||||
ui_obj_import_settings(op->layout, &ptr);
|
||||
}
|
||||
|
||||
|
@ -467,9 +463,9 @@ void WM_OT_obj_import(struct wmOperatorType *ot)
|
|||
ot->name = "Import Wavefront OBJ";
|
||||
ot->description = "Load a Wavefront OBJ scene";
|
||||
ot->idname = "WM_OT_obj_import";
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_PRESET;
|
||||
ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
|
||||
|
||||
ot->invoke = wm_obj_import_invoke;
|
||||
ot->invoke = wm_io_import_invoke;
|
||||
ot->exec = wm_obj_import_exec;
|
||||
ot->poll = WM_operator_winactive;
|
||||
ot->ui = wm_obj_import_draw;
|
||||
|
@ -482,6 +478,7 @@ void WM_OT_obj_import(struct wmOperatorType *ot)
|
|||
WM_FILESEL_DIRECTORY | WM_FILESEL_FILES,
|
||||
FILE_DEFAULTDISPLAY,
|
||||
FILE_SORT_DEFAULT);
|
||||
skip_save_import_paths_props(ot, WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILES);
|
||||
RNA_def_float(
|
||||
ot->srna,
|
||||
"global_scale",
|
||||
|
@ -533,4 +530,22 @@ void WM_OT_obj_import(struct wmOperatorType *ot)
|
|||
RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
}
|
||||
|
||||
bool obj_file_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
|
||||
{
|
||||
if (drag->type == WM_DRAG_PATH) {
|
||||
const eFileSel_File_Types file_type = WM_drag_get_path_file_type(drag);
|
||||
if (file_type == FILE_TYPE_OBJECT_IO &&
|
||||
BLI_path_extension_check(WM_drag_get_path(drag), ".obj")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WM_obj_dropbox_add()
|
||||
{
|
||||
ListBase *lb = WM_dropboxmap_find("Window", 0, 0);
|
||||
WM_dropbox_add(lb, "WM_OT_obj_import", obj_file_drop_poll, files_drop_copy, NULL, NULL);
|
||||
}
|
||||
|
||||
#endif /* WITH_IO_WAVEFRONT_OBJ */
|
||||
|
|
|
@ -10,3 +10,4 @@ struct wmOperatorType;
|
|||
|
||||
void WM_OT_obj_export(struct wmOperatorType *ot);
|
||||
void WM_OT_obj_import(struct wmOperatorType *ot);
|
||||
void WM_obj_dropbox_add();
|
||||
|
|
|
@ -33,18 +33,22 @@ void ED_operatortypes_io(void)
|
|||
/* Collada operators: */
|
||||
WM_operatortype_append(WM_OT_collada_export);
|
||||
WM_operatortype_append(WM_OT_collada_import);
|
||||
// WM_collada_dropbox_add();
|
||||
#endif
|
||||
#ifdef WITH_ALEMBIC
|
||||
WM_operatortype_append(WM_OT_alembic_import);
|
||||
WM_operatortype_append(WM_OT_alembic_export);
|
||||
// WM_alembic_dropbox_add();
|
||||
#endif
|
||||
#ifdef WITH_USD
|
||||
WM_operatortype_append(WM_OT_usd_import);
|
||||
WM_operatortype_append(WM_OT_usd_export);
|
||||
// WM_usd_dropbox_add();
|
||||
#endif
|
||||
|
||||
#ifdef WITH_IO_GPENCIL
|
||||
WM_operatortype_append(WM_OT_gpencil_import_svg);
|
||||
// WM_gpencil_dropbox_add();
|
||||
# ifdef WITH_PUGIXML
|
||||
WM_operatortype_append(WM_OT_gpencil_export_svg);
|
||||
# endif
|
||||
|
@ -63,14 +67,17 @@ void ED_operatortypes_io(void)
|
|||
#ifdef WITH_IO_WAVEFRONT_OBJ
|
||||
WM_operatortype_append(WM_OT_obj_export);
|
||||
WM_operatortype_append(WM_OT_obj_import);
|
||||
WM_obj_dropbox_add();
|
||||
#endif
|
||||
|
||||
#ifdef WITH_IO_PLY
|
||||
WM_operatortype_append(WM_OT_ply_export);
|
||||
WM_operatortype_append(WM_OT_ply_import);
|
||||
// WM_ply_dropbox_add();
|
||||
#endif
|
||||
|
||||
#ifdef WITH_IO_STL
|
||||
WM_operatortype_append(WM_OT_stl_import);
|
||||
// WM_stl_dropbox_add();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#if defined(WITH_COLLADA) || defined(WITH_IO_GPENCIL) || defined(WITH_IO_WAVEFRONT_OBJ) || \
|
||||
defined(WITH_IO_PLY) || defined(WITH_IO_STL) || defined(WITH_USD)
|
||||
|
||||
# include "DNA_space_types.h"
|
||||
|
||||
# include "BKE_context.h"
|
||||
|
||||
# include "BLI_path_util.h"
|
||||
# include "BLI_string.h"
|
||||
# include "BLI_utildefines.h"
|
||||
# include "BLT_translation.h"
|
||||
|
||||
# include "ED_fileselect.h"
|
||||
|
||||
# include "RNA_access.h"
|
||||
# include "RNA_define.h"
|
||||
|
||||
# include "UI_interface.h"
|
||||
|
||||
# include "WM_api.h"
|
||||
# include "io_utils.h"
|
||||
|
||||
int wm_io_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
{
|
||||
char filepath[FILE_MAX];
|
||||
RNA_string_get(op->ptr, "filepath", filepath);
|
||||
if (filepath[0]) {
|
||||
return WM_operator_props_dialog_popup(C, op, 300);
|
||||
}
|
||||
WM_event_add_fileselect(C, op);
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
void skip_save_import_paths_props(wmOperatorType *ot, const eFileSel_Flag flag)
|
||||
{
|
||||
if (flag & WM_FILESEL_FILEPATH) {
|
||||
RNA_def_property_flag(RNA_struct_type_find_property(ot->srna, "filepath"), PROP_SKIP_SAVE);
|
||||
}
|
||||
if (flag & WM_FILESEL_FILENAME) {
|
||||
RNA_def_property_flag(RNA_struct_type_find_property(ot->srna, "filename"), PROP_SKIP_SAVE);
|
||||
}
|
||||
if (flag & WM_FILESEL_DIRECTORY) {
|
||||
RNA_def_property_flag(RNA_struct_type_find_property(ot->srna, "directory"), PROP_SKIP_SAVE);
|
||||
}
|
||||
if (flag & WM_FILESEL_FILES) {
|
||||
RNA_def_property_flag(RNA_struct_type_find_property(ot->srna, "files"), PROP_SKIP_SAVE);
|
||||
}
|
||||
if (flag & WM_FILESEL_RELPATH) {
|
||||
RNA_def_property_flag(RNA_struct_type_find_property(ot->srna, "relative_path"),
|
||||
PROP_SKIP_SAVE);
|
||||
}
|
||||
}
|
||||
|
||||
void files_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
|
||||
{
|
||||
|
||||
RNA_string_set(drop->ptr, "filepath", WM_drag_get_path(drag));
|
||||
|
||||
// TODO(@guishe): Add support for multiple drag&drop files import
|
||||
char dir[FILE_MAX], file[FILE_MAX];
|
||||
BLI_split_dirfile(WM_drag_get_path(drag), dir, file, sizeof(dir), sizeof(file));
|
||||
|
||||
RNA_string_set(drop->ptr, "directory", dir);
|
||||
|
||||
RNA_collection_clear(drop->ptr, "files");
|
||||
PointerRNA itemptr;
|
||||
RNA_collection_add(drop->ptr, "files", &itemptr);
|
||||
RNA_string_set(&itemptr, "name", file);
|
||||
}
|
||||
|
||||
void file_drop_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop)
|
||||
{
|
||||
RNA_string_set(drop->ptr, "filepath", WM_drag_get_path(drag));
|
||||
}
|
||||
|
||||
void file_drop_info_draw(bContext *C, wmOperator *op, int icon)
|
||||
{
|
||||
ScrArea *area = CTX_wm_area(C);
|
||||
if (area->spacetype != SPACE_FILE) {
|
||||
char filepath[FILE_MAX];
|
||||
RNA_string_get(op->ptr, "filepath", filepath);
|
||||
uiLayout *box = uiLayoutBox(op->layout);
|
||||
uiItemL(box, filepath, icon);
|
||||
}
|
||||
}
|
||||
|
||||
void files_drop_info_draw(bContext *C, wmOperator *op, int icon)
|
||||
{
|
||||
ScrArea *area = CTX_wm_area(C);
|
||||
if (area->spacetype != SPACE_FILE) {
|
||||
char label[FILE_MAX] = "Multiple files selected.";
|
||||
|
||||
if (RNA_collection_length(op->ptr, "files") == 1) {
|
||||
RNA_string_get(op->ptr, "filepath", label);
|
||||
}
|
||||
uiLayout *box = uiLayoutBox(op->layout);
|
||||
uiItemL(box, label, icon);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,27 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(WITH_COLLADA) || defined(WITH_IO_GPENCIL) || defined(WITH_IO_WAVEFRONT_OBJ) || \
|
||||
defined(WITH_IO_PLY) || defined(WITH_IO_STL) || defined(WITH_USD)
|
||||
|
||||
# include "WM_types.h"
|
||||
|
||||
struct wmOperator;
|
||||
struct wmOperatorType;
|
||||
struct wmDrag;
|
||||
struct wmDropBox;
|
||||
|
||||
int wm_io_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event));
|
||||
|
||||
void skip_save_import_paths_props(wmOperatorType *ot, const eFileSel_Flag flag);
|
||||
|
||||
void file_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop);
|
||||
// Function that copies file directories for operators that support importing multiple files
|
||||
void files_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop);
|
||||
|
||||
void file_drop_info_draw(bContext *C, wmOperator *op, int icon);
|
||||
// Function that summarizes file information for operators that support importing multiple files
|
||||
void files_drop_info_draw(bContext *C, wmOperator *op, int icon);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue