Blender V4.3
file_ops.cc File Reference
#include "BLI_utildefines.h"
#include "BLI_blenlib.h"
#include "BLI_linklist.h"
#include "BKE_appdir.hh"
#include "BKE_blendfile.hh"
#include "BKE_context.hh"
#include "BKE_main.hh"
#include "BKE_report.hh"
#include "BKE_screen.hh"
#include "BLT_translation.hh"
#include "ED_fileselect.hh"
#include "ED_screen.hh"
#include "ED_select_utils.hh"
#include "UI_interface.hh"
#include "UI_interface_icons.hh"
#include "UI_resources.hh"
#include "MEM_guardedalloc.h"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "UI_view2d.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "file_intern.hh"
#include "filelist.hh"
#include "fsmenu.h"
#include <cctype>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>

Go to the source code of this file.

Functions

Bookmark Utilities
static bool fsmenu_write_file_and_refresh_or_report_error (FSMenu *fsmenu, ScrArea *area, ReportList *reports)
 
Box Select Operator
static int file_box_select_find_last_selected (SpaceFile *sfile, ARegion *region, const FileSelection *sel, const int mouse_xy[2])
 
static int file_box_select_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
static int file_box_select_exec (bContext *C, wmOperator *op)
 
void FILE_OT_select_box (wmOperatorType *ot)
 
Select Pick Operator
static rcti file_select_mval_to_select_rect (const int mval[2])
 
static int file_select_exec (bContext *C, wmOperator *op)
 
void FILE_OT_select (wmOperatorType *ot)
 
Select Walk Operator
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)
 
static bool file_walk_select_do (bContext *C, SpaceFile *sfile, FileSelectParams *params, const int direction, const bool extend, const bool fill)
 
static int file_walk_select_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
void FILE_OT_select_walk (wmOperatorType *ot)
 
Select All Operator
static int file_select_all_exec (bContext *C, wmOperator *op)
 
void FILE_OT_select_all (wmOperatorType *ot)
 
View Selected Operator
static int file_view_selected_exec (bContext *C, wmOperator *)
 
void FILE_OT_view_selected (wmOperatorType *ot)
 
Select Bookmark Operator
static int bookmark_select_exec (bContext *C, wmOperator *op)
 
void FILE_OT_select_bookmark (wmOperatorType *ot)
 
Add Bookmark Operator
static int bookmark_add_exec (bContext *C, wmOperator *op)
 
void FILE_OT_bookmark_add (wmOperatorType *ot)
 
Delete Bookmark Operator
static int bookmark_delete_exec (bContext *C, wmOperator *op)
 
void FILE_OT_bookmark_delete (wmOperatorType *ot)
 
Cleanup Bookmark Operator
static int bookmark_cleanup_exec (bContext *C, wmOperator *op)
 
void FILE_OT_bookmark_cleanup (wmOperatorType *ot)
 
Reset Recent Blend Files Operator
static int reset_recent_exec (bContext *C, wmOperator *op)
 
void FILE_OT_reset_recent (wmOperatorType *ot)
 
Highlight File Operator
int file_highlight_set (SpaceFile *sfile, ARegion *region, int mx, int my)
 
static int file_highlight_invoke (bContext *C, wmOperator *, const wmEvent *event)
 
void FILE_OT_highlight (wmOperatorType *ot)
 
Sort from Column Operator
static int file_column_sort_ui_context_invoke (bContext *C, wmOperator *, const wmEvent *event)
 
void FILE_OT_sort_column_ui_context (wmOperatorType *ot)
 
Cancel File Selector Operator
static bool file_operator_poll (bContext *C)
 
static int file_cancel_exec (bContext *C, wmOperator *)
 
void FILE_OT_cancel (wmOperatorType *ot)
 
Operator Utilities
void file_sfile_to_operator_ex (bContext *C, Main *bmain, wmOperator *op, SpaceFile *sfile, char *filepath)
 
void file_sfile_to_operator (bContext *C, Main *bmain, wmOperator *op, SpaceFile *sfile)
 
