67
69
#include "info_intern.h"
71
/********************* pack blend file libararies operator *********************/
73
static int pack_libraries_exec(bContext *C, wmOperator *op)
75
Main *bmain = CTX_data_main(C);
77
packLibraries(bmain, op->reports);
79
return OPERATOR_FINISHED;
82
void FILE_OT_pack_libraries(wmOperatorType *ot)
85
ot->name = "Pack Blender Libraries";
86
ot->idname = "FILE_OT_pack_libraries";
87
ot->description = "Pack all used Blender library files into the current .blend";
90
ot->exec = pack_libraries_exec;
93
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
96
static int unpack_libraries_exec(bContext *C, wmOperator *op)
98
Main *bmain = CTX_data_main(C);
100
unpackLibraries(bmain, op->reports);
102
return OPERATOR_FINISHED;
105
static int unpack_libraries_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
107
return WM_operator_confirm_message(C, op, "Unpack Blender Libraries - creates directories, all new paths should work");
110
void FILE_OT_unpack_libraries(wmOperatorType *ot)
113
ot->name = "Unpack Blender Libraries";
114
ot->idname = "FILE_OT_unpack_libraries";
115
ot->description = "Unpack all used Blender library files from this .blend file";
118
ot->invoke = unpack_libraries_invoke;
119
ot->exec = unpack_libraries_exec;
122
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
69
126
/********************* pack all operator *********************/
71
128
static int pack_all_exec(bContext *C, wmOperator *op)
73
130
Main *bmain = CTX_data_main(C);
75
132
packAll(bmain, op->reports);
76
133
G.fileflags |= G_AUTOPACK;
78
135
return OPERATOR_FINISHED;
83
140
Main *bmain = CTX_data_main(C);
87
144
// first check for dirty images
88
145
for (ima = bmain->image.first; ima; ima = ima->id.next) {
89
146
if (ima->ibufs.first) { /* XXX FIX */
90
ibuf = BKE_image_get_ibuf(ima, NULL);
147
ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
92
if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
149
if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) {
150
BKE_image_release_ibuf(ima, ibuf, NULL);
154
BKE_image_release_ibuf(ima, ibuf, NULL);
98
159
uiPupMenuOkee(C, "FILE_OT_pack_all", "Some images are painted on. These changes will be lost. Continue?");
99
160
return OPERATOR_CANCELLED;
102
163
return pack_all_exec(C, op);
123
186
{PF_WRITE_LOCAL, "WRITE_LOCAL", 0, "Write files to current directory (overwrite existing files)", ""},
124
187
{PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use files in original location (create when necessary)", ""},
125
188
{PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write files to original location (overwrite existing files)", ""},
126
{PF_KEEP, "KEEP", 0, "Disable AutoPack, keep all packed files", ""},
189
{PF_KEEP, "KEEP", 0, "Disable Auto-pack, keep all packed files", ""},
127
190
/* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */
128
191
{0, NULL, 0, NULL, NULL}};
187
251
RNA_def_enum(ot->srna, "method", unpack_all_method_items, PF_USE_LOCAL, "Method", "How to unpack");
254
/********************* unpack single item operator *********************/
256
static const EnumPropertyItem unpack_item_method_items[] = {
257
{PF_USE_LOCAL, "USE_LOCAL", 0, "Use file from current directory (create when necessary)", ""},
258
{PF_WRITE_LOCAL, "WRITE_LOCAL", 0, "Write file to current directory (overwrite existing file)", ""},
259
{PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use file in original location (create when necessary)", ""},
260
{PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write file to original location (overwrite existing file)", ""},
261
/* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */
262
{0, NULL, 0, NULL, NULL}};
265
static int unpack_item_exec(bContext *C, wmOperator *op)
267
Main *bmain = CTX_data_main(C);
269
char idname[MAX_ID_NAME - 2];
270
int type = RNA_int_get(op->ptr, "id_type");
271
int method = RNA_enum_get(op->ptr, "method");
273
RNA_string_get(op->ptr, "id_name", idname);
274
id = BKE_libblock_find_name(type, idname);
277
BKE_report(op->reports, RPT_WARNING, "No packed file");
278
return OPERATOR_CANCELLED;
281
if (method != PF_KEEP)
282
BKE_unpack_id(bmain, id, op->reports, method); /* XXX PF_ASK can't work here */
284
G.fileflags &= ~G_AUTOPACK;
286
return OPERATOR_FINISHED;
289
static int unpack_item_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
294
pup = uiPupMenuBegin(C, "Unpack", ICON_NONE);
295
layout = uiPupMenuLayout(pup);
297
uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
298
uiItemsFullEnumO(layout, op->type->idname, "method", op->ptr->data, WM_OP_EXEC_REGION_WIN, 0);
300
uiPupMenuEnd(C, pup);
302
return OPERATOR_CANCELLED;
305
void FILE_OT_unpack_item(wmOperatorType *ot)
308
ot->name = "Unpack Item";
309
ot->idname = "FILE_OT_unpack_item";
310
ot->description = "Unpack this file to an external file";
313
ot->exec = unpack_item_exec;
314
ot->invoke = unpack_item_invoke;
317
ot->flag = OPTYPE_UNDO;
320
RNA_def_enum(ot->srna, "method", unpack_item_method_items, PF_USE_LOCAL, "Method", "How to unpack");
321
RNA_def_string(ot->srna, "id_name", "", BKE_ST_MAXNAME, "ID name", "Name of ID block to unpack");
322
RNA_def_int(ot->srna, "id_type", ID_IM, 0, INT_MAX, "ID Type", "Identifier type of ID block", 0, INT_MAX);
190
326
/********************* make paths relative operator *********************/
192
328
static int make_paths_relative_exec(bContext *C, wmOperator *op)
194
330
Main *bmain = CTX_data_main(C);
196
332
if (!G.relbase_valid) {
197
BKE_report(op->reports, RPT_WARNING, "Can't set relative paths with an unsaved blend file");
333
BKE_report(op->reports, RPT_WARNING, "Cannot set relative paths with an unsaved blend file");
198
334
return OPERATOR_CANCELLED;
201
makeFilesRelative(bmain, bmain->name, op->reports);
337
BKE_bpath_relative_convert(bmain, bmain->name, op->reports);
203
339
/* redraw everything so any changed paths register */
204
340
WM_main_add_notifier(NC_WINDOW, NULL);
226
363
Main *bmain = CTX_data_main(C);
228
365
if (!G.relbase_valid) {
229
BKE_report(op->reports, RPT_WARNING, "Can't set absolute paths with an unsaved blend file");
366
BKE_report(op->reports, RPT_WARNING, "Cannot set absolute paths with an unsaved blend file");
230
367
return OPERATOR_CANCELLED;
233
makeFilesAbsolute(bmain, bmain->name, op->reports);
370
BKE_bpath_absolute_convert(bmain, bmain->name, op->reports);
235
372
/* redraw everything so any changed paths register */
236
373
WM_main_add_notifier(NC_WINDOW, NULL);