From 461717274091113112416d2733d4b44eacb57017 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 1 Jul 2021 15:09:08 +0200 Subject: Fix race condition when loading multiple File/Asset Browsers at once When multiple File or Asset Browsers would load at once (e.g. when loading a file with two File Browsers open) and they would load multiple directories or .blend files (using the Recursions option in the File Browser or loading an asset library with multiple .blends), often only one File/Asset Browser would correctly load all files. Others would be incomplete or entirely empty. That was because of a race condition, where the directories or .blend files would be loaded concurrently and the first one that finished would cancel the other ones. This again happened because they used the job system with the same "owner", which by design makes all jobs with the same owner cancel as soon as the first is finished. Address this by making sure they have different owners. That is, not the scene anymore, but the filelist the job belongs to. Doesn't make much sense to use the scene as owner for scene-unrelated file loading anyway. Steps to reproduce were: * Open two File Browsers as regular editors. * In the Display Settings popover, set "Recursions" to 2 or 3 levels. * Navigate to a directory with plenty of subdirectories in both File Browsers. * Save the file. * Reload the file, one of the File Browsers likely has an incomplete file list. Alternatively, use Asset Browsers and open an asset library containing multiple .blends. --- source/blender/editors/space_file/file_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 0584e2ff938..1ba1c1d6954 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1882,7 +1882,7 @@ static int file_refresh_exec(bContext *C, wmOperator *UNUSED(unused)) SpaceFile *sfile = CTX_wm_space_file(C); struct FSMenu *fsmenu = ED_fsmenu_get(); - ED_fileselect_clear(wm, CTX_data_scene(C), sfile); + ED_fileselect_clear(wm, sfile); /* refresh system directory menu */ fsmenu_refresh_system_category(fsmenu); @@ -2360,7 +2360,7 @@ static int file_directory_new_exec(bContext *C, wmOperator *op) sfile->scroll_offset = 0; /* reload dir to make sure we're seeing what's in the directory */ - ED_fileselect_clear(wm, CTX_data_scene(C), sfile); + ED_fileselect_clear(wm, sfile); if (do_diropen) { BLI_strncpy(params->dir, path, sizeof(params->dir)); @@ -2611,7 +2611,7 @@ static int file_hidedot_exec(bContext *C, wmOperator *UNUSED(unused)) if (params) { params->flag ^= FILE_HIDE_DOT; - ED_fileselect_clear(wm, CTX_data_scene(C), sfile); + ED_fileselect_clear(wm, sfile); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); } @@ -2908,7 +2908,7 @@ static int file_delete_exec(bContext *C, wmOperator *op) } } - ED_fileselect_clear(wm, CTX_data_scene(C), sfile); + ED_fileselect_clear(wm, sfile); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); return OPERATOR_FINISHED; -- cgit v1.2.3 From 9b89de2571b0c3fa2276b5c2ae589e0ec831d1f5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 3 Jul 2021 23:08:40 +1000 Subject: Cleanup: consistent use of tags: NOTE/TODO/FIXME/XXX Also use doxy style function reference `#` prefix chars when referencing identifiers. --- source/blender/editors/space_file/file_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 1ba1c1d6954..60e79a6f563 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1023,7 +1023,7 @@ void FILE_OT_view_selected(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. */ -/* TODO disallow bookmark editing in assets mode? */ +/* TODO: disallow bookmark editing in assets mode? */ static int bookmark_select_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); @@ -2093,7 +2093,7 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w sfile->layout, (int)region->v2d.cur.xmin, (int)-region->v2d.cur.ymax); const int last_visible_item = first_visible_item + numfiles_layout + 1; - /* Note: the special case for vertical layout is because filename is at the bottom of items then, + /* NOTE: the special case for vertical layout is because filename is at the bottom of items then, * so we artificially move current row back one step, to ensure we show bottom of * active item rather than its top (important in case visible height is low). */ const int middle_offset = max_ii( @@ -2400,7 +2400,7 @@ void FILE_OT_directory_new(struct wmOperatorType *ot) /** \name Refresh File List Operator * \{ */ -/* TODO This should go to BLI_path_utils. */ +/* TODO: This should go to BLI_path_utils. */ static void file_expand_directory(bContext *C) { Main *bmain = CTX_data_main(C); @@ -2441,7 +2441,7 @@ static void file_expand_directory(bContext *C) } } -/* TODO check we still need this, it's annoying to have OS-specific code here... :/ */ +/* TODO: check we still need this, it's annoying to have OS-specific code here... :/. */ #if defined(WIN32) static bool can_create_dir(const char *dir) { -- cgit v1.2.3 From 2eca9c7ed4e9819564a7be474e281e6f3b296107 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 5 Jul 2021 13:30:47 +0200 Subject: Cleanup: Move common File Browser renaming code into functions Code would manually do the same things in a couple of places, obvious case of unnecessary code duplication. --- source/blender/editors/space_file/file_ops.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 60e79a6f563..49c3a29b67b 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2059,13 +2059,15 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w } } + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = CTX_wm_window(C); + /* if we are not editing, we are done */ if (edit_idx == -1) { /* Do not invalidate timer if filerename is still pending, * we might still be building the filelist and yet have to find edited entry. */ if (params->rename_flag == 0) { - WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); - sfile->smoothscroll_timer = NULL; + file_params_smoothscroll_timer_clear(wm, win, sfile); } return OPERATOR_PASS_THROUGH; } @@ -2073,8 +2075,7 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w /* we need the correct area for scrolling */ region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW); if (!region || region->regiontype != RGN_TYPE_WINDOW) { - WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); - sfile->smoothscroll_timer = NULL; + file_params_smoothscroll_timer_clear(wm, win, sfile); return OPERATOR_PASS_THROUGH; } @@ -2131,13 +2132,11 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w (max_middle_offset - middle_offset < items_block_size)); if (is_ready && (is_centered || is_full_start || is_full_end)) { - WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer); - sfile->smoothscroll_timer = NULL; + file_params_smoothscroll_timer_clear(wm, win, sfile); /* Post-scroll (after rename has been validated by user) is done, * rename process is totally finished, cleanup. */ if ((params->rename_flag & FILE_PARAMS_RENAME_POSTSCROLL_ACTIVE) != 0) { - params->renamefile[0] = '\0'; - params->rename_flag = 0; + file_params_renamefile_clear(params); } return OPERATOR_FINISHED; } @@ -2346,18 +2345,16 @@ static int file_directory_new_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + eFileSel_Params_RenameFlag rename_flag = params->rename_flag; + /* If we don't enter the directory directly, remember file to jump into editing. */ if (do_diropen == false) { BLI_strncpy(params->renamefile, name, FILE_MAXFILE); - params->rename_flag = FILE_PARAMS_RENAME_PENDING; + rename_flag = FILE_PARAMS_RENAME_PENDING; } - /* Set timer to smoothly view newly generated file. */ - if (sfile->smoothscroll_timer != NULL) { - WM_event_remove_timer(wm, CTX_wm_window(C), sfile->smoothscroll_timer); - } - sfile->smoothscroll_timer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER1, 1.0 / 1000.0); - sfile->scroll_offset = 0; + file_params_invoke_rename_postscroll(wm, CTX_wm_window(C), sfile); + params->rename_flag = rename_flag; /* reload dir to make sure we're seeing what's in the directory */ ED_fileselect_clear(wm, sfile); -- cgit v1.2.3 From cadda7aa5cd557fd34cddf58b9f4bb2e8db52847 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 5 Jul 2021 16:02:56 +0200 Subject: Assets: Disable file renaming operator for Asset Browsers This operator only works with renaming files, not assets. --- source/blender/editors/space_file/file_ops.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 49c3a29b67b..612f3a67aa3 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2801,6 +2801,11 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } +static bool file_rename_poll(bContext *C) +{ + return ED_operator_file_active(C) && !ED_fileselect_is_asset_browser(CTX_wm_space_file(C)); +} + void FILE_OT_rename(struct wmOperatorType *ot) { /* identifiers */ @@ -2811,7 +2816,7 @@ void FILE_OT_rename(struct wmOperatorType *ot) /* api callbacks */ ot->invoke = file_rename_invoke; ot->exec = file_rename_exec; - ot->poll = ED_operator_file_active; + ot->poll = file_rename_poll; } /** \} */ -- cgit v1.2.3 From 5bbbc98471a5b8c8384789a4f88d112d003a6350 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 7 Jul 2021 12:55:19 +1000 Subject: Cleanup: spelling in comments --- source/blender/editors/space_file/file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 612f3a67aa3..d91cc0f0b54 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -239,7 +239,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen) } /** - * \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) { -- cgit v1.2.3 From 13672f8b3244c7c834789f3edb058d938bdd1168 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 7 Jul 2021 18:15:16 +0200 Subject: Cleanup: Move file deselection function to more appropriate file `filesel.c` seems like the place that should contain file selection functions. Previously it was in `file_ops.c` because that was the only file that actually used it. But a followup commit needs it from a different file. --- source/blender/editors/space_file/file_ops.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index d91cc0f0b54..aeb6c7fd521 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -104,15 +104,6 @@ static FileSelection find_file_mouse_rect(SpaceFile *sfile, return sel; } -static void file_deselect_all(SpaceFile *sfile, uint flag) -{ - FileSelection sel; - sel.first = 0; - sel.last = filelist_files_ensure(sfile->files) - 1; - - filelist_entries_select_index_range_set(sfile->files, &sel, FILE_SEL_REMOVE, flag, CHECK_ALL); -} - typedef enum FileSelect { FILE_SELECT_NOTHING = 0, FILE_SELECT_DIR = 1, @@ -444,7 +435,7 @@ static int file_box_select_modal(bContext *C, wmOperator *op, const wmEvent *eve if ((sel.first != params->sel_first) || (sel.last != params->sel_last)) { int idx; - file_deselect_all(sfile, FILE_SEL_HIGHLIGHTED); + file_select_deselect_all(sfile, FILE_SEL_HIGHLIGHTED); filelist_entries_select_index_range_set( sfile->files, &sel, FILE_SEL_ADD, FILE_SEL_HIGHLIGHTED, CHECK_ALL); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); @@ -472,7 +463,7 @@ static int file_box_select_modal(bContext *C, wmOperator *op, const wmEvent *eve params->highlight_file = -1; params->sel_first = params->sel_last = -1; fileselect_file_set(sfile, params->active_file); - file_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); } @@ -491,7 +482,7 @@ static int file_box_select_exec(bContext *C, wmOperator *op) const eSelectOp sel_op = RNA_enum_get(op->ptr, "mode"); const bool select = (sel_op != SEL_OP_SUB); if (SEL_OP_USE_PRE_DESELECT(sel_op)) { - file_deselect_all(sfile, FILE_SEL_SELECTED); + file_select_deselect_all(sfile, FILE_SEL_SELECTED); } ED_fileselect_layout_isect_rect(sfile->layout, ®ion->v2d, &rect, &rect); @@ -573,7 +564,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) if ((idx >= 0) && (idx < numfiles)) { /* single select, deselect all selected first */ if (!extend) { - file_deselect_all(sfile, FILE_SEL_SELECTED); + file_select_deselect_all(sfile, FILE_SEL_SELECTED); } } } @@ -588,7 +579,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) if (ret == FILE_SELECT_NOTHING) { if (deselect_all) { - file_deselect_all(sfile, FILE_SEL_SELECTED); + file_select_deselect_all(sfile, FILE_SEL_SELECTED); } } else if (ret == FILE_SELECT_DIR) { @@ -721,7 +712,7 @@ static bool file_walk_select_selection_set(wmWindow *win, } else { /* deselect all first */ - file_deselect_all(sfile, FILE_SEL_SELECTED); + file_select_deselect_all(sfile, FILE_SEL_SELECTED); /* highlight file under mouse pos */ params->highlight_file = -1; -- cgit v1.2.3 From f4cb3ccd9c070dce24db98436ccf2e0e70000077 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 7 Jul 2021 19:24:06 +0200 Subject: Assets: Keep assets active after renaming, ensure they are scrolled into view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When renaming an ID somewhere in the UI after marking it as asset, it would often get lost in the Asset Browser (scrolled out of view). It would also get deactivated. This patch makes sure that if an asset is active whose ID gets renamed, it is kept active and visible. That is important for a fast, uninterrupted asset creation workflow, where users often rename assets while working in the asset browser. Old code stored the new file-name to identify a file after re-reading the file-list after the rename. For assets that doesn't work because there may be multiple assets with the same name. Here the simple solution of just storing the pointer to the renamed ID is chosen, rather than relying on the file-name in this case. (Should be fine with undo, since the ID * reference is short lived, it's not stored over possible undo steps. If it turns out to have issues, I rather switch to a rename_id_uuid, but keep that separate from the file->uid). Reviewed by: Sybren Stüvel Differential Revision: https://developer.blender.org/D11119 --- source/blender/editors/space_file/file_ops.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index aeb6c7fd521..995383d9d0e 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2340,6 +2340,7 @@ static int file_directory_new_exec(bContext *C, wmOperator *op) /* If we don't enter the directory directly, remember file to jump into editing. */ if (do_diropen == false) { + BLI_assert(params->rename_id == NULL || !"File rename handling should immediately clear rename_id when done, because otherwise it will keep taking precedence over renamefile."); BLI_strncpy(params->renamefile, name, FILE_MAXFILE); rename_flag = FILE_PARAMS_RENAME_PENDING; } -- cgit v1.2.3 From 63da2c4082a432379fc7fa4ed0d2c34b4cb2858d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 22 Jul 2021 00:46:45 +1000 Subject: Cleanup: replace BLI_assert(test || !"text") with BLI_assert_msg(test, text) --- source/blender/editors/space_file/file_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 995383d9d0e..4d25524cd19 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2340,7 +2340,9 @@ static int file_directory_new_exec(bContext *C, wmOperator *op) /* If we don't enter the directory directly, remember file to jump into editing. */ if (do_diropen == false) { - BLI_assert(params->rename_id == NULL || !"File rename handling should immediately clear rename_id when done, because otherwise it will keep taking precedence over renamefile."); + BLI_assert_msg(params->rename_id == NULL, + "File rename handling should immediately clear rename_id when done, " + "because otherwise it will keep taking precedence over renamefile."); BLI_strncpy(params->renamefile, name, FILE_MAXFILE); rename_flag = FILE_PARAMS_RENAME_PENDING; } -- cgit v1.2.3 From 3316e28418a2ce624c61324d8d3fd284afabf71b Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 30 Jul 2021 16:23:17 +0200 Subject: Preferences: Move "Register File Association" to preferences level The operator was register as a "file" operator, which are by convention used for File Browser operators only. Move it to the "preferences" operators, where it's displayed in the UI too. --- source/blender/editors/space_file/file_ops.c | 37 ---------------------------- 1 file changed, 37 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 4d25524cd19..e65156167a9 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2623,43 +2623,6 @@ void FILE_OT_hidedot(struct wmOperatorType *ot) /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Associate File Type Operator (Windows only) - * \{ */ - -static int associate_blend_exec(bContext *UNUSED(C), wmOperator *op) -{ -#ifdef WIN32 - WM_cursor_wait(true); - if (BLI_windows_register_blend_extension(true)) { - BKE_report(op->reports, RPT_INFO, "File association registered"); - WM_cursor_wait(false); - return OPERATOR_FINISHED; - } - else { - BKE_report(op->reports, RPT_ERROR, "Unable to register file association"); - WM_cursor_wait(false); - return OPERATOR_CANCELLED; - } -#else - BKE_report(op->reports, RPT_WARNING, "Operator Not supported"); - return OPERATOR_CANCELLED; -#endif -} - -void FILE_OT_associate_blend(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Register File Association"; - ot->description = "Use this installation for .blend files and to display thumbnails"; - ot->idname = "FILE_OT_associate_blend"; - - /* api callbacks */ - ot->exec = associate_blend_exec; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Increment Filename Operator * \{ */ -- cgit v1.2.3 From b90887da5a37088d295fe86445cf62c9fc8fdea4 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 30 Jul 2021 18:39:45 +0200 Subject: Cleanup: Refactor logic of file deletion poll callback * Early exit instead of complex if-else blocks. * Avoid iterating over entire file list. * Use `true`/`false` for boolean values. * Declare variables in smaller scopes. --- source/blender/editors/space_file/file_ops.c | 37 +++++++++++++--------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index e65156167a9..7c608e2115d 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2784,33 +2784,30 @@ void FILE_OT_rename(struct wmOperatorType *ot) static bool file_delete_poll(bContext *C) { - bool poll = ED_operator_file_active(C); + if (!ED_operator_file_active(C)) { + return false; + } + SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_active_params(sfile); + if (!sfile || !params) { + return false; + } - if (sfile && params) { - char dir[FILE_MAX_LIBEXTRA]; - int numfiles = filelist_files_ensure(sfile->files); - int i; - int num_selected = 0; + char dir[FILE_MAX_LIBEXTRA]; + if (filelist_islibrary(sfile->files, dir, NULL)) { + return false; + } - if (filelist_islibrary(sfile->files, dir, NULL)) { - poll = 0; - } - for (i = 0; i < numfiles; i++) { - if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL)) { - num_selected++; - } - } - if (num_selected <= 0) { - poll = 0; + int numfiles = filelist_files_ensure(sfile->files); + for (int i = 0; i < numfiles; i++) { + if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL)) { + /* Has a selected file -> the operator can run. */ + return true; } } - else { - poll = 0; - } - return poll; + return false; } static bool file_delete_single(const FileSelectParams *params, -- cgit v1.2.3 From f7836019b37152558f6808f81eea6344aa8d9608 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 30 Jul 2021 18:55:03 +0200 Subject: Fix incorrect poll function used for file path dropping The operator to drop file paths into the File Browser was just checking if there's an active window. This wasn't really an issue since the operator was only used as drop-operator for the File Browser. But the operator would show up in the operator search. Plus, for asset browsing, we'll also have to check the file browsing mode, so the more specific poll function will be needed. --- source/blender/editors/space_file/file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 7c608e2115d..ac59b4ce7b5 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2241,7 +2241,7 @@ void FILE_OT_filepath_drop(wmOperatorType *ot) ot->idname = "FILE_OT_filepath_drop"; ot->exec = filepath_drop_exec; - ot->poll = WM_operator_winactive; + ot->poll = ED_operator_file_active; RNA_def_string_file_path(ot->srna, "filepath", "Path", FILE_MAX, "", ""); } -- cgit v1.2.3 From 0b10a964741d19cf7ada6d72cfaa6ffea9eded4b Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 30 Jul 2021 19:03:02 +0200 Subject: Assets: Disable File Browser only operators for asset browsing These operators shouldn't be available in the Asset Browser. https://developer.blender.org/T83556 Added a comment to each operator poll assignment to explicitly mention the intention. That should also remind devs to decide if the operator should apply for both file & asset browsing when copy & pasting operator definition code. --- source/blender/editors/space_file/file_ops.c | 67 +++++++++++++++++----------- 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index ac59b4ce7b5..616e7fe51db 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -513,6 +513,7 @@ void FILE_OT_select_box(wmOperatorType *ot) ot->invoke = WM_gesture_box_invoke; ot->exec = file_box_select_exec; ot->modal = file_box_select_modal; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; ot->cancel = WM_gesture_box_cancel; @@ -606,6 +607,7 @@ void FILE_OT_select(wmOperatorType *ot) /* api callbacks */ ot->invoke = file_select_invoke; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; /* properties */ @@ -864,6 +866,7 @@ void FILE_OT_select_walk(wmOperatorType *ot) /* api callbacks */ ot->invoke = file_walk_select_invoke; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; /* properties */ @@ -951,6 +954,7 @@ void FILE_OT_select_all(wmOperatorType *ot) /* api callbacks */ ot->exec = file_select_all_exec; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; /* properties */ @@ -1003,6 +1007,7 @@ void FILE_OT_view_selected(wmOperatorType *ot) /* api callbacks */ ot->exec = file_view_selected_exec; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; } @@ -1014,7 +1019,6 @@ void FILE_OT_view_selected(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. */ -/* TODO: disallow bookmark editing in assets mode? */ static int bookmark_select_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); @@ -1047,7 +1051,8 @@ void FILE_OT_select_bookmark(wmOperatorType *ot) /* api callbacks */ ot->exec = bookmark_select_exec; - ot->poll = ED_operator_file_active; + /* Bookmarks are for file browsing only (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* properties */ prop = RNA_def_string(ot->srna, "dir", NULL, FILE_MAXDIR, "Directory", ""); @@ -1093,7 +1098,8 @@ void FILE_OT_bookmark_add(wmOperatorType *ot) /* api callbacks */ ot->exec = bookmark_add_exec; - ot->poll = ED_operator_file_active; + /* Bookmarks are for file browsing only (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; } /** \} */ @@ -1147,7 +1153,8 @@ void FILE_OT_bookmark_delete(wmOperatorType *ot) /* api callbacks */ ot->exec = bookmark_delete_exec; - ot->poll = ED_operator_file_active; + /* Bookmarks are for file browsing only (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* properties */ prop = RNA_def_int(ot->srna, "index", -1, -1, 20000, "Index", "", -1, 20000); @@ -1205,7 +1212,8 @@ void FILE_OT_bookmark_cleanup(wmOperatorType *ot) /* api callbacks */ ot->exec = bookmark_cleanup_exec; - ot->poll = ED_operator_file_active; + /* Bookmarks are for file browsing only (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* properties */ } @@ -1293,8 +1301,9 @@ void FILE_OT_bookmark_move(wmOperatorType *ot) ot->description = "Move the active bookmark up/down in the list"; /* api callbacks */ - ot->poll = ED_operator_file_active; ot->exec = bookmark_move_exec; + /* Bookmarks are for file browsing only (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* flags */ ot->flag = OPTYPE_REGISTER; /* No undo! */ @@ -1341,7 +1350,8 @@ void FILE_OT_reset_recent(wmOperatorType *ot) /* api callbacks */ ot->exec = reset_recent_exec; - ot->poll = ED_operator_file_active; + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; } /** \} */ @@ -1414,6 +1424,7 @@ void FILE_OT_highlight(struct wmOperatorType *ot) /* api callbacks */ ot->invoke = file_highlight_invoke; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; } @@ -1465,6 +1476,7 @@ void FILE_OT_sort_column_ui_context(wmOperatorType *ot) /* api callbacks */ ot->invoke = file_column_sort_ui_context_invoke; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; ot->flag = OPTYPE_INTERNAL; @@ -1478,7 +1490,7 @@ void FILE_OT_sort_column_ui_context(wmOperatorType *ot) static bool file_operator_poll(bContext *C) { - bool poll = ED_operator_file_active(C); + bool poll = ED_operator_file_browsing_active(C); SpaceFile *sfile = CTX_wm_space_file(C); if (!sfile || !sfile->op) { @@ -1801,7 +1813,7 @@ void FILE_OT_execute(struct wmOperatorType *ot) * * Avoid using #file_operator_poll since this is also used for entering directories * which is used even when the file manager doesn't have an operator. */ - ot->poll = ED_operator_file_active; + ot->poll = ED_operator_file_browsing_active; } /** @@ -1856,7 +1868,7 @@ void FILE_OT_mouse_execute(wmOperatorType *ot) /* api callbacks */ ot->invoke = file_execute_mouse_invoke; - ot->poll = ED_operator_file_active; + ot->poll = ED_operator_file_browsing_active; ot->flag = OPTYPE_INTERNAL; } @@ -1895,6 +1907,7 @@ void FILE_OT_refresh(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_refresh_exec; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ } @@ -1935,7 +1948,8 @@ void FILE_OT_parent(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_parent_exec; - ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */ } /** \} */ @@ -1970,7 +1984,8 @@ void FILE_OT_previous(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_previous_exec; - ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */ } /** \} */ @@ -2006,7 +2021,8 @@ void FILE_OT_next(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_next_exec; - ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */ } /** \} */ @@ -2197,7 +2213,7 @@ void FILE_OT_smoothscroll(wmOperatorType *ot) /* api callbacks */ ot->invoke = file_smoothscroll_invoke; - + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; } @@ -2241,7 +2257,8 @@ void FILE_OT_filepath_drop(wmOperatorType *ot) ot->idname = "FILE_OT_filepath_drop"; ot->exec = filepath_drop_exec; - ot->poll = ED_operator_file_active; + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; RNA_def_string_file_path(ot->srna, "filepath", "Path", FILE_MAX, "", ""); } @@ -2375,7 +2392,8 @@ void FILE_OT_directory_new(struct wmOperatorType *ot) /* api callbacks */ ot->invoke = WM_operator_confirm_or_exec; ot->exec = file_directory_new_exec; - ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */ prop = RNA_def_string_dir_path( ot->srna, "directory", NULL, FILE_MAX, "Directory", "Name of new directory"); @@ -2618,7 +2636,8 @@ void FILE_OT_hidedot(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_hidedot_exec; - ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */ } /** \} */ @@ -2631,7 +2650,8 @@ static bool file_filenum_poll(bContext *C) { SpaceFile *sfile = CTX_wm_space_file(C); - if (!ED_operator_file_active(C)) { + /* File browsing only operator (not asset browsing). */ + if (!ED_operator_file_browsing_active(C)) { return false; } @@ -2758,11 +2778,6 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } -static bool file_rename_poll(bContext *C) -{ - return ED_operator_file_active(C) && !ED_fileselect_is_asset_browser(CTX_wm_space_file(C)); -} - void FILE_OT_rename(struct wmOperatorType *ot) { /* identifiers */ @@ -2773,7 +2788,8 @@ void FILE_OT_rename(struct wmOperatorType *ot) /* api callbacks */ ot->invoke = file_rename_invoke; ot->exec = file_rename_exec; - ot->poll = file_rename_poll; + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; } /** \} */ @@ -2784,7 +2800,7 @@ void FILE_OT_rename(struct wmOperatorType *ot) static bool file_delete_poll(bContext *C) { - if (!ED_operator_file_active(C)) { + if (!ED_operator_file_browsing_active(C)) { return false; } @@ -2920,6 +2936,7 @@ void FILE_OT_start_filter(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_start_filter_exec; + /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; } -- cgit v1.2.3 From 3ff5d8f719f592c2ea17533532708e883a8baa96 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 2 Aug 2021 16:59:10 +0200 Subject: Asset Browser: Proper context menu for assets Add a context menu dedicated to asset operations to the Asset Browser. There are two separate context menus to keep things separated well and avoid confusing if-else logic (similar to D12057 & D12059). Their polls make sure they are displayed for the right contexts only. Also (to be committed as followup cleanup): Remove now unused special handling for assets in file delete operator. Differential Revision: https://developer.blender.org/D12062 --- source/blender/editors/space_file/file_ops.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 616e7fe51db..944eb9988fa 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2830,20 +2830,10 @@ static bool file_delete_single(const FileSelectParams *params, FileDirEntry *file, const char **r_error_message) { - if (file->typeflag & FILE_TYPE_ASSET) { - ID *id = filelist_file_get_id(file); - if (!id) { - *r_error_message = "File is not a local data-block asset."; - return false; - } - ED_asset_clear_id(id); - } - else { - char str[FILE_MAX]; - BLI_join_dirfile(str, sizeof(str), params->dir, file->relpath); - if (BLI_delete_soft(str, r_error_message) != 0 || BLI_exists(str)) { - return false; - } + char str[FILE_MAX]; + BLI_join_dirfile(str, sizeof(str), params->dir, file->relpath); + if (BLI_delete_soft(str, r_error_message) != 0 || BLI_exists(str)) { + return false; } return true; -- cgit v1.2.3 From aab7540b7a4460fdc414857493fa1c6cc5d7d972 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 10 Aug 2021 12:00:27 +0200 Subject: Fix crash: mouse is over file space during startup. When blender starts and the mouse is over a file/asset browser it crashes. This is because blender wants to highlight a file, but the layout isn't initialized yet. --- source/blender/editors/space_file/file_ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 944eb9988fa..c7e5f744455 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1366,7 +1366,9 @@ int file_highlight_set(SpaceFile *sfile, ARegion *region, int mx, int my) FileSelectParams *params; int numfiles, origfile; - if (sfile == NULL || sfile->files == NULL) { + /* In case blender starts where the mouse is over a File broser, this operator can be invoked + * when the sfile or sfile->layout isn't initialized yet. */ + if (sfile == NULL || sfile->files == NULL || sfile->layout == NULL) { return 0; } -- cgit v1.2.3 From 05879f2c36e9e59ca62011aafb266a7b8dd64656 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 10 Aug 2021 12:54:06 +0200 Subject: File/Asset Browser: Select/Activate File on Right Click for Context Menu Right clicking would spawn the context menu under the cursor, but some operators would actually act on the active asset/file which wasn't the one clicked on. When multiple files are selected and one of them is right-clicked on, selection is not changed to allow operations on multiple files. E.g. deletion. This makes the File/Asset Browser match the Outliner (in behavior, not implementation). For the right-click selection keymap: * The context menu still only spawns on W. * Bonus: Right click now does something, it actually selects files! I could have done additional changes here to avoid this, but it seems like a good addition. This is also a better alternative to rB5edfde58fe60, which didn't work properly either. Using rename from the context menu would only work if the clicked on file was also active... Differential Revision: https://developer.blender.org/D12065 Reviewed by: Campbell Barton --- source/blender/editors/space_file/file_ops.c | 43 ++++++++++++++++------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index c7e5f744455..d1ef1b33023 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -546,6 +546,9 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool fill = RNA_boolean_get(op->ptr, "fill"); const bool do_diropen = RNA_boolean_get(op->ptr, "open"); const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all"); + const bool only_activate_if_selected = RNA_boolean_get(op->ptr, "only_activate_if_selected"); + /* Used so right mouse clicks can do both, activate and spawn the context menu. */ + const bool pass_through = RNA_boolean_get(op->ptr, "pass_through"); if (region->regiontype != RGN_TYPE_WINDOW) { return OPERATOR_CANCELLED; @@ -563,8 +566,13 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) int numfiles = filelist_files_ensure(sfile->files); if ((idx >= 0) && (idx < numfiles)) { + const bool is_selected = filelist_entry_select_index_get(sfile->files, idx, CHECK_ALL) & + FILE_SEL_SELECTED; + if (only_activate_if_selected && is_selected) { + /* Don't deselect other items. */ + } /* single select, deselect all selected first */ - if (!extend) { + else if (!extend) { file_select_deselect_all(sfile, FILE_SEL_SELECTED); } } @@ -593,7 +601,7 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) WM_event_add_mousemove(CTX_wm_window(C)); /* for directory changes */ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); - return OPERATOR_FINISHED; + return pass_through ? (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH) : OPERATOR_FINISHED; } void FILE_OT_select(wmOperatorType *ot) @@ -628,6 +636,20 @@ void FILE_OT_select(wmOperatorType *ot) "Deselect On Nothing", "Deselect all when nothing under the cursor"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, + "only_activate_if_selected", + false, + "Only Activate if Selected", + "Do not change selection if the item under the cursor is already " + "selected, only activate it"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, + "pass_through", + false, + "Pass Through", + "Even on successful execution, pass the event on so other operators can " + "execute on it as well"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN); } /** \} */ @@ -2752,20 +2774,6 @@ static void file_rename_state_activate(SpaceFile *sfile, int file_idx, bool requ } } -static int file_rename_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) -{ - ScrArea *area = CTX_wm_area(C); - SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C); - FileSelectParams *params = ED_fileselect_get_active_params(sfile); - - if (params) { - file_rename_state_activate(sfile, params->active_file, true); - ED_area_tag_redraw(area); - } - - return OPERATOR_FINISHED; -} - static int file_rename_exec(bContext *C, wmOperator *UNUSED(op)) { ScrArea *area = CTX_wm_area(C); @@ -2773,7 +2781,7 @@ static int file_rename_exec(bContext *C, wmOperator *UNUSED(op)) FileSelectParams *params = ED_fileselect_get_active_params(sfile); if (params) { - file_rename_state_activate(sfile, params->highlight_file, false); + file_rename_state_activate(sfile, params->active_file, false); ED_area_tag_redraw(area); } @@ -2788,7 +2796,6 @@ void FILE_OT_rename(struct wmOperatorType *ot) ot->idname = "FILE_OT_rename"; /* api callbacks */ - ot->invoke = file_rename_invoke; ot->exec = file_rename_exec; /* File browsing only operator (not asset browsing). */ ot->poll = ED_operator_file_browsing_active; -- cgit v1.2.3 From 1ef275963d1cfa257de184f38a2abb04a5df3ac7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 12 Aug 2021 14:34:41 +1000 Subject: Cleanup: use C++ style comments for disabled code --- source/blender/editors/space_file/file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index d1ef1b33023..08d741545a8 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2540,7 +2540,7 @@ void file_directory_enter_handle(bContext *C, void *UNUSED(arg_unused), void *UN /* don't do for now because it selects entire text instead of * placing cursor at the end */ - /* UI_textbutton_activate_but(C, but); */ + // UI_textbutton_activate_but(C, but); } #if defined(WIN32) else if (!can_create_dir(params->dir)) { -- cgit v1.2.3 From c741558509a35317209bbfd3ff77c413f791a47c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 12 Aug 2021 14:34:43 +1000 Subject: Cleanup: spelling in comments --- source/blender/editors/space_file/file_ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 08d741545a8..2f1acd2ca4d 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1388,8 +1388,8 @@ int file_highlight_set(SpaceFile *sfile, ARegion *region, int mx, int my) FileSelectParams *params; int numfiles, origfile; - /* In case blender starts where the mouse is over a File broser, this operator can be invoked - * when the sfile or sfile->layout isn't initialized yet. */ + /* In case blender starts where the mouse is over a File browser, + * this operator can be invoked when the `sfile` or `sfile->layout` isn't initialized yet. */ if (sfile == NULL || sfile->files == NULL || sfile->layout == NULL) { return 0; } -- cgit v1.2.3 From 847d355cab47bca3a2afa1c516dcd712c321b856 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 27 Sep 2021 18:45:49 +0200 Subject: File/Asset Browser: Don't deselect other items when dragging Basically this enables the select-tweaking behavior as per the guidelines: https://wiki.blender.org/wiki/Human_Interface_Guidelines/Selection#Select-tweaking. We use this in most other other editors that allow selecting and dragging multiple items. But besides the consistency improvement, this is important if we want to support dragging multiple assets (or files) in future. We want to support this at least for dragging multiple assets into an asset catalog for the upcoming asset catalog UI. --- source/blender/editors/space_file/file_ops.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 2f1acd2ca4d..d0f2a4fdc4c 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -536,7 +536,7 @@ static rcti file_select_mval_to_select_rect(const int mval[2]) return rect; } -static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) +static int file_select_exec(bContext *C, wmOperator *op) { ARegion *region = CTX_wm_region(C); SpaceFile *sfile = CTX_wm_space_file(C); @@ -549,17 +549,27 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) const bool only_activate_if_selected = RNA_boolean_get(op->ptr, "only_activate_if_selected"); /* Used so right mouse clicks can do both, activate and spawn the context menu. */ const bool pass_through = RNA_boolean_get(op->ptr, "pass_through"); + bool wait_to_deselect_others = RNA_boolean_get(op->ptr, "wait_to_deselect_others"); if (region->regiontype != RGN_TYPE_WINDOW) { return OPERATOR_CANCELLED; } - rect = file_select_mval_to_select_rect(event->mval); + int mval[2]; + mval[0] = RNA_int_get(op->ptr, "mouse_x"); + mval[1] = RNA_int_get(op->ptr, "mouse_y"); + rect = file_select_mval_to_select_rect(mval); if (!ED_fileselect_layout_is_inside_pt(sfile->layout, ®ion->v2d, rect.xmin, rect.ymin)) { return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } + if (extend || fill) { + wait_to_deselect_others = false; + } + + int ret_val = OPERATOR_FINISHED; + const FileSelectParams *params = ED_fileselect_get_active_params(sfile); if (sfile && params) { int idx = params->highlight_file; @@ -571,6 +581,9 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) if (only_activate_if_selected && is_selected) { /* Don't deselect other items. */ } + else if (wait_to_deselect_others && is_selected) { + ret_val = OPERATOR_RUNNING_MODAL; + } /* single select, deselect all selected first */ else if (!extend) { file_select_deselect_all(sfile, FILE_SEL_SELECTED); @@ -601,7 +614,10 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) WM_event_add_mousemove(CTX_wm_window(C)); /* for directory changes */ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); - return pass_through ? (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH) : OPERATOR_FINISHED; + if ((ret_val == OPERATOR_FINISHED) && pass_through) { + ret_val |= OPERATOR_PASS_THROUGH; + } + return ret_val; } void FILE_OT_select(wmOperatorType *ot) @@ -614,11 +630,14 @@ void FILE_OT_select(wmOperatorType *ot) ot->description = "Handle mouse clicks to select and activate items"; /* api callbacks */ - ot->invoke = file_select_invoke; + ot->invoke = WM_generic_select_invoke; + ot->exec = file_select_exec; + ot->modal = WM_generic_select_modal; /* Operator works for file or asset browsing */ ot->poll = ED_operator_file_active; /* properties */ + WM_operator_properties_generic_select(ot); prop = RNA_def_boolean(ot->srna, "extend", false, -- cgit v1.2.3 From 2743d746ea4f38c098512f6dd6fc33d5a62429d3 Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Wed, 20 Oct 2021 23:45:30 +1100 Subject: Cleanup: use an array for wmEvent cursor position variables Use arrays for wmEvent coordinates, this quiets warnings with GCC11. - `x, y` -> `xy`. - `prevx, prevy` -> `prev_xy`. - `prevclickx, prevclicky` -> `prev_click_xy`. There is still some cleanup such as using `copy_v2_v2_int()`, this can be done separately. Reviewed By: campbellbarton, Severin Ref D12901 --- source/blender/editors/space_file/file_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index d0f2a4fdc4c..f647e1d4e4f 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1449,7 +1449,7 @@ static int file_highlight_invoke(bContext *C, wmOperator *UNUSED(op), const wmEv ARegion *region = CTX_wm_region(C); SpaceFile *sfile = CTX_wm_space_file(C); - if (!file_highlight_set(sfile, region, event->x, event->y)) { + if (!file_highlight_set(sfile, region, event->xy[0], event->xy[1])) { return OPERATOR_PASS_THROUGH; } -- cgit v1.2.3 From dcdbaf89bd114aaf066cec57bb619b828c159719 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 29 Oct 2021 16:45:08 +0200 Subject: Asset Browser: Correct name & tooltip for asset list refresh operator The name and tooltip were talking about file-lists, which exposes the fact that the Asset Browser uses the File Browser code in the UI, which we shouldn't do. This can confuse users. Instead have a dedicated operator for the Asset Browser with a proper name and tooltip. --- source/blender/editors/space_file/file_ops.c | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index f647e1d4e4f..4eb10e65867 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1950,8 +1950,36 @@ void FILE_OT_refresh(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_refresh_exec; - /* Operator works for file or asset browsing */ - ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ + ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */ +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Refresh Asset Library Operator + * \{ */ + +static int file_asset_library_refresh_exec(bContext *C, wmOperator *UNUSED(unused)) +{ + wmWindowManager *wm = CTX_wm_manager(C); + SpaceFile *sfile = CTX_wm_space_file(C); + + ED_fileselect_clear(wm, sfile); + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); + + return OPERATOR_FINISHED; +} + +void FILE_OT_asset_library_refresh(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Refresh Asset Library"; + ot->description = "Reread assets and asset catalogs from the asset library on disk"; + ot->idname = "FILE_OT_asset_library_refresh"; + + /* api callbacks */ + ot->exec = file_asset_library_refresh_exec; + ot->poll = ED_operator_asset_browsing_active; } /** \} */ -- cgit v1.2.3 From a0633e2484f21c9f80842c10b46b3af98b54d25a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 1 Nov 2021 13:09:02 +1100 Subject: Fix crash when "HOME" environment variable isn't defined Accessing the default directory in the file selector would crash if HOME was undefined. Add BKE_appdir_folder_default_or_root which never returns NULL. --- source/blender/editors/space_file/file_ops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/space_file/file_ops.c') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index f647e1d4e4f..a83e1974baf 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2463,12 +2463,14 @@ static void file_expand_directory(bContext *C) if (BLI_path_is_rel(params->dir)) { /* Use of 'default' folder here is just to avoid an error message on '//' prefix. */ BLI_path_abs(params->dir, - G.relbase_valid ? BKE_main_blendfile_path(bmain) : BKE_appdir_folder_default()); + G.relbase_valid ? BKE_main_blendfile_path(bmain) : + BKE_appdir_folder_default_or_root()); } else if (params->dir[0] == '~') { char tmpstr[sizeof(params->dir) - 1]; BLI_strncpy(tmpstr, params->dir + 1, sizeof(tmpstr)); - BLI_join_dirfile(params->dir, sizeof(params->dir), BKE_appdir_folder_default(), tmpstr); + BLI_path_join( + params->dir, sizeof(params->dir), BKE_appdir_folder_default_or_root(), tmpstr, NULL); } else if (params->dir[0] == '\0') -- cgit v1.2.3