void file_operator_to_sfile (Main *bmain, SpaceFile *sfile, wmOperator *op)
 
void file_sfile_filepath_set (SpaceFile *sfile, const char *filepath)
 
void file_draw_check_ex (bContext *C, ScrArea *area)
 
void file_draw_check (bContext *C)
 
void file_draw_check_cb (bContext *C, void *, void *)
 
bool file_draw_check_exists (SpaceFile *sfile)
 
Execute File Window Operator
static bool file_execute (bContext *C, SpaceFile *sfile)
 
static int file_exec (bContext *C, wmOperator *)
 
void FILE_OT_execute (wmOperatorType *ot)
 
static bool file_ensure_hovered_is_active (bContext *C, const wmEvent *event)
 
static int file_execute_mouse_invoke (bContext *C, wmOperator *, const wmEvent *event)
 
void FILE_OT_mouse_execute (wmOperatorType *ot)
 
Refresh File List Operator
static int file_refresh_exec (bContext *C, wmOperator *)
 
void FILE_OT_refresh (wmOperatorType *ot)
 
static void file_expand_directory (bContext *C)
 
void file_directory_enter_handle (bContext *C, void *, void *)
 
void file_filename_enter_handle (bContext *C, void *, void *arg_but)
 
Navigate Parent Operator
static int file_parent_exec (bContext *C, wmOperator *)
 
void FILE_OT_parent (wmOperatorType *ot)
 
Navigate Previous Operator
static int file_previous_exec (bContext *C, wmOperator *)
 
void FILE_OT_previous (wmOperatorType *ot)
 
Navigate Next Operator
static int file_next_exec (bContext *C, wmOperator *)
 
void FILE_OT_next (wmOperatorType *ot)
 
Smooth Scroll Operator
static int file_smoothscroll_invoke (bContext *C, wmOperator *, const wmEvent *event)
 
void FILE_OT_smoothscroll (wmOperatorType *ot)
 
File Selector Drop Operator
static int filepath_drop_exec (bContext *C, wmOperator *op)
 
void FILE_OT_filepath_drop (wmOperatorType *ot)
 
New Directory Operator
static bool new_folder_path (const char *parent, char r_dirpath_full[FILE_MAX], char r_dirname[FILE_MAXFILE])
 
static int file_directory_new_exec (bContext *C, wmOperator *op)
 
static int file_directory_new_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
void FILE_OT_directory_new (wmOperatorType *ot)
 
Toggle Show Hidden Files Operator
static int file_hidedot_exec (bContext *C, wmOperator *)
 
void FILE_OT_hidedot (wmOperatorType *ot)
 
Increment Filename Operator
static bool file_filenum_poll (bContext *C)
 
static void filenum_newname (char *filename, size_t filename_maxncpy, int add)
 
static int file_filenum_exec (bContext *C, wmOperator *op)
 
void FILE_OT_filenum (wmOperatorType *ot)
 
Rename File/Directory Operator
static void file_rename_state_activate (SpaceFile *sfile, int file_idx, bool require_selected)
 
static int file_rename_exec (bContext *C, wmOperator *)
 
void FILE_OT_rename (wmOperatorType *ot)
 
Delete File Operator
static bool file_delete_poll (bContext *C)
 
static bool file_delete_single (const FileList *files, FileDirEntry *file, const char **r_error_message)
 
static int file_delete_exec (bContext *C, wmOperator *op)
 
static int file_delete_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
void FILE_OT_delete (wmOperatorType *ot)
 
Enter Filter Text Operator
static int file_start_filter_exec (bContext *C, wmOperator *)
 
void FILE_OT_start_filter (wmOperatorType *ot)
 
Edit Directory Path Operator
static int file_edit_directory_path_exec (bContext *C, wmOperator *)
 
void FILE_OT_edit_directory_path (wmOperatorType *ot)
 
Macro Operators
void ED_operatormacros_file ()
 

File Selection Utilities

