diff options
Diffstat (limited to 'source/blender/editors/space_file/file_ops.c')
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 331 |
1 files changed, 176 insertions, 155 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 0584e2ff938..844514759f3 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, @@ -239,7 +230,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) { @@ -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); @@ -522,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; @@ -544,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); @@ -554,26 +546,47 @@ 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"); + 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; 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. */ + } + else if (wait_to_deselect_others && is_selected) { + ret_val = OPERATOR_RUNNING_MODAL; + } /* single select, deselect all selected first */ - if (!extend) { - file_deselect_all(sfile, FILE_SEL_SELECTED); + else if (!extend) { + file_select_deselect_all(sfile, FILE_SEL_SELECTED); } } } @@ -588,7 +601,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) { @@ -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 OPERATOR_FINISHED; + if ((ret_val == OPERATOR_FINISHED) && pass_through) { + ret_val |= OPERATOR_PASS_THROUGH; + } + return ret_val; } void FILE_OT_select(wmOperatorType *ot) @@ -614,10 +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, @@ -635,6 +655,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); } /** \} */ @@ -721,7 +755,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; @@ -873,6 +907,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 */ @@ -960,6 +995,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 */ @@ -1012,6 +1048,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; } @@ -1023,7 +1060,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); @@ -1056,7 +1092,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", ""); @@ -1102,7 +1139,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; } /** \} */ @@ -1156,7 +1194,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); @@ -1214,7 +1253,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 */ } @@ -1302,8 +1342,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! */ @@ -1350,7 +1391,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; } /** \} */ @@ -1365,7 +1407,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 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; } @@ -1405,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; } @@ -1423,6 +1467,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; } @@ -1474,6 +1519,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; @@ -1487,7 +1533,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) { @@ -1810,7 +1856,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; } /** @@ -1865,7 +1911,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; } @@ -1882,7 +1928,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); @@ -1904,7 +1950,36 @@ void FILE_OT_refresh(struct wmOperatorType *ot) /* api callbacks */ ot->exec = file_refresh_exec; - 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; } /** \} */ @@ -1944,7 +2019,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 */ } /** \} */ @@ -1979,7 +2055,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 */ } /** \} */ @@ -2015,7 +2092,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 */ } /** \} */ @@ -2059,13 +2137,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 +2153,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; } @@ -2093,7 +2172,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( @@ -2131,13 +2210,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; } @@ -2207,7 +2284,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; } @@ -2251,7 +2328,8 @@ void FILE_OT_filepath_drop(wmOperatorType *ot) ot->idname = "FILE_OT_filepath_drop"; ot->exec = filepath_drop_exec; - ot->poll = WM_operator_winactive; + /* 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, "", ""); } @@ -2346,21 +2424,22 @@ 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_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); - 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, CTX_data_scene(C), sfile); + ED_fileselect_clear(wm, sfile); if (do_diropen) { BLI_strncpy(params->dir, path, sizeof(params->dir)); @@ -2384,7 +2463,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"); @@ -2400,7 +2480,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); @@ -2411,12 +2491,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') @@ -2441,7 +2523,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) { @@ -2507,7 +2589,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)) { @@ -2611,7 +2693,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); } @@ -2627,44 +2709,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 */ -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \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; + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; /* <- important, handler is on window level */ } /** \} */ @@ -2677,7 +2723,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; } @@ -2776,20 +2823,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); @@ -2797,7 +2830,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); } @@ -2812,9 +2845,9 @@ void FILE_OT_rename(struct wmOperatorType *ot) ot->idname = "FILE_OT_rename"; /* api callbacks */ - ot->invoke = file_rename_invoke; ot->exec = file_rename_exec; - ot->poll = ED_operator_file_active; + /* File browsing only operator (not asset browsing). */ + ot->poll = ED_operator_file_browsing_active; } /** \} */ @@ -2825,53 +2858,40 @@ 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_browsing_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, 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; @@ -2908,7 +2928,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; @@ -2964,6 +2984,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; } |