~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/space_info/info_ops.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
#include "BLI_blenlib.h"
42
42
#include "BLI_math.h"
43
 
#include "BLI_bpath.h"
 
43
#include "BKE_bpath.h"
44
44
#include "BLI_utildefines.h"
45
45
 
46
46
#include "BKE_context.h"
47
47
#include "BKE_global.h"
48
48
#include "BKE_image.h"
 
49
#include "BKE_library.h"
49
50
#include "BKE_main.h"
50
51
#include "BKE_packedFile.h"
51
52
#include "BKE_report.h"
 
53
#include "BKE_screen.h"
52
54
 
53
55
 
54
56
#include "WM_api.h"
66
68
 
67
69
#include "info_intern.h"
68
70
 
 
71
/********************* pack blend file libararies operator *********************/
 
72
 
 
73
static int pack_libraries_exec(bContext *C, wmOperator *op)
 
74
{
 
75
        Main *bmain = CTX_data_main(C);
 
76
 
 
77
        packLibraries(bmain, op->reports);
 
78
 
 
79
        return OPERATOR_FINISHED;
 
80
}
 
81
 
 
82
void FILE_OT_pack_libraries(wmOperatorType *ot)
 
83
{
 
84
        /* identifiers */
 
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";
 
88
        
 
89
        /* api callbacks */
 
90
        ot->exec = pack_libraries_exec;
 
91
 
 
92
        /* flags */
 
93
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
94
}
 
95
 
 
96
static int unpack_libraries_exec(bContext *C, wmOperator *op)
 
97
{
 
98
        Main *bmain = CTX_data_main(C);
 
99
        
 
100
        unpackLibraries(bmain, op->reports);
 
101
        
 
102
        return OPERATOR_FINISHED;
 
103
}
 
104
 
 
105
static int unpack_libraries_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
106
{
 
107
        return WM_operator_confirm_message(C, op, "Unpack Blender Libraries - creates directories, all new paths should work");
 
108
}
 
109
 
 
110
void FILE_OT_unpack_libraries(wmOperatorType *ot)
 
111
{
 
112
        /* identifiers */
 
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";
 
116
        
 
117
        /* api callbacks */
 
118
        ot->invoke = unpack_libraries_invoke;
 
119
        ot->exec = unpack_libraries_exec;
 
120
        
 
121
        /* flags */
 
122
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
123
}
 
124
 
 
125
 
69
126
/********************* pack all operator *********************/
70
127
 
71
128
static int pack_all_exec(bContext *C, wmOperator *op)
72
129
{
73
130
        Main *bmain = CTX_data_main(C);
74
 
 
 
131
        
75
132
        packAll(bmain, op->reports);
76
133
        G.fileflags |= G_AUTOPACK;
77
 
 
 
134
        
78
135
        return OPERATOR_FINISHED;
79
136
}
80
137
 
83
140
        Main *bmain = CTX_data_main(C);
84
141
        Image *ima;
85
142
        ImBuf *ibuf;
86
 
 
 
143
        
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);
91
148
                        
92
 
                        if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))
 
149
                        if (ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) {
 
150
                                BKE_image_release_ibuf(ima, ibuf, NULL);
93
151
                                break;
 
152
                        }
 
153
                        
 
154
                        BKE_image_release_ibuf(ima, ibuf, NULL);
94
155
                }
95
156
        }
96
 
 
 
157
        
97
158
        if (ima) {
98
159
                uiPupMenuOkee(C, "FILE_OT_pack_all", "Some images are painted on. These changes will be lost. Continue?");
99
160
                return OPERATOR_CANCELLED;
100
161
        }
101
 
 
 
162
        
102
163
        return pack_all_exec(C, op);
103
164
}
104
165
 
107
168
        /* identifiers */
108
169
        ot->name = "Pack All";
109
170
        ot->idname = "FILE_OT_pack_all";
 
171
        ot->description = "Pack all used external files into the .blend";
110
172
        
111
173
        /* api callbacks */
112
174
        ot->exec = pack_all_exec;
113
175
        ot->invoke = pack_all_invoke;
114
 
 
 
176
        
115
177
        /* flags */
