Collection IO: Enable file exporters to be specified on Collections #116646
|
@ -54,10 +54,13 @@ class COLLECTION_PT_collection_flags(CollectionButtonsPanel, Panel):
|
|||
class COLLECTION_PT_io_handlers(CollectionButtonsPanel, Panel):
|
||||
bl_label = "IO Handlers"
|
||||
|
||||
def draw(self, _context):
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
collection = context.collection
|
||||
|
||||
layout.operator("wm.call_menu", text="Add IO Handler", icon='ADD').name = "COLLECTION_MT_io_handler_add"
|
||||
layout.operator("COLLECTION_OT_io_export_all", icon='EXPORT')
|
||||
if collection.io_handlers:
|
||||
layout.operator("COLLECTION_OT_io_export_all", icon='EXPORT')
|
||||
layout.template_collection_exporters()
|
||||
|
||||
|
||||
|
|
|
@ -156,14 +156,6 @@ static void collection_copy_data(Main *bmain, ID *id_dst, const ID *id_src, cons
|
|||
}
|
||||
}
|
||||
|
||||
static void io_handler_item_free(IOHandlerData *data)
|
||||
{
|
||||
if (data->export_properties) {
|
||||
IDP_FreeProperty(data->export_properties);
|
||||
data->export_properties = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void collection_free_data(ID *id)
|
||||
{
|
||||
Collection *collection = (Collection *)id;
|
||||
|
@ -181,7 +173,9 @@ static void collection_free_data(ID *id)
|
|||
BLI_freelistN(&collection->runtime.parents);
|
||||
|
||||
LISTBASE_FOREACH (IOHandlerData *, data, &collection->io_handlers) {
|
||||
io_handler_item_free(data);
|
||||
if (data->export_properties) {
|
||||
IDP_FreeProperty(data->export_properties);
|
||||
}
|
||||
}
|
||||
BLI_freelistN(&collection->io_handlers);
|
||||
|
||||
|
|
|
@ -2351,14 +2351,14 @@ void uiTemplateModifiers(uiLayout * /*layout*/, bContext *C)
|
|||
# pragma optimize("", off)
|
||||
#endif
|
||||
void draw_export_controls(
|
||||
bContext *C, uiLayout *layout, PointerRNA *ptr, FileHandlerType *fh, int id)
|
||||
bContext *C, uiLayout *layout, PointerRNA *ptr, FileHandlerType *fh, int index)
|
||||
{
|
||||
uiLayout *box = uiLayoutBox(layout);
|
||||
uiLayout *row = uiLayoutRow(box, true);
|
||||
uiItemR(row, ptr, "filepath", UI_ITEM_NONE, nullptr, ICON_NONE);
|
||||
uiItemS(row);
|
||||
uiItemIntO(row, "", ICON_EXPORT, "COLLECTION_OT_io_handler_export", "id", id);
|
||||
uiItemIntO(row, "", ICON_X, "COLLECTION_OT_io_handler_remove", "id", id);
|
||||
uiItemIntO(row, "", ICON_EXPORT, "COLLECTION_OT_io_handler_export", "index", index);
|
||||
uiItemIntO(row, "", ICON_X, "COLLECTION_OT_io_handler_remove", "index", index);
|
||||
}
|
||||
|
||||
void draw_export_properties(bContext *C, uiLayout *layout, PointerRNA *ptr, FileHandlerType *fh)
|
||||
|
@ -2418,14 +2418,12 @@ void draw_export_properties(bContext *C, uiLayout *layout, PointerRNA *ptr, File
|
|||
|
||||
void uiTemplateCollectionExporters(uiLayout *layout, bContext *C)
|
||||
{
|
||||
ARegion *region = CTX_wm_region(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
LayerCollection *layer_coll = BKE_view_layer_active_collection_get(view_layer);
|
||||
ListBase *io_handlers = &layer_coll->collection->io_handlers;
|
||||
Collection *collection = CTX_data_collection(C);
|
||||
ListBase *io_handlers = &collection->io_handlers;
|
||||
|
||||
/* Draw all the IO handlers. */
|
||||
int id = 0;
|
||||
LISTBASE_FOREACH_INDEX (IOHandlerData *, data, io_handlers, id) {
|
||||
int index = 0;
|
||||
LISTBASE_FOREACH_INDEX (IOHandlerData *, data, io_handlers, index) {
|
||||
FileHandlerType *fh = BKE_file_handler_find(data->fh_idname);
|
||||
if (!fh) {
|
||||
continue;
|
||||
|
@ -2440,7 +2438,7 @@ void uiTemplateCollectionExporters(uiLayout *layout, bContext *C)
|
|||
PointerRNA io_handler_ptr = RNA_pointer_create(nullptr, &RNA_IOHandlerData, data);
|
||||
|
||||
if (uiLayout *panel_layout = uiLayoutPanel(C, layout, fh->label, &io_handler_ptr, "is_open")) {
|
||||
draw_export_controls(C, panel_layout, &prop_ptr, fh, id);
|
||||
draw_export_controls(C, panel_layout, &prop_ptr, fh, index);
|
||||
draw_export_properties(C, panel_layout, &prop_ptr, fh);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -423,9 +423,8 @@ void COLLECTION_OT_create(wmOperatorType *ot)
|
|||
|
||||
static int collection_io_handler_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
LayerCollection *layer_coll = BKE_view_layer_active_collection_get(view_layer);
|
||||
ListBase *io_handlers = &layer_coll->collection->io_handlers;
|
||||
Collection *collection = CTX_data_collection(C);
|
||||
ListBase *io_handlers = &collection->io_handlers;
|
||||
|
||||
char name[MAX_ID_NAME - 2]; /* id name */
|
||||
RNA_string_get(op->ptr, "name", name);
|
||||
|
@ -474,20 +473,23 @@ void COLLECTION_OT_io_handler_add(wmOperatorType *ot)
|
|||
|
||||
static int collection_io_handler_remove_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
LayerCollection *layer_coll = BKE_view_layer_active_collection_get(view_layer);
|
||||
ListBase *io_handlers = &layer_coll->collection->io_handlers;
|
||||
Collection *collection = CTX_data_collection(C);
|
||||
ListBase *io_handlers = &collection->io_handlers;
|
||||
|
||||
int id = RNA_int_get(op->ptr, "id");
|
||||
IOHandlerData *data = static_cast<IOHandlerData *>(
|
||||
BLI_listbase_string_or_index_find(io_handlers, nullptr, 0, id));
|
||||
int index = RNA_int_get(op->ptr, "index");
|
||||
IOHandlerData *data = static_cast<IOHandlerData *>(BLI_findlink(io_handlers, index));
|
||||
if (!data) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
if (data->export_properties) {
|
||||
IDP_FreeProperty(data->export_properties);
|
||||
data->export_properties = nullptr;
|
||||
}
|
||||
|
||||
BLI_remlink(io_handlers, data);
|
||||
MEM_freeN(data);
|
||||
|
||||
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_PROPERTIES, nullptr);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
@ -506,7 +508,7 @@ void COLLECTION_OT_io_handler_remove(wmOperatorType *ot)
|
|||
/* flags */
|
||||
deadpin marked this conversation as resolved
Outdated
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
RNA_def_int(ot->srna, "id", 0, 0, INT_MAX, "Id", "IO Handler id", 0, INT_MAX);
|
||||
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "IO Handler index", 0, INT_MAX);
|
||||
}
|
||||
|
||||
deadpin marked this conversation as resolved
Outdated
Brecht Van Lommel
commented
IO Handler index -> Exporter index IO Handler index -> Exporter index
|
||||
static int io_handler_export(bContext *C, IOHandlerData *data)
|
||||
|
@ -528,13 +530,14 @@ static int io_handler_export(bContext *C, IOHandlerData *data)
|
|||
|
||||
static int collection_io_handler_export_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
LayerCollection *layer_coll = BKE_view_layer_active_collection_get(view_layer);
|
||||
ListBase *io_handlers = &layer_coll->collection->io_handlers;
|
||||
Collection *collection = CTX_data_collection(C);
|
||||
ListBase *io_handlers = &collection->io_handlers;
|
||||
|
||||
int id = RNA_int_get(op->ptr, "id");
|
||||
IOHandlerData *data = static_cast<IOHandlerData *>(
|
||||
BLI_listbase_string_or_index_find(io_handlers, nullptr, 0, id));
|
||||
int index = RNA_int_get(op->ptr, "index");
|
||||
IOHandlerData *data = static_cast<IOHandlerData *>(BLI_findlink(io_handlers, index));
|
||||
if (!data) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
return io_handler_export(C, data);
|
||||
}
|
||||
|
@ -553,14 +556,13 @@ void COLLECTION_OT_io_handler_export(wmOperatorType *ot)
|
|||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
RNA_def_int(ot->srna, "id", 0, 0, INT_MAX, "Id", "IO Handler id", 0, INT_MAX);
|
||||
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "IO Handler index", 0, INT_MAX);
|
||||
}
|
||||
|
||||
static int collection_io_export_all_exec(bContext *C, wmOperator * /*op*/)
|
||||
{
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
LayerCollection *layer_coll = BKE_view_layer_active_collection_get(view_layer);
|
||||
ListBase *io_handlers = &layer_coll->collection->io_handlers;
|
||||
Collection *collection = CTX_data_collection(C);
|
||||
ListBase *io_handlers = &collection->io_handlers;
|
||||
|
||||
LISTBASE_FOREACH (IOHandlerData *, data, io_handlers) {
|
||||
io_handler_export(C, data);
|
||||
|
|
Loading…
Reference in New Issue
Same comment about poll function.