diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2018-06-05 16:10:33 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2018-06-05 17:33:46 +0300 |
commit | 481cdb08ed6f33a09d0e6843d1024db93c301178 (patch) | |
tree | 77166d130bfff2d5dca884676aaeff6bc0758f96 /source/blender/editors/space_file | |
parent | 1d97e948d2c4867306e7fb5ce5fccf8b72c13391 (diff) |
Cleanup: use new accessors to blendfile path (Main.name).
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/file_draw.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_intern.h | 6 | ||||
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 48 | ||||
-rw-r--r-- | source/blender/editors/space_file/filelist.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 12 |
5 files changed, 46 insertions, 31 deletions
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index befdf6751ee..fd9a9ff9ab1 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -412,6 +412,7 @@ static void file_draw_preview( static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) { + Main *bmain = CTX_data_main(C); char newname[FILE_MAX + 12]; char orgname[FILE_MAX + 12]; char filename[FILE_MAX + 12]; @@ -420,10 +421,11 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); - BLI_make_file_string(G.main->name, orgname, sfile->params->dir, oldname); + const char *blendfile_path = BKE_main_blendfile_path(bmain); + BLI_make_file_string(blendfile_path, orgname, sfile->params->dir, oldname); BLI_strncpy(filename, sfile->params->renameedit, sizeof(filename)); BLI_filename_make_safe(filename); - BLI_make_file_string(G.main->name, newname, sfile->params->dir, filename); + BLI_make_file_string(blendfile_path, newname, sfile->params->dir, filename); if (!STREQ(orgname, newname)) { if (!BLI_exists(newname)) { diff --git a/source/blender/editors/space_file/file_intern.h b/source/blender/editors/space_file/file_intern.h index 977d9fe7f3a..742715039cf 100644 --- a/source/blender/editors/space_file/file_intern.h +++ b/source/blender/editors/space_file/file_intern.h @@ -109,9 +109,9 @@ void file_filename_enter_handle(bContext *C, void *arg_unused, void *arg_but); int file_highlight_set(struct SpaceFile *sfile, struct ARegion *ar, int mx, int my); void file_sfile_filepath_set(struct SpaceFile *sfile, const char *filepath); -void file_sfile_to_operator_ex(struct wmOperator *op, struct SpaceFile *sfile, char *filepath); -void file_sfile_to_operator(struct wmOperator *op, struct SpaceFile *sfile); -void file_operator_to_sfile(struct SpaceFile *sfile, struct wmOperator *op); +void file_sfile_to_operator_ex(bContext *C, struct wmOperator *op, struct SpaceFile *sfile, char *filepath); +void file_sfile_to_operator(bContext *C, struct wmOperator *op, struct SpaceFile *sfile); +void file_operator_to_sfile(bContext *C, struct SpaceFile *sfile, struct wmOperator *op); /* filesel.c */ diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 828cca53012..0cd31ce7ca5 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -176,6 +176,7 @@ 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) { + Main *bmain = CTX_data_main(C); FileSelect retval = FILE_SELECT_NOTHING; SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_params(sfile); @@ -213,7 +214,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) } } else { - BLI_cleanup_dir(G.main->name, params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), params->dir); strcat(params->dir, file->relpath); BLI_add_slash(params->dir); } @@ -826,6 +827,7 @@ void FILE_OT_select_all_toggle(wmOperatorType *ot) /* Note we could get rid of this one, but it's used by some addon so... Does not hurt keeping it around for now. */ static int bookmark_select_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); PropertyRNA *prop; @@ -835,7 +837,7 @@ static int bookmark_select_exec(bContext *C, wmOperator *op) RNA_property_string_get(op->ptr, prop, entry); BLI_strncpy(params->dir, entry, sizeof(params->dir)); - BLI_cleanup_dir(G.main->name, params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), params->dir); ED_file_change_dir(C); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); @@ -1200,15 +1202,16 @@ void FILE_OT_cancel(struct wmOperatorType *ot) } -void file_sfile_to_operator_ex(wmOperator *op, SpaceFile *sfile, char *filepath) +void file_sfile_to_operator_ex(bContext *C, wmOperator *op, SpaceFile *sfile, char *filepath) { + Main *bmain = CTX_data_main(C); PropertyRNA *prop; BLI_join_dirfile(filepath, FILE_MAX, sfile->params->dir, sfile->params->file); /* XXX, not real length */ if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) { if (RNA_property_boolean_get(op->ptr, prop)) { - BLI_path_rel(filepath, G.main->name); + BLI_path_rel(filepath, BKE_main_blendfile_path(bmain)); } } @@ -1270,15 +1273,16 @@ void file_sfile_to_operator_ex(wmOperator *op, SpaceFile *sfile, char *filepath) } } -void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile) +void file_sfile_to_operator(bContext *C, wmOperator *op, SpaceFile *sfile) { char filepath[FILE_MAX]; - file_sfile_to_operator_ex(op, sfile, filepath); + file_sfile_to_operator_ex(C, op, sfile, filepath); } -void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op) +void file_operator_to_sfile(bContext *C, SpaceFile *sfile, wmOperator *op) { + Main *bmain = CTX_data_main(C); PropertyRNA *prop; /* If neither of the above are set, split the filepath back */ @@ -1298,7 +1302,7 @@ void file_operator_to_sfile(SpaceFile *sfile, wmOperator *op) /* we could check for relative_path property which is used when converting * in the other direction but doesnt hurt to do this every time */ - BLI_path_abs(sfile->params->dir, G.main->name); + BLI_path_abs(sfile->params->dir, BKE_main_blendfile_path(bmain)); /* XXX, files and dirs updates missing, not really so important though */ } @@ -1330,11 +1334,11 @@ void file_draw_check(bContext *C) wmOperator *op = sfile->op; if (op) { /* fail on reload */ if (op->type->check) { - file_sfile_to_operator(op, sfile); + file_sfile_to_operator(C, op, sfile); /* redraw */ if (op->type->check(C, op)) { - file_operator_to_sfile(sfile, op); + file_operator_to_sfile(C, sfile, op); /* redraw, else the changed settings wont get updated */ ED_area_tag_redraw(CTX_wm_area(C)); @@ -1369,6 +1373,7 @@ bool file_draw_check_exists(SpaceFile *sfile) int file_exec(bContext *C, wmOperator *exec_op) { + Main *bmain = CTX_data_main(C); wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); const struct FileDirEntry *file = filelist_file(sfile->files, sfile->params->active_file); @@ -1384,7 +1389,7 @@ int file_exec(bContext *C, wmOperator *exec_op) BLI_parent_dir(sfile->params->dir); } else { - BLI_cleanup_path(G.main->name, sfile->params->dir); + BLI_cleanup_path(BKE_main_blendfile_path(bmain), sfile->params->dir); BLI_path_append(sfile->params->dir, sizeof(sfile->params->dir) - 1, file->relpath); BLI_add_slash(sfile->params->dir); } @@ -1413,14 +1418,14 @@ int file_exec(bContext *C, wmOperator *exec_op) sfile->op = NULL; - file_sfile_to_operator_ex(op, sfile, filepath); + file_sfile_to_operator_ex(C, op, sfile, filepath); if (BLI_exists(sfile->params->dir)) { fsmenu_insert_entry(ED_fsmenu_get(), FS_CATEGORY_RECENT, sfile->params->dir, NULL, FS_INSERT_SAVE | FS_INSERT_FIRST); } - BLI_make_file_string(G.main->name, filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), + BLI_make_file_string(BKE_main_blendfile_path(bmain), filepath, BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE); fsmenu_write_file(ED_fsmenu_get(), filepath); WM_event_fileselect_event(wm, op, EVT_FILESELECT_EXEC); @@ -1452,11 +1457,12 @@ void FILE_OT_execute(struct wmOperatorType *ot) int file_parent_exec(bContext *C, wmOperator *UNUSED(unused)) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { if (BLI_parent_dir(sfile->params->dir)) { - BLI_cleanup_dir(G.main->name, sfile->params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); ED_file_change_dir(C); if (sfile->params->recursion_level > 1) { /* Disable 'dirtree' recursion when going up in tree. */ @@ -1694,7 +1700,7 @@ static int filepath_drop_exec(bContext *C, wmOperator *op) file_sfile_filepath_set(sfile, filepath); if (sfile->op) { - file_sfile_to_operator(sfile->op, sfile); + file_sfile_to_operator(C, sfile->op, sfile); file_draw_check(C); } @@ -1840,12 +1846,13 @@ void FILE_OT_directory_new(struct wmOperatorType *ot) /* TODO This should go to BLI_path_utils. */ static void file_expand_directory(bContext *C) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { if (BLI_path_is_rel(sfile->params->dir)) { /* Use of 'default' folder here is just to avoid an error message on '//' prefix. */ - BLI_path_abs(sfile->params->dir, G.relbase_valid ? G.main->name : BKE_appdir_folder_default()); + BLI_path_abs(sfile->params->dir, G.relbase_valid ? BKE_main_blendfile_path(bmain) : BKE_appdir_folder_default()); } else if (sfile->params->dir[0] == '~') { char tmpstr[sizeof(sfile->params->dir) - 1]; @@ -1898,6 +1905,7 @@ static bool can_create_dir(const char *dir) void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UNUSED(arg_but)) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); if (sfile->params) { @@ -1928,7 +1936,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN } } - BLI_cleanup_dir(G.main->name, sfile->params->dir); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), sfile->params->dir); if (filelist_is_dir(sfile->files, sfile->params->dir)) { /* if directory exists, enter it immediately */ @@ -1975,6 +1983,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg_but) { + Main *bmain = CTX_data_main(C); SpaceFile *sfile = CTX_wm_space_file(C); uiBut *but = arg_but; char matched_file[FILE_MAX]; @@ -2004,7 +2013,7 @@ void file_filename_enter_handle(bContext *C, void *UNUSED(arg_unused), void *arg /* if directory, open it and empty filename field */ if (filelist_is_dir(sfile->files, filepath)) { - BLI_cleanup_dir(G.main->name, filepath); + BLI_cleanup_dir(BKE_main_blendfile_path(bmain), filepath); BLI_strncpy(sfile->params->dir, filepath, sizeof(sfile->params->dir)); sfile->params->file[0] = '\0'; ED_file_change_dir(C); @@ -2269,6 +2278,7 @@ static int file_delete_poll(bContext *C) int file_delete_exec(bContext *C, wmOperator *op) { char str[FILE_MAX]; + Main *bmain = CTX_data_main(C); wmWindowManager *wm = CTX_wm_manager(C); SpaceFile *sfile = CTX_wm_space_file(C); ScrArea *sa = CTX_wm_area(C); @@ -2281,7 +2291,7 @@ int file_delete_exec(bContext *C, wmOperator *op) for (i = 0; i < numfiles; i++) { if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) { file = filelist_file(sfile->files, i); - BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relpath); + BLI_make_file_string(BKE_main_blendfile_path(bmain), str, sfile->params->dir, file->relpath); if (BLI_delete(str, false, false) != 0 || BLI_exists(str)) { diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index c975479e402..0dd0aca48c6 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -1419,7 +1419,7 @@ void filelist_setdir(struct FileList *filelist, char *r_dir) { BLI_assert(strlen(r_dir) < FILE_MAX_LIBEXTRA); - BLI_cleanup_dir(G.main->name, r_dir); + BLI_cleanup_dir(BKE_main_blendfile_path_from_global(), r_dir); const bool is_valid_path = filelist->checkdirf(filelist, r_dir, true); BLI_assert(is_valid_path); UNUSED_VARS_NDEBUG(is_valid_path); @@ -2700,13 +2700,14 @@ static void filelist_readjob_free(void *flrjv) void filelist_readjob_start(FileList *filelist, const bContext *C) { + Main *bmain = CTX_data_main(C); wmJob *wm_job; FileListReadJob *flrj; /* prepare job data */ flrj = MEM_callocN(sizeof(*flrj), __func__); flrj->filelist = filelist; - BLI_strncpy(flrj->main_name, G.main->name, sizeof(flrj->main_name)); + BLI_strncpy(flrj->main_name, BKE_main_blendfile_path(bmain), sizeof(flrj->main_name)); filelist->flags &= ~(FL_FORCE_RESET | FL_IS_READY); filelist->flags |= FL_IS_PENDING; diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 99307b1961d..4723ee07a7d 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -96,11 +96,13 @@ short ED_fileselect_set_params(SpaceFile *sfile) FileSelectParams *params; wmOperator *op = sfile->op; + const char *blendfile_path = BKE_main_blendfile_path_from_global(); + /* create new parameters if necessary */ if (!sfile->params) { sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams"); /* set path to most recently opened .blend */ - BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); + BLI_split_dirfile(blendfile_path, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file)); sfile->params->filter_glob[0] = '\0'; /* set the default thumbnails size */ sfile->params->thumbnail_size = 128; @@ -149,8 +151,8 @@ short ED_fileselect_set_params(SpaceFile *sfile) } if (params->dir[0]) { - BLI_cleanup_dir(G.main->name, params->dir); - BLI_path_abs(params->dir, G.main->name); + BLI_cleanup_dir(blendfile_path, params->dir); + BLI_path_abs(params->dir, blendfile_path); } if (is_directory == true && is_filename == false && is_filepath == false && is_files == false) { @@ -282,8 +284,8 @@ short ED_fileselect_set_params(SpaceFile *sfile) sfile->folders_prev = folderlist_new(); if (!sfile->params->dir[0]) { - if (G.main->name[0]) { - BLI_split_dir_part(G.main->name, sfile->params->dir, sizeof(sfile->params->dir)); + if (blendfile_path[0] != '\0') { + BLI_split_dir_part(blendfile_path, sfile->params->dir, sizeof(sfile->params->dir)); } else { const char *doc_path = BKE_appdir_folder_default(); |