enum  FileSelect { FILE_SELECT_NOTHING = 0 , FILE_SELECT_DIR = 1 , FILE_SELECT_FILE = 2 }
 
static FileSelection find_file_mouse_rect (SpaceFile *sfile, ARegion *region, const rcti *rect_region)
 
static void clamp_to_filelist (int numfiles, FileSelection *sel)
 
static FileSelection file_selection_get (bContext *C, const rcti *rect, bool fill)
 
static FileSelect file_select_do (bContext *C, int selected_idx, bool do_diropen)
 
static bool file_is_any_selected (FileList *files)
 
static FileSelection file_current_selection_range_get (FileList *files)
 
static void file_ensure_inside_viewbounds (ARegion *region, SpaceFile *sfile, const int file)
 
static void file_ensure_selection_inside_viewbounds (ARegion *region, SpaceFile *sfile, FileSelection *sel)
 
static FileSelect file_select (bContext *C, const rcti *rect, FileSelType select, bool fill, bool do_diropen)
 

Reorder Bookmark Operator

enum  { FILE_BOOKMARK_MOVE_TOP = -2 , FILE_BOOKMARK_MOVE_UP = -1 , FILE_BOOKMARK_MOVE_DOWN = 1 , FILE_BOOKMARK_MOVE_BOTTOM = 2 }
 
static int bookmark_move_exec (bContext *C, wmOperator *op)
 
static bool file_bookmark_move_poll (bContext *C)
 
void FILE_OT_bookmark_move (wmOperatorType *ot)
 

External operations that can performed on files.

static const EnumPropertyItem file_external_operation []
 
static int file_external_operation_exec (bContext *C, wmOperator *op)
 
static std::string file_external_operation_get_description (bContext *, wmOperatorType *, PointerRNA *ptr)
 
void FILE_OT_external_operation (wmOperatorType *ot)
 
static void file_os_operations_menu_item (uiLayout *layout, wmOperatorType *ot, const char *path, FileExternalOperation operation)
 
static void file_os_operations_menu_draw (const bContext *C_const, Menu *menu)
 
static bool file_os_operations_menu_poll (const bContext *C_const, MenuType *)
 
void file_external_operations_menu_register ()
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FILE_BOOKMARK_MOVE_TOP 
FILE_BOOKMARK_MOVE_UP 
FILE_BOOKMARK_MOVE_DOWN 
FILE_BOOKMARK_MOVE_BOTTOM 

Definition at line 1267 of file file_ops.cc.

◆ FileSelect

enum FileSelect
Enumerator
FILE_SELECT_NOTHING 
FILE_SELECT_DIR 
FILE_SELECT_FILE 

Definition at line 90 of file file_ops.cc.

Function Documentation

◆ bookmark_add_exec()

◆ bookmark_cleanup_exec()

◆ bookmark_delete_exec()

◆ bookmark_move_exec()

◆ bookmark_select_exec()

◆ clamp_to_filelist()

static void clamp_to_filelist ( int numfiles,
FileSelection * sel )
static

Definition at line 96 of file file_ops.cc.

References FileSelection::first, and FileSelection::last.

Referenced by file_selection_get().

◆ ED_operatormacros_file()

void ED_operatormacros_file ( )

Definition at line 3309 of file file_ops.cc.

Referenced by ED_spacemacros_init().

◆ file_bookmark_move_poll()

static bool file_bookmark_move_poll ( bContext * C)
static

◆ file_box_select_exec()

◆ file_box_select_find_last_selected()

static int file_box_select_find_last_selected ( SpaceFile * sfile,
ARegion * region,
const FileSelection * sel,
const int mouse_xy[2] )
static

◆ file_box_select_modal()

◆ file_cancel_exec()

static int file_cancel_exec ( bContext * C,
wmOperator *  )
static

◆ file_column_sort_ui_context_invoke()

◆ file_current_selection_range_get()

static FileSelection file_current_selection_range_get ( FileList * files)
static

◆ file_delete_exec()

