Blender V5.3
file_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_fileops.hh"
10#include "BLI_linklist.hh"
11#include "BLI_listbase.hh"
12#include "BLI_math_base_c.hh"
13#include "BLI_path_utils.hh"
14#include "BLI_string.hh"
15#include "BLI_string_utf8.hh"
16#include "BLI_utildefines.hh"
17
18#include "BKE_appdir.hh"
19#include "BKE_blendfile.hh"
20#include "BKE_context.hh"
21#include "BKE_main.hh"
22#include "BKE_report.hh"
23#include "BKE_screen.hh"
24
25#include "BLT_translation.hh"
26
27#ifdef WIN32
28# include "BLI_winstuff.hh"
29#endif
30
31#include "ED_fileselect.hh"
32#include "ED_screen.hh"
33#include "ED_select_utils.hh"
34
35#include "UI_interface.hh"
36#include "UI_interface_icons.hh"
38#include "UI_resources.hh"
39
40#include "MEM_guardedalloc.h"
41
42#include "RNA_access.hh"
43#include "RNA_define.hh"
44
45#include "UI_view2d.hh"
46
47#include "WM_api.hh"
48#include "WM_types.hh"
49
50#include "file_intern.hh"
51#include "filelist.hh"
52#include "fsmenu.hh"
53
54#include <algorithm>
55#include <cctype>
56#include <cerrno>
57#include <cstdio>
58#include <cstdlib>
59#include <cstring>
60
61namespace blender {
62
63/* -------------------------------------------------------------------- */
66
68 ARegion *region,
69 const rcti *rect_region)
70{
71 FileSelection sel;
72
73 View2D *v2d = &region->v2d;
74 rcti rect_view;
75 rctf rect_view_fl;
76 rctf rect_region_fl;
77
78 BLI_rctf_rcti_copy(&rect_region_fl, rect_region);
79
80 /* Okay, manipulating v2d rects here is hacky... */
81 v2d->mask.ymax -= sfile->layout->offset_top;
82 v2d->cur.ymax -= sfile->layout->offset_top;
83 ui::view2d_region_to_view_rctf(v2d, &rect_region_fl, &rect_view_fl);
84 v2d->mask.ymax += sfile->layout->offset_top;
85 v2d->cur.ymax += sfile->layout->offset_top;
86
87 BLI_rcti_init(&rect_view,
88 int(v2d->tot.xmin + rect_view_fl.xmin),
89 int(v2d->tot.xmin + rect_view_fl.xmax),
90 int(v2d->tot.ymax - rect_view_fl.ymin),
91 int(v2d->tot.ymax - rect_view_fl.ymax));
92
93 sel = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view);
94
95 return sel;
96}
97
103
104static void clamp_to_filelist(int numfiles, FileSelection *sel)
105{
106 /* box select before the first file */
107 if ((sel->first < 0) && (sel->last >= 0)) {
108 sel->first = 0;
109 }
110 /* don't select if everything is outside filelist */
111 if ((sel->first >= numfiles) && ((sel->last < 0) || (sel->last >= numfiles))) {
112 sel->first = -1;
113 sel->last = -1;
114 }
115
116 /* fix if last file invalid */
117 if ((sel->first > 0) && (sel->last < 0)) {
118 sel->last = numfiles - 1;
119 }
120
121 /* clamp */
122 if (sel->first >= numfiles) {
123 sel->first = numfiles - 1;
124 }
125 if (sel->last >= numfiles) {
126 sel->last = numfiles - 1;
127 }
128}
129
130static FileSelection file_selection_get(bContext *C, const rcti *rect, bool fill)
131{
132 ARegion *region = CTX_wm_region(C);
133 SpaceFile *sfile = CTX_wm_space_file(C);
134 int numfiles = filelist_files_ensure(sfile->files);
135 FileSelection sel;
136
137 sel = find_file_mouse_rect(sfile, region, rect);
138 if (!((sel.first == -1) && (sel.last == -1))) {
139 clamp_to_filelist(numfiles, &sel);
140 }
141
142 /* if desired, fill the selection up from the last selected file to the current one */
143 if (fill && (sel.last >= 0) && (sel.last < numfiles)) {
144 int f;
145 /* Try to find a smaller-index selected item. */
146 for (f = sel.last; f >= 0; f--) {
148 break;
149 }
150 }
151 if (f >= 0) {
152 sel.first = f + 1;
153 }
154 /* If none found, try to find a higher-index selected item. */
155 else {
156 for (f = sel.first; f < numfiles; f++) {
158 break;
159 }
160 }
161 if (f < numfiles) {
162 sel.last = f - 1;
163 }
164 }
165 }
166 return sel;
167}
168
169static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
170{
171 Main *bmain = CTX_data_main(C);
173 SpaceFile *sfile = CTX_wm_space_file(C);
175 int numfiles = filelist_files_ensure(sfile->files);
176 const FileDirEntry *file;
177
178 /* make the selected file active */
179 if ((selected_idx >= 0) && (selected_idx < numfiles) &&
180 (file = filelist_file(sfile->files, selected_idx)))
181 {
182 params->highlight_file = selected_idx;
183 params->active_file = selected_idx;
184
185 if (file->typeflag & FILE_TYPE_DIR) {
186 const bool is_parent_dir = FILENAME_IS_PARENT(file->relpath);
187
188 if (do_diropen == false) {
189 retval = FILE_SELECT_DIR;
190 }
191 /* the path is too long and we are not going up! */
192 else if (!is_parent_dir && strlen(params->dir) + strlen(file->relpath) >= FILE_MAX) {
193 // XXX error("Path too long, cannot enter this directory");
194 }
195 else {
196 if (is_parent_dir) {
197 /* Avoids `/../../`. */
198 BLI_path_parent_dir(params->dir);
199
200 if (params->recursion_level > 1) {
201 /* Disable `dirtree` recursion when going up in tree. */
202 params->recursion_level = 0;
204 }
205 }
206 else if (file->redirection_path) {
207 STRNCPY(params->dir, file->redirection_path);
209 BLI_path_normalize_dir(params->dir, sizeof(params->dir));
210 }
211 else {
213 BLI_path_normalize_dir(params->dir, sizeof(params->dir));
214 BLI_path_append_dir(params->dir, sizeof(params->dir), file->relpath);
215 }
216
218 retval = FILE_SELECT_DIR;
219 }
220 }
221 else {
222 retval = FILE_SELECT_FILE;
223 }
224 fileselect_file_set(C, sfile, selected_idx);
225 }
226 return retval;
227}
228
233{
234 const int numfiles = filelist_files_ensure(files);
235 int i;
236
237 /* Is any file selected ? */
238 for (i = 0; i < numfiles; i++) {
240 return true;
241 }
242 }
243
244 return false;
245}
246
248{
249 const int numfiles = filelist_files_ensure(files);
250 FileSelection selection = {-1, -1};
251
252 /* Iterate over the files once but in two loops, one to find the first selected file, and the
253 * other to find the last. */
254
255 int file_index;
256 for (file_index = 0; file_index < numfiles; file_index++) {
257 if (filelist_entry_is_selected(files, file_index)) {
258 /* First selected entry found. */
259 selection.first = file_index;
260 break;
261 }
262 }
263
264 for (; file_index < numfiles; file_index++) {
265 if (filelist_entry_is_selected(files, file_index)) {
266 selection.last = file_index;
267 /* Keep looping, we may find more selected files. */
268 }
269 }
270
271 return selection;
272}
273
277static void file_ensure_inside_viewbounds(ARegion *region, SpaceFile *sfile, const int file)
278{
279 FileLayout *layout = ED_fileselect_get_layout(sfile, region);
280 rctf *cur = &region->v2d.cur;
281 rcti rect;
282 bool changed = true;
283
284 file_tile_boundbox(region, layout, file, &rect);
285
286 /* down - also use if tile is higher than viewbounds so view is aligned to file name */
287 if (cur->ymin > rect.ymin || layout->tile_h > region->winy) {
288 cur->ymin = rect.ymin - (2 * layout->tile_border_y);
289 cur->ymax = cur->ymin + region->winy;
290 }
291 /* up */
292 else if ((cur->ymax - layout->offset_top) < rect.ymax) {
293 cur->ymax = rect.ymax + layout->tile_border_y + layout->offset_top;
294 cur->ymin = cur->ymax - region->winy;
295 }
296 /* left - also use if tile is wider than viewbounds so view is aligned to file name */
297 else if (cur->xmin > rect.xmin || layout->tile_w > region->winx) {
298 cur->xmin = rect.xmin - layout->tile_border_x;
299 cur->xmax = cur->xmin + region->winx;
300 }
301 /* right */
302 else if (cur->xmax < rect.xmax) {
303 cur->xmax = rect.xmax + (2 * layout->tile_border_x);
304 cur->xmin = cur->xmax - region->winx;
305 }
306 else {
307 BLI_assert(cur->xmin <= rect.xmin && cur->xmax >= rect.xmax && cur->ymin <= rect.ymin &&
308 (cur->ymax - layout->offset_top) >= rect.ymax);
309 changed = false;
310 }
311
312 if (changed) {
314 }
315}
316
318 SpaceFile *sfile,
319 FileSelection *sel)
320{
321 const FileLayout *layout = ED_fileselect_get_layout(sfile, region);
322
323 if (((layout->flag & FILE_LAYOUT_HOR) && region->winx <= (1.2f * layout->tile_w)) &&
324 ((layout->flag & FILE_LAYOUT_VER) && region->winy <= (2.0f * layout->tile_h)))
325 {
326 return;
327 }
328
329 /* Adjust view to display selection. Doing iterations for first and last
330 * selected item makes view showing as much of the selection possible.
331 * Not really useful if tiles are (almost) bigger than viewbounds though. */
332 file_ensure_inside_viewbounds(region, sfile, sel->last);
333 file_ensure_inside_viewbounds(region, sfile, sel->first);
334}
335
337 bContext *C, const rcti *rect, FileSelType select, bool fill, bool do_diropen)
338{
339 SpaceFile *sfile = CTX_wm_space_file(C);
342 FileSelection sel = file_selection_get(C, rect, fill); /* get the selection */
343 const FileCheckType check_type = (params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
344
345 /* flag the files as selected in the filelist */
347 sfile->files, &sel, select, FILE_SEL_SELECTED, check_type);
348
349 /* Don't act on multiple selected files */
350 if (sel.first != sel.last) {
351 select = FileSelType(0);
352 }
353
354 /* Do we have a valid selection and are we actually selecting */
355 if ((sel.last >= 0) && (select != FILE_SEL_REMOVE)) {
356 /* Check last selection, if selected, act on the file or dir */
357 if (filelist_entry_select_index_get(sfile->files, sel.last, check_type)) {
358 retval = file_select_do(C, sel.last, do_diropen);
359 }
360 }
361
362 if (select != FILE_SEL_ADD && !file_is_any_selected(sfile->files)) {
363 params->active_file = -1;
364 }
365 else if (sel.last >= 0) {
366 ARegion *region = CTX_wm_region(C);
367 file_ensure_selection_inside_viewbounds(region, sfile, &sel);
368 }
369
370 /* update operator for name change event */
372
373 return retval;
374}
375
377
378/* -------------------------------------------------------------------- */
381
386 ScrArea *area,
387 ReportList *reports)
388{
389 /* NOTE: use warning instead of error here, because the bookmark operation may be part of
390 * other actions which should not cause the operator to fail entirely. */
391 const std::optional<std::string> cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG,
392 nullptr);
393 if (!cfgdir.has_value()) {
394 BKE_report(reports, RPT_ERROR, "Unable to create configuration directory to write bookmarks");
395 return false;
396 }
397
398 char filepath[FILE_MAX];
399 BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_BOOKMARK_FILE);
400 if (!fsmenu_write_file(fsmenu, filepath)) {
401 BKE_reportf(reports, RPT_ERROR, "Unable to open or write bookmark file \"%s\"", filepath);
402 return false;
403 }
404
406 ED_area_tag_redraw(area);
407 return true;
408}
409
411
412/* -------------------------------------------------------------------- */
415
417 ARegion *region,
418 const FileSelection *sel,
419 const int mouse_xy[2])
420{
421 FileLayout *layout = ED_fileselect_get_layout(sfile, region);
422 rcti bounds_first, bounds_last;
423 int dist_first, dist_last;
424 float mouseco_view[2];
425
426 ui::view2d_region_to_view(&region->v2d, UNPACK2(mouse_xy), &mouseco_view[0], &mouseco_view[1]);
427
428 file_tile_boundbox(region, layout, sel->first, &bounds_first);
429 file_tile_boundbox(region, layout, sel->last, &bounds_last);
430
431 /* are first and last in the same column (horizontal layout)/row (vertical layout)? */
432 if ((layout->flag & FILE_LAYOUT_HOR && bounds_first.xmin == bounds_last.xmin) ||
433 (layout->flag & FILE_LAYOUT_VER && bounds_first.ymin != bounds_last.ymin))
434 {
435 /* use vertical distance */
436 const int my_loc = int(mouseco_view[1]);
437 dist_first = BLI_rcti_length_y(&bounds_first, my_loc);
438 dist_last = BLI_rcti_length_y(&bounds_last, my_loc);
439 }
440 else {
441 /* use horizontal distance */
442 const int mx_loc = int(mouseco_view[0]);
443 dist_first = BLI_rcti_length_x(&bounds_first, mx_loc);
444 dist_last = BLI_rcti_length_x(&bounds_last, mx_loc);
445 }
446
447 return (dist_first < dist_last) ? sel->first : sel->last;
448}
449
451{
452 ARegion *region = CTX_wm_region(C);
453 SpaceFile *sfile = CTX_wm_space_file(C);
455 FileSelection sel;
456 rcti rect;
457
459
460 result = WM_gesture_box_modal(C, op, event);
461
464
465 ED_fileselect_layout_isect_rect(sfile->layout, &region->v2d, &rect, &rect);
466
467 sel = file_selection_get(C, &rect, false);
468 if ((sel.first != params->sel_first) || (sel.last != params->sel_last)) {
469 int idx;
470
475
476 for (idx = sel.last; idx >= 0; idx--) {
477 const FileDirEntry *file = filelist_file(sfile->files, idx);
478
479 /* Don't highlight read-only file (".." or ".") on box select. */
480 if (FILENAME_IS_CURRPAR(file->relpath)) {
483 }
484
485 /* make sure highlight_file is no readonly file */
486 if (sel.last == idx) {
487 params->highlight_file = idx;
488 }
489 }
490 }
491 params->sel_first = sel.first;
492 params->sel_last = sel.last;
493 params->active_file = file_box_select_find_last_selected(sfile, region, &sel, event->mval);
494 }
495 else {
496 params->highlight_file = -1;
497 params->sel_first = params->sel_last = -1;
498 fileselect_file_set(C, sfile, params->active_file);
501 }
502
503 return result;
504}
505
507{
508 ARegion *region = CTX_wm_region(C);
509 SpaceFile *sfile = CTX_wm_space_file(C);
510 rcti rect;
512
513 if (sfile->files == nullptr || sfile->layout == nullptr) {
514 return OPERATOR_CANCELLED;
515 }
516
518
519 const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
520 const bool select = (sel_op != SEL_OP_SUB);
521 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
523 }
524
525 ED_fileselect_layout_isect_rect(sfile->layout, &region->v2d, &rect, &rect);
526
527 ret = file_select(C, &rect, select ? FILE_SEL_ADD : FILE_SEL_REMOVE, false, false);
528
529 /* unselect '..' parent entry - it's not supposed to be selected if more than
530 * one file is selected */
532
533 if (FILE_SELECT_DIR == ret) {
535 }
536 else if (FILE_SELECT_FILE == ret) {
538 }
539 return OPERATOR_FINISHED;
540}
541
543{
544 /* identifiers */
545 ot->name = "Box Select";
546 ot->description = "Activate/select the file(s) contained in the border";
547 ot->idname = "FILE_OT_select_box";
548
549 /* API callbacks. */
553 /* Operator works for file or asset browsing */
556
557 /* properties */
560}
561
563
564/* -------------------------------------------------------------------- */
567
568static rcti file_select_mval_to_select_rect(const int mval[2])
569{
570 rcti rect;
571 rect.xmin = rect.xmax = mval[0];
572 rect.ymin = rect.ymax = mval[1];
573 return rect;
574}
575
577{
578 ARegion *region = CTX_wm_region(C);
579 SpaceFile *sfile = CTX_wm_space_file(C);
581 rcti rect;
582 const bool extend = RNA_boolean_get(op->ptr, "extend");
583 const bool fill = RNA_boolean_get(op->ptr, "fill");
584 const bool do_diropen = RNA_boolean_get(op->ptr, "open");
585 const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all");
586 const bool only_activate_if_selected = RNA_boolean_get(op->ptr, "only_activate_if_selected");
587 /* Used so right mouse clicks can do both, activate and spawn the context menu. */
588 const bool pass_through = RNA_boolean_get(op->ptr, "pass_through");
589 bool wait_to_deselect_others = RNA_boolean_get(op->ptr, "wait_to_deselect_others");
590
591 int mval[2];
592 mval[0] = RNA_int_get(op->ptr, "mouse_x");
593 mval[1] = RNA_int_get(op->ptr, "mouse_y");
595
596 if (sfile->files == nullptr || sfile->layout == nullptr) {
597 return OPERATOR_CANCELLED;
598 }
599 if (!ED_fileselect_layout_is_inside_pt(sfile->layout, &region->v2d, rect.xmin, rect.ymin)) {
601 }
602
603 if (extend || fill) {
604 wait_to_deselect_others = false;
605 }
606
608
610 if (params) {
611 int idx = params->highlight_file;
612 int numfiles = filelist_files_ensure(sfile->files);
613
614 if ((idx >= 0) && (idx < numfiles)) {
615 const bool is_selected = filelist_entry_select_index_get(sfile->files, idx, CHECK_ALL) &
617 if (only_activate_if_selected && is_selected) {
618 /* Don't deselect other items. */
619 }
620 else if (wait_to_deselect_others && is_selected) {
621 ret_val = OPERATOR_RUNNING_MODAL;
622 }
623 /* single select, deselect all selected first */
624 else if (!extend) {
626 }
627 }
628 }
629
630 ret = file_select(C, &rect, extend ? FILE_SEL_TOGGLE : FILE_SEL_ADD, fill, do_diropen);
631
632 if (extend) {
633 /* unselect '..' parent entry - it's not supposed to be selected if more
634 * than one file is selected */
636 }
637
638 if (ret == FILE_SELECT_NOTHING) {
639 if (deselect_all) {
641 }
642 }
643 else if (ret == FILE_SELECT_DIR) {
645 }
646 else if (ret == FILE_SELECT_FILE) {
648 }
649
650 WM_event_add_mousemove(CTX_wm_window(C)); /* for directory changes */
652
653 if ((ret_val == OPERATOR_FINISHED) && pass_through) {
654 ret_val |= OPERATOR_PASS_THROUGH;
655 }
656 return ret_val;
657}
658
660{
661 PropertyRNA *prop;
662
663 /* identifiers */
664 ot->name = "Select";
665 ot->idname = "FILE_OT_select";
666 ot->description = "Handle mouse clicks to select and activate items";
667
668 /* API callbacks. */
672 /* Operator works for file or asset browsing */
674
675 /* properties */
677 prop = RNA_def_boolean(ot->srna,
678 "extend",
679 false,
680 "Extend",
681 "Extend selection instead of deselecting everything first");
683 prop = RNA_def_boolean(
684 ot->srna, "fill", false, "Fill", "Select everything beginning with the last selection");
687 prop = RNA_def_boolean(ot->srna, "open", true, "Open", "Open a directory when selecting it");
689 prop = RNA_def_boolean(ot->srna,
690 "deselect_all",
691 false,
692 "Deselect On Nothing",
693 "Deselect all when nothing under the cursor");
695 prop = RNA_def_boolean(ot->srna,
696 "only_activate_if_selected",
697 false,
698 "Only Activate if Selected",
699 "Do not change selection if the item under the cursor is already "
700 "selected, only activate it");
702 prop = RNA_def_boolean(ot->srna,
703 "pass_through",
704 false,
705 "Pass Through",
706 "Even on successful execution, pass the event on so other operators can "
707 "execute on it as well");
709}
710
712
713/* -------------------------------------------------------------------- */
716
721 wmWindow *win,
722 ARegion *region,
723 SpaceFile *sfile,
724 const int direction,
725 const int numfiles,
726 const int active_old,
727 const int active_new,
728 const int other_site,
729 const bool has_selection,
730 const bool extend,
731 const bool fill)
732{
734 FileList *files = sfile->files;
735 const int last_sel = params->active_file; /* store old value */
736 int active = active_old; /* could use active_old instead, just for readability */
737 bool deselect = false;
738
739 BLI_assert(params);
740
741 if (numfiles == 0) {
742 /* No files visible, nothing to do. */
743 return false;
744 }
745
746 if (has_selection) {
747 if (extend && filelist_entry_select_index_get(files, active_old, CHECK_ALL) &&
748 filelist_entry_select_index_get(files, active_new, CHECK_ALL))
749 {
750 /* conditions for deselecting: initial file is selected, new file is
751 * selected and either other_side isn't selected/found or we use fill */
752 deselect = (fill || other_site == -1 ||
753 !filelist_entry_select_index_get(files, other_site, CHECK_ALL));
754
755 /* don't change highlight_file here since we either want to deselect active or we want
756 * to walk through a block of selected files without selecting/deselecting anything */
757 params->active_file = active_new;
758 /* but we want to change active if we use fill
759 * (needed to get correct selection bounds) */
760 if (deselect && fill) {
761 active = active_new;
762 }
763 }
764 else {
765 /* regular selection change */
766 params->active_file = active = active_new;
767 }
768 }
769 else {
770 /* select last file */
771 if (ELEM(direction, UI_SELECT_WALK_UP, UI_SELECT_WALK_LEFT)) {
772 params->active_file = active = numfiles - 1;
773 }
774 /* select first file */
775 else if (ELEM(direction, UI_SELECT_WALK_DOWN, UI_SELECT_WALK_RIGHT)) {
776 params->active_file = active = 0;
777 }
778 else {
779 BLI_assert(0);
780 }
781 }
782
783 if (active < 0) {
784 return false;
785 }
786
787 if (extend) {
788 /* highlight the active walker file for extended selection for better visual feedback */
789 params->highlight_file = params->active_file;
790
791 /* unselect '..' parent entry - it's not supposed to be selected if more
792 * than one file is selected */
794 }
795 else {
796 /* deselect all first */
798
799 /* highlight file under mouse pos */
800 params->highlight_file = -1;
802 }
803
804 /* do the actual selection */
805 if (fill) {
806 FileSelection sel = {std::min(active, last_sel), std::max(active, last_sel)};
807
808 /* fill selection between last and first selected file */
810 files, &sel, deselect ? FILE_SEL_REMOVE : FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
811 /* entire sel is cleared here, so select active again */
812 if (deselect) {
814 }
815
816 /* unselect '..' parent entry - it's not supposed to be selected if more
817 * than one file is selected */
818 if ((sel.last - sel.first) > 1) {
820 }
821 }
822 else {
824 files, active, deselect ? FILE_SEL_REMOVE : FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL);
825 }
826
827 BLI_assert(IN_RANGE(active, -1, numfiles));
828 fileselect_file_set(C, sfile, params->active_file);
829
830 /* ensure newly selected file is inside viewbounds */
831 file_ensure_inside_viewbounds(region, sfile, params->active_file);
832
833 /* selection changed */
834 return true;
835}
836
841 SpaceFile *sfile,
842 FileSelectParams *params,
843 const int direction,
844 const bool extend,
845 const bool fill)
846{
847 wmWindow *win = CTX_wm_window(C);
848 ARegion *region = CTX_wm_region(C);
849 FileList *files = sfile->files;
850 const int numfiles = filelist_files_ensure(files);
851 const bool has_selection = file_is_any_selected(files);
852 const int active_old = params->active_file;
853 int active_new = -1;
854 int other_site = -1; /* file on the other site of active_old */
855
856 /* *** get all needed files for handling selection *** */
857
858 if (numfiles == 0) {
859 /* No files visible, nothing to do. */
860 return false;
861 }
862
863 if (has_selection) {
864 FileLayout *layout = ED_fileselect_get_layout(sfile, region);
865 const int idx_shift = (layout->flag & FILE_LAYOUT_HOR) ? layout->rows : layout->flow_columns;
866
867 if ((layout->flag & FILE_LAYOUT_HOR && direction == UI_SELECT_WALK_UP) ||
868 (layout->flag & FILE_LAYOUT_VER && direction == UI_SELECT_WALK_LEFT))
869 {
870 active_new = active_old - 1;
871 other_site = active_old + 1;
872 }
873 else if ((layout->flag & FILE_LAYOUT_HOR && direction == UI_SELECT_WALK_DOWN) ||
874 (layout->flag & FILE_LAYOUT_VER && direction == UI_SELECT_WALK_RIGHT))
875 {
876 active_new = active_old + 1;
877 other_site = active_old - 1;
878 }
879 else if ((layout->flag & FILE_LAYOUT_HOR && direction == UI_SELECT_WALK_LEFT) ||
880 (layout->flag & FILE_LAYOUT_VER && direction == UI_SELECT_WALK_UP))
881 {
882 active_new = active_old - idx_shift;
883 other_site = active_old + idx_shift;
884 }
885 else if ((layout->flag & FILE_LAYOUT_HOR && direction == UI_SELECT_WALK_RIGHT) ||
886 (layout->flag & FILE_LAYOUT_VER && direction == UI_SELECT_WALK_DOWN))
887 {
888
889 active_new = active_old + idx_shift;
890 other_site = active_old - idx_shift;
891 }
892 else {
893 BLI_assert(0);
894 }
895
896 if (!IN_RANGE(active_new, -1, numfiles)) {
897 if (extend) {
898 /* extend to invalid file -> abort */
899 return false;
900 }
901 /* if we don't extend, selecting '..' (index == 0) is allowed so
902 * using key selection to go to parent directory is possible */
903 if (active_new != 0) {
904 /* select initial file */
905 active_new = active_old;
906 }
907 }
908 if (!IN_RANGE(other_site, 0, numfiles)) {
909 other_site = -1;
910 }
911 }
912
914 win,
915 region,
916 sfile,
917 direction,
918 numfiles,
919 active_old,
920 active_new,
921 other_site,
922 has_selection,
923 extend,
924 fill);
925}
926
928 wmOperator *op,
929 const wmEvent * /*event*/)
930{
931 SpaceFile *sfile = reinterpret_cast<SpaceFile *>(CTX_wm_space_data(C));
933 const int direction = RNA_enum_get(op->ptr, "direction");
934 const bool extend = RNA_boolean_get(op->ptr, "extend");
935 const bool fill = RNA_boolean_get(op->ptr, "fill");
936
937 if (file_walk_select_do(C, sfile, params, direction, extend, fill)) {
939 return OPERATOR_FINISHED;
940 }
941
942 return OPERATOR_CANCELLED;
943}
944
946{
947 PropertyRNA *prop;
948
949 /* identifiers */
950 ot->name = "Walk Select/Deselect File";
951 ot->description = "Select/Deselect files by walking through them";
952 ot->idname = "FILE_OT_select_walk";
953
954 /* API callbacks. */
956 /* Operator works for file or asset browsing */
958
959 /* properties */
961 prop = RNA_def_boolean(ot->srna,
962 "extend",
963 false,
964 "Extend",
965 "Extend selection instead of deselecting everything first");
967 prop = RNA_def_boolean(
968 ot->srna, "fill", false, "Fill", "Select everything beginning with the last selection");
971}
972
974
975/* -------------------------------------------------------------------- */
978
980{
981 ScrArea *area = CTX_wm_area(C);
982 SpaceFile *sfile = CTX_wm_space_file(C);
984 FileSelection sel;
985
986 if (sfile->files == nullptr || params == nullptr) {
987 return OPERATOR_CANCELLED;
988 }
989
990 const int numfiles = filelist_files_ensure(sfile->files);
991 int action = RNA_enum_get(op->ptr, "action");
992
993 if (action == SEL_TOGGLE) {
995 }
996
997 sel.first = 0;
998 sel.last = numfiles - 1;
999
1000 FileCheckType check_type;
1001 FileSelType filesel_type;
1002
1003 switch (action) {
1004 case SEL_SELECT:
1005 case SEL_INVERT: {
1006 check_type = (params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
1007 filesel_type = (action == SEL_INVERT) ? FILE_SEL_TOGGLE : FILE_SEL_ADD;
1008 break;
1009 }
1010 case SEL_DESELECT: {
1011 check_type = CHECK_ALL;
1012 filesel_type = FILE_SEL_REMOVE;
1013 break;
1014 }
1015 default: {
1016 BLI_assert(0);
1017 return OPERATOR_CANCELLED;
1018 }
1019 }
1020
1022 sfile->files, &sel, filesel_type, FILE_SEL_SELECTED, check_type);
1023
1024 params->active_file = -1;
1025 if (action != SEL_DESELECT) {
1026 for (int i = 0; i < numfiles; i++) {
1027 if (filelist_entry_select_index_get(sfile->files, i, check_type)) {
1028 params->active_file = i;
1029 break;
1030 }
1031 }
1032 }
1033
1036 ED_area_tag_redraw(area);
1037
1038 return OPERATOR_FINISHED;
1039}
1040
1042{
1043 /* identifiers */
1044 ot->name = "(De)select All Files";
1045 ot->description = "Select or deselect all files";
1046 ot->idname = "FILE_OT_select_all";
1047
1048 /* API callbacks. */
1050 /* Operator works for file or asset browsing */
1052
1053 /* properties */
1055}
1056
1058
1059/* -------------------------------------------------------------------- */
1062
1064{
1065 SpaceFile *sfile = CTX_wm_space_file(C);
1067
1068 if (sfile->files == nullptr || params == nullptr) {
1069 return OPERATOR_CANCELLED;
1070 }
1071
1073
1074 if (sel.first == -1 && sel.last == -1 && params->active_file == -1) {
1075 /* Nothing was selected. */
1076 return OPERATOR_CANCELLED;
1077 }
1078
1079 /* Extend the selection area with the active file, as it may not be selected but still is
1080 * important to have in view. NOTE: active_file gets -1 after a search has been cleared/updated.
1081 */
1082 if (params->active_file != -1) {
1083 if (sel.first == -1 || params->active_file < sel.first) {
1084 sel.first = params->active_file;
1085 }
1086 if (sel.last == -1 || params->active_file > sel.last) {
1087 sel.last = params->active_file;
1088 }
1089 }
1090
1091 ScrArea *area = CTX_wm_area(C);
1092 ARegion *region = CTX_wm_region(C);
1093 file_ensure_selection_inside_viewbounds(region, sfile, &sel);
1094
1097 ED_area_tag_redraw(area);
1098
1099 return OPERATOR_FINISHED;
1100}
1101
1103{
1104 /* identifiers */
1105 ot->name = "Frame Selected";
1106 ot->description = "Scroll the selected files into view";
1107 ot->idname = "FILE_OT_view_selected";
1108
1109 /* API callbacks. */
1111 /* Operator works for file or asset browsing */
1113}
1114
1116
1117/* -------------------------------------------------------------------- */
1120
1121/* Note we could get rid of this one, but it's used by some addon so...
1122 * Does not hurt keeping it around for now. */
1124{
1125 Main *bmain = CTX_data_main(C);
1126 SpaceFile *sfile = CTX_wm_space_file(C);
1127
1128 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "dir");
1130 if (params == nullptr) [[unlikely]] {
1131 return OPERATOR_CANCELLED;
1132 }
1133 char entry[256];
1134
1135 RNA_property_string_get(op->ptr, prop, entry);
1136 STRNCPY(params->dir, entry);
1137 BLI_path_abs(params->dir, BKE_main_blendfile_path(bmain));
1138 BLI_path_normalize_dir(params->dir, sizeof(params->dir));
1140
1142
1143 return OPERATOR_FINISHED;
1144}
1145
1147{
1148 PropertyRNA *prop;
1149
1150 /* identifiers */
1151 ot->name = "Select Directory";
1152 ot->description = "Select a bookmarked directory";
1153 ot->idname = "FILE_OT_select_bookmark";
1154
1155 /* API callbacks. */
1157 /* Bookmarks are for file browsing only (not asset browsing). */
1159
1160 /* properties */
1161 prop = RNA_def_string(ot->srna, "dir", nullptr, FILE_MAXDIR, "Directory", "");
1163}
1164
1166
1167/* -------------------------------------------------------------------- */
1170
1172{
1173 ScrArea *area = CTX_wm_area(C);
1174 SpaceFile *sfile = CTX_wm_space_file(C);
1175 FSMenu *fsmenu = ED_fsmenu_get();
1177 if (!params) {
1178 return OPERATOR_CANCELLED;
1179 }
1180
1181 if (params->dir[0] != '\0') {
1182
1184 fsmenu, FS_CATEGORY_BOOKMARKS, params->dir, nullptr, ICON_FILE_FOLDER, FS_INSERT_SAVE);
1186 }
1187 return OPERATOR_FINISHED;
1188}
1189
1191{
1192 /* identifiers */
1193 ot->name = "Add Bookmark";
1194 ot->description = "Add a bookmark for the selected/active directory";
1195 ot->idname = "FILE_OT_bookmark_add";
1196
1197 /* API callbacks. */
1198 ot->exec = bookmark_add_exec;
1199 /* Bookmarks are for file browsing only (not asset browsing). */
1201}
1202
1204
1205/* -------------------------------------------------------------------- */
1208
1210{
1211 ScrArea *area = CTX_wm_area(C);
1212 SpaceFile *sfile = CTX_wm_space_file(C);
1213 FSMenu *fsmenu = ED_fsmenu_get();
1214 int nentries = ED_fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
1215
1216 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "index");
1217 const int index = RNA_property_is_set(op->ptr, prop) ? RNA_property_int_get(op->ptr, prop) :
1218 sfile->bookmarknr;
1219 if ((index > -1) && (index < nentries)) {
1222 }
1223
1224 return OPERATOR_FINISHED;
1225}
1226
1228{
1229 PropertyRNA *prop;
1230
1231 /* identifiers */
1232 ot->name = "Delete Bookmark";
1233 ot->description = "Delete selected bookmark";
1234 ot->idname = "FILE_OT_bookmark_delete";
1235
1236 /* API callbacks. */
1238 /* Bookmarks are for file browsing only (not asset browsing). */
1240
1241 /* properties */
1242 prop = RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000);
1244}
1245
1247
1248/* -------------------------------------------------------------------- */
1251
1253{
1254 ScrArea *area = CTX_wm_area(C);
1255 FSMenu *fsmenu = ED_fsmenu_get();
1256 FSMenuEntry *fsme_next, *fsme = ED_fsmenu_get_category(fsmenu, FS_CATEGORY_BOOKMARKS);
1257 int index;
1258 bool changed = false;
1259
1260 for (index = 0; fsme; fsme = fsme_next) {
1261 fsme_next = fsme->next;
1262
1263 if (!BLI_is_dir(fsme->path)) {
1265 changed = true;
1266 }
1267 else {
1268 index++;
1269 }
1270 }
1271
1272 if (changed) {
1274 }
1275
1276 return OPERATOR_FINISHED;
1277}
1278
1280{
1281 /* identifiers */
1282 ot->name = "Cleanup Bookmarks";
1283 ot->description = "Delete all invalid bookmarks";
1284 ot->idname = "FILE_OT_bookmark_cleanup";
1285
1286 /* API callbacks. */
1288 /* Bookmarks are for file browsing only (not asset browsing). */
1290
1291 /* properties */
1292}
1293
1295
1296/* -------------------------------------------------------------------- */
1299
1300enum {
1305};
1306
1308{
1309 ScrArea *area = CTX_wm_area(C);
1310 SpaceFile *sfile = CTX_wm_space_file(C);
1311 FSMenu *fsmenu = ED_fsmenu_get();
1313 const FSMenuEntry *fsmentry_org = fsmentry;
1314
1315 const int direction = RNA_enum_get(op->ptr, "direction");
1316 const int totitems = ED_fsmenu_get_nentries(fsmenu, FS_CATEGORY_BOOKMARKS);
1317 const int act_index = sfile->bookmarknr;
1318 int new_index;
1319
1320 if (totitems < 2) {
1321 return OPERATOR_CANCELLED;
1322 }
1323
1324 switch (direction) {
1326 new_index = 0;
1327 break;
1329 new_index = totitems - 1;
1330 break;
1333 default:
1334 new_index = (totitems + act_index + direction) % totitems;
1335 break;
1336 }
1337
1338 if (new_index == act_index) {
1339 return OPERATOR_CANCELLED;
1340 }
1341
1342 BLI_linklist_move_item(reinterpret_cast<LinkNode **>(&fsmentry), act_index, new_index);
1343 if (fsmentry != fsmentry_org) {
1345 }
1346
1347 /* Need to update active bookmark number. */
1348 sfile->bookmarknr = new_index;
1349
1351
1352 return OPERATOR_FINISHED;
1353}
1354
1356{
1357 SpaceFile *sfile = CTX_wm_space_file(C);
1358
1359 /* Bookmarks are for file browsing only (not asset browsing). */
1361 return false;
1362 }
1363
1364 return sfile->bookmarknr != -1;
1365}
1366
1368{
1369 static const EnumPropertyItem slot_move[] = {
1370 {FILE_BOOKMARK_MOVE_TOP, "TOP", 0, "Top", "Top of the list"},
1371 {FILE_BOOKMARK_MOVE_UP, "UP", 0, "Up", ""},
1372 {FILE_BOOKMARK_MOVE_DOWN, "DOWN", 0, "Down", ""},
1373 {FILE_BOOKMARK_MOVE_BOTTOM, "BOTTOM", 0, "Bottom", "Bottom of the list"},
1374 {0, nullptr, 0, nullptr, nullptr}};
1375
1376 /* identifiers */
1377 ot->name = "Move Bookmark";
1378 ot->idname = "FILE_OT_bookmark_move";
1379 ot->description = "Move the active bookmark up/down in the list";
1380
1381 /* API callbacks. */
1384
1385 /* flags */
1386 ot->flag = OPTYPE_REGISTER; /* No undo! */
1387
1388 RNA_def_enum(ot->srna,
1389 "direction",
1390 slot_move,
1391 0,
1392 "Direction",
1393 "Direction to move the active bookmark towards");
1394}
1395
1397
1398/* -------------------------------------------------------------------- */
1401
1403{
1404 ScrArea *area = CTX_wm_area(C);
1405 FSMenu *fsmenu = ED_fsmenu_get();
1406
1407 while (ED_fsmenu_get_entry(fsmenu, FS_CATEGORY_RECENT, 0) != nullptr) {
1409 }
1410
1412
1413 return OPERATOR_FINISHED;
1414}
1415
1417{
1418 /* identifiers */
1419 ot->name = "Reset Recent";
1420 ot->description = "Reset recent files";
1421 ot->idname = "FILE_OT_reset_recent";
1422
1423 /* API callbacks. */
1424 ot->exec = reset_recent_exec;
1425 /* File browsing only operator (not asset browsing). */
1427}
1428
1430
1431/* -------------------------------------------------------------------- */
1434
1435int file_highlight_set(SpaceFile *sfile, ARegion *region, int mx, int my)
1436{
1437 View2D *v2d = &region->v2d;
1438 FileSelectParams *params;
1439 int numfiles, origfile;
1440
1441 /* In case blender starts where the mouse is over a File browser,
1442 * this operator can be invoked when the `sfile` or `sfile->layout` isn't initialized yet. */
1443 if (sfile == nullptr || sfile->files == nullptr || sfile->layout == nullptr) {
1444 return 0;
1445 }
1446
1447 params = ED_fileselect_get_active_params(sfile);
1448 /* In case #SpaceFile.browse_mode just changed, the area may be pending a refresh still, which is
1449 * what creates the params for the current browse mode. See #93508. */
1450 if (!params) {
1451 return false;
1452 }
1453 numfiles = filelist_files_ensure(sfile->files);
1454
1455 origfile = params->highlight_file;
1456
1457 mx -= region->winrct.xmin;
1458 my -= region->winrct.ymin;
1459
1460 if (ED_fileselect_layout_is_inside_pt(sfile->layout, v2d, mx, my)) {
1461 float fx, fy;
1462 int highlight_file;
1463
1464 ui::view2d_region_to_view(v2d, mx, my, &fx, &fy);
1465
1466 highlight_file = ED_fileselect_layout_offset(
1467 sfile->layout, int(v2d->tot.xmin + fx), int(v2d->tot.ymax - fy));
1468
1469 if ((highlight_file >= 0) && (highlight_file < numfiles)) {
1470 params->highlight_file = highlight_file;
1471 }
1472 else {
1473 params->highlight_file = -1;
1474 }
1475 }
1476 else {
1477 params->highlight_file = -1;
1478 }
1479
1480 return (params->highlight_file != origfile);
1481}
1482
1484 wmOperator * /*op*/,
1485 const wmEvent *event)
1486{
1487 ARegion *region = CTX_wm_region(C);
1488 SpaceFile *sfile = CTX_wm_space_file(C);
1489
1490 if (!file_highlight_set(sfile, region, event->xy[0], event->xy[1])) {
1491 return OPERATOR_PASS_THROUGH;
1492 }
1493
1495
1496 return OPERATOR_PASS_THROUGH;
1497}
1498
1500{
1501 /* identifiers */
1502 ot->name = "Highlight File";
1503 ot->description = "Highlight selected file(s)";
1504 ot->idname = "FILE_OT_highlight";
1505
1506 /* API callbacks. */
1508 /* Operator works for file or asset browsing */
1510}
1511
1513
1514/* -------------------------------------------------------------------- */
1517
1519 wmOperator * /*op*/,
1520 const wmEvent *event)
1521{
1522 const ARegion *region = CTX_wm_region(C);
1523 SpaceFile *sfile = CTX_wm_space_file(C);
1524
1526 &region->v2d, sfile->layout, event->mval[0], event->mval[1]))
1527 {
1530 &region->v2d, params, sfile->layout, event->mval[0]);
1531
1532 if (column_type != COLUMN_NONE) {
1533 const FileAttributeColumn *column = &sfile->layout->attribute_columns[column_type];
1534
1536 if (params->sort == column->sort_type) {
1537 /* Already sorting by selected column -> toggle sort invert (three state logic). */
1538 params->flag ^= FILE_SORT_INVERT;
1539 }
1540 else {
1541 params->sort = column->sort_type;
1542 params->flag &= ~FILE_SORT_INVERT;
1543 }
1544
1546 }
1547 }
1548
1549 return OPERATOR_PASS_THROUGH;
1550}
1551
1553{
1554 /* identifiers */
1555 ot->name = "Sort from Column";
1556 ot->description = "Change sorting to use column under cursor";
1557 ot->idname = "FILE_OT_sort_column_ui_context";
1558
1559 /* API callbacks. */
1561 /* Operator works for file or asset browsing */
1563
1564 ot->flag = OPTYPE_INTERNAL;
1565}
1566
1568
1569/* -------------------------------------------------------------------- */
1572
1574{
1576 SpaceFile *sfile = CTX_wm_space_file(C);
1577
1578 if (!sfile || !sfile->op) {
1579 poll = false;
1580 }
1581
1582 return poll;
1583}
1584
1586{
1588 SpaceFile *sfile = CTX_wm_space_file(C);
1589 wmOperator *op = sfile->op;
1590
1591 sfile->op = nullptr;
1592
1594
1595 return OPERATOR_FINISHED;
1596}
1597
1599{
1600 /* identifiers */
1601 ot->name = "Cancel File Operation";
1602 ot->description = "Cancel file operation";
1603 ot->idname = "FILE_OT_cancel";
1604
1605 /* API callbacks. */
1606 ot->exec = file_cancel_exec;
1608}
1609
1611
1612/* -------------------------------------------------------------------- */
1615
1617 bContext *C, Main *bmain, wmOperator *op, SpaceFile *sfile, char *filepath)
1618{
1620 PropertyRNA *prop;
1621 char dir[FILE_MAX];
1622
1623 STRNCPY(dir, params->dir);
1625
1626 /* XXX, not real length */
1627 if (params->file[0]) {
1628 BLI_path_join(filepath, FILE_MAX, params->dir, params->file);
1629 }
1630 else {
1631 BLI_strncpy(filepath, dir, FILE_MAX);
1632 }
1633
1634 if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
1635 if (RNA_property_boolean_get(op->ptr, prop)) {
1636 BLI_path_rel(filepath, BKE_main_blendfile_path(bmain));
1638 }
1639 }
1640
1641 char value[FILE_MAX];
1642 if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
1643 RNA_property_string_get(op->ptr, prop, value);
1644 RNA_property_string_set(op->ptr, prop, params->file);
1645 if (RNA_property_update_check(prop) && !STREQ(params->file, value)) {
1646 RNA_property_update(C, op->ptr, prop);
1647 }
1648 }
1649 if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
1650 RNA_property_string_get(op->ptr, prop, value);
1651 RNA_property_string_set(op->ptr, prop, dir);
1652 if (RNA_property_update_check(prop) && !STREQ(dir, value)) {
1653 RNA_property_update(C, op->ptr, prop);
1654 }
1655 }
1656 if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
1657 RNA_property_string_get(op->ptr, prop, value);
1658 RNA_property_string_set(op->ptr, prop, filepath);
1659 if (RNA_property_update_check(prop) && !STREQ(filepath, value)) {
1660 RNA_property_update(C, op->ptr, prop);
1661 }
1662 }
1663
1664 /* some ops have multiple files to select */
1665 /* this is called on operators check() so clear collections first since
1666 * they may be already set. */
1667 {
1668 int i, numfiles = filelist_files_ensure(sfile->files);
1669
1670 if ((prop = RNA_struct_find_property(op->ptr, "files"))) {
1671 PointerRNA itemptr;
1672 int num_files = 0;
1674 for (i = 0; i < numfiles; i++) {
1676 FileDirEntry *file = filelist_file(sfile->files, i);
1677 /* Cannot (currently) mix regular items and alias/shortcuts in multiple selection. */
1678 if (!file->redirection_path) {
1679 RNA_property_collection_add(op->ptr, prop, &itemptr);
1680 RNA_string_set(&itemptr, "name", file->relpath);
1681 num_files++;
1682 }
1683 }
1684 }
1685 /* make sure the file specified in the filename button is added even if no
1686 * files selected */
1687 if (0 == num_files) {
1688 RNA_property_collection_add(op->ptr, prop, &itemptr);
1689 RNA_string_set(&itemptr, "name", params->file);
1690 }
1691 }
1692
1693 if ((prop = RNA_struct_find_property(op->ptr, "dirs"))) {
1694 PointerRNA itemptr;
1695 int num_dirs = 0;
1697 for (i = 0; i < numfiles; i++) {
1699 FileDirEntry *file = filelist_file(sfile->files, i);
1700 RNA_property_collection_add(op->ptr, prop, &itemptr);
1701 RNA_string_set(&itemptr, "name", file->relpath);
1702 num_dirs++;
1703 }
1704 }
1705
1706 /* make sure the directory specified in the button is added even if no
1707 * directory selected */
1708 if (0 == num_dirs) {
1709 RNA_property_collection_add(op->ptr, prop, &itemptr);
1710 RNA_string_set(&itemptr, "name", params->dir);
1711 }
1712 }
1713 }
1714}
1716{
1717 char filepath_dummy[FILE_MAX];
1718
1719 file_sfile_to_operator_ex(C, bmain, op, sfile, filepath_dummy);
1720}
1721
1723{
1725 PropertyRNA *prop;
1726
1727 /* If neither of the above are set, split the filepath back */
1728 if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
1729 char filepath[FILE_MAX];
1730 RNA_property_string_get(op->ptr, prop, filepath);
1732 filepath, params->dir, sizeof(params->dir), params->file, sizeof(params->file));
1733 }
1734 else {
1735 if ((prop = RNA_struct_find_property(op->ptr, "filename"))) {
1736 RNA_property_string_get(op->ptr, prop, params->file);
1737 }
1738 if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
1739 RNA_property_string_get(op->ptr, prop, params->dir);
1740 }
1741 }
1742
1743 /* we could check for relative_path property which is used when converting
1744 * in the other direction but doesn't hurt to do this every time */
1745 BLI_path_abs(params->dir, BKE_main_blendfile_path(bmain));
1746
1747 /* XXX, files and dirs updates missing, not really so important though */
1748}
1749
1750void file_sfile_filepath_set(SpaceFile *sfile, const char *filepath)
1751{
1753 BLI_assert(BLI_exists(filepath));
1754
1755 if (BLI_is_dir(filepath)) {
1756 STRNCPY(params->dir, filepath);
1757 }
1758 else {
1759 if ((params->flag & FILE_DIRSEL_ONLY) == 0) {
1761 filepath, params->dir, sizeof(params->dir), params->file, sizeof(params->file));
1762 }
1763 else {
1764 BLI_path_split_dir_part(filepath, params->dir, sizeof(params->dir));
1765 }
1766 }
1767}
1768
1770{
1771 /* May happen when manipulating non-active spaces. */
1772 if (area->spacetype != SPACE_FILE) [[unlikely]] {
1773 return;
1774 }
1775 SpaceFile *sfile = area->spacedata.first_as<SpaceFile>();
1776 wmOperator *op = sfile->op;
1777 if (op) { /* fail on reload */
1778 if (op->type->check) {
1779 Main *bmain = CTX_data_main(C);
1780 file_sfile_to_operator(C, bmain, op, sfile);
1781
1782 /* redraw */
1783 if (op->type->check(C, op)) {
1784 file_operator_to_sfile(bmain, sfile, op);
1785
1786 /* redraw, else the changed settings won't get updated */
1787 ED_area_tag_redraw(area);
1788 }
1789 }
1790 }
1791}
1792
1794{
1795 ScrArea *area = CTX_wm_area(C);
1796 file_draw_check_ex(C, area);
1797}
1798
1799void file_draw_check_cb(bContext *C, void * /*arg1*/, void * /*arg2*/)
1800{
1802}
1803
1805{
1806 if (sfile->op) { /* fails on reload */
1808 if (params && (params->flag & FILE_CHECK_EXISTING)) {
1809 char filepath[FILE_MAX];
1810 BLI_path_join(filepath, sizeof(filepath), params->dir, params->file);
1811 if (BLI_is_file(filepath)) {
1812 return true;
1813 }
1814 }
1815 }
1816
1817 return false;
1818}
1819
1821
1822/* -------------------------------------------------------------------- */
1825
1827 {FILE_EXTERNAL_OPERATION_OPEN, "OPEN", 0, "Open", "Open the file"},
1828 {FILE_EXTERNAL_OPERATION_FOLDER_OPEN, "FOLDER_OPEN", 0, "Open Folder", "Open the folder"},
1829 {FILE_EXTERNAL_OPERATION_EDIT, "EDIT", 0, "Edit", "Edit the file"},
1830 {FILE_EXTERNAL_OPERATION_NEW, "NEW", 0, "New", "Create a new file of this type"},
1831 {FILE_EXTERNAL_OPERATION_FIND, "FIND", 0, "Find File", "Search for files of this type"},
1832 {FILE_EXTERNAL_OPERATION_SHOW, "SHOW", 0, "Show", "Show this file"},
1833 {FILE_EXTERNAL_OPERATION_PLAY, "PLAY", 0, "Play", "Play this file"},
1834 {FILE_EXTERNAL_OPERATION_BROWSE, "BROWSE", 0, "Browse", "Browse this file"},
1835 {FILE_EXTERNAL_OPERATION_PREVIEW, "PREVIEW", 0, "Preview", "Preview this file"},
1836 {FILE_EXTERNAL_OPERATION_PRINT, "PRINT", 0, "Print", "Print this file"},
1837 {FILE_EXTERNAL_OPERATION_INSTALL, "INSTALL", 0, "Install", "Install this file"},
1838 {FILE_EXTERNAL_OPERATION_RUNAS, "RUNAS", 0, "Run As User", "Run as specific user"},
1840 "PROPERTIES",
1841 0,
1842 "Properties",
1843 "Show OS Properties for this item"},
1845 "FOLDER_FIND",
1846 0,
1847 "Find in Folder",
1848 "Search for items in this folder"},
1850 "CMD",
1851 0,
1852 "Command Prompt Here",
1853 "Open a command prompt here"},
1854 {0, nullptr, 0, nullptr, nullptr}};
1855
1857{
1859 /* File browsing only operator (not asset browsing). */
1860 return OPERATOR_CANCELLED;
1861 }
1862
1863 SpaceFile *sfile = CTX_wm_space_file(C);
1865 if (!sfile || !params) {
1866 return OPERATOR_CANCELLED;
1867 }
1868 char dir[FILE_MAX_LIBEXTRA];
1869 if (filelist_islibrary(sfile->files, dir, nullptr)) {
1870 return OPERATOR_CANCELLED;
1871 }
1872 int numfiles = filelist_files_ensure(sfile->files);
1873 FileDirEntry *fileentry = nullptr;
1874 int num_selected = 0;
1875 for (int i = 0; i < numfiles; i++) {
1877 fileentry = filelist_file(sfile->files, i);
1878 num_selected++;
1879 }
1880 }
1881 if (!fileentry || num_selected > 1) {
1882 return OPERATOR_CANCELLED;
1883 }
1884
1886 "operation");
1887
1888 char filepath[FILE_MAX_LIBEXTRA];
1889 if (!(fileentry->typeflag & FILE_TYPE_DIR) && (operation == FILE_EXTERNAL_OPERATION_FOLDER_OPEN))
1890 {
1891 const char *root = filelist_dir(sfile->files);
1892 STRNCPY(filepath, root);
1893 }
1894 else {
1895 filelist_file_get_full_path(sfile->files, fileentry, filepath);
1896 }
1897
1899
1900#ifdef WIN32
1901 if (!(fileentry->typeflag & FILE_TYPE_DIR) &&
1903 {
1904 /* Not a folder path, so for these operations use the root. */
1905 const char *root = filelist_dir(sfile->files);
1906 if (BLI_file_external_operation_execute(root, operation)) {
1908 return OPERATOR_FINISHED;
1909 }
1910 }
1911 if (BLI_file_external_operation_execute(filepath, operation)) {
1913 return OPERATOR_FINISHED;
1914 }
1915#else
1916 wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true);
1918 RNA_string_set(&op_props, "filepath", filepath);
1920 C, ot, wm::OpCallContext::InvokeDefault, &op_props, nullptr);
1921 WM_operator_properties_free(&op_props);
1922
1923 if (retval == OPERATOR_FINISHED) {
1925 return OPERATOR_FINISHED;
1926 }
1927#endif
1928
1930 op->reports, RPT_ERROR, "Failure to perform external file operation on \"%s\"", filepath);
1932 return OPERATOR_CANCELLED;
1933}
1934
1936 wmOperatorType * /*ot*/,
1937 PointerRNA *ptr)
1938{
1939 const char *description = "";
1940 RNA_enum_description(file_external_operation, RNA_enum_get(ptr, "operation"), &description);
1941 return TIP_(description);
1942}
1943
1945{
1946 /* identifiers */
1947 ot->name = "External File Operation";
1948 ot->idname = "FILE_OT_external_operation";
1949 ot->description = "Perform external operation on a file or folder";
1950
1951 /* API callbacks. */
1954
1955 /* flags */
1956 ot->flag = OPTYPE_REGISTER; /* No undo! */
1957
1958 /* properties */
1959 RNA_def_enum(ot->srna,
1960 "operation",
1963 "Operation",
1964 "Operation to perform on the selected file or path");
1965}
1966
1968 wmOperatorType *ot,
1969 const char *path,
1970 FileExternalOperation operation)
1971{
1972#ifdef WIN32
1973 if (!BLI_file_external_operation_supported(path, operation)) {
1974 return;
1975 }
1976#else
1977 UNUSED_VARS(path);
1979 return;
1980 }
1981#endif
1982
1983 const char *title = "";
1984 RNA_enum_name(file_external_operation, operation, &title);
1985
1986 PointerRNA props_ptr = layout.op(
1987 ot, IFACE_(title), ICON_NONE, wm::OpCallContext::InvokeDefault, UI_ITEM_NONE);
1988 RNA_enum_set(&props_ptr, "operation", operation);
1989}
1990
1991static void file_os_operations_menu_draw(const bContext *C_const, Menu *menu)
1992{
1993 bContext *C = const_cast<bContext *>(C_const);
1994
1995 /* File browsing only operator (not asset browsing). */
1997 return;
1998 }
1999
2000 SpaceFile *sfile = CTX_wm_space_file(C);
2002 if (!sfile || !params) {
2003 return;
2004 }
2005
2006 char dir[FILE_MAX_LIBEXTRA];
2007 if (filelist_islibrary(sfile->files, dir, nullptr)) {
2008 return;
2009 }
2010
2011 int numfiles = filelist_files_ensure(sfile->files);
2012 FileDirEntry *fileentry = nullptr;
2013 int num_selected = 0;
2014
2015 for (int i = 0; i < numfiles; i++) {
2017 fileentry = filelist_file(sfile->files, i);
2018 num_selected++;
2019 }
2020 }
2021
2022 if (!fileentry || num_selected > 1) {
2023 return;
2024 }
2025
2026 char path[FILE_MAX_LIBEXTRA];
2027 filelist_file_get_full_path(sfile->files, fileentry, path);
2028 const char *root = filelist_dir(sfile->files);
2029
2030 ui::Layout &layout = *menu->layout;
2032 wmOperatorType *ot = WM_operatortype_find("FILE_OT_external_operation", true);
2033
2034 if (fileentry->typeflag & FILE_TYPE_DIR) {
2038 }
2039 else {
2054 }
2055}
2056
2057static bool file_os_operations_menu_poll(const bContext *C_const, MenuType * /*mt*/)
2058{
2059 bContext *C = const_cast<bContext *>(C_const);
2060
2061 /* File browsing only operator (not asset browsing). */
2063 return false;
2064 }
2065
2066 SpaceFile *sfile = CTX_wm_space_file(C);
2068
2069 if (sfile && params) {
2070 char dir[FILE_MAX_LIBEXTRA];
2071 if (filelist_islibrary(sfile->files, dir, nullptr)) {
2072 return false;
2073 }
2074
2075 int numfiles = filelist_files_ensure(sfile->files);
2076 int num_selected = 0;
2077 for (int i = 0; i < numfiles; i++) {
2079 num_selected++;
2080 }
2081 }
2082
2083 if (num_selected > 1) {
2084 CTX_wm_operator_poll_msg_set(C, "More than one item is selected");
2085 }
2086 else if (num_selected < 1) {
2087 CTX_wm_operator_poll_msg_set(C, "No items are selected");
2088 }
2089 else {
2090 return true;
2091 }
2092 }
2093
2094 return false;
2095}
2096
2098{
2099 MenuType *mt;
2100
2101 mt = MEM_new_zeroed<MenuType>("spacetype file menu file operations");
2102 STRNCPY_UTF8(mt->idname, "FILEBROWSER_MT_operations_menu");
2103 STRNCPY_UTF8(mt->label, N_("External"));
2107 WM_menutype_add(mt);
2108}
2109
2111
2112/* -------------------------------------------------------------------- */
2115
2119static bool file_execute(bContext *C, SpaceFile *sfile)
2120{
2121 Main *bmain = CTX_data_main(C);
2123 if (!params) {
2124 return false;
2125 }
2126 FileDirEntry *file = filelist_file(sfile->files, params->active_file);
2127
2128 if (file && file->redirection_path) {
2129 /* redirection_path is an absolute path that takes precedence
2130 * over using params->dir + params->file. */
2132 params->dir,
2133 sizeof(params->dir),
2134 params->file,
2135 sizeof(params->file));
2136 /* Update relpath with redirected filename as well so that the alternative
2137 * combination of params->dir + relpath remains valid as well. */
2138 MEM_delete(file->relpath);
2139 file->relpath = BLI_strdup(params->file);
2140 }
2141
2142 /* directory change */
2143 if (file && (file->typeflag & FILE_TYPE_DIR)) {
2144 if (!file->relpath) {
2145 return false;
2146 }
2147
2148 if (FILENAME_IS_PARENT(file->relpath)) {
2149 BLI_path_parent_dir(params->dir);
2150 }
2151 else {
2152 BLI_path_abs(params->dir, BKE_main_blendfile_path(bmain));
2154 BLI_path_append_dir(params->dir, sizeof(params->dir), file->relpath);
2155 }
2157 }
2158 /* Opening file, sends events now, so things get handled on window-queue level. */
2159 else if (sfile->op) {
2160 ScrArea *area = CTX_wm_area(C);
2161 FSMenu *fsmenu = ED_fsmenu_get();
2162 wmOperator *op = sfile->op;
2163 char filepath[FILE_MAX];
2164
2165 sfile->op = nullptr;
2166
2167 file_sfile_to_operator_ex(C, bmain, op, sfile, filepath);
2168
2169 if (BLI_exists(params->dir)) {
2170 fsmenu_insert_entry(fsmenu,
2172 params->dir,
2173 nullptr,
2174 ICON_FILE_FOLDER,
2176 }
2177
2179
2181 }
2182
2183 return true;
2184}
2185
2187{
2188 SpaceFile *sfile = CTX_wm_space_file(C);
2189
2190 if (!file_execute(C, sfile)) {
2191 return OPERATOR_CANCELLED;
2192 }
2193
2194 return OPERATOR_FINISHED;
2195}
2196
2198 wmOperatorType * /*ot*/,
2199 PointerRNA * /*ptr*/)
2200{
2201 SpaceFile *sfile = CTX_wm_space_file(C);
2202 if (sfile->op && sfile->op->type && sfile->op->type->description) {
2203 /* Return the description of the executed operator. Don't use get_description
2204 * as that will return file details for #WM_OT_open_mainfile. */
2205 return TIP_(sfile->op->type->description);
2206 }
2207 return {};
2208}
2209
2211{
2212 /* identifiers */
2213 ot->name = "Execute File Window";
2214 ot->description = "Execute selected file";
2215 ot->idname = "FILE_OT_execute";
2217
2218 /* API callbacks. */
2219 ot->exec = file_exec;
2220 /* Important since handler is on window level.
2221 *
2222 * Avoid using #file_operator_poll since this is also used for entering directories
2223 * which is used even when the file manager doesn't have an operator. */
2225}
2226
2231{
2233 if (file_select(C, &rect, FILE_SEL_ADD, false, false) == FILE_SELECT_NOTHING) {
2234 return false;
2235 }
2236
2237 return true;
2238}
2239
2241 wmOperator * /*op*/,
2242 const wmEvent *event)
2243{
2244 ARegion *region = CTX_wm_region(C);
2245 SpaceFile *sfile = CTX_wm_space_file(C);
2246
2248 sfile->layout, &region->v2d, event->mval[0], event->mval[1]))
2249 {
2251 }
2252
2253 /* Note that this isn't needed practically, because the keymap already activates the hovered item
2254 * on mouse-press. This execute operator is called afterwards on the double-click event then.
2255 * However relying on this would be fragile and could break with keymap changes, so better to
2256 * have this mouse-execute operator that makes sure once more that the hovered file is active. */
2257 if (!file_ensure_hovered_is_active(C, event)) {
2258 return OPERATOR_CANCELLED;
2259 }
2260
2261 if (!file_execute(C, sfile)) {
2262 return OPERATOR_CANCELLED;
2263 }
2264
2265 return OPERATOR_FINISHED;
2266}
2267
2269{
2270 /* identifiers */
2271 ot->name = "Execute File";
2272 ot->description =
2273 "Perform the current execute action for the file under the cursor (e.g. open the file)";
2274 ot->idname = "FILE_OT_mouse_execute";
2275
2276 /* API callbacks. */
2279
2280 ot->flag = OPTYPE_INTERNAL;
2281}
2282
2284
2285/* -------------------------------------------------------------------- */
2288
2290{
2292 SpaceFile *sfile = CTX_wm_space_file(C);
2293 FSMenu *fsmenu = ED_fsmenu_get();
2294
2295 ED_fileselect_clear(wm, sfile);
2296
2297 /* refresh system directory menu */
2299
2301
2302 return OPERATOR_FINISHED;
2303}
2304
2306{
2307 /* identifiers */
2308 ot->name = "Refresh File List";
2309 ot->description = "Refresh the file list";
2310 ot->idname = "FILE_OT_refresh";
2311
2312 /* API callbacks. */
2313 ot->exec = file_refresh_exec;
2314 ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */
2315}
2316
2318
2319/* -------------------------------------------------------------------- */
2322
2324{
2325 Main *bmain = CTX_data_main(C);
2326 SpaceFile *sfile = CTX_wm_space_file(C);
2328
2329 if (params) {
2330 if (BLI_path_parent_dir(params->dir)) {
2331 BLI_path_abs(params->dir, BKE_main_blendfile_path(bmain));
2332 BLI_path_normalize_dir(params->dir, sizeof(params->dir));
2334 if (params->recursion_level > 1) {
2335 /* Disable `dirtree` recursion when going up in tree. */
2336 params->recursion_level = 0;
2338 }
2340 }
2341 }
2342
2343 return OPERATOR_FINISHED;
2344}
2345
2347{
2348 /* identifiers */
2349 ot->name = "Parent Directory";
2350 ot->description = "Move to parent directory";
2351 ot->idname = "FILE_OT_parent";
2352
2353 /* API callbacks. */
2354 ot->exec = file_parent_exec;
2355 /* File browsing only operator (not asset browsing). */
2356 ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */
2357}
2358
2360
2361/* -------------------------------------------------------------------- */
2364
2366{
2367 SpaceFile *sfile = CTX_wm_space_file(C);
2369
2370 if (params) {
2371 folderlist_pushdir(sfile->folders_next, params->dir);
2372 folderlist_popdir(sfile->folders_prev, params->dir);
2373 folderlist_pushdir(sfile->folders_next, params->dir);
2374
2376 }
2378
2379 return OPERATOR_FINISHED;
2380}
2381
2383{
2384 /* identifiers */
2385 ot->name = "Previous Folder";
2386 ot->description = "Move to previous folder";
2387 ot->idname = "FILE_OT_previous";
2388
2389 /* API callbacks. */
2391 /* File browsing only operator (not asset browsing). */
2392 ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */
2393}
2394
2396
2397/* -------------------------------------------------------------------- */
2400
2402{
2403 SpaceFile *sfile = CTX_wm_space_file(C);
2405 if (params) {
2406 folderlist_pushdir(sfile->folders_prev, params->dir);
2407 folderlist_popdir(sfile->folders_next, params->dir);
2408
2409 /* update folders_prev so we can check for it in #folderlist_clear_next() */
2410 folderlist_pushdir(sfile->folders_prev, params->dir);
2411
2413 }
2415
2416 return OPERATOR_FINISHED;
2417}
2418
2420{
2421 /* identifiers */
2422 ot->name = "Next Folder";
2423 ot->description = "Move to next folder";
2424 ot->idname = "FILE_OT_next";
2425
2426 /* API callbacks. */
2427 ot->exec = file_next_exec;
2428 /* File browsing only operator (not asset browsing). */
2429 ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */
2430}
2431
2433
2434/* -------------------------------------------------------------------- */
2437
2438/* only meant for timer usage */
2440 wmOperator * /*op*/,
2441 const wmEvent *event)
2442{
2443 ScrArea *area = CTX_wm_area(C);
2444 SpaceFile *sfile = CTX_wm_space_file(C);
2445 ARegion *region, *region_ctx = CTX_wm_region(C);
2446 const bool is_horizontal = (sfile->layout->flag & FILE_LAYOUT_HOR) != 0;
2447 int i;
2448
2449 /* escape if not our timer */
2450 if (sfile->smoothscroll_timer == nullptr || sfile->smoothscroll_timer != event->customdata) {
2451 return OPERATOR_PASS_THROUGH;
2452 }
2453
2454 const int numfiles = filelist_files_ensure(sfile->files);
2455
2456 /* Due to asynchronous nature of file listing, we may execute this code before `file_refresh()`
2457 * editing entry is available in our listing,
2458 * so we also have to handle switching to rename mode here. */
2460 if ((params->rename_flag &
2462 {
2463 file_params_renamefile_activate(sfile, params);
2464 }
2465
2466 /* check if we are editing a name */
2467 int edit_idx = -1;
2468 for (i = 0; i < numfiles; i++) {
2471 {
2472 edit_idx = i;
2473 break;
2474 }
2475 }
2476
2478 wmWindow *win = CTX_wm_window(C);
2479
2480 /* if we are not editing, we are done */
2481 if (edit_idx == -1) {
2482 /* Do not invalidate timer if file-rename is still pending,
2483 * we might still be building the filelist and yet have to find edited entry. */
2484 if (params->rename_flag == 0) {
2486 }
2487 return OPERATOR_PASS_THROUGH;
2488 }
2489
2490 /* we need the correct area for scrolling */
2492 if (!region || region->regiontype != RGN_TYPE_WINDOW) {
2494 return OPERATOR_PASS_THROUGH;
2495 }
2496
2497 /* Number of items in a block (i.e. lines in a column in horizontal layout, or columns in a line
2498 * in vertical layout).
2499 */
2500 const int items_block_size = is_horizontal ? sfile->layout->rows : sfile->layout->flow_columns;
2501
2502 /* Scroll offset is the first file in the row/column we are editing in. */
2503 if (sfile->scroll_offset == 0) {
2504 sfile->scroll_offset = (edit_idx / items_block_size) * items_block_size;
2505 }
2506
2507 const int numfiles_layout = ED_fileselect_layout_numfiles(sfile->layout, region);
2508 const int first_visible_item = ED_fileselect_layout_offset(
2509 sfile->layout, int(region->v2d.cur.xmin), int(-region->v2d.cur.ymax));
2510 const int last_visible_item = first_visible_item + numfiles_layout + 1;
2511
2512 /* NOTE: the special case for vertical layout is because filename is at the bottom of items then,
2513 * so we artificially move current row back one step, to ensure we show bottom of
2514 * active item rather than its top (important in case visible height is low). */
2515 const int middle_offset = max_ii(
2516 0, (first_visible_item + last_visible_item) / 2 - (is_horizontal ? 0 : items_block_size));
2517
2518 const int min_middle_offset = numfiles_layout / 2;
2519 const int max_middle_offset = ((numfiles / items_block_size) * items_block_size +
2520 ((numfiles % items_block_size) != 0 ? items_block_size : 0)) -
2521 (numfiles_layout / 2);
2522 /* Actual (physical) scrolling info, in pixels, used to detect whether we are fully at the
2523 * beginning/end of the view. */
2524 /* Note that there is a weird glitch, that sometimes tot rctf is smaller than cur rctf...
2525 * that is why we still need to keep the min/max_middle_offset checks too. :( */
2526 const float min_tot_scroll = is_horizontal ? region->v2d.tot.xmin : -region->v2d.tot.ymax;
2527 const float max_tot_scroll = is_horizontal ? region->v2d.tot.xmax : -region->v2d.tot.ymin;
2528 const float min_curr_scroll = is_horizontal ? region->v2d.cur.xmin : -region->v2d.cur.ymax;
2529 const float max_curr_scroll = is_horizontal ? region->v2d.cur.xmax : -region->v2d.cur.ymin;
2530
2531 /* Check if we have reached our final scroll position. */
2532 /* File-list has to be ready, otherwise it makes no sense to stop scrolling yet. */
2533 const bool is_ready = filelist_is_ready(sfile->files);
2534 /* Edited item must be in the 'middle' of shown area (kind of approximated).
2535 * Note that we have to do the check in 'block space', not in 'item space' here. */
2536 const bool is_centered = (abs(middle_offset / items_block_size -
2537 sfile->scroll_offset / items_block_size) == 0);
2538 /* OR edited item must be towards the beginning, and we are scrolled fully to the start. */
2539 const bool is_full_start = ((sfile->scroll_offset < min_middle_offset) &&
2540 (min_curr_scroll - min_tot_scroll < 1.0f) &&
2541 (middle_offset - min_middle_offset < items_block_size));
2542 /* OR edited item must be towards the end, and we are scrolled fully to the end.
2543 * This one is crucial (unlike the one for the beginning), because without it scrolling
2544 * fully to the end, and last column or row will end up only partially drawn. */
2545 const bool is_full_end = ((sfile->scroll_offset > max_middle_offset) &&
2546 (max_tot_scroll - max_curr_scroll < 1.0f) &&
2547 (max_middle_offset - middle_offset < items_block_size));
2548
2549 if (is_ready && (is_centered || is_full_start || is_full_end)) {
2551 /* Post-scroll (after rename has been validated by user) is done,
2552 * rename process is totally finished, cleanup. */
2555 }
2556 return OPERATOR_FINISHED;
2557 }
2558
2559 /* Temporarily set context to the main window region,
2560 * so that the pan operator works. */
2561 CTX_wm_region_set(C, region);
2562
2563 /* scroll one step in the desired direction */
2564 int deltax = 0;
2565 int deltay = 0;
2566
2567 /* We adjust speed of scrolling to avoid tens of seconds of it in e.g. directories with tens of
2568 * thousands of folders... See #65782. */
2569 /* This will slow down scrolling when approaching final goal, also avoids going too far and
2570 * having to bounce back... */
2571
2572 /* Number of blocks (columns in horizontal layout, rows otherwise) between current middle of
2573 * screen, and final goal position. */
2574 const int diff_offset = sfile->scroll_offset / items_block_size -
2575 middle_offset / items_block_size;
2576 /* convert diff_offset into pixels. */
2577 const int diff_offset_delta = abs(diff_offset) *
2578 (is_horizontal ?
2579 sfile->layout->tile_w + 2 * sfile->layout->tile_border_x :
2580 sfile->layout->tile_h + 2 * sfile->layout->tile_border_y);
2581 const int scroll_delta = max_ii(2, diff_offset_delta / 15);
2582
2583 if (diff_offset < 0) {
2584 if (is_horizontal) {
2585 deltax = -scroll_delta;
2586 }
2587 else {
2588 deltay = scroll_delta;
2589 }
2590 }
2591 else {
2592 if (is_horizontal) {
2593 deltax = scroll_delta;
2594 }
2595 else {
2596 deltay = -scroll_delta;
2597 }
2598 }
2599 PointerRNA op_ptr = WM_operator_properties_create("VIEW2D_OT_pan");
2600 RNA_int_set(&op_ptr, "deltax", deltax);
2601 RNA_int_set(&op_ptr, "deltay", deltay);
2602
2603 WM_operator_name_call(C, "VIEW2D_OT_pan", wm::OpCallContext::ExecDefault, &op_ptr, event);
2605
2606 ED_region_tag_redraw(region);
2607
2608 /* and restore context */
2609 CTX_wm_region_set(C, region_ctx);
2610
2611 return OPERATOR_FINISHED;
2612}
2613
2615{
2616 /* identifiers */
2617 ot->name = "Smooth Scroll";
2618 ot->idname = "FILE_OT_smoothscroll";
2619 ot->description = "Smooth scroll to make editable file visible";
2620
2621 /* API callbacks. */
2623 /* Operator works for file or asset browsing */
2625}
2626
2628
2629/* -------------------------------------------------------------------- */
2632
2634{
2635 Main *bmain = CTX_data_main(C);
2636 SpaceFile *sfile = CTX_wm_space_file(C);
2637
2638 if (sfile) {
2639 char filepath[FILE_MAX];
2640
2641 RNA_string_get(op->ptr, "filepath", filepath);
2642 if (!BLI_exists(filepath)) {
2643 BKE_report(op->reports, RPT_ERROR, "File does not exist");
2644 return OPERATOR_CANCELLED;
2645 }
2646
2647 file_sfile_filepath_set(sfile, filepath);
2648
2649 if (sfile->op) {
2650 file_sfile_to_operator(C, bmain, sfile->op, sfile);
2652 }
2653
2655 return OPERATOR_FINISHED;
2656 }
2657
2658 return OPERATOR_CANCELLED;
2659}
2660
2662{
2663 ot->name = "File Selector Drop";
2664 ot->idname = "FILE_OT_filepath_drop";
2665
2667 /* File browsing only operator (not asset browsing). */
2669
2670 RNA_def_string_file_path(ot->srna, "filepath", "Path", FILE_MAX, "", "");
2671}
2672
2674
2675/* -------------------------------------------------------------------- */
2678
2685static bool new_folder_path(const char *parent,
2686 char r_dirpath_full[FILE_MAX],
2687 char r_dirname[FILE_MAXFILE])
2688{
2689 int i = 1;
2690 int len = 0;
2691
2692 BLI_strncpy(r_dirname, "New Folder", FILE_MAXFILE);
2693 BLI_path_join(r_dirpath_full, FILE_MAX, parent, r_dirname);
2694 /* check whether r_dirpath_full with the name already exists, in this case
2695 * add number to the name. Check length of generated name to avoid
2696 * crazy case of huge number of folders each named 'New Folder (x)' */
2697 while (BLI_exists(r_dirpath_full) && (len < FILE_MAXFILE)) {
2698 len = BLI_snprintf_utf8(r_dirname, FILE_MAXFILE, "New Folder(%d)", i);
2699 BLI_path_join(r_dirpath_full, FILE_MAX, parent, r_dirname);
2700 i++;
2701 }
2702
2703 return (len < FILE_MAXFILE);
2704}
2705
2707{
2708 char dirname[FILE_MAXFILE];
2709 char dirpath[FILE_MAX];
2710 bool generate_name = true;
2711
2713 SpaceFile *sfile = CTX_wm_space_file(C);
2715 const bool do_diropen = RNA_boolean_get(op->ptr, "open");
2716
2717 if (!params) {
2718 BKE_report(op->reports, RPT_WARNING, "No parent directory given");
2719 return OPERATOR_CANCELLED;
2720 }
2721
2722 dirpath[0] = '\0';
2723
2724 {
2725 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "directory");
2726 RNA_property_string_get(op->ptr, prop, dirpath);
2727 if (dirpath[0] != '\0') {
2728 generate_name = false;
2729 }
2730 }
2731
2732 if (generate_name) {
2733 /* create a new, non-existing folder name */
2734 if (!new_folder_path(params->dir, dirpath, dirname)) {
2735 BKE_report(op->reports, RPT_ERROR, "Could not create new folder name");
2736 return OPERATOR_CANCELLED;
2737 }
2738 }
2739 else { /* We assume we are able to generate a valid name! */
2740 char org_path[FILE_MAX];
2741
2742 STRNCPY(org_path, dirpath);
2743 if (BLI_path_make_safe(dirpath)) {
2744 BKE_reportf(op->reports,
2746 "'%s' given path is OS-invalid, creating '%s' path instead",
2747 org_path,
2748 dirpath);
2749 }
2750 }
2751
2752 /* create the file */
2753 errno = 0;
2754 if (!BLI_dir_create_recursive(dirpath) ||
2755 /* Should no more be needed,
2756 * now that BLI_dir_create_recursive returns a success state - but kept just in case. */
2757 !BLI_exists(dirpath))
2758 {
2759 BKE_reportf(op->reports,
2760 RPT_ERROR,
2761 "Could not create new folder: %s",
2762 errno ? strerror(errno) : "unknown error");
2763 return OPERATOR_CANCELLED;
2764 }
2765
2767
2768 /* If we don't enter the directory directly, remember file to jump into editing. */
2769 if (do_diropen == false) {
2770 BLI_assert_msg(params->rename_id == nullptr,
2771 "File rename handling should immediately clear rename_id when done, "
2772 "because otherwise it will keep taking precedence over renamefile.");
2773 STRNCPY(params->renamefile, dirname);
2774 rename_flag = FILE_PARAMS_RENAME_PENDING;
2775 }
2776
2778 params->rename_flag = rename_flag;
2779
2780 /* reload dir to make sure we're seeing what's in the directory */
2781 ED_fileselect_clear(wm, sfile);
2782
2783 if (do_diropen) {
2784 STRNCPY(params->dir, dirpath);
2786 }
2787
2789
2790 return OPERATOR_FINISHED;
2791}
2792
2794 wmOperator *op,
2795 const wmEvent * /*event*/)
2796{
2797 /* NOTE: confirm is needed because this operator is invoked
2798 * when entering a path from the file selector. Without a confirmation,
2799 * a typo will create the path without any prompt. See #128567. */
2800 if (RNA_boolean_get(op->ptr, "confirm")) {
2802 op,
2803 IFACE_("Create new directory?"),
2804 nullptr,
2805 IFACE_("Create"),
2807 false);
2808 }
2809 return file_directory_new_exec(C, op);
2810}
2811
2813{
2814 PropertyRNA *prop;
2815
2816 /* identifiers */
2817 ot->name = "Create New Directory";
2818 ot->description = "Create a new directory";
2819 ot->idname = "FILE_OT_directory_new";
2820
2821 /* API callbacks. */
2824 /* File browsing only operator (not asset browsing). */
2825 ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */
2826
2828 ot->srna, "directory", nullptr, FILE_MAX, "Directory", "Name of new directory");
2830 prop = RNA_def_boolean(ot->srna, "open", false, "Open", "Open new directory");
2833}
2834
2836
2837/* -------------------------------------------------------------------- */
2840
2841static void file_expand_directory(const Main *bmain, FileSelectParams *params)
2842{
2843 /* NOTE: Arbitrary conventions are used here which are OK for user facing logic
2844 * Attempting to resolve the path to *something* valid is OK for user input
2845 * but not suitable for `BLI_path_utils.hh` which is used for lower level path handling. */
2846
2847 /* The path was invalid, fall back to the default root. */
2848 bool do_reset = false;
2849
2850 if (params->dir[0] == '\0') {
2851 do_reset = true;
2852 }
2853 else if (BLI_path_is_rel(params->dir)) { /* `//` literal. */
2854 const char *blendfile_path = BKE_main_blendfile_path(bmain);
2855 if (blendfile_path[0] != '\0') {
2856 BLI_path_abs(params->dir, blendfile_path);
2857 }
2858 else {
2859 /* Ignore relative paths for unsaved files.
2860 * It's enough of a corner case that any attempt to resolve the path
2861 * is more likely to confuse users about the meaning of `//`. */
2862 do_reset = true;
2863 }
2864 }
2865 else if (params->dir[0] == '~') {
2866 /* While path handling expansion typically doesn't support home directory expansion
2867 * in Blender, this is a convenience to be able to type in a single character.
2868 * Even though this is a UNIX convention, it's harmless to expand on WIN32 as well. */
2869 if (const char *home_dir = BLI_dir_home()) {
2870 char tmpstr[sizeof(params->dir) - 1];
2871 STRNCPY(tmpstr, params->dir + 1);
2872 BLI_path_join(params->dir, sizeof(params->dir), home_dir, tmpstr);
2873 }
2874 else {
2875 do_reset = true;
2876 }
2877 }
2878#ifdef WIN32
2879 else if (BLI_path_is_win32_drive_only(params->dir)) {
2880 /* Change `C:` --> `C:\`, see: #28102. */
2881 params->dir[2] = SEP;
2882 params->dir[3] = '\0';
2883 }
2884 else if (BLI_path_is_unc(params->dir)) {
2885 BLI_path_normalize_unc(params->dir, sizeof(params->dir));
2886 }
2887#endif /* WIN32 */
2888
2889 if (do_reset) {
2891 }
2892}
2893
2899{
2900 /* NOTE(@ideasman42): This function checks if the user should be prompted
2901 * to create the path when a non-existent path is entered into the directory field.
2902 *
2903 * Typically when the intention is to create a path, it's simply created only showing
2904 * feedback if the operation failed. In the case of entering a path as text any typo
2905 * in the would immediately be created (if possible) which isn't good, see: #128567.
2906 *
2907 * The reason to treat user input differently here is the user could input anything,
2908 * e.g. values such as a single space. This resolves to the current-working-directory:
2909 * `$PWD/ ` which is a valid path name and could be created
2910 * (this was in fact the behavior until v4.4).
2911 *
2912 * As this can be error prone, performs basic sanity checks on `dir`.
2913 * - Ensure it's an absolute path.
2914 * - It contains a writable parent path.
2915 * - For WIN32: The UNC path is a directory and not a "share".
2916 *
2917 * While these checks don't need to be comprehensive,
2918 * they should prevent accidents and confusing situations. */
2919
2920 /* If the user types in a name with no absolute prefix,
2921 * creating a directory relative to the CWD doesn't make sense from the UI. */
2922 if (!BLI_path_is_abs_from_cwd(dir)) {
2923 return false;
2924 }
2925
2926 /* If none of the parents exist, the directory can't be created.
2927 * This prevents the popup to create a new path showing on WIN32
2928 * for a drive-letter that doesn't exist (for example). */
2929 {
2930 char tdir[FILE_MAX_LIBEXTRA];
2931 STRNCPY(tdir, dir);
2933 return false;
2934 }
2935 }
2936
2937#if defined(WIN32)
2938 /* For UNC paths we need to check whether the parent of the new
2939 * directory is a proper directory itself and not a share or the
2940 * UNC root (server name) itself. Calling #BLI_is_dir does this. */
2941 if (BLI_path_is_unc(dir)) {
2942 char tdir[FILE_MAX_LIBEXTRA];
2943 STRNCPY(tdir, dir);
2944 BLI_path_parent_dir(tdir);
2945 if (!BLI_is_dir(tdir)) {
2946 return false;
2947 }
2948 }
2949#endif /* WIN32 */
2950
2951 return true;
2952}
2953
2954void file_directory_enter_handle(bContext *C, void * /*arg_unused*/, void * /*arg_but*/)
2955{
2956 SpaceFile *sfile = CTX_wm_space_file(C);
2958 if (params == nullptr) [[unlikely]] {
2959 return;
2960 }
2961
2962 const Main *bmain = CTX_data_main(C);
2963 char old_dir[sizeof(params->dir)] = {0};
2964
2965 STRNCPY(old_dir, params->dir);
2966
2967 file_expand_directory(bmain, params);
2968
2969 /* Special case, user may have pasted a path including a file-name into the directory. */
2970 if (!filelist_is_dir(sfile->files, params->dir)) {
2971 char tdir[FILE_MAX_LIBEXTRA];
2972 char *group, *name;
2973
2974 if (BLI_is_file(params->dir)) {
2975 char dirpath[sizeof(params->dir)];
2976 STRNCPY(dirpath, params->dir);
2978 dirpath, params->dir, sizeof(params->dir), params->file, sizeof(params->file));
2979 }
2980 else if (BKE_blendfile_library_path_explode(params->dir, tdir, &group, &name)) {
2981 if (group) {
2982 BLI_path_append(tdir, sizeof(tdir), group);
2983 }
2984 STRNCPY(params->dir, tdir);
2985 if (name) {
2986 STRNCPY(params->file, name);
2987 }
2988 else {
2989 params->file[0] = '\0';
2990 }
2991 }
2992 }
2993
2994 /* #file_expand_directory will have made absolute. */
2995 BLI_assert(!BLI_path_is_rel(params->dir));
2996 BLI_path_normalize_dir(params->dir, sizeof(params->dir));
2997
2998 if (filelist_is_dir(sfile->files, params->dir)) {
2999 /* Avoids flickering when nothing's changed. */
3000 if (!STREQ(params->dir, old_dir)) {
3001 /* If directory exists, enter it immediately. */
3003 }
3004 }
3005 else if (!can_create_dir_from_user_input(params->dir)) {
3006 const char *lastdir = folderlist_peeklastdir(sfile->folders_prev);
3007 if (lastdir) {
3008 STRNCPY(params->dir, lastdir);
3009 }
3010 }
3011 else {
3012 const char *lastdir = folderlist_peeklastdir(sfile->folders_prev);
3013 char tdir[FILE_MAX_LIBEXTRA];
3014
3015 /* If we are "inside" a `.blend` library, we cannot do anything. */
3016 if (lastdir && BKE_blendfile_library_path_explode(lastdir, tdir, nullptr, nullptr)) {
3017 STRNCPY(params->dir, lastdir);
3018 }
3019 else {
3020 /* If not, ask to create it and enter if confirmed. */
3021 wmOperatorType *ot = WM_operatortype_find("FILE_OT_directory_new", false);
3023 RNA_string_set(&ptr, "directory", params->dir);
3024 RNA_boolean_set(&ptr, "open", true);
3025 /* Enable confirmation prompt, else it's too easy to accidentally create new directories. */
3026 RNA_boolean_set(&ptr, "confirm", true);
3027
3028 if (lastdir) {
3029 STRNCPY(params->dir, lastdir);
3030 }
3031
3034 }
3035 }
3036
3038}
3039
3040void file_filename_enter_handle(bContext *C, void * /*arg_unused*/, void *arg_but)
3041{
3042 SpaceFile *sfile = CTX_wm_space_file(C);
3044 if (params == nullptr) [[unlikely]] {
3045 return;
3046 }
3047
3048 const Main *bmain = CTX_data_main(C);
3049 ui::Button *but = static_cast<ui::Button *>(arg_but);
3050
3051 file_expand_directory(bmain, params);
3052
3053 char matched_file[FILE_MAX] = "";
3054 int matches = file_select_match(sfile, params->file, matched_file);
3055
3056 /* It's important this runs *after* #file_select_match,
3057 * so making "safe" doesn't remove shell-style globing characters. */
3058 const bool allow_tokens = (params->flag & FILE_PATH_TOKENS_ALLOW) != 0;
3059 BLI_path_make_safe_filename_ex(params->file, allow_tokens);
3060
3061 if (matches) {
3062 /* Replace the pattern (or filename that the user typed in),
3063 * with the first selected file of the match. */
3064 STRNCPY(params->file, matched_file);
3065
3067
3068 if (matches == 1) {
3069 char filepath[sizeof(params->dir)];
3070 BLI_path_join(filepath, sizeof(params->dir), params->dir, params->file);
3071
3072 /* If directory, open it and empty filename field. */
3073 if (filelist_is_dir(sfile->files, filepath)) {
3074 BLI_path_abs(filepath, BKE_main_blendfile_path(bmain));
3075 BLI_path_normalize_dir(filepath, sizeof(filepath));
3076 STRNCPY(params->dir, filepath);
3077 params->file[0] = '\0';
3079 textbutton_activate_but(C, but);
3081 }
3082 }
3083 else {
3084 BLI_assert(matches > 1);
3086 }
3087 }
3088}
3089
3091
3092/* -------------------------------------------------------------------- */
3095
3097{
3099 SpaceFile *sfile = CTX_wm_space_file(C);
3101
3102 if (params) {
3103 params->flag ^= FILE_HIDE_DOT;
3104 ED_fileselect_clear(wm, sfile);
3106 }
3107
3108 return OPERATOR_FINISHED;
3109}
3110
3112{
3113 /* identifiers */
3114 ot->name = "Toggle Hide Dot Files";
3115 ot->description = "Toggle hide hidden dot files";
3116 ot->idname = "FILE_OT_hidedot";
3117
3118 /* API callbacks. */
3119 ot->exec = file_hidedot_exec;
3120 /* File browsing only operator (not asset browsing). */
3121 ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */
3122}
3123
3125
3126/* -------------------------------------------------------------------- */
3129
3131{
3132 SpaceFile *sfile = CTX_wm_space_file(C);
3133
3134 /* File browsing only operator (not asset browsing). */
3136 return false;
3137 }
3138
3140 return params && (params->flag & FILE_CHECK_EXISTING);
3141}
3142
3147static void filenum_newname(char *filename, size_t filename_maxncpy, int add)
3148{
3149 char head[FILE_MAXFILE], tail[FILE_MAXFILE];
3150 int pic;
3151 ushort digits;
3152
3153 pic = BLI_path_sequence_decode(filename, head, sizeof(head), tail, sizeof(tail), &digits);
3154
3155 /* are we going from 100 -> 99 or from 10 -> 9 */
3156 if (add < 0 && digits > 0) {
3157 int i, exp;
3158 exp = 1;
3159 for (i = digits; i > 1; i--) {
3160 exp *= 10;
3161 }
3162 if (pic >= exp && (pic + add) < exp) {
3163 digits--;
3164 }
3165 }
3166
3167 pic += add;
3168 pic = std::max(pic, 0);
3169 BLI_path_sequence_encode(filename, filename_maxncpy, head, tail, digits, pic);
3170}
3171
3173{
3174 SpaceFile *sfile = CTX_wm_space_file(C);
3176 ScrArea *area = CTX_wm_area(C);
3177
3178 int inc = RNA_int_get(op->ptr, "increment");
3179 if (params && (inc != 0)) {
3180 filenum_newname(params->file, sizeof(params->file), inc);
3181 ED_area_tag_redraw(area);
3183 // WM_event_add_notifier(C, NC_WINDOW, nullptr);
3184 }
3185
3186 return OPERATOR_FINISHED;
3187}
3188
3190{
3191 /* identifiers */
3192 ot->name = "Increment Number in Filename";
3193 ot->description = "Increment number in filename";
3194 ot->idname = "FILE_OT_filenum";
3195
3196 /* API callbacks. */
3197 ot->exec = file_filenum_exec;
3198 ot->poll = file_filenum_poll;
3199
3200 /* props */
3201 RNA_def_int(ot->srna, "increment", 1, -100, 100, "Increment", "", -100, 100);
3202}
3203
3205
3206/* -------------------------------------------------------------------- */
3209
3210static void file_rename_state_activate(SpaceFile *sfile, int file_idx, bool require_selected)
3211{
3212 const int numfiles = filelist_files_ensure(sfile->files);
3213
3214 if ((file_idx >= 0) && (file_idx < numfiles)) {
3215 FileDirEntry *file = filelist_file(sfile->files, file_idx);
3216
3217 if ((require_selected == false) ||
3219 {
3221
3223 sfile->files, file_idx, FILE_SEL_ADD, FILE_SEL_EDITING, CHECK_ALL);
3224 STRNCPY(params->renamefile, file->relpath);
3225 /* We can skip the pending state,
3226 * as we can directly set FILE_SEL_EDITING on the expected entry here. */
3228 }
3229 }
3230}
3231
3233{
3234 ScrArea *area = CTX_wm_area(C);
3235 SpaceFile *sfile = reinterpret_cast<SpaceFile *>(CTX_wm_space_data(C));
3237
3238 if (params) {
3239 file_rename_state_activate(sfile, params->active_file, false);
3240 ED_area_tag_redraw(area);
3241 }
3242
3243 return OPERATOR_FINISHED;
3244}
3245
3247{
3248 /* identifiers */
3249 ot->name = "Rename File or Directory";
3250 ot->description = "Rename file or file directory";
3251 ot->idname = "FILE_OT_rename";
3252
3253 /* API callbacks. */
3254 ot->exec = file_rename_exec;
3255 /* File browsing only operator (not asset browsing). */
3257}
3258
3260
3261/* -------------------------------------------------------------------- */
3264
3266{
3268 return false;
3269 }
3270
3271 SpaceFile *sfile = CTX_wm_space_file(C);
3273 if (!sfile || !params) {
3274 return false;
3275 }
3276
3277 char dir[FILE_MAX_LIBEXTRA];
3278 if (filelist_islibrary(sfile->files, dir, nullptr)) {
3279 return false;
3280 }
3281
3282 int numfiles = filelist_files_ensure(sfile->files);
3283 for (int i = 0; i < numfiles; i++) {
3285 /* Has a selected file -> the operator can run. */
3286 return true;
3287 }
3288 }
3289
3290 return false;
3291}
3292
3293static bool file_delete_single(const FileList *files,
3294 FileDirEntry *file,
3295 const char **r_error_message)
3296{
3297 char filepath[FILE_MAX_LIBEXTRA];
3298 filelist_file_get_full_path(files, file, filepath);
3299 if (BLI_delete_soft(filepath, r_error_message) != 0 || BLI_exists(filepath)) {
3300 return false;
3301 }
3302
3303 return true;
3304}
3305
3307{
3309 SpaceFile *sfile = CTX_wm_space_file(C);
3310 int numfiles = filelist_files_ensure(sfile->files);
3311
3312 const char *error_message = nullptr;
3313 bool report_error = false;
3314 errno = 0;
3315 for (int i = 0; i < numfiles; i++) {
3317 FileDirEntry *file = filelist_file(sfile->files, i);
3318 if (!file_delete_single(sfile->files, file, &error_message)) {
3319 report_error = true;
3320 }
3321 }
3322 }
3323
3324 if (report_error) {
3325 const char *error_prefix = "Could not delete file or directory: ";
3326 const char *errno_message = errno ? strerror(errno) : "unknown error";
3327 if (error_message != nullptr) {
3328 BKE_reportf(op->reports, RPT_ERROR, "%s%s, %s", error_prefix, error_message, errno_message);
3329 }
3330 else {
3331 BKE_reportf(op->reports, RPT_ERROR, "%s%s", error_prefix, errno_message);
3332 }
3333 }
3334
3335 ED_fileselect_clear(wm, sfile);
3337
3338 return OPERATOR_FINISHED;
3339}
3340
3342{
3344 op,
3345 IFACE_("Delete selected files?"),
3346 nullptr,
3347 IFACE_("Delete"),
3349 false);
3350}
3351
3353{
3354 /* identifiers */
3355 ot->name = "Delete Selected Files";
3356 ot->description = "Move selected files to the trash or recycle bin";
3357 ot->idname = "FILE_OT_delete";
3358
3359 /* API callbacks. */
3361 ot->exec = file_delete_exec;
3362 ot->poll = file_delete_poll; /* <- important, handler is on window level */
3363}
3364
3366
3367/* -------------------------------------------------------------------- */
3370
3372{
3373 const ScrArea *area = CTX_wm_area(C);
3374 const SpaceFile *sfile = CTX_wm_space_file(C);
3376
3377 if (area) {
3378 int regiontype = sfile->browse_mode == FILE_BROWSE_MODE_FILES ? RGN_TYPE_UI : RGN_TYPE_HEADER;
3379 ARegion *region = BKE_region_find_in_listbase_by_type(&area->regionbase, regiontype);
3380 if (region) {
3381 ED_region_activate_rna_prop(C, region, params, "filter_search");
3382 }
3383 }
3384
3385 return OPERATOR_FINISHED;
3386}
3387
3389{
3390 /* identifiers */
3391 ot->name = "Filter";
3392 ot->description = "Start entering filter text";
3393 ot->idname = "FILE_OT_start_filter";
3394
3395 /* API callbacks. */
3397 /* Operator works for file or asset browsing */
3399}
3400
3402
3403/* -------------------------------------------------------------------- */
3406
3408{
3409 const ScrArea *area = CTX_wm_area(C);
3410 const SpaceFile *sfile = CTX_wm_space_file(C);
3412
3413 if (area) {
3414 for (ARegion &region : area->regionbase) {
3415 if (ui::textbutton_activate_rna(C, &region, params, "directory")) {
3416 break;
3417 }
3418 }
3419 }
3420
3421 return OPERATOR_FINISHED;
3422}
3423
3425{
3426 /* identifiers */
3427 ot->name = "Edit Directory Path";
3428 ot->description = "Start editing directory field";
3429 ot->idname = "FILE_OT_edit_directory_path";
3430
3431 /* API callbacks. */
3434}
3435
3437
3438/* -------------------------------------------------------------------- */
3441
3443{
3444 // wmOperatorType *ot;
3445 // wmOperatorTypeMacro *otmacro;
3446
3447 /* future macros */
3448}
3449
3451
3452} // namespace blender
#define BLENDER_BOOKMARK_FILE
File and directory operations.
#define FILE_MAXFILE
#define FILE_MAX
#define BLI_path_join(...)
#define FILENAME_IS_CURRPAR(_n)
#define FILE_MAXDIR
#define FILENAME_IS_PARENT(_n)
#define STRNCPY_UTF8(dst, src)
Compatibility-like things for windows.
const char * dirname(char *path)
#define TIP_(msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define BLT_I18NCONTEXT_EDITOR_FILEBROWSER
#define FILE_MAX_LIBEXTRA
#define FILE_LAYOUT_HOR
#define FILE_LAYOUT_VER
#define SEL_OP_USE_PRE_DESELECT(sel_op)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define ND_SPACE_FILE_PARAMS
Definition WM_types.hh:566
#define NC_SPACE
Definition WM_types.hh:405
#define ND_SPACE_FILE_LIST
Definition WM_types.hh:567
#define UNPACK2(a)
#define UNUSED_VARS(...)
#define IN_RANGE(a, b, c)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define exp
#define abs
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
std::string filename(const std::string_view &str, size_t pos)
void view2d_curRect_validate(View2D *v2d)
Definition view2d.cc:810
bool textbutton_activate_rna(const bContext *C, ARegion *region, const void *rna_poin_data, const char *rna_prop_id)
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst) ATTR_NONNULL()
Definition view2d.cc:1657
BMesh Iterators.
eDirEntry_SelectFlag filelist_entry_select_index_get(FileList *filelist, int index, FileCheckType check)
Definition filelist.cc:2084
void file_params_renamefile_activate(SpaceFile *sfile, FileSelectParams *params)
Definition filesel.cc:1437
void FILE_OT_select_bookmark(wmOperatorType *ot)
Definition file_ops.cc:1146
static wmOperatorStatus file_parent_exec(bContext *C, wmOperator *)
Definition file_ops.cc:2323
static wmOperatorStatus file_directory_new_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:2706
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void file_os_operations_menu_item(ui::Layout &layout, wmOperatorType *ot, const char *path, FileExternalOperation operation)
Definition file_ops.cc:1967
static wmOperatorStatus file_delete_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:3306
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
FSMenu * ED_fsmenu_get()
Definition fsmenu.cc:48
int ED_fileselect_layout_offset(FileLayout *layout, int x, int y)
Definition filesel.cc:853
ScrArea * CTX_wm_area(const bContext *C)
void file_draw_check_cb(bContext *C, void *arg1, void *arg2)
Definition file_ops.cc:1799
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
int ED_fileselect_layout_numfiles(FileLayout *layout, ARegion *region)
Definition filesel.cc:767
void FILE_OT_highlight(wmOperatorType *ot)
Definition file_ops.cc:1499
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
@ RPT_WARNING
Definition BKE_report.hh:40
void FILE_OT_bookmark_move(wmOperatorType *ot)
Definition file_ops.cc:1367
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
FileLayout * ED_fileselect_get_layout(SpaceFile *sfile, ARegion *region)
Definition filesel.cc:1185
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
static void file_expand_directory(const Main *bmain, FileSelectParams *params)
Definition file_ops.cc:2841
void file_tile_boundbox(const ARegion *region, FileLayout *layout, int file, rcti *r_bounds)
Definition file_utils.cc:23
void ED_file_change_dir(bContext *C)
Definition filesel.cc:1226
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus file_select_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:576
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
static wmOperatorStatus bookmark_delete_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:1209
static wmOperatorStatus reset_recent_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:1402
const char * folderlist_peeklastdir(ListBaseT< FolderList > *folderlist)
bool filelist_is_dir(const FileList *filelist, const char *path)
Definition filelist.cc:1128
void file_draw_check(bContext *C)
Definition file_ops.cc:1793
int BLI_rcti_length_x(const rcti *rect, int x)
Definition rct.cc:151
std::optional< std::string > BKE_appdir_folder_id_create(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:822
void filelist_entry_parent_select_set(FileList *filelist, FileSelType select, eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:2110
int file_select_match(SpaceFile *sfile, const char *pattern, char *matched_file)
Definition filesel.cc:1241
bool BKE_blendfile_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
Definition blendfile.cc:94
bool BLI_path_make_safe(char *path) ATTR_NONNULL(1)
void ED_operatormacros_file()
Definition file_ops.cc:3442
static bool file_execute(bContext *C, SpaceFile *sfile)
Definition file_ops.cc:2119
void WM_operator_properties_free(PointerRNA *ptr)
void FILE_OT_delete(wmOperatorType *ot)
Definition file_ops.cc:3352
void FILE_OT_rename(wmOperatorType *ot)
Definition file_ops.cc:3246
int BLI_path_normalize_dir(char *dir, size_t dir_maxncpy) ATTR_NONNULL(1)
void FILE_OT_view_selected(wmOperatorType *ot)
Definition file_ops.cc:1102
static wmOperatorStatus file_next_exec(bContext *C, wmOperator *)
Definition file_ops.cc:2401
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
Definition fileops_c.cc:416
void FILE_OT_directory_new(wmOperatorType *ot)
Definition file_ops.cc:2812
void FILE_OT_bookmark_cleanup(wmOperatorType *ot)
Definition file_ops.cc:1279
FSMenuEntry * ED_fsmenu_get_entry(FSMenu *fsmenu, FSMenuCategory category, int idx)
Definition fsmenu.cc:113
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
static bool file_operator_poll(bContext *C)
Definition file_ops.cc:1573
void FILE_OT_smoothscroll(wmOperatorType *ot)
Definition file_ops.cc:2614
static wmOperatorStatus file_view_selected_exec(bContext *C, wmOperator *)
Definition file_ops.cc:1063
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
size_t size_t BLI_path_append_dir(char *__restrict dst, size_t dst_maxncpy, const char *__restrict dir) ATTR_NONNULL(1
static bool file_os_operations_menu_poll(const bContext *C_const, MenuType *)
Definition file_ops.cc:2057
unsigned short ushort
Definition BKE_text.h:56
void filelist_setrecursion(FileList *filelist, int recursion_level)
Definition filelist.cc:1150
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void BLI_linklist_move_item(LinkNode **listp, int curr_index, int new_index) ATTR_NONNULL(1)
static std::string file_external_operation_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
Definition file_ops.cc:1935
static wmOperatorStatus bookmark_select_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:1123
PropertyRNA * RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
void FILE_OT_cancel(wmOperatorType *ot)
Definition file_ops.cc:1598
bool ED_operator_file_active(bContext *C)
@ FILE_BOOKMARK_MOVE_BOTTOM
Definition file_ops.cc:1304
@ FILE_BOOKMARK_MOVE_UP
Definition file_ops.cc:1302
@ FILE_BOOKMARK_MOVE_DOWN
Definition file_ops.cc:1303
@ FILE_BOOKMARK_MOVE_TOP
Definition file_ops.cc:1301
size_t BLI_path_append(char *__restrict dst, size_t dst_maxncpy, const char *__restrict file) ATTR_NONNULL(1
void fsmenu_refresh_system_category(FSMenu *fsmenu)
Definition fsmenu.cc:493
wmWindow * CTX_wm_window(const bContext *C)
void FILE_OT_select_box(wmOperatorType *ot)
Definition file_ops.cc:542
void FILE_OT_select(wmOperatorType *ot)
Definition file_ops.cc:659
@ FILE_BROWSE_MODE_FILES
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
static wmOperatorStatus file_previous_exec(bContext *C, wmOperator *)
Definition file_ops.cc:2365
MINLINE int max_ii(int a, int b)
void file_directory_enter_handle(bContext *C, void *arg_unused, void *arg_but)
Definition file_ops.cc:2954
static rcti file_select_mval_to_select_rect(const int mval[2])
Definition file_ops.cc:568
@ FILE_SEL_TOGGLE
Definition filelist.hh:39
@ FILE_SEL_REMOVE
Definition filelist.hh:37
@ FILE_SEL_ADD
Definition filelist.hh:38
static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
Definition file_ops.cc:169
bool BLI_file_external_operation_execute(const char *filepath, FileExternalOperation operation)
Definition fileops_c.cc:159
wmOperatorStatus WM_generic_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void file_params_smoothscroll_timer_clear(wmWindowManager *wm, wmWindow *win, SpaceFile *sfile)
Definition filesel.cc:1387
void file_select_deselect_all(SpaceFile *sfile, eDirEntry_SelectFlag flag)
Definition filesel.cc:1232
bool fsmenu_write_file(FSMenu *fsmenu, const char *filepath)
Definition fsmenu.cc:387
static wmOperatorStatus file_select_all_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:979
eDirEntry_SelectFlag filelist_entry_select_get(FileList *filelist, FileDirEntry *entry, FileCheckType check)
Definition filelist.cc:2066
static wmOperatorStatus file_filenum_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:3172
static wmOperatorStatus file_smoothscroll_invoke(bContext *C, wmOperator *, const wmEvent *event)
Definition file_ops.cc:2439
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src)
void WM_operator_properties_select_all(wmOperatorType *ot)
static bool file_ensure_hovered_is_active(bContext *C, const wmEvent *event)
Definition file_ops.cc:2230
@ FILE_PARAMS_RENAME_ACTIVE
@ FILE_PARAMS_RENAME_POSTSCROLL_PENDING
@ FILE_PARAMS_RENAME_POSTSCROLL_ACTIVE
@ FILE_PARAMS_RENAME_PENDING
@ EVT_FILESELECT_CANCEL
static wmOperatorStatus bookmark_cleanup_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:1252
static bool can_create_dir_from_user_input(const char dir[FILE_MAX_LIBEXTRA])
Definition file_ops.cc:2898
void ED_fsmenu_set_category(FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsm_head)
Definition fsmenu.cc:80
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
const char * BLI_dir_home()
Definition storage.cc:99
bool ED_fileselect_layout_is_inside_pt(const FileLayout *layout, const View2D *v2d, int x, int y)
Definition filesel.cc:888
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
void FILE_OT_parent(wmOperatorType *ot)
Definition file_ops.cc:2346
void WM_operator_properties_select_walk_direction(wmOperatorType *ot)
static void file_rename_state_activate(SpaceFile *sfile, int file_idx, bool require_selected)
Definition file_ops.cc:3210
void FILE_OT_edit_directory_path(wmOperatorType *ot)
Definition file_ops.cc:3424
PointerRNA WM_operator_properties_create(const char *opstring)
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
void FILE_OT_filepath_drop(wmOperatorType *ot)
Definition file_ops.cc:2661
void fsmenu_insert_entry(FSMenu *fsmenu, FSMenuCategory category, const char *path, const char *name, int icon, FSMenuInsert flag)
Definition fsmenu.cc:229
static bool file_filenum_poll(bContext *C)
Definition file_ops.cc:3130
FileAttributeColumnType file_attribute_column_type_find_isect(const View2D *v2d, const FileSelectParams *params, FileLayout *layout, int x)
Definition filesel.cc:949
FileSelection ED_fileselect_layout_offset_rect(FileLayout *layout, const rcti *rect)
Definition filesel.cc:801
void FILE_OT_start_filter(wmOperatorType *ot)
Definition file_ops.cc:3388
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
int BLI_rcti_length_y(const rcti *rect, int y)
Definition rct.cc:162
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
bool BLI_path_is_unc(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
const char * BKE_appdir_folder_root() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:154
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void FILE_OT_filenum(wmOperatorType *ot)
Definition file_ops.cc:3189
FileDirEntry * filelist_file(FileList *filelist, int index)
Definition filelist.cc:1349
static wmOperatorStatus file_column_sort_ui_context_invoke(bContext *C, wmOperator *, const wmEvent *event)
Definition file_ops.cc:1518
static wmOperatorStatus bookmark_add_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:1171
static bool file_bookmark_move_poll(bContext *C)
Definition file_ops.cc:1355
static wmOperatorStatus file_exec(bContext *C, wmOperator *)
Definition file_ops.cc:2186
void filelist_entry_select_index_set(FileList *filelist, int index, FileSelType select, eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:2036
FileCheckType
Definition filelist.hh:42
@ CHECK_ALL
Definition filelist.hh:45
@ CHECK_DIRS
Definition filelist.hh:43
@ CHECK_FILES
Definition filelist.hh:44
static std::string file_execute_get_description(bContext *C, wmOperatorType *, PointerRNA *)
Definition file_ops.cc:2197
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void file_sfile_to_operator_ex(bContext *C, Main *bmain, wmOperator *op, SpaceFile *sfile, char *filepath)
Definition file_ops.cc:1616
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
static wmOperatorStatus bookmark_move_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:1307
bool filelist_islibrary(FileList *filelist, char *dir, char **r_group)
Definition filelist.cc:2120
wmWindowManager * CTX_wm_manager(const bContext *C)
bool BLI_path_is_abs_from_cwd(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
void FILE_OT_hidedot(wmOperatorType *ot)
Definition file_ops.cc:3111
bool filelist_is_ready(const FileList *filelist)
Definition filelist.cc:1220
void ED_fileselect_clear(wmWindowManager *wm, SpaceFile *sfile)
Definition filesel.cc:1335
void WM_operator_properties_border_to_rcti(wmOperator *op, rcti *r_rect)
@ FILE_PATH_TOKENS_ALLOW
void FILE_OT_next(wmOperatorType *ot)
Definition file_ops.cc:2419
static wmOperatorStatus file_cancel_exec(bContext *C, wmOperator *)
Definition file_ops.cc:1585
static wmOperatorStatus file_highlight_invoke(bContext *C, wmOperator *, const wmEvent *event)
Definition file_ops.cc:1483
static wmOperatorStatus file_box_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition file_ops.cc:450
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
void FILE_OT_external_operation(wmOperatorType *ot)
Definition file_ops.cc:1944
void file_external_operations_menu_register()
Definition file_ops.cc:2097
void file_params_renamefile_clear(FileSelectParams *params)
Definition filesel.cc:1423
static wmOperatorStatus file_refresh_exec(bContext *C, wmOperator *)
Definition file_ops.cc:2289
void WM_operator_properties_gesture_box(wmOperatorType *ot)
void file_params_invoke_rename_postscroll(wmWindowManager *wm, wmWindow *win, SpaceFile *sfile)
Definition filesel.cc:1393
int filelist_files_ensure(FileList *filelist)
Definition filelist.cc:1235
void FILE_OT_sort_column_ui_context(wmOperatorType *ot)
Definition file_ops.cc:1552
void folderlist_pushdir(ListBaseT< FolderList > *folderlist, const char *dir)
bool RNA_property_update_check(PropertyRNA *prop)
bool BLI_path_is_win32_drive_only(const char *path)
void FILE_OT_refresh(wmOperatorType *ot)
Definition file_ops.cc:2305
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
FileAttributeColumnType
void FILE_OT_bookmark_add(wmOperatorType *ot)
Definition file_ops.cc:1190
static void file_ensure_inside_viewbounds(ARegion *region, SpaceFile *sfile, const int file)
Definition file_ops.cc:277
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
int BLI_path_slash_ensure(char *path, size_t path_maxncpy) ATTR_NONNULL(1)
wmOperatorStatus WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
FileSelectParams * ED_fileselect_get_active_params(const SpaceFile *sfile)
Definition filesel.cc:393
void file_operator_to_sfile(Main *bmain, SpaceFile *sfile, wmOperator *op)
Definition file_ops.cc:1722
bool ED_operator_region_file_active(bContext *C)
static bool file_delete_poll(bContext *C)
Definition file_ops.cc:3265
void WM_event_fileselect_event(wmWindowManager *wm, void *ophandle, const int eventval)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
static wmOperatorStatus file_start_filter_exec(bContext *C, wmOperator *)
Definition file_ops.cc:3371
void FILE_OT_bookmark_delete(wmOperatorType *ot)
Definition file_ops.cc:1227
static void filenum_newname(char *filename, size_t filename_maxncpy, int add)
Definition file_ops.cc:3147
static wmOperatorStatus file_hidedot_exec(bContext *C, wmOperator *)
Definition file_ops.cc:3096
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:457
bool file_draw_check_exists(SpaceFile *sfile)
Definition file_ops.cc:1804
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
int BLI_delete_soft(const char *filepath, const char **r_error_message) ATTR_NONNULL()
unsigned int filelist_entry_select_set(const FileList *filelist, const FileDirEntry *entry, FileSelType select, const eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:1987
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
ARegion * BKE_region_find_in_listbase_by_type(const ListBaseT< ARegion > *regionbase, const int region_type)
Definition screen.cc:987
static wmOperatorStatus file_directory_new_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition file_ops.cc:2793
void FILE_OT_mouse_execute(wmOperatorType *ot)
Definition file_ops.cc:2268
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
SpaceLink * CTX_wm_space_data(const bContext *C)
static bool file_delete_single(const FileList *files, FileDirEntry *file, const char **r_error_message)
Definition file_ops.cc:3293
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
bool BLI_path_parent_dir(char *path) ATTR_NONNULL(1)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
static FileSelection file_selection_get(bContext *C, const rcti *rect, bool fill)
Definition file_ops.cc:130
static wmOperatorStatus file_delete_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition file_ops.cc:3341
void FILE_OT_select_walk(wmOperatorType *ot)
Definition file_ops.cc:945
void file_sfile_filepath_set(SpaceFile *sfile, const char *filepath)
Definition file_ops.cc:1750
void FILE_OT_execute(wmOperatorType *ot)
Definition file_ops.cc:2210
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
static bool file_walk_select_selection_set(bContext *C, wmWindow *win, ARegion *region, SpaceFile *sfile, const int direction, const int numfiles, const int active_old, const int active_new, const int other_site, const bool has_selection, const bool extend, const bool fill)
Definition file_ops.cc:720
@ WM_CURSOR_WAIT
Definition wm_cursors.hh:19
@ WM_CURSOR_DEFAULT
Definition wm_cursors.hh:17
void file_sfile_to_operator(bContext *C, Main *bmain, wmOperator *op, SpaceFile *sfile)
Definition file_ops.cc:1715
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void file_draw_check_ex(bContext *C, ScrArea *area)
Definition file_ops.cc:1769
bool WM_menutype_add(MenuType *mt)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus file_edit_directory_path_exec(bContext *C, wmOperator *)
Definition file_ops.cc:3407
void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select, bool fill, bool do_diropen)
Definition file_ops.cc:336
int file_highlight_set(SpaceFile *sfile, ARegion *region, int mx, int my)
Definition file_ops.cc:1435
bool RNA_enum_description(const EnumPropertyItem *item, const int value, const char **r_description)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
Definition path_utils.cc:61
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
void BLI_path_split_dir_file(const char *filepath, char *dir, size_t dir_maxncpy, char *file, size_t file_maxncpy) ATTR_NONNULL(1
static int file_box_select_find_last_selected(SpaceFile *sfile, ARegion *region, const FileSelection *sel, const int mouse_xy[2])
Definition file_ops.cc:416
@ FILE_SELECT_FILE
Definition file_ops.cc:101
@ FILE_SELECT_DIR
Definition file_ops.cc:100
@ FILE_SELECT_NOTHING
Definition file_ops.cc:99
void folderlist_popdir(ListBaseT< FolderList > *folderlist, char *dir)
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
void FILE_OT_reset_recent(wmOperatorType *ot)
Definition file_ops.cc:1416
bool filelist_entry_is_selected(FileList *filelist, int index)
Definition filelist.cc:2097
void WM_operator_properties_select_operation_simple(wmOperatorType *ot)
@ FS_CATEGORY_BOOKMARKS
static void clamp_to_filelist(int numfiles, FileSelection *sel)
Definition file_ops.cc:104
SpaceFile * CTX_wm_space_file(const bContext *C)
void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but)
Definition file_ops.cc:3040
static wmOperatorStatus file_walk_select_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition file_ops.cc:927
int BLI_path_normalize_native(char *path) ATTR_NONNULL(1)
void fileselect_file_set(bContext *C, SpaceFile *sfile, int index)
Definition filesel.cc:753
void CTX_wm_region_set(bContext *C, ARegion *region)
void WM_cursor_set(wmWindow *win, int curs)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
static void file_ensure_selection_inside_viewbounds(ARegion *region, SpaceFile *sfile, FileSelection *sel)
Definition file_ops.cc:317
void ED_area_tag_refresh(ScrArea *area)
Definition area.cc:813
void fsmenu_remove_entry(FSMenu *fsmenu, FSMenuCategory category, int idx)
Definition fsmenu.cc:354
void FILE_OT_previous(wmOperatorType *ot)
Definition file_ops.cc:2382
static wmOperatorStatus filepath_drop_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:2633
static bool file_is_any_selected(FileList *files)
Definition file_ops.cc:232
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void filelist_entries_select_index_range_set(FileList *filelist, FileSelection *sel, FileSelType select, eDirEntry_SelectFlag flag, FileCheckType check)
Definition filelist.cc:2049
bool BLI_file_external_operation_supported(const char *filepath, FileExternalOperation operation)
Definition fileops_c.cc:148
static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *region, const rcti *rect_region)
Definition file_ops.cc:67
static wmOperatorStatus file_external_operation_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:1856
int ED_fsmenu_get_nentries(FSMenu *fsmenu, FSMenuCategory category)
Definition fsmenu.cc:101
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ BLENDER_USER_CONFIG
constexpr char SEP
void ED_region_activate_rna_prop(bContext *C, ARegion *region, const void *data, StringRefNull prop_name)
Definition area.cc:696
void WM_event_add_mousemove(wmWindow *win)
bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL(1)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
static FileSelection file_current_selection_range_get(FileList *files)
Definition file_ops.cc:247
FSMenuEntry * ED_fsmenu_get_category(FSMenu *fsmenu, FSMenuCategory category)
Definition fsmenu.cc:56
void filelist_file_get_full_path(const FileList *filelist, const FileDirEntry *file, char r_filepath[1282])
const char * filelist_dir(const FileList *filelist)
Definition filelist.cc:1123
static void file_os_operations_menu_draw(const bContext *C_const, Menu *menu)
Definition file_ops.cc:1991
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:469
static bool new_folder_path(const char *parent, char r_dirpath_full[FILE_MAX], char r_dirname[FILE_MAXFILE])
Definition file_ops.cc:2685
FileExternalOperation
@ FILE_EXTERNAL_OPERATION_FOLDER_OPEN
@ FILE_EXTERNAL_OPERATION_FOLDER_CMD
@ FILE_EXTERNAL_OPERATION_EDIT
@ FILE_EXTERNAL_OPERATION_FIND
@ FILE_EXTERNAL_OPERATION_SHOW
@ FILE_EXTERNAL_OPERATION_BROWSE
@ FILE_EXTERNAL_OPERATION_INSTALL
@ FILE_EXTERNAL_OPERATION_PROPERTIES
@ FILE_EXTERNAL_OPERATION_PLAY
@ FILE_EXTERNAL_OPERATION_PRINT
@ FILE_EXTERNAL_OPERATION_PREVIEW
@ FILE_EXTERNAL_OPERATION_FOLDER_FIND
@ FILE_EXTERNAL_OPERATION_RUNAS
@ FILE_EXTERNAL_OPERATION_NEW
@ FILE_EXTERNAL_OPERATION_OPEN
static bool fsmenu_write_file_and_refresh_or_report_error(FSMenu *fsmenu, ScrArea *area, ReportList *reports)
Definition file_ops.cc:385
ARegion * CTX_wm_region(const bContext *C)
void FILE_OT_select_all(wmOperatorType *ot)
Definition file_ops.cc:1041
void WM_operator_properties_generic_select(wmOperatorType *ot)
static wmOperatorStatus file_rename_exec(bContext *C, wmOperator *)
Definition file_ops.cc:3232
bool ED_fileselect_layout_isect_rect(const FileLayout *layout, const View2D *v2d, const rcti *rect, rcti *r_dst)
Definition filesel.cc:895
static bool file_walk_select_do(bContext *C, SpaceFile *sfile, FileSelectParams *params, const int direction, const bool extend, const bool fill)
Definition file_ops.cc:840
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
static const EnumPropertyItem file_external_operation[]
Definition file_ops.cc:1826
static wmOperatorStatus file_execute_mouse_invoke(bContext *C, wmOperator *, const wmEvent *event)
Definition file_ops.cc:2240
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
bool ED_operator_file_browsing_active(bContext *C)
bool file_attribute_column_header_is_inside(const View2D *v2d, const FileLayout *layout, int x, int y)
Definition filesel.cc:921
bool BLI_path_make_safe_filename_ex(char *filename, bool allow_tokens) ATTR_NONNULL(1)
static wmOperatorStatus file_box_select_exec(bContext *C, wmOperator *op)
Definition file_ops.cc:506
eRegion_Type regiontype
FileAttributeColumn attribute_columns[ATTRIBUTE_COLUMN_MAX]
eFileSel_Params_RenameFlag rename_flag
eFileSel_Params_Flag flag
char idname[BKE_ST_MAXNAME]
bool(*) poll(const bContext *C, MenuType *mt)
char translation_context[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
void(*) draw(const bContext *C, Menu *menu)
ui::Layout * layout
ListBaseT< ARegion > regionbase
ListBaseT< SpaceLink > spacedata
eFileBrowse_Mode browse_mode
ListBaseT< struct FolderList > * folders_prev
ListBaseT< struct FolderList > * folders_next
struct wmOperator * op
struct wmTimer * smoothscroll_timer
struct FileLayout * layout
struct FileList * files
void operator_context_set(wm::OpCallContext opcontext)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports
struct wmOperatorType * type
#define N_(msgid)