diff options
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 8c4b2a1b8a6..93367ad3d3c 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1351,18 +1351,17 @@ static int file_column_sort_ui_context_invoke(bContext *C, if (column_type != COLUMN_NONE) { const FileAttributeColumn *column = &sfile->layout->attribute_columns[column_type]; - if (column->sort_type != FILE_SORT_NONE) { - if (sfile->params->sort == column->sort_type) { - /* Already sorting by selected column -> toggle sort invert (three state logic). */ - sfile->params->flag ^= FILE_SORT_INVERT; - } - else { - sfile->params->sort = column->sort_type; - sfile->params->flag &= ~FILE_SORT_INVERT; - } - - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); + BLI_assert(column->sort_type != FILE_SORT_DEFAULT); + if (sfile->params->sort == column->sort_type) { + /* Already sorting by selected column -> toggle sort invert (three state logic). */ + sfile->params->flag ^= FILE_SORT_INVERT; } + else { + sfile->params->sort = column->sort_type; + sfile->params->flag &= ~FILE_SORT_INVERT; + } + + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); } } @@ -1432,9 +1431,8 @@ void FILE_OT_cancel(struct wmOperatorType *ot) /** \name Operator Utilities * \{ */ -void file_sfile_to_operator_ex(bContext *C, wmOperator *op, SpaceFile *sfile, char *filepath) +void file_sfile_to_operator_ex(Main *bmain, wmOperator *op, SpaceFile *sfile, char *filepath) { - Main *bmain = CTX_data_main(C); PropertyRNA *prop; /* XXX, not real length */ @@ -1507,16 +1505,15 @@ void file_sfile_to_operator_ex(bContext *C, wmOperator *op, SpaceFile *sfile, ch } } } -void file_sfile_to_operator(bContext *C, wmOperator *op, SpaceFile *sfile) +void file_sfile_to_operator(Main *bmain, wmOperator *op, SpaceFile *sfile) { - char filepath[FILE_MAX]; + char filepath_dummy[FILE_MAX]; - file_sfile_to_operator_ex(C, op, sfile, filepath); + file_sfile_to_operator_ex(bmain, op, sfile, filepath_dummy); } -void file_operator_to_sfile(bContext *C, SpaceFile *sfile, wmOperator *op) +void file_operator_to_sfile(Main *bmain, SpaceFile *sfile, wmOperator *op) { - Main *bmain = CTX_data_main(C); PropertyRNA *prop; /* If neither of the above are set, split the filepath back */ @@ -1569,25 +1566,36 @@ void file_sfile_filepath_set(SpaceFile *sfile, const char *filepath) } } -void file_draw_check(bContext *C) +void file_draw_check_ex(bContext *C, ScrArea *area) { - SpaceFile *sfile = CTX_wm_space_file(C); + /* May happen when manipulating non-active spaces. */ + if (UNLIKELY(area->spacetype != SPACE_FILE)) { + return; + } + SpaceFile *sfile = area->spacedata.first; wmOperator *op = sfile->op; if (op) { /* fail on reload */ if (op->type->check) { - file_sfile_to_operator(C, op, sfile); + Main *bmain = CTX_data_main(C); + file_sfile_to_operator(bmain, op, sfile); /* redraw */ if (op->type->check(C, op)) { - file_operator_to_sfile(C, sfile, op); + file_operator_to_sfile(bmain, sfile, op); /* redraw, else the changed settings wont get updated */ - ED_area_tag_redraw(CTX_wm_area(C)); + ED_area_tag_redraw(area); } } } } +void file_draw_check(bContext *C) +{ + ScrArea *area = CTX_wm_area(C); + file_draw_check_ex(C, area); +} + /* for use with; UI_block_func_set */ void file_draw_check_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2)) { @@ -1675,7 +1683,7 @@ static int file_exec(bContext *C, wmOperator *exec_op) sfile->op = NULL; - file_sfile_to_operator_ex(C, op, sfile, filepath); + file_sfile_to_operator_ex(bmain, op, sfile, filepath); if (BLI_exists(sfile->params->dir)) { fsmenu_insert_entry(ED_fsmenu_get(), @@ -1868,7 +1876,7 @@ static int file_next_exec(bContext *C, wmOperator *UNUSED(unused)) folderlist_pushdir(sfile->folders_prev, sfile->params->dir); folderlist_popdir(sfile->folders_next, sfile->params->dir); - // update folders_prev so we can check for it in folderlist_clear_next() + /* update folders_prev so we can check for it in #folderlist_clear_next() */ folderlist_pushdir(sfile->folders_prev, sfile->params->dir); ED_file_change_dir(C); @@ -2091,6 +2099,7 @@ void FILE_OT_smoothscroll(wmOperatorType *ot) static int filepath_drop_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile) { @@ -2105,7 +2114,7 @@ static int filepath_drop_exec(bContext *C, wmOperator *op) file_sfile_filepath_set(sfile, filepath); if (sfile->op) { - file_sfile_to_operator(C, sfile->op, sfile); + file_sfile_to_operator(bmain, sfile->op, sfile); file_draw_check(C); } @@ -2299,7 +2308,7 @@ static void file_expand_directory(bContext *C) { BLI_windows_get_default_root_dir(sfile->params->dir); } - /* change "C:" --> "C:\", [#28102] */ + /* change "C:" --> "C:\", T28102. */ else if ((isalpha(sfile->params->dir[0]) && (sfile->params->dir[1] == ':')) && (sfile->params->dir[2] == '\0')) { sfile->params->dir[2] = '\\'; @@ -2405,7 +2414,8 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN WM_operator_properties_create_ptr(&ptr, ot); RNA_string_set(&ptr, "directory", sfile->params->dir); RNA_boolean_set(&ptr, "open", true); - /* Enable confirmation prompt, else it's too easy to accidentaly create new directories. */ + /* Enable confirmation prompt, else it's too easy + * to accidentally create new directories. */ RNA_boolean_set(&ptr, "confirm", true); if (lastdir) { |