◆ file_delete_invoke()

static int file_delete_invoke ( bContext * C,
wmOperator * op,
const wmEvent *  )
static

Definition at line 3213 of file file_ops.cc.

References ALERT_ICON_NONE, IFACE_, and WM_operator_confirm_ex().

Referenced by FILE_OT_delete().

◆ file_delete_poll()

◆ file_delete_single()

static bool file_delete_single ( const FileList * files,
FileDirEntry * file,
const char ** r_error_message )
static

◆ file_directory_enter_handle()

◆ file_directory_new_exec()

◆ file_directory_new_invoke()

static int file_directory_new_invoke ( bContext * C,
wmOperator * op,
const wmEvent *  )
static

◆ file_draw_check()

◆ file_draw_check_cb()

void file_draw_check_cb ( bContext * C,
void * arg1,
void * arg2 )

For use with; UI_block_func_set.

Definition at line 1760 of file file_ops.cc.

References file_draw_check().

Referenced by ED_file_path_button(), file_panel_execution_buttons_draw(), and file_panel_operator().

◆ file_draw_check_ex()

◆ file_draw_check_exists()

bool file_draw_check_exists ( SpaceFile * sfile)

◆ file_edit_directory_path_exec()

static int file_edit_directory_path_exec ( bContext * C,
wmOperator *  )
static

◆ file_ensure_hovered_is_active()

static bool file_ensure_hovered_is_active ( bContext * C,
const wmEvent * event )
static
Returns
false if the mouse doesn't hover a selectable item.

Definition at line 2145 of file file_ops.cc.

References FILE_SEL_ADD, file_select(), file_select_mval_to_select_rect(), FILE_SELECT_NOTHING, and wmEvent::mval.

Referenced by file_execute_mouse_invoke().

◆ file_ensure_inside_viewbounds()

static void file_ensure_inside_viewbounds ( ARegion * region,
SpaceFile * sfile,
const int file )
static

◆ file_ensure_selection_inside_viewbounds()

static void file_ensure_selection_inside_viewbounds ( ARegion * region,
SpaceFile * sfile,
FileSelection * sel )
static

◆ file_exec()

static int file_exec ( bContext * C,
wmOperator *  )
static

Definition at line 2115 of file file_ops.cc.

References CTX_wm_space_file(), file_execute(), OPERATOR_CANCELLED, and OPERATOR_FINISHED.

Referenced by FILE_OT_execute().

◆ file_execute()

◆ file_execute_mouse_invoke()

◆ file_expand_directory()

◆ file_external_operation_exec()

◆ file_external_operation_get_description()

static std::string file_external_operation_get_description ( bContext * ,
wmOperatorType * ,
PointerRNA * ptr )
static

◆ file_external_operations_menu_register()

◆ file_filename_enter_handle()

◆ file_filenum_exec()

◆ file_filenum_poll()

static bool file_filenum_poll ( bContext * C)
static

◆ file_hidedot_exec()

◆ file_highlight_invoke()

static int file_highlight_invoke ( bContext * C,
wmOperator * ,
const wmEvent * event )
static

◆ file_highlight_set()

◆ file_is_any_selected()

static bool file_is_any_selected ( FileList * files)
static
Warning
Loops over all files so better use cautiously.

Definition at line 224 of file file_ops.cc.

References CHECK_ALL, filelist_entry_select_index_get(), and filelist_files_ensure().

Referenced by file_select(), file_select_all_exec(), and file_walk_select_do().

◆ file_next_exec()

◆ file_operator_poll()

static bool file_operator_poll ( bContext * C)
static

Definition at line 1538 of file file_ops.cc.

References CTX_wm_space_file(), ED_operator_file_browsing_active(), and SpaceFile::op.

Referenced by FILE_OT_cancel().

◆ file_operator_to_sfile()

◆ file_os_operations_menu_draw()

◆ file_os_operations_menu_item()

◆ file_os_operations_menu_poll()

◆ FILE_OT_bookmark_add()

