Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-09-12 10:55:36 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-09-12 10:59:26 +0300
commit29af082e4a0f46659f9c54b435ade36f999baa4b (patch)
tree49c89e5c99bb4f73e4bd69260c39f029496e993d
parent8c1726918374e1d2d2123e17bae8db5aadde3433 (diff)
Fix T70255: Setting file browser bookmark from Python crashes
Support setting bookmarks even when the file browser isn't the active space.
-rw-r--r--source/blender/editors/include/ED_fileselect.h1
-rw-r--r--source/blender/editors/space_file/file_intern.h7
-rw-r--r--source/blender/editors/space_file/file_ops.c39
-rw-r--r--source/blender/editors/space_file/filesel.c29
-rw-r--r--source/blender/makesrna/intern/rna_space.c5
5 files changed, 56 insertions, 25 deletions
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index 47b8eb543f4..341f97943a5 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -150,6 +150,7 @@ int ED_file_extension_icon(const char *path);
void ED_file_read_bookmarks(void);
+void ED_file_change_dir_ex(struct bContext *C, struct bScreen *screen, struct ScrArea *area);
void ED_file_change_dir(struct bContext *C);
void ED_file_path_button(struct bScreen *screen,
diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h
index 44131693628..b459c02d9e5 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -39,6 +39,7 @@ struct View2D;
void file_calc_previews(const bContext *C, ARegion *region);
void file_draw_list(const bContext *C, ARegion *region);
+void file_draw_check_ex(bContext *C, struct ScrArea *area);
void file_draw_check(bContext *C);
void file_draw_check_cb(bContext *C, void *arg1, void *arg2);
bool file_draw_check_exists(SpaceFile *sfile);
@@ -80,13 +81,13 @@ void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but);
int file_highlight_set(struct SpaceFile *sfile, struct ARegion *region, int mx, int my);
void file_sfile_filepath_set(struct SpaceFile *sfile, const char *filepath);
-void file_sfile_to_operator_ex(bContext *C,
+void file_sfile_to_operator_ex(struct Main *bmain,
struct wmOperator *op,
struct SpaceFile *sfile,
char *filepath);
-void file_sfile_to_operator(bContext *C, struct wmOperator *op, struct SpaceFile *sfile);
+void file_sfile_to_operator(struct Main *bmain, struct wmOperator *op, struct SpaceFile *sfile);
-void file_operator_to_sfile(bContext *C, struct SpaceFile *sfile, struct wmOperator *op);
+void file_operator_to_sfile(struct Main *bmain, struct SpaceFile *sfile, struct wmOperator *op);
/* filesel.c */
void fileselect_file_set(SpaceFile *sfile, const int index);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 8c4b2a1b8a6..b3587fc7f97 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -1432,9 +1432,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 +1506,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 +1567,37 @@ 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)
+{
+ SpaceFile *sfile = CTX_wm_space_file(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 +1685,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(),
@@ -2091,6 +2101,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 +2116,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);
}
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 306d6cba50e..9fc4e8936f4 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -828,13 +828,23 @@ FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, ARegion *region)
return sfile->layout;
}
-void ED_file_change_dir(bContext *C)
+/**
+ * Support updating the directory even when this isn't the active space
+ * needed so RNA properties update function isn't context sensitive, see T70255.
+ */
+void ED_file_change_dir_ex(bContext *C, bScreen *screen, ScrArea *area)
{
- wmWindowManager *wm = CTX_wm_manager(C);
- 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;
if (sfile->params) {
- ED_fileselect_clear(wm, CTX_data_scene(C), sfile);
+ wmWindowManager *wm = CTX_wm_manager(C);
+ Scene *scene = WM_windows_scene_get_from_screen(wm, screen);
+ if (LIKELY(scene != NULL)) {
+ ED_fileselect_clear(wm, scene, sfile);
+ }
/* Clear search string, it is very rare to want to keep that filter while changing dir,
* and usually very annoying to keep it actually! */
@@ -853,10 +863,17 @@ void ED_file_change_dir(bContext *C)
folderlist_pushdir(sfile->folders_prev, sfile->params->dir);
- file_draw_check(C);
+ file_draw_check_ex(C, area);
}
}
+void ED_file_change_dir(bContext *C)
+{
+ bScreen *screen = CTX_wm_screen(C);
+ ScrArea *area = CTX_wm_area(C);
+ ED_file_change_dir_ex(C, screen, area);
+}
+
int file_select_match(struct SpaceFile *sfile, const char *pattern, char *matched_file)
{
int match = 0;
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 794b516489a..317759ce418 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2606,9 +2606,10 @@ static void rna_FileBrowser_FSMenu_active_range(PointerRNA *UNUSED(ptr),
*max = *softmax = ED_fsmenu_get_nentries(fsmenu, category) - 1;
}
-static void rna_FileBrowser_FSMenu_active_update(struct bContext *C, PointerRNA *UNUSED(ptr))
+static void rna_FileBrowser_FSMenu_active_update(struct bContext *C, PointerRNA *ptr)
{
- ED_file_change_dir(C);
+ ScrArea *area = rna_area_from_space(ptr);
+ ED_file_change_dir_ex(C, (bScreen *)ptr->owner_id, area);
}
static int rna_FileBrowser_FSMenuSystem_active_get(PointerRNA *ptr)