[Bf-blender-cvs] [420cc8a0934] blender-projects-basics: Add operator to open project settings window (like preferences)

Julian Eisel noreply at git.blender.org
Mon Oct 3 22:41:30 CEST 2022


Commit: 420cc8a093410807c732a628e08bd425cb0e80cb
Author: Julian Eisel
Date:   Mon Oct 3 22:40:44 2022 +0200
Branches: blender-projects-basics
https://developer.blender.org/rB420cc8a093410807c732a628e08bd425cb0e80cb

Add operator to open project settings window (like preferences)

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

M	release/scripts/startup/bl_ui/space_topbar.py
M	source/blender/editors/screen/screen_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index aedd9dfb41f..e42e6c80fd6 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -618,6 +618,7 @@ class TOPBAR_MT_edit(Menu):
 
         layout.operator("screen.userpref_show",
                         text="Preferences...", icon='PREFERENCES')
+        layout.operator("screen.project_settings_show", text="Project Settings...")
 
 
 class TOPBAR_MT_window(Menu):
@@ -743,6 +744,7 @@ class TOPBAR_MT_file_context_menu(Menu):
 
         layout.operator("screen.userpref_show",
                         text="Preferences...", icon='PREFERENCES')
+        layout.operator("screen.project_settings_show", text="Project Settings...")
 
 
 class TOPBAR_MT_workspace_menu(Menu):
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index e04cf5c6d68..22a4c33e10b 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -5032,7 +5032,14 @@ static void SCREEN_OT_back_to_previous(struct wmOperatorType *ot)
 /** \name Show User Preferences Operator
  * \{ */
 
-static int userpref_show_exec(bContext *C, wmOperator *op)
+/**
+ * Shared window opening logic for preferences and project settings.
+ * \return True on success.
+ */
+static bool settings_window_show(bContext *C,
+                                 eSpace_Type space_type,
+                                 const char *window_title,
+                                 ReportList *reports)
 {
   wmWindow *win_cur = CTX_wm_window(C);
   /* Use eventstate, not event from _invoke, so this can be called through exec(). */
@@ -5040,26 +5047,14 @@ static int userpref_show_exec(bContext *C, wmOperator *op)
   int sizex = (500 + UI_NAVIGATION_REGION_WIDTH) * UI_DPI_FAC;
   int sizey = 520 * UI_DPI_FAC;
 
-  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "section");
-  if (prop && RNA_property_is_set(op->ptr, prop)) {
-    /* Set active section via RNA, so it can fail properly. */
-
-    PointerRNA pref_ptr;
-    RNA_pointer_create(NULL, &RNA_Preferences, &U, &pref_ptr);
-    PropertyRNA *active_section_prop = RNA_struct_find_property(&pref_ptr, "active_section");
-
-    RNA_property_enum_set(&pref_ptr, active_section_prop, RNA_property_enum_get(op->ptr, prop));
-    RNA_property_update(C, &pref_ptr, active_section_prop);
-  }
-
   /* changes context! */
   if (WM_window_open(C,
-                     IFACE_("Blender Preferences"),
+                     window_title,
                      event->xy[0],
                      event->xy[1],
                      sizex,
                      sizey,
-                     SPACE_USERPREF,
+                     space_type,
                      false,
                      false,
                      true,
@@ -5068,18 +5063,43 @@ static int userpref_show_exec(bContext *C, wmOperator *op)
      * So hiding in the temp window makes sense. */
     ScrArea *area = CTX_wm_area(C);
     ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
-
-    region->flag |= RGN_FLAG_HIDDEN;
-    ED_region_visibility_change_update(C, area, region);
+    if (region) {
+      region->flag |= RGN_FLAG_HIDDEN;
+      ED_region_visibility_change_update(C, area, region);
+    }
 
     /* And also show the region with "Load & Save" buttons. */
     region = BKE_area_find_region_type(area, RGN_TYPE_EXECUTE);
-    region->flag &= ~RGN_FLAG_HIDDEN;
-    ED_region_visibility_change_update(C, area, region);
+    if (region) {
+      region->flag &= ~RGN_FLAG_HIDDEN;
+      ED_region_visibility_change_update(C, area, region);
+    }
+
+    return true;
+  }
+
+  BKE_report(reports, RPT_ERROR, "Failed to open window!");
+  return false;
+}
+
+static int userpref_show_exec(bContext *C, wmOperator *op)
+{
+  PropertyRNA *prop = RNA_struct_find_property(op->ptr, "section");
+  if (prop && RNA_property_is_set(op->ptr, prop)) {
+    /* Set active section via RNA, so it can fail properly. */
 
+    PointerRNA pref_ptr;
+    RNA_pointer_create(NULL, &RNA_Preferences, &U, &pref_ptr);
+    PropertyRNA *active_section_prop = RNA_struct_find_property(&pref_ptr, "active_section");
+
+    RNA_property_enum_set(&pref_ptr, active_section_prop, RNA_property_enum_get(op->ptr, prop));
+    RNA_property_update(C, &pref_ptr, active_section_prop);
+  }
+
+  if (settings_window_show(C, SPACE_USERPREF, IFACE_("Blender Preferences"), op->reports)) {
     return OPERATOR_FINISHED;
   }
-  BKE_report(op->reports, RPT_ERROR, "Failed to open window!");
+
   return OPERATOR_CANCELLED;
 }
 
@@ -5107,6 +5127,34 @@ static void SCREEN_OT_userpref_show(struct wmOperatorType *ot)
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Show Project Settings Operator
+ * \{ */
+
+static int project_settings_show_exec(bContext *C, wmOperator *op)
+{
+  if (settings_window_show(
+          C, SPACE_PROJECT_SETTINGS, IFACE_("Blender Project Settings"), op->reports)) {
+    return OPERATOR_FINISHED;
+  }
+
+  return OPERATOR_CANCELLED;
+}
+
+static void SCREEN_OT_project_settings_show(struct wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Open Project Settings...";
+  ot->description = "Edit configuration for the active Blender project";
+  ot->idname = "SCREEN_OT_project_settings_show";
+
+  /* api callbacks */
+  ot->exec = project_settings_show_exec;
+  ot->poll = ED_operator_screenactive_nobackground; /* Not in background as this opens a window. */
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Show Drivers Editor Operator
  * \{ */
@@ -5695,6 +5743,7 @@ void ED_operatortypes_screen(void)
   WM_operatortype_append(SCREEN_OT_screenshot);
   WM_operatortype_append(SCREEN_OT_screenshot_area);
   WM_operatortype_append(SCREEN_OT_userpref_show);
+  WM_operatortype_append(SCREEN_OT_project_settings_show);
   WM_operatortype_append(SCREEN_OT_drivers_editor_show);
   WM_operatortype_append(SCREEN_OT_info_log_show);
   WM_operatortype_append(SCREEN_OT_region_blend);



More information about the Bf-blender-cvs mailing list