116
178
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
117
179
}
118
180
 
 
181
 
119
182
/********************* unpack all operator *********************/
120
183
 
121
184
static const EnumPropertyItem unpack_all_method_items[] = {
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}};
129
192
 
149
212
        count = countPackedFiles(bmain);
150
213
        
151
214
        if (!count) {
152
 
                BKE_report(op->reports, RPT_WARNING, "No packed files. Autopack disabled");
 
215
                BKE_report(op->reports, RPT_WARNING, "No packed files (auto-pack disabled)");
153
216
                G.fileflags &= ~G_AUTOPACK;
154
217
                return OPERATOR_CANCELLED;
155
218
        }
175
238
        /* identifiers */
176
239
        ot->name = "Unpack All";
177
240
        ot->idname = "FILE_OT_unpack_all";
 
241
        ot->description = "Unpack all files packed into this .blend to external ones";
178
242
        
179
243
        /* api callbacks */
180
244
        ot->exec = unpack_all_exec;
187
251
        RNA_def_enum(ot->srna, "method", unpack_all_method_items, PF_USE_LOCAL, "Method", "How to unpack");
188
252
}
189
253
 
 
254
/********************* unpack single item operator *********************/
 
255
 
 
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}};
 
263
 
 
264
 
 
265
static int unpack_item_exec(bContext *C, wmOperator *op)
 
266
{
 
267
        Main *bmain = CTX_data_main(C);
 
268
        ID *id;
 
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");
 
272
 
 
273
        RNA_string_get(op->ptr, "id_name", idname);
 
274
        id = BKE_libblock_find_name(type, idname);
 
275
 
 
276
        if (id == NULL) {
 
277
                BKE_report(op->reports, RPT_WARNING, "No packed file");
 
278
                return OPERATOR_CANCELLED;
 
279
        }
 
280
        
 
281
        if (method != PF_KEEP)
 
282
                BKE_unpack_id(bmain, id, op->reports, method);  /* XXX PF_ASK can't work here */
 
283
        
 
284
        G.fileflags &= ~G_AUTOPACK;
 
285
        
 
286
        return OPERATOR_FINISHED;
 
287
}
 
288
 
 
289
static int unpack_item_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
290
{
 
291
        uiPopupMenu *pup;
 
292
        uiLayout *layout;
 
293
        
 
294
        pup = uiPupMenuBegin(C, "Unpack", ICON_NONE);
 
295
        layout = uiPupMenuLayout(pup);
 
296
        
 
297
        uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
 
298
        uiItemsFullEnumO(layout, op->type->idname, "method", op->ptr->data, WM_OP_EXEC_REGION_WIN, 0);
 
299
        
 
300
        uiPupMenuEnd(C, pup);
 
301
        
 
302
        return OPERATOR_CANCELLED;
 
303
}
 
304
 
 
305
void FILE_OT_unpack_item(wmOperatorType *ot)
 
306
{
 
307
        /* identifiers */
 
308
        ot->name = "Unpack Item";
 
309
        ot->idname = "FILE_OT_unpack_item";
 
310
        ot->description = "Unpack this file to an external file";
 
311
        
 
312
        /* api callbacks */
 
313
        ot->exec = unpack_item_exec;
 
314
        ot->invoke = unpack_item_invoke;
 
315
        
 
316
        /* flags */
 
317
        ot->flag = OPTYPE_UNDO;
 
318
        
 
319
        /* properties */
 
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);
 
323
}
 
324
 
 
325
 
190
326
/********************* make paths relative operator *********************/
191
327
 
192
328
static int make_paths_relative_exec(bContext *C, wmOperator *op)
194
330
        Main *bmain = CTX_data_main(C);
195
331
 
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;
199
335
        }
200
336
 
201
 
        makeFilesRelative(bmain, bmain->name, op->reports);
 
337
        BKE_bpath_relative_convert(bmain, bmain->name, op->reports);
202
338
 
203
339
        /* redraw everything so any changed paths register */
204
340
        WM_main_add_notifier(NC_WINDOW, NULL);
211
347
        /* identifiers */
212
348
        ot->name = "Make All Paths Relative";