◆ FILE_OT_bookmark_cleanup()

◆ FILE_OT_bookmark_delete()

◆ FILE_OT_bookmark_move()

◆ FILE_OT_cancel()

◆ FILE_OT_delete()

◆ FILE_OT_directory_new()

◆ FILE_OT_edit_directory_path()

◆ FILE_OT_execute()

◆ FILE_OT_external_operation()

◆ FILE_OT_filenum()

◆ FILE_OT_filepath_drop()

◆ FILE_OT_hidedot()

◆ FILE_OT_highlight()

◆ FILE_OT_mouse_execute()

void FILE_OT_mouse_execute ( wmOperatorType * ot)

Variation of FILE_OT_execute that accounts for some mouse specific handling. Otherwise calls the same logic.

Definition at line 2181 of file file_ops.cc.

References wmOperatorType::description, ED_operator_file_browsing_active(), file_execute_mouse_invoke(), wmOperatorType::flag, wmOperatorType::idname, wmOperatorType::invoke, wmOperatorType::name, OPTYPE_INTERNAL, ot, and wmOperatorType::poll.

Referenced by file_operatortypes().

◆ FILE_OT_next()

◆ FILE_OT_parent()

◆ FILE_OT_previous()

◆ FILE_OT_refresh()

◆ FILE_OT_rename()

◆ FILE_OT_reset_recent()

◆ FILE_OT_select()

◆ FILE_OT_select_all()

◆ FILE_OT_select_bookmark()

◆ FILE_OT_select_box()

◆ FILE_OT_select_walk()

◆ FILE_OT_smoothscroll()

◆ FILE_OT_sort_column_ui_context()

◆ FILE_OT_start_filter()

◆ FILE_OT_view_selected()

◆ file_parent_exec()

◆ file_previous_exec()

◆ file_refresh_exec()

◆ file_rename_exec()

◆ file_rename_state_activate()

◆ file_select()

◆ file_select_all_exec()

◆ file_select_do()

◆ file_select_exec()

◆ file_select_mval_to_select_rect()

static rcti file_select_mval_to_select_rect ( const int mval[2])
static

Definition at line 556 of file file_ops.cc.

References rcti::xmax, rcti::xmin, rcti::ymax, and rcti::ymin.

Referenced by file_ensure_hovered_is_active(), and file_select_exec().

◆ file_selection_get()

◆ file_sfile_filepath_set()

void file_sfile_filepath_set ( SpaceFile * sfile,
const char * filepath )

Use to set the file selector path from some arbitrary source.

Definition at line 1711 of file file_ops.cc.

References BLI_assert, BLI_exists(), BLI_is_dir(), BLI_path_split_dir_file(), BLI_path_split_dir_part(), ED_fileselect_get_active_params(), FILE_DIRSEL_ONLY, params, and STRNCPY.

Referenced by filepath_drop_exec().

◆ file_sfile_to_operator()

void file_sfile_to_operator ( bContext * C,
Main * bmain,
wmOperator * op,
SpaceFile * sfile )

Definition at line 1676 of file file_ops.cc.

References FILE_MAX, and file_sfile_to_operator_ex().

Referenced by file_draw_check_ex(), filepath_drop_exec(), and fileselect_file_set().

◆ file_sfile_to_operator_ex()

◆ file_smoothscroll_invoke()

◆ file_start_filter_exec()

static int file_start_filter_exec ( bContext * C,
wmOperator *  )
static

◆ file_view_selected_exec()

◆ file_walk_select_do()

◆ file_walk_select_invoke()

◆ file_walk_select_selection_set()

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 )
static

◆ filenum_newname()

static void filenum_newname ( char * filename,
size_t filename_maxncpy,
int add )
static

Looks for a string of digits within filename (using BLI_path_sequence_decode) and adjusts it by add.

Definition at line 3017 of file file_ops.cc.

References add(), BLI_path_sequence_decode(), BLI_path_sequence_encode(), exp(), and FILE_MAXFILE.

Referenced by file_filenum_exec().

