68
#define NOTACTIVEFILE 0
72
66
/* ---------- FILE SELECTION ------------ */
73
static FileSelection find_file_mouse_rect(SpaceFile *sfile, struct ARegion* ar, const rcti* rect)
67
static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect)
76
float fxmin,fymin,fxmax, fymax;
70
float fxmin, fymin, fxmax, fymax;
78
View2D* v2d = &ar->v2d;
72
View2D *v2d = &ar->v2d;
81
75
UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin, &fxmin, &fymin);
82
76
UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax, &fxmax, &fymax);
84
BLI_init_rcti(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax));
78
BLI_rcti_init(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax));
86
80
sel = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view);
91
static void file_deselect_all(SpaceFile* sfile, unsigned int flag)
85
static void file_deselect_all(SpaceFile *sfile, unsigned int flag)
95
sel.last = filelist_numfiles(sfile->files)-1;
89
sel.last = filelist_numfiles(sfile->files) - 1;
97
91
filelist_select(sfile->files, &sel, FILE_SEL_REMOVE, flag, CHECK_ALL);
118
112
/* fix if last file invalid */
119
113
if ( (sel->first > 0) && (sel->last < 0) )
120
sel->last = numfiles-1;
114
sel->last = numfiles - 1;
123
117
if ( (sel->first >= numfiles) ) {
124
sel->first = numfiles-1;
118
sel->first = numfiles - 1;
126
120
if ( (sel->last >= numfiles) ) {
127
sel->last = numfiles-1;
121
sel->last = numfiles - 1;
131
static FileSelection file_selection_get(bContext* C, const rcti* rect, short fill)
125
static FileSelection file_selection_get(bContext *C, const rcti *rect, short fill)
133
ARegion *ar= CTX_wm_region(C);
134
SpaceFile *sfile= CTX_wm_space_file(C);
127
ARegion *ar = CTX_wm_region(C);
128
SpaceFile *sfile = CTX_wm_space_file(C);
135
129
int numfiles = filelist_numfiles(sfile->files);
136
130
FileSelection sel;
138
132
sel = find_file_mouse_rect(sfile, ar, rect);
139
if ( !((sel.first == -1) && (sel.last == -1)) ) {
133
if (!((sel.first == -1) && (sel.last == -1)) ) {
140
134
clamp_to_filelist(numfiles, &sel);
144
138
/* if desired, fill the selection up from the last selected file to the current one */
145
139
if (fill && (sel.last >= 0) && (sel.last < numfiles) ) {
148
if ( filelist_is_selected(sfile->files, f, CHECK_ALL) )
142
if (filelist_is_selected(sfile->files, f, CHECK_ALL) )
159
static FileSelect file_select_do(bContext* C, int selected_idx)
153
static FileSelect file_select_do(bContext *C, int selected_idx, short do_diropen)
161
155
FileSelect retval = FILE_SELECT_NOTHING;
162
SpaceFile *sfile= CTX_wm_space_file(C);
156
SpaceFile *sfile = CTX_wm_space_file(C);
163
157
FileSelectParams *params = ED_fileselect_get_params(sfile);
164
158
int numfiles = filelist_numfiles(sfile->files);
165
struct direntry* file;
159
struct direntry *file;
167
161
/* make the selected file active */
168
if ( (selected_idx >= 0) &&
169
(selected_idx < numfiles) &&
170
(file= filelist_file(sfile->files, selected_idx)))
162
if ((selected_idx >= 0) &&
163
(selected_idx < numfiles) &&
164
(file = filelist_file(sfile->files, selected_idx)))
172
166
params->active_file = selected_idx;
174
168
if (S_ISDIR(file->type)) {
169
if (do_diropen == FALSE) {
170
params->file[0] = '\0';
171
retval = FILE_SELECT_DIR;
175
173
/* the path is too long and we are not going up! */
176
if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) {
174
else if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX) {
177
175
// XXX error("Path too long, cannot enter this directory");
180
if (strcmp(file->relname, "..")==0) {
178
if (strcmp(file->relname, "..") == 0) {
181
179
/* avoids /../../ */
182
180
BLI_parent_dir(params->dir);
205
static FileSelect file_select(bContext* C, const rcti* rect, FileSelType select, short fill)
203
static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, short fill, short do_diropen)
207
SpaceFile *sfile= CTX_wm_space_file(C);
205
SpaceFile *sfile = CTX_wm_space_file(C);
208
206
FileSelect retval = FILE_SELECT_NOTHING;
209
FileSelection sel= file_selection_get(C, rect, fill); /* get the selection */
210
const FileCheckType check_type= (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
207
FileSelection sel = file_selection_get(C, rect, fill); /* get the selection */
208
const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
212
210
/* flag the files as selected in the filelist */
213
211
filelist_select(sfile->files, &sel, select, SELECTED_FILE, check_type);
219
217
if ((sel.last >= 0) && ((select == FILE_SEL_ADD) || (select == FILE_SEL_TOGGLE))) {
220
218
/* Check last selection, if selected, act on the file or dir */
221
219
if (filelist_is_selected(sfile->files, sel.last, check_type)) {
222
retval = file_select_do(C, sel.last);
220
retval = file_select_do(C, sel.last, do_diropen);
232
230
static int file_border_select_modal(bContext *C, wmOperator *op, wmEvent *event)
234
ARegion *ar= CTX_wm_region(C);
235
SpaceFile *sfile= CTX_wm_space_file(C);
232
ARegion *ar = CTX_wm_region(C);
233
SpaceFile *sfile = CTX_wm_space_file(C);
236
234
FileSelectParams *params = ED_fileselect_get_params(sfile);
237
235
FileSelection sel;
242
result= WM_border_select_modal(C, op, event);
244
if (result==OPERATOR_RUNNING_MODAL) {
246
rect.xmin = RNA_int_get(op->ptr, "xmin");
247
rect.ymin = RNA_int_get(op->ptr, "ymin");
248
rect.xmax = RNA_int_get(op->ptr, "xmax");
249
rect.ymax = RNA_int_get(op->ptr, "ymax");
251
BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect);
240
result = WM_border_select_modal(C, op, event);
242
if (result == OPERATOR_RUNNING_MODAL) {
244
WM_operator_properties_border_to_rcti(op, &rect);
246
BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect);
253
248
sel = file_selection_get(C, &rect, 0);
254
249
if ( (sel.first != params->sel_first) || (sel.last != params->sel_last) ) {
255
250
file_deselect_all(sfile, HILITED_FILE);
256
251
filelist_select(sfile->files, &sel, FILE_SEL_ADD, HILITED_FILE, CHECK_ALL);
257
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
252
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
259
254
params->sel_first = sel.first; params->sel_last = sel.last;
272
267
static int file_border_select_exec(bContext *C, wmOperator *op)
274
ARegion *ar= CTX_wm_region(C);
269
ARegion *ar = CTX_wm_region(C);
277
int extend= RNA_boolean_get(op->ptr, "extend");
278
short select= (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
272
int extend = RNA_boolean_get(op->ptr, "extend");
273
short select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT);
280
rect.xmin = RNA_int_get(op->ptr, "xmin");
281
rect.ymin = RNA_int_get(op->ptr, "ymin");
282
rect.xmax = RNA_int_get(op->ptr, "xmax");
283
rect.ymax = RNA_int_get(op->ptr, "ymax");
275
WM_operator_properties_border_to_rcti(op, &rect);
286
SpaceFile *sfile= CTX_wm_space_file(C);
278
SpaceFile *sfile = CTX_wm_space_file(C);
288
280
file_deselect_all(sfile, SELECTED_FILE);
291
BLI_isect_rcti(&(ar->v2d.mask), &rect, &rect);
283
BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect);
293
ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, 0);
285
ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, FALSE, FALSE);
294
286
if (FILE_SELECT_DIR == ret) {
295
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
287
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
297
289
else if (FILE_SELECT_FILE == ret) {
298
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
290
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
300
292
return OPERATOR_FINISHED;
314
306
ot->poll = ED_operator_file_active;
315
307
ot->cancel = WM_border_select_cancel;
318
310
WM_operator_properties_gesture_border(ot, 1);
321
313
static int file_select_invoke(bContext *C, wmOperator *op, wmEvent *event)
323
ARegion *ar= CTX_wm_region(C);
324
SpaceFile *sfile= CTX_wm_space_file(C);
315
ARegion *ar = CTX_wm_region(C);
316
SpaceFile *sfile = CTX_wm_space_file(C);
327
319
int extend = RNA_boolean_get(op->ptr, "extend");
328
320
int fill = RNA_boolean_get(op->ptr, "fill");
321
int do_diropen = RNA_boolean_get(op->ptr, "open");
330
323
if (ar->regiontype != RGN_TYPE_WINDOW)
331
324
return OPERATOR_CANCELLED;
333
326
rect.xmin = rect.xmax = event->mval[0];
334
327
rect.ymin = rect.ymax = event->mval[1];
336
if (!BLI_in_rcti(&ar->v2d.mask, rect.xmin, rect.ymin))
329
if (!BLI_rcti_isect_pt(&ar->v2d.mask, rect.xmin, rect.ymin))
337
330
return OPERATOR_CANCELLED;
339
332
/* single select, deselect all selected first */
340
333
if (!extend) file_deselect_all(sfile, SELECTED_FILE);
342
ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill);
335
ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill, do_diropen);
343
336
if (FILE_SELECT_DIR == ret)
344
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
337
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
345
338
else if (FILE_SELECT_FILE == ret)
346
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
339
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
348
341
WM_event_add_mousemove(C); /* for directory changes */
349
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
342
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
351
344
return OPERATOR_FINISHED;
354
347
void FILE_OT_select(wmOperatorType *ot)
356
351
/* identifiers */
357
352
ot->name = "Activate/Select File";
358
353
ot->description = "Activate/select file";
362
357
ot->invoke = file_select_invoke;
363
358
ot->poll = ED_operator_file_active;
366
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first");
367
RNA_def_boolean(ot->srna, "fill", 0, "Fill", "Select everything beginning with the last selection");
361
prop = RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first");
362
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
363
prop = RNA_def_boolean(ot->srna, "fill", FALSE, "Fill", "Select everything beginning with the last selection");
364
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
365
prop = RNA_def_boolean(ot->srna, "open", TRUE, "Open", "Open a directory when selecting it");
366
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
370
369
static int file_select_all_exec(bContext *C, wmOperator *UNUSED(op))
372
ScrArea *sa= CTX_wm_area(C);
373
SpaceFile *sfile= CTX_wm_space_file(C);
371
ScrArea *sa = CTX_wm_area(C);
372
SpaceFile *sfile = CTX_wm_space_file(C);
374
373
FileSelection sel;
375
374
int numfiles = filelist_numfiles(sfile->files);
377
376
int is_selected = 0;
380
sel.last = numfiles-1;
379
sel.last = numfiles - 1;
382
381
/* Is any file selected ? */
383
for ( i=0; i < numfiles; ++i) {
382
for (i = 0; i < numfiles; ++i) {
384
383
if (filelist_is_selected(sfile->files, i, CHECK_ALL)) {
391
390
filelist_select(sfile->files, &sel, FILE_SEL_REMOVE, SELECTED_FILE, CHECK_ALL);
394
const FileCheckType check_type= (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
393
const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
395
394
filelist_select(sfile->files, &sel, FILE_SEL_ADD, SELECTED_FILE, check_type);
397
396
ED_area_tag_redraw(sa);
409
408
ot->exec = file_select_all_exec;
410
409
ot->poll = ED_operator_file_active;
417
414
/* ---------- BOOKMARKS ----------- */
419
416
static int bookmark_select_exec(bContext *C, wmOperator *op)
421
SpaceFile *sfile= CTX_wm_space_file(C);
418
SpaceFile *sfile = CTX_wm_space_file(C);
423
420
if (RNA_struct_find_property(op->ptr, "dir")) {
425
FileSelectParams* params = sfile->params;
422
FileSelectParams *params = sfile->params;
427
424
RNA_string_get(op->ptr, "dir", entry);
428
425
BLI_strncpy(params->dir, entry, sizeof(params->dir));
429
426
BLI_cleanup_dir(G.main->name, params->dir);
430
427
file_change_dir(C, 1);
432
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
429
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
435
432
return OPERATOR_FINISHED;
446
445
ot->exec = bookmark_select_exec;
447
446
ot->poll = ED_operator_file_active;
449
RNA_def_string(ot->srna, "dir", "", 256, "Dir", "");
449
prop = RNA_def_string(ot->srna, "dir", "", FILE_MAXDIR, "Dir", "");
450
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
452
453
static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op))
454
ScrArea *sa= CTX_wm_area(C);
455
SpaceFile *sfile= CTX_wm_space_file(C);
456
struct FSMenu* fsmenu = fsmenu_get();
457
struct FileSelectParams* params= ED_fileselect_get_params(sfile);
455
ScrArea *sa = CTX_wm_area(C);
456
SpaceFile *sfile = CTX_wm_space_file(C);
457
struct FSMenu *fsmenu = fsmenu_get();
458
struct FileSelectParams *params = ED_fileselect_get_params(sfile);
459
460
if (params->dir[0] != '\0') {
460
461
char name[FILE_MAX];
462
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, 0, 1);
463
fsmenu_insert_entry(fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, FS_INSERT_SAVE);
463
464
BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
464
465
fsmenu_write_file(fsmenu, name);
483
484
static int bookmark_delete_exec(bContext *C, wmOperator *op)
485
ScrArea *sa= CTX_wm_area(C);
486
struct FSMenu* fsmenu = fsmenu_get();
486
ScrArea *sa = CTX_wm_area(C);
487
struct FSMenu *fsmenu = fsmenu_get();
487
488
int nentries = fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
489
490
if (RNA_struct_find_property(op->ptr, "index")) {
490
491
int index = RNA_int_get(op->ptr, "index");
491
if ( (index >-1) && (index < nentries)) {
492
if ( (index > -1) && (index < nentries)) {
492
493
char name[FILE_MAX];
494
495
fsmenu_remove_entry(fsmenu, FS_CATEGORY_BOOKMARKS, index);
512
515
ot->exec = bookmark_delete_exec;
513
516
ot->poll = ED_operator_file_active;
515
RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
518
int file_hilight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
520
View2D* v2d = &ar->v2d;
521
FileSelectParams* params;
522
int numfiles, origfile;
524
if (sfile==NULL || sfile->files==NULL) return 0;
519
prop = RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
520
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
523
static int reset_recent_exec(bContext *C, wmOperator *UNUSED(op))
525
ScrArea *sa = CTX_wm_area(C);
527
struct FSMenu *fsmenu = fsmenu_get();
529
while (fsmenu_get_entry(fsmenu, FS_CATEGORY_RECENT, 0) != NULL) {
530
fsmenu_remove_entry(fsmenu, FS_CATEGORY_RECENT, 0);
532
BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
533
fsmenu_write_file(fsmenu, name);
534
ED_area_tag_redraw(sa);
536
return OPERATOR_FINISHED;
539
void FILE_OT_reset_recent(wmOperatorType *ot)
542
ot->name = "Reset Recent";
543
ot->description = "Reset Recent files";
544
ot->idname = "FILE_OT_reset_recent";
547
ot->exec = reset_recent_exec;
548
ot->poll = ED_operator_file_active;
552
int file_highlight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
554
View2D *v2d = &ar->v2d;
555
FileSelectParams *params;
556
int numfiles, origfile;
558
if (sfile == NULL || sfile->files == NULL) return 0;
526
560
numfiles = filelist_numfiles(sfile->files);
527
561
params = ED_fileselect_get_params(sfile);
529
origfile= params->active_file;
563
origfile = params->active_file;
531
565
mx -= ar->winrct.xmin;
532
566
my -= ar->winrct.ymin;
534
if (BLI_in_rcti(&ar->v2d.mask, mx, my)) {
568
if (BLI_rcti_isect_pt(&ar->v2d.mask, mx, my)) {
540
574
active_file = ED_fileselect_layout_offset(sfile->layout, (int)(v2d->tot.xmin + fx), (int)(v2d->tot.ymax - fy));
542
576
if ((active_file >= 0) && (active_file < numfiles))
543
params->active_file=active_file;
577
params->active_file = active_file;
545
params->active_file= -1;
579
params->active_file = -1;
548
params->active_file= -1;
582
params->active_file = -1;
550
584
return (params->active_file != origfile);
553
587
static int file_highlight_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
555
ARegion *ar= CTX_wm_region(C);
556
SpaceFile *sfile= CTX_wm_space_file(C);
589
ARegion *ar = CTX_wm_region(C);
590
SpaceFile *sfile = CTX_wm_space_file(C);
558
if (!file_hilight_set(sfile, ar, event->x, event->y))
592
if (!file_highlight_set(sfile, ar, event->x, event->y))
559
593
return OPERATOR_CANCELLED;
561
595
ED_area_tag_redraw(CTX_wm_area(C));
634
668
* they may be already set. */
636
670
PointerRNA itemptr;
637
PropertyRNA *prop_files= RNA_struct_find_property(op->ptr, "files");
638
PropertyRNA *prop_dirs= RNA_struct_find_property(op->ptr, "dirs");
671
PropertyRNA *prop_files = RNA_struct_find_property(op->ptr, "files");
672
PropertyRNA *prop_dirs = RNA_struct_find_property(op->ptr, "dirs");
639
673
int i, numfiles = filelist_numfiles(sfile->files);
641
675
if (prop_files) {
642
677
RNA_property_collection_clear(op->ptr, prop_files);
643
for (i=0; i<numfiles; i++) {
678
for (i = 0; i < numfiles; i++) {
644
679
if (filelist_is_selected(sfile->files, i, CHECK_FILES)) {
645
struct direntry *file= filelist_file(sfile->files, i);
680
struct direntry *file = filelist_file(sfile->files, i);
646
681
RNA_property_collection_add(op->ptr, prop_files, &itemptr);
647
682
RNA_string_set(&itemptr, "name", file->relname);
686
/* make sure the file specified in the filename button is added even if no files selected */
687
if (0 == num_files) {
688
RNA_property_collection_add(op->ptr, prop_files, &itemptr);
689
RNA_string_set(&itemptr, "name", sfile->params->file);
653
695
RNA_property_collection_clear(op->ptr, prop_dirs);
654
for (i=0; i<numfiles; i++) {
696
for (i = 0; i < numfiles; i++) {
655
697
if (filelist_is_selected(sfile->files, i, CHECK_DIRS)) {
656
struct direntry *file= filelist_file(sfile->files, i);
698
struct direntry *file = filelist_file(sfile->files, i);
657
699
RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
658
700
RNA_string_set(&itemptr, "name", file->relname);
705
/* make sure the directory specified in the button is added even if no directory selected */
707
RNA_property_collection_add(op->ptr, prop_dirs, &itemptr);
708
RNA_string_set(&itemptr, "name", sfile->params->dir);
669
718
PropertyRNA *prop;
671
720
/* If neither of the above are set, split the filepath back */
672
if ((prop= RNA_struct_find_property(op->ptr, "filepath"))) {
721
if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
673
722
char filepath[FILE_MAX];
674
723
RNA_property_string_get(op->ptr, prop, filepath);
675
724
BLI_split_dirfile(filepath, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
678
if ((prop= RNA_struct_find_property(op->ptr, "filename"))) {
727
if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
679
728
RNA_property_string_get(op->ptr, prop, sfile->params->file);
681
if ((prop= RNA_struct_find_property(op->ptr, "directory"))) {
730
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
682
731
RNA_property_string_get(op->ptr, prop, sfile->params->dir);
730
779
/* sends events now, so things get handled on windowqueue level */
731
780
int file_exec(bContext *C, wmOperator *exec_op)
733
SpaceFile *sfile= CTX_wm_space_file(C);
782
SpaceFile *sfile = CTX_wm_space_file(C);
734
783
char filepath[FILE_MAX];
737
wmOperator *op= sfile->op;
786
wmOperator *op = sfile->op;
739
788
/* when used as a macro, for doubleclick,
740
789
* to prevent closing when doubleclicking on .. item */
741
790
if (RNA_boolean_get(exec_op->ptr, "need_active")) {
744
for (i=0; i<filelist_numfiles(sfile->files); i++) {
793
for (i = 0; i < filelist_numfiles(sfile->files); i++) {
745
794
if (filelist_is_selected(sfile->files, i, CHECK_ALL)) {
756
805
file_sfile_to_operator(op, sfile, filepath);
758
if (BLI_exists(sfile->params->dir))
759
fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, 0, 1);
807
if (BLI_exists(sfile->params->dir)) {
808
fsmenu_insert_entry(fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, FS_INSERT_SAVE | FS_INSERT_FIRST);
761
811
BLI_make_file_string(G.main->name, filepath, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
762
812
fsmenu_write_file(fsmenu_get(), filepath);
789
840
int file_parent_exec(bContext *C, wmOperator *UNUSED(unused))
791
SpaceFile *sfile= CTX_wm_space_file(C);
842
SpaceFile *sfile = CTX_wm_space_file(C);
793
844
if (sfile->params) {
794
845
if (BLI_has_parent(sfile->params->dir)) {
795
846
BLI_parent_dir(sfile->params->dir);
796
847
BLI_cleanup_dir(G.main->name, sfile->params->dir);
797
848
file_change_dir(C, 0);
798
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
849
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
802
853
return OPERATOR_FINISHED;
820
871
static int file_refresh_exec(bContext *C, wmOperator *UNUSED(unused))
822
SpaceFile *sfile= CTX_wm_space_file(C);
873
SpaceFile *sfile = CTX_wm_space_file(C);
874
struct FSMenu *fsmenu = fsmenu_get();
824
876
ED_fileselect_clear(C, sfile);
826
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
878
/* refresh system directory menu */
879
fsmenu_refresh_system_category(fsmenu);
881
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
828
883
return OPERATOR_FINISHED;
897
952
static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
899
954
ScrArea *sa = CTX_wm_area(C);
900
SpaceFile *sfile= CTX_wm_space_file(C);
901
ARegion *ar, *oldar= CTX_wm_region(C);
955
SpaceFile *sfile = CTX_wm_space_file(C);
956
ARegion *ar, *oldar = CTX_wm_region(C);
903
958
int numfiles, numfiles_layout;
904
959
int edit_idx = 0;
907
962
/* escape if not our timer */
908
if (sfile->smoothscroll_timer==NULL || sfile->smoothscroll_timer!=event->customdata)
963
if (sfile->smoothscroll_timer == NULL || sfile->smoothscroll_timer != event->customdata)
909
964
return OPERATOR_PASS_THROUGH;
911
966
numfiles = filelist_numfiles(sfile->files);
913
968
/* check if we are editing a name */
914
for (i=0; i < numfiles; ++i)
969
for (i = 0; i < numfiles; ++i) {
916
970
if (filelist_is_selected(sfile->files, i, CHECK_ALL) ) {
922
976
/* if we are not editing, we are done */
924
978
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
925
sfile->smoothscroll_timer=NULL;
979
sfile->smoothscroll_timer = NULL;
926
980
return OPERATOR_PASS_THROUGH;
930
984
ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
931
985
if (!ar || ar->regiontype != RGN_TYPE_WINDOW) {
932
986
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
933
sfile->smoothscroll_timer=NULL;
987
sfile->smoothscroll_timer = NULL;
934
988
return OPERATOR_PASS_THROUGH;
937
991
offset = ED_fileselect_layout_offset(sfile->layout, (int)ar->v2d.cur.xmin, (int)-ar->v2d.cur.ymax);
938
if (offset<0) offset=0;
992
if (offset < 0) offset = 0;
940
994
/* scroll offset is the first file in the row/column we are editing in */
941
995
if (sfile->scroll_offset == 0) {
942
996
if (sfile->layout->flag & FILE_LAYOUT_HOR) {
943
sfile->scroll_offset = (edit_idx/sfile->layout->rows)*sfile->layout->rows;
997
sfile->scroll_offset = (edit_idx / sfile->layout->rows) * sfile->layout->rows;
944
998
if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->rows;
947
sfile->scroll_offset = (edit_idx/sfile->layout->columns)*sfile->layout->columns;
1001
sfile->scroll_offset = (edit_idx / sfile->layout->columns) * sfile->layout->columns;
948
1002
if (sfile->scroll_offset <= offset) sfile->scroll_offset -= sfile->layout->columns;
1008
1062
/* create a new, non-existing folder name, returns 1 if successful, 0 if name couldn't be created.
1009
1063
* The actual name is returned in 'name', 'folder' contains the complete path, including the new folder name.
1011
static int new_folder_path(const char* parent, char *folder, char *name)
1065
static int new_folder_path(const char *parent, char *folder, char *name)
1018
1072
/* check whether folder with the name already exists, in this case
1019
1073
* add number to the name. Check length of generated name to avoid
1020
1074
* crazy case of huge number of folders each named 'New Folder (x)' */
1021
while (BLI_exists(folder) && (len<FILE_MAXFILE)) {
1075
while (BLI_exists(folder) && (len < FILE_MAXFILE)) {
1022
1076
len = BLI_snprintf(name, FILE_MAXFILE, "New Folder(%d)", i);
1023
1077
BLI_join_dirfile(folder, FILE_MAX, parent, name); /* XXX, not real length */
1027
return (len<FILE_MAXFILE);
1081
return (len < FILE_MAXFILE);
1030
1084
int file_directory_new_exec(bContext *C, wmOperator *op)
1032
1086
char name[FILE_MAXFILE];
1033
1087
char path[FILE_MAX];
1034
int generate_name= 1;
1088
int generate_name = 1;
1036
SpaceFile *sfile= CTX_wm_space_file(C);
1090
SpaceFile *sfile = CTX_wm_space_file(C);
1038
1092
if (!sfile->params) {
1039
BKE_report(op->reports,RPT_WARNING, "No parent directory given");
1093
BKE_report(op->reports, RPT_WARNING, "No parent directory given");
1040
1094
return OPERATOR_CANCELLED;
1045
1099
if (RNA_struct_find_property(op->ptr, "directory")) {
1046
1100
RNA_string_get(op->ptr, "directory", path);
1047
if (path[0] != '\0') generate_name= 0;
1101
if (path[0] != '\0') generate_name = 0;
1050
1104
if (generate_name) {
1051
1105
/* create a new, non-existing folder name */
1052
1106
if (!new_folder_path(sfile->params->dir, path, name)) {
1053
BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder name");
1107
BKE_report(op->reports, RPT_ERROR, "Could not create new folder name");
1054
1108
return OPERATOR_CANCELLED;
1059
1113
BLI_dir_create_recursive(path);
1061
1115
if (!BLI_exists(path)) {
1062
BKE_report(op->reports,RPT_ERROR, "Couldn't create new folder");
1116
BKE_report(op->reports, RPT_ERROR, "Could not create new folder");
1063
1117
return OPERATOR_CANCELLED;
1066
1120
/* now remember file to jump into editing */
1067
1121
BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
1069
1123
/* set timer to smoothly view newly generated file */
1070
sfile->smoothscroll_timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/1000.0); /* max 30 frs/sec */
1071
sfile->scroll_offset=0;
1124
sfile->smoothscroll_timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0 / 1000.0); /* max 30 frs/sec */
1125
sfile->scroll_offset = 0;
1073
1127
/* reload dir to make sure we're seeing what's in the directory */
1074
1128
ED_fileselect_clear(C, sfile);
1075
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
1129
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
1077
1131
return OPERATOR_FINISHED;
1090
1146
ot->exec = file_directory_new_exec;
1091
1147
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
1093
RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Name of new directory");
1149
prop = RNA_def_string_dir_path(ot->srna, "directory", "", FILE_MAX, "Directory", "Name of new directory");
1150
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
1098
1155
static void file_expand_directory(bContext *C)
1100
SpaceFile *sfile= CTX_wm_space_file(C);
1157
SpaceFile *sfile = CTX_wm_space_file(C);
1102
1159
if (sfile->params) {
1103
if ( sfile->params->dir[0] == '~' ) {
1104
char tmpstr[sizeof(sfile->params->dir)-1];
1105
BLI_strncpy(tmpstr, sfile->params->dir+1, sizeof(tmpstr));
1160
/* TODO, what about // when relbase isn't valid? */
1161
if (G.relbase_valid && BLI_path_is_rel(sfile->params->dir)) {
1162
BLI_path_abs(sfile->params->dir, G.main->name);
1164
else if (sfile->params->dir[0] == '~') {
1165
char tmpstr[sizeof(sfile->params->dir) - 1];
1166
BLI_strncpy(tmpstr, sfile->params->dir + 1, sizeof(tmpstr));
1106
1167
BLI_join_dirfile(sfile->params->dir, sizeof(sfile->params->dir), BLI_getDefaultDocumentFolder(), tmpstr);
1119
1180
/* change "C:" --> "C:\", [#28102] */
1120
1181
else if ( (isalpha(sfile->params->dir[0]) &&
1121
(sfile->params->dir[1] == ':')) &&
1182
(sfile->params->dir[1] == ':')) &&
1122
1183
(sfile->params->dir[2] == '\0')
1125
sfile->params->dir[2]= '\\';
1126
sfile->params->dir[3]= '\0';
1186
sfile->params->dir[2] = '\\';
1187
sfile->params->dir[3] = '\0';
1132
1193
static int file_directory_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
1134
SpaceFile *sfile= CTX_wm_space_file(C);
1195
SpaceFile *sfile = CTX_wm_space_file(C);
1136
1197
if (sfile->params) {
1137
1198
file_expand_directory(C);
1139
1200
if (!BLI_exists(sfile->params->dir)) {
1140
1201
return WM_operator_confirm_message(C, op, "Create new directory?");
1143
1204
return file_directory_exec(C, op);
1170
1231
BLI_add_slash(sfile->params->dir);
1171
1232
file_change_dir(C, 1);
1173
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
1234
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
1177
1237
return OPERATOR_FINISHED;
1180
1240
int file_filename_exec(bContext *C, wmOperator *UNUSED(unused))
1182
SpaceFile *sfile= CTX_wm_space_file(C);
1242
SpaceFile *sfile = CTX_wm_space_file(C);
1243
char matched_file[FILE_MAX];
1184
1244
if (sfile->params) {
1185
if (file_select_match(sfile, sfile->params->file)) {
1245
matched_file[0] = '\0';
1246
if (file_select_match(sfile, sfile->params->file, matched_file)) {
1247
/* int i, numfiles = filelist_numfiles(sfile->files); */ /* XXX UNUSED */
1186
1248
sfile->params->file[0] = '\0';
1187
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_PARAMS, NULL);
1249
/* replace the pattern (or filename that the user typed in, with the first selected file of the match */
1250
BLI_strncpy(sfile->params->file, matched_file, sizeof(sfile->params->file));
1252
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL);
1191
1256
return OPERATOR_FINISHED;
1228
1293
static int file_hidedot_exec(bContext *C, wmOperator *UNUSED(unused))
1230
SpaceFile *sfile= CTX_wm_space_file(C);
1295
SpaceFile *sfile = CTX_wm_space_file(C);
1232
1297
if (sfile->params) {
1233
1298
sfile->params->flag ^= FILE_HIDE_DOT;
1234
1299
ED_fileselect_clear(C, sfile);
1235
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
1300
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
1238
1303
return OPERATOR_FINISHED;
1251
1316
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
1254
struct ARegion *file_buttons_region(struct ScrArea *sa)
1319
ARegion *file_buttons_region(ScrArea *sa)
1256
1321
ARegion *ar, *arnew;
1258
for (ar= sa->regionbase.first; ar; ar= ar->next)
1259
if (ar->regiontype==RGN_TYPE_CHANNELS)
1323
for (ar = sa->regionbase.first; ar; ar = ar->next)
1324
if (ar->regiontype == RGN_TYPE_CHANNELS)
1262
1327
/* add subdiv level; after header */
1263
for (ar= sa->regionbase.first; ar; ar= ar->next)
1264
if (ar->regiontype==RGN_TYPE_HEADER)
1328
for (ar = sa->regionbase.first; ar; ar = ar->next)
1329
if (ar->regiontype == RGN_TYPE_HEADER)
1267
1332
/* is error! */
1268
if (ar==NULL) return NULL;
1333
if (ar == NULL) return NULL;
1270
arnew= MEM_callocN(sizeof(ARegion), "buttons for file panels");
1335
arnew = MEM_callocN(sizeof(ARegion), "buttons for file panels");
1272
1337
BLI_insertlinkafter(&sa->regionbase, ar, arnew);
1273
arnew->regiontype= RGN_TYPE_CHANNELS;
1274
arnew->alignment= RGN_ALIGN_LEFT;
1338
arnew->regiontype = RGN_TYPE_CHANNELS;
1339
arnew->alignment = RGN_ALIGN_LEFT;
1276
1341
arnew->flag = RGN_FLAG_HIDDEN;
1331
1396
ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
1334
RNA_def_int(ot->srna, "increment", 1, -100, 100, "Increment", "", -100,100);
1399
RNA_def_int(ot->srna, "increment", 1, -100, 100, "Increment", "", -100, 100);
1337
1402
static int file_rename_exec(bContext *C, wmOperator *UNUSED(op))
1339
ScrArea *sa= CTX_wm_area(C);
1340
SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C);
1404
ScrArea *sa = CTX_wm_area(C);
1405
SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
1342
1407
if (sfile->params) {
1343
1408
int idx = sfile->params->active_file;
1344
1409
int numfiles = filelist_numfiles(sfile->files);
1345
if ( (0<=idx) && (idx<numfiles) ) {
1346
struct direntry *file= filelist_file(sfile->files, idx);
1410
if ( (0 <= idx) && (idx < numfiles) ) {
1411
struct direntry *file = filelist_file(sfile->files, idx);
1347
1412
filelist_select_file(sfile->files, idx, FILE_SEL_ADD, EDITING_FILE, CHECK_ALL);
1348
1413
BLI_strncpy(sfile->params->renameedit, file->relname, FILE_MAXFILE);
1349
sfile->params->renamefile[0]= '\0';
1414
sfile->params->renamefile[0] = '\0';
1351
1416
ED_area_tag_redraw(sa);
1358
1423
static int file_rename_poll(bContext *C)
1360
1425
int poll = ED_operator_file_active(C);
1361
SpaceFile *sfile= CTX_wm_space_file(C);
1426
SpaceFile *sfile = CTX_wm_space_file(C);
1363
1428
if (sfile && sfile->params) {
1364
if (sfile->params->active_file < 0) {
1429
if (sfile->params->active_file < 0) {
1368
char dir[FILE_MAX], group[FILE_MAX];
1369
if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
1433
char dir[FILE_MAX], group[FILE_MAX];
1434
if (filelist_islibrary(sfile->files, dir, group)) poll = 0;
1390
1455
static int file_delete_poll(bContext *C)
1392
1457
int poll = ED_operator_file_active(C);
1393
SpaceFile *sfile= CTX_wm_space_file(C);
1394
struct direntry* file;
1458
SpaceFile *sfile = CTX_wm_space_file(C);
1459
struct direntry *file;
1396
1461
if (sfile && sfile->params) {
1397
if (sfile->params->active_file < 0) {
1462
if (sfile->params->active_file < 0) {
1401
char dir[FILE_MAX], group[FILE_MAX];
1402
if (filelist_islibrary(sfile->files, dir, group)) poll= 0;
1466
char dir[FILE_MAX], group[FILE_MAX];
1467
if (filelist_islibrary(sfile->files, dir, group)) poll = 0;
1403
1468
file = filelist_file(sfile->files, sfile->params->active_file);
1404
if (file && S_ISDIR(file->type)) poll= 0;
1469
if (file && S_ISDIR(file->type)) poll = 0;
1413
1478
int file_delete_exec(bContext *C, wmOperator *UNUSED(op))
1415
1480
char str[FILE_MAX];
1416
SpaceFile *sfile= CTX_wm_space_file(C);
1417
struct direntry* file;
1481
SpaceFile *sfile = CTX_wm_space_file(C);
1482
struct direntry *file;
1420
1485
file = filelist_file(sfile->files, sfile->params->active_file);
1421
1486
BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relname);
1422
BLI_delete(str, 0, 0);
1487
BLI_delete(str, 0, 0);
1423
1488
ED_fileselect_clear(C, sfile);
1424
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_FILE_LIST, NULL);
1489
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);
1426
1491
return OPERATOR_FINISHED;