213
349
        ot->idname = "FILE_OT_make_paths_relative";
 
350
        ot->description = "Make all paths to external files relative to current .blend";
214
351
        
215
352
        /* api callbacks */
216
353
        ot->exec = make_paths_relative_exec;
226
363
        Main *bmain = CTX_data_main(C);
227
364
 
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;
231
368
        }
232
369
 
233
 
        makeFilesAbsolute(bmain, bmain->name, op->reports);
 
370
        BKE_bpath_absolute_convert(bmain, bmain->name, op->reports);
234
371
 
235
372
        /* redraw everything so any changed paths register */
236
373
        WM_main_add_notifier(NC_WINDOW, NULL);
243
380
        /* identifiers */
244
381
        ot->name = "Make All Paths Absolute";
245
382
        ot->idname = "FILE_OT_make_paths_absolute";
 
383
        ot->description = "Make all paths to external files absolute";
246
384
        
247
385
        /* api callbacks */
248
386
        ot->exec = make_paths_absolute_exec;
258
396
        Main *bmain = CTX_data_main(C);
259
397
 
260
398
        /* run the missing file check */
261
 
        checkMissingFiles(bmain, op->reports);
 
399
        BKE_bpath_missing_files_check(bmain, op->reports);
262
400
        
263
401
        return OPERATOR_FINISHED;
264
402
}
268
406
        /* identifiers */
269
407
        ot->name = "Report Missing Files";
270
408
        ot->idname = "FILE_OT_report_missing_files";
 
409
        ot->description = "Report all missing external files";
271
410
        
272
411
        /* api callbacks */
273
412
        ot->exec = report_missing_files_exec;
282
421
{
283
422
        Main *bmain = CTX_data_main(C);
284
423
        const char *searchpath = RNA_string_get_alloc(op->ptr, "filepath", NULL, 0);
285
 
        findMissingFiles(bmain, searchpath, op->reports);
 
424
        BKE_bpath_missing_files_find(bmain, searchpath, op->reports);
286
425
        MEM_freeN((void *)searchpath);
287
426
 
288
427
        return OPERATOR_FINISHED;
300
439
        /* identifiers */
301
440
        ot->name = "Find Missing Files";
302
441
        ot->idname = "FILE_OT_find_missing_files";
 
442
        ot->description = "Try to find missing external files";
303
443
        
304
444
        /* api callbacks */
305
445
        ot->exec = find_missing_files_exec;
309
449
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
310
450
 
311
451
        /* properties */
312
 
        WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
 
452
        WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE,
 
453
                                       WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
313
454
}
314
455
 
315
456
/********************* report box operator *********************/
334
475
        ReportTimerInfo *rti;
335
476
        float progress = 0.0, color_progress = 0.0;
336
477
        float neutral_col[3] = {0.35, 0.35, 0.35};
337
 
        float neutral_grey = 0.6;
 
478
        float neutral_gray = 0.6;
338
479
        float timeout = 0.0, color_timeout = 0.0;
339
480
        int send_note = 0;
340
481
        
379
520
                        rti->col[1] = 0.45;
380
521
                        rti->col[2] = 0.7;
381
522
                }
382
 
                rti->greyscale = 0.75;
 
523
                rti->grayscale = 0.75;
383
524
                rti->widthfac = 1.0;
384
525
        }
385
526
        
392
533
                
393
534
                /* fade colors out sharply according to progress through fade-out duration */
394
535
                interp_v3_v3v3(rti->col, rti->col, neutral_col, color_progress);
395
 
                rti->greyscale = interpf(neutral_grey, rti->greyscale, color_progress);
 
536
                rti->grayscale = interpf(neutral_gray, rti->grayscale, color_progress);
396
537
        }
397
538
 
398
539
        /* collapse report at end of timeout */
414
555
        /* identifiers */
415
556
        ot->name = "Update Reports Display";
416
557
        ot->idname = "INFO_OT_reports_display_update";
 
558
        ot->description = "Update the display of reports in Blender UI (internal use)";
417
559
        
418
560
        /* api callbacks */
419
561
        ot->invoke = update_reports_display_invoke;