Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_file/file_ops.c
| Show First 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | if (file->typeflag & FILE_TYPE_DIR) { | ||||
| ED_file_change_dir(C); | ED_file_change_dir(C); | ||||
| retval = FILE_SELECT_DIR; | retval = FILE_SELECT_DIR; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| retval = FILE_SELECT_FILE; | retval = FILE_SELECT_FILE; | ||||
| } | } | ||||
| fileselect_file_set(sfile, selected_idx); | fileselect_file_set(C, sfile, selected_idx); | ||||
| } | } | ||||
| return retval; | return retval; | ||||
| } | } | ||||
| /** | /** | ||||
| * \warning Loops over all files so better use cautiously. | * \warning Loops over all files so better use cautiously. | ||||
| */ | */ | ||||
| static bool file_is_any_selected(struct FileList *files) | static bool file_is_any_selected(struct FileList *files) | ||||
| ▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | if (result == OPERATOR_RUNNING_MODAL) { | ||||
| } | } | ||||
| params->sel_first = sel.first; | params->sel_first = sel.first; | ||||
| params->sel_last = sel.last; | params->sel_last = sel.last; | ||||
| params->active_file = file_box_select_find_last_selected(sfile, region, &sel, event->mval); | params->active_file = file_box_select_find_last_selected(sfile, region, &sel, event->mval); | ||||
| } | } | ||||
| else { | else { | ||||
| params->highlight_file = -1; | params->highlight_file = -1; | ||||
| params->sel_first = params->sel_last = -1; | params->sel_first = params->sel_last = -1; | ||||
| fileselect_file_set(sfile, params->active_file); | fileselect_file_set(C, sfile, params->active_file); | ||||
| file_select_deselect_all(sfile, FILE_SEL_HIGHLIGHTED); | file_select_deselect_all(sfile, FILE_SEL_HIGHLIGHTED); | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| static int file_box_select_exec(bContext *C, wmOperator *op) | static int file_box_select_exec(bContext *C, wmOperator *op) | ||||
| ▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Select Walk Operator | /** \name Select Walk Operator | ||||
| * \{ */ | * \{ */ | ||||
| /** | /** | ||||
| * \returns true if selection has changed | * \returns true if selection has changed | ||||
| */ | */ | ||||
| static bool file_walk_select_selection_set(wmWindow *win, | static bool file_walk_select_selection_set(struct bContext* C, | ||||
| wmWindow *win, | |||||
| ARegion *region, | ARegion *region, | ||||
| SpaceFile *sfile, | SpaceFile *sfile, | ||||
| const int direction, | const int direction, | ||||
| const int numfiles, | const int numfiles, | ||||
| const int active_old, | const int active_old, | ||||
| const int active_new, | const int active_new, | ||||
| const int other_site, | const int other_site, | ||||
| const bool has_selection, | const bool has_selection, | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | if (fill) { | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| filelist_entry_select_index_set( | filelist_entry_select_index_set( | ||||
| files, active, deselect ? FILE_SEL_REMOVE : FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL); | files, active, deselect ? FILE_SEL_REMOVE : FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL); | ||||
| } | } | ||||
| BLI_assert(IN_RANGE(active, -1, numfiles)); | BLI_assert(IN_RANGE(active, -1, numfiles)); | ||||
| fileselect_file_set(sfile, params->active_file); | fileselect_file_set(C, sfile, params->active_file); | ||||
| /* ensure newly selected file is inside viewbounds */ | /* ensure newly selected file is inside viewbounds */ | ||||
| file_ensure_inside_viewbounds(region, sfile, params->active_file); | file_ensure_inside_viewbounds(region, sfile, params->active_file); | ||||
| /* selection changed */ | /* selection changed */ | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | if (!IN_RANGE(active_new, -1, numfiles)) { | ||||
| active_new = active_old; | active_new = active_old; | ||||
| } | } | ||||
| } | } | ||||
| if (!IN_RANGE(other_site, 0, numfiles)) { | if (!IN_RANGE(other_site, 0, numfiles)) { | ||||
| other_site = -1; | other_site = -1; | ||||
| } | } | ||||
| } | } | ||||
| return file_walk_select_selection_set(win, | return file_walk_select_selection_set(C, | ||||
| win, | |||||
| region, | region, | ||||
| sfile, | sfile, | ||||
| direction, | direction, | ||||
| numfiles, | numfiles, | ||||
| active_old, | active_old, | ||||
| active_new, | active_new, | ||||
| other_site, | other_site, | ||||
| has_selection, | has_selection, | ||||
| ▲ Show 20 Lines • Show All 649 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Operator Utilities | /** \name Operator Utilities | ||||
| * \{ */ | * \{ */ | ||||
| void file_sfile_to_operator_ex(Main *bmain, wmOperator *op, SpaceFile *sfile, char *filepath) | void file_sfile_to_operator_ex(bContext* C, Main *bmain, wmOperator *op, SpaceFile *sfile, char *filepath) | ||||
| { | { | ||||
| FileSelectParams *params = ED_fileselect_get_active_params(sfile); | FileSelectParams *params = ED_fileselect_get_active_params(sfile); | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* XXX, not real length */ | /* XXX, not real length */ | ||||
| BLI_join_dirfile(filepath, FILE_MAX, params->dir, params->file); | BLI_join_dirfile(filepath, FILE_MAX, params->dir, params->file); | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) { | if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) { | ||||
| if (RNA_property_boolean_get(op->ptr, prop)) { | if (RNA_property_boolean_get(op->ptr, prop)) { | ||||
| BLI_path_rel(filepath, BKE_main_blendfile_path(bmain)); | BLI_path_rel(filepath, BKE_main_blendfile_path(bmain)); | ||||
| } | } | ||||
| } | } | ||||
| char value[FILE_MAX]; | |||||
| if ((prop = RNA_struct_find_property(op->ptr, "filename"))) { | if ((prop = RNA_struct_find_property(op->ptr, "filename"))) { | ||||
| RNA_property_string_get(op->ptr, prop, value); | |||||
| RNA_property_string_set(op->ptr, prop, params->file); | RNA_property_string_set(op->ptr, prop, params->file); | ||||
| if (RNA_property_update_check(prop) && !STREQ(params->file, value)) { | |||||
| RNA_property_update(C, op->ptr, prop); | |||||
| } | |||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "directory"))) { | if ((prop = RNA_struct_find_property(op->ptr, "directory"))) { | ||||
| RNA_property_string_get(op->ptr, prop, value); | |||||
| RNA_property_string_set(op->ptr, prop, params->dir); | RNA_property_string_set(op->ptr, prop, params->dir); | ||||
| if (RNA_property_update_check(prop) && !STREQ(params->dir, value)) { | |||||
| RNA_property_update(C, op->ptr, prop); | |||||
| } | |||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) { | if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) { | ||||
| RNA_property_string_get(op->ptr, prop, value); | |||||
| RNA_property_string_set(op->ptr, prop, filepath); | RNA_property_string_set(op->ptr, prop, filepath); | ||||
| if (RNA_property_update_check(prop) && !STREQ(filepath, value)) { | |||||
| RNA_property_update(C, op->ptr, prop); | |||||
| } | |||||
cmbasnett: Note to reviewer: special care is taken here not to send update events if the value hasn't… | |||||
| } | } | ||||
| /* some ops have multiple files to select */ | /* some ops have multiple files to select */ | ||||
| /* this is called on operators check() so clear collections first since | /* this is called on operators check() so clear collections first since | ||||
| * they may be already set. */ | * they may be already set. */ | ||||
| { | { | ||||
| int i, numfiles = filelist_files_ensure(sfile->files); | int i, numfiles = filelist_files_ensure(sfile->files); | ||||
| Show All 37 Lines | if ((prop = RNA_struct_find_property(op->ptr, "dirs"))) { | ||||
| * directory selected */ | * directory selected */ | ||||
| if (0 == num_dirs) { | if (0 == num_dirs) { | ||||
| RNA_property_collection_add(op->ptr, prop, &itemptr); | RNA_property_collection_add(op->ptr, prop, &itemptr); | ||||
| RNA_string_set(&itemptr, "name", params->dir); | RNA_string_set(&itemptr, "name", params->dir); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void file_sfile_to_operator(Main *bmain, wmOperator *op, SpaceFile *sfile) | void file_sfile_to_operator(bContext *C, Main *bmain, wmOperator *op, SpaceFile *sfile) | ||||
| { | { | ||||
| char filepath_dummy[FILE_MAX]; | char filepath_dummy[FILE_MAX]; | ||||
| file_sfile_to_operator_ex(bmain, op, sfile, filepath_dummy); | file_sfile_to_operator_ex(C, bmain, op, sfile, filepath_dummy); | ||||
| } | } | ||||
| void file_operator_to_sfile(Main *bmain, SpaceFile *sfile, wmOperator *op) | void file_operator_to_sfile(Main *bmain, SpaceFile *sfile, wmOperator *op) | ||||
| { | { | ||||
| FileSelectParams *params = ED_fileselect_get_active_params(sfile); | FileSelectParams *params = ED_fileselect_get_active_params(sfile); | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* If neither of the above are set, split the filepath back */ | /* If neither of the above are set, split the filepath back */ | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | void file_draw_check_ex(bContext *C, ScrArea *area) | ||||
| if (UNLIKELY(area->spacetype != SPACE_FILE)) { | if (UNLIKELY(area->spacetype != SPACE_FILE)) { | ||||
| return; | return; | ||||
| } | } | ||||
| SpaceFile *sfile = area->spacedata.first; | SpaceFile *sfile = area->spacedata.first; | ||||
| wmOperator *op = sfile->op; | wmOperator *op = sfile->op; | ||||
| if (op) { /* fail on reload */ | if (op) { /* fail on reload */ | ||||
| if (op->type->check) { | if (op->type->check) { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| file_sfile_to_operator(bmain, op, sfile); | file_sfile_to_operator(C, bmain, op, sfile); | ||||
| /* redraw */ | /* redraw */ | ||||
| if (op->type->check(C, op)) { | if (op->type->check(C, op)) { | ||||
| file_operator_to_sfile(bmain, sfile, op); | file_operator_to_sfile(bmain, sfile, op); | ||||
| /* redraw, else the changed settings won't get updated */ | /* redraw, else the changed settings won't get updated */ | ||||
| ED_area_tag_redraw(area); | ED_area_tag_redraw(area); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | static bool file_execute(bContext *C, SpaceFile *sfile) | ||||
| else if (sfile->op) { | else if (sfile->op) { | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| struct FSMenu *fsmenu = ED_fsmenu_get(); | struct FSMenu *fsmenu = ED_fsmenu_get(); | ||||
| wmOperator *op = sfile->op; | wmOperator *op = sfile->op; | ||||
| char filepath[FILE_MAX]; | char filepath[FILE_MAX]; | ||||
| sfile->op = NULL; | sfile->op = NULL; | ||||
| file_sfile_to_operator_ex(bmain, op, sfile, filepath); | file_sfile_to_operator_ex(C, bmain, op, sfile, filepath); | ||||
| if (BLI_exists(params->dir)) { | if (BLI_exists(params->dir)) { | ||||
| fsmenu_insert_entry(fsmenu, | fsmenu_insert_entry(fsmenu, | ||||
| FS_CATEGORY_RECENT, | FS_CATEGORY_RECENT, | ||||
| params->dir, | params->dir, | ||||
| NULL, | NULL, | ||||
| ICON_FILE_FOLDER, | ICON_FILE_FOLDER, | ||||
| FS_INSERT_SAVE | FS_INSERT_FIRST); | FS_INSERT_SAVE | FS_INSERT_FIRST); | ||||
| ▲ Show 20 Lines • Show All 448 Lines • ▼ Show 20 Lines | if (sfile) { | ||||
| if (!BLI_exists(filepath)) { | if (!BLI_exists(filepath)) { | ||||
| BKE_report(op->reports, RPT_ERROR, "File does not exist"); | BKE_report(op->reports, RPT_ERROR, "File does not exist"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| file_sfile_filepath_set(sfile, filepath); | file_sfile_filepath_set(sfile, filepath); | ||||
| if (sfile->op) { | if (sfile->op) { | ||||
| file_sfile_to_operator(bmain, sfile->op, sfile); | file_sfile_to_operator(C, bmain, sfile->op, sfile); | ||||
| file_draw_check(C); | file_draw_check(C); | ||||
| } | } | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| ▲ Show 20 Lines • Show All 725 Lines • Show Last 20 Lines | |||||
Note to reviewer: special care is taken here not to send update events if the value hasn't actually changed. Otherwise, the update function is spammed every time the UI is redrawn.