[Bf-blender-cvs] [0b10a964741] master: Assets: Disable File Browser only operators for asset browsing

Julian Eisel noreply at git.blender.org
Fri Jul 30 19:08:07 CEST 2021


Commit: 0b10a964741d19cf7ada6d72cfaa6ffea9eded4b
Author: Julian Eisel
Date:   Fri Jul 30 19:03:02 2021 +0200
Branches: master
https://developer.blender.org/rB0b10a964741d19cf7ada6d72cfaa6ffea9eded4b

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.

===================================================================

M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/filesel.c

===================================================================

diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index e57e2316d93..82057c726a5 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -140,6 +140,7 @@ void ED_fileselect_clear(struct wmWindowManager *wm, struct SpaceFile *sfile);
 
 void ED_fileselect_exit(struct wmWindowManager *wm, struct SpaceFile *sfile);
 
+bool ED_fileselect_is_file_browser(const struct SpaceFile *sfile);
 bool ED_fileselect_is_asset_browser(const struct SpaceFile *sfile);
 struct ID *ED_fileselect_active_asset_get(const struct SpaceFile *sfile);
 
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 823050b46f7..60ef3e740c6 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -317,6 +317,8 @@ bool ED_operator_animview_active(struct bContext *C);
 bool ED_operator_outliner_active(struct bContext *C);
 bool ED_operator_outliner_active_no_editobject(struct bContext *C);
 bool ED_operator_file_active(struct bContext *C);
+bool ED_operator_file_browsing_active(struct bContext *C);
+bool ED_operator_asset_browsing_active(struct bContext *C);
 bool ED_operator_spreadsheet_active(struct bContext *C);
 bool ED_operator_action_active(struct bContext *C);
 bool ED_operator_buttons_active(struct bContext *C);
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 3d0d856b1c5..8d7d742e44b 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -70,6 +70,7 @@
 #include "ED_anim_api.h"
 #include "ED_armature.h"
 #include "ED_clip.h"
+#include "ED_fileselect.h"
 #include "ED_image.h"
 #include "ED_keyframes_keylist.h"
 #include "ED_mesh.h"
@@ -274,11 +275,37 @@ bool ED_operator_outliner_active_no_editobject(bContext *C)
   return false;
 }
 
+/**
+ * \note Will return true for file spaces in either file or asset browsing mode! See
+ *       #ED_operator_file_browsing_active() (file browsing only) and
+ *       #ED_operator_asset_browsing_active() (asset browsing only).
+ */
 bool ED_operator_file_active(bContext *C)
 {
   return ed_spacetype_test(C, SPACE_FILE);
 }
 
+/**
+ * \note Will only return true if the file space is in file browsing mode, not asset browsing! See
+ *       #ED_operator_file_active() (file or asset browsing) and
+ *       #ED_operator_asset_browsing_active() (asset browsing only).
+ */
+bool ED_operator_file_browsing_active(bContext *C)
+{
+  if (ed_spacetype_test(C, SPACE_FILE)) {
+    return ED_fileselect_is_file_browser(CTX_wm_space_file(C));
+  }
+  return false;
+}
+
+bool ED_operator_asset_browsing_active(bContext *C)
+{
+  if (ed_spacetype_test(C, SPACE_FILE)) {
+    return ED_fileselect_is_asset_browser(CTX_wm_space_file(C));
+  }
+  return false;
+}
+
 bool ED_operator_spreadsheet_active(bContext *C)
 {
   return ed_spacetype_test(C, SPACE_SPREADSHEET);
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 asse

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list