◆ filepath_drop_exec()

◆ find_file_mouse_rect()

◆ fsmenu_write_file_and_refresh_or_report_error()

static bool fsmenu_write_file_and_refresh_or_report_error ( FSMenu * fsmenu,
ScrArea * area,
ReportList * reports )
static

◆ new_folder_path()

static bool new_folder_path ( const char * parent,
char r_dirpath_full[FILE_MAX],
char r_dirname[FILE_MAXFILE] )
static

Create a new, non-existing folder dirname, returns true if successful, false if name couldn't be created. The actual name is returned in r_dirpath, r_dirpath_full contains the complete path, including the new folder name.

Definition at line 2600 of file file_ops.cc.

References BLI_exists(), BLI_path_join, BLI_snprintf(), BLI_strncpy(), FILE_MAX, FILE_MAXFILE, and len.

Referenced by file_directory_new_exec().

◆ reset_recent_exec()

Variable Documentation

◆ file_external_operation

const EnumPropertyItem file_external_operation[]
static
Initial value:
= {
{FILE_EXTERNAL_OPERATION_OPEN, "OPEN", 0, "Open", "Open the file"},
{FILE_EXTERNAL_OPERATION_FOLDER_OPEN, "FOLDER_OPEN", 0, "Open Folder", "Open the folder"},
{FILE_EXTERNAL_OPERATION_EDIT, "EDIT", 0, "Edit", "Edit the file"},
{FILE_EXTERNAL_OPERATION_NEW, "NEW", 0, "New", "Create a new file of this type"},
{FILE_EXTERNAL_OPERATION_FIND, "FIND", 0, "Find File", "Search for files of this type"},
{FILE_EXTERNAL_OPERATION_SHOW, "SHOW", 0, "Show", "Show this file"},
{FILE_EXTERNAL_OPERATION_PLAY, "PLAY", 0, "Play", "Play this file"},
{FILE_EXTERNAL_OPERATION_BROWSE, "BROWSE", 0, "Browse", "Browse this file"},
{FILE_EXTERNAL_OPERATION_PREVIEW, "PREVIEW", 0, "Preview", "Preview this file"},
{FILE_EXTERNAL_OPERATION_PRINT, "PRINT", 0, "Print", "Print this file"},
{FILE_EXTERNAL_OPERATION_INSTALL, "INSTALL", 0, "Install", "Install this file"},
{FILE_EXTERNAL_OPERATION_RUNAS, "RUNAS", 0, "Run As User", "Run as specific user"},
"PROPERTIES",
0,
"Properties",
"Show OS Properties for this item"},
"FOLDER_FIND",
0,
"Find in Folder",
"Search for items in this folder"},
"CMD",
0,
"Command Prompt Here",
"Open a command prompt here"},
{0, nullptr, 0, nullptr, nullptr}}
@ FILE_EXTERNAL_OPERATION_FOLDER_OPEN
@ FILE_EXTERNAL_OPERATION_FOLDER_CMD
@ FILE_EXTERNAL_OPERATION_OPEN
@ FILE_EXTERNAL_OPERATION_PRINT
@ FILE_EXTERNAL_OPERATION_INSTALL
@ FILE_EXTERNAL_OPERATION_PLAY
@ FILE_EXTERNAL_OPERATION_BROWSE
@ FILE_EXTERNAL_OPERATION_PREVIEW
@ FILE_EXTERNAL_OPERATION_RUNAS
@ FILE_EXTERNAL_OPERATION_FOLDER_FIND
@ FILE_EXTERNAL_OPERATION_NEW
@ FILE_EXTERNAL_OPERATION_EDIT
@ FILE_EXTERNAL_OPERATION_PROPERTIES
@ FILE_EXTERNAL_OPERATION_FIND
@ FILE_EXTERNAL_OPERATION_SHOW

Definition at line 1787 of file file_ops.cc.

Referenced by file_external_operation_get_description(), file_os_operations_menu_item(), and FILE_OT_external_operation().