[Bf-blender-cvs] [525f24f1ba5] blender-projects-basics: Disable buttons if no project is loaded, always show hint then

Julian Eisel noreply at git.blender.org
Thu Oct 6 17:04:05 CEST 2022


Commit: 525f24f1ba54e56ad8f85837af1a905c12332384
Author: Julian Eisel
Date:   Thu Oct 6 16:58:57 2022 +0200
Branches: blender-projects-basics
https://developer.blender.org/rB525f24f1ba54e56ad8f85837af1a905c12332384

Disable buttons if no project is loaded, always show hint then

Disable the navigation and "Save Settings" buttons when there is no
active project.

The message saying that no project is loaded always shows up now, even
if the UI somehow displays a section that is not the "General" one.

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

M	release/scripts/startup/bl_ui/space_project_settings.py
M	source/blender/editors/space_project_settings/space_project_settings.cc
M	source/blender/windowmanager/intern/wm_files.c

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

diff --git a/release/scripts/startup/bl_ui/space_project_settings.py b/release/scripts/startup/bl_ui/space_project_settings.py
index 0a099cf2c1a..cfed8889580 100644
--- a/release/scripts/startup/bl_ui/space_project_settings.py
+++ b/release/scripts/startup/bl_ui/space_project_settings.py
@@ -52,8 +52,10 @@ class PROJECTSETTINGS_PT_navigation_bar(Panel):
         layout = self.layout
 
         space_data = context.space_data
+        project = context.project
 
         col = layout.column()
+        col.enabled = project is not None
 
         col.scale_x = 1.3
         col.scale_y = 1.3
@@ -99,6 +101,25 @@ class PROJECTSETTINGS_PT_save_project_settings(Panel):
 
         PROJECTSETTINGS_HT_header.draw_buttons(layout, context)
 
+
+class PROJECTSETTINGS_PT_no_project(CenterAlignMixIn, Panel):
+    bl_space_type = 'PROJECT_SETTINGS'
+    bl_region_type = 'WINDOW'
+    # Special hardcoded context.
+    bl_context = "no_project"
+    bl_label = "No Project"
+    bl_options = {'HIDE_HEADER'}
+
+    @classmethod
+    def poll(cls, context):
+        return (context.project is None)
+
+    def draw_centered(self, context, layout):
+        layout = self.layout
+
+        layout.label(text="No active project.", icon='INFO')
+
+
 class PROJECTSETTINGS_PT_setup(CenterAlignMixIn, Panel):
     bl_space_type = 'PROJECT_SETTINGS'
     bl_region_type = 'WINDOW'
@@ -109,10 +130,6 @@ class PROJECTSETTINGS_PT_setup(CenterAlignMixIn, Panel):
     def draw_centered(self, context, layout):
         project = context.project
 
-        if not project:
-            layout.label(text="No active project.", icon='INFO')
-            return
-
         layout.prop(project, "name")
         layout.prop(project, "root_path", text="Location")
 
@@ -123,6 +140,7 @@ classes = (
     PROJECTSETTINGS_MT_view,
     PROJECTSETTINGS_PT_navigation_bar,
     PROJECTSETTINGS_PT_save_project_settings,
+    PROJECTSETTINGS_PT_no_project,
     PROJECTSETTINGS_PT_setup,
 )
 
diff --git a/source/blender/editors/space_project_settings/space_project_settings.cc b/source/blender/editors/space_project_settings/space_project_settings.cc
index f58c600977b..3c62bbaf3e4 100644
--- a/source/blender/editors/space_project_settings/space_project_settings.cc
+++ b/source/blender/editors/space_project_settings/space_project_settings.cc
@@ -129,8 +129,12 @@ static void project_settings_main_region_layout(const bContext *C, ARegion *regi
   char id_lower[64];
   const char *contexts[2] = {id_lower, NULL};
 
-  /* Avoid duplicating identifiers, use existing RNA enum. */
-  {
+  if (!CTX_wm_project()) {
+    /* Special context for when there is no project. UI can draw a special panel then. */
+    STRNCPY(id_lower, "no_project");
+  }
+  else {
+    /* Avoid duplicating identifiers, use existing RNA enum. */
     const EnumPropertyItem *items = rna_enum_project_settings_section_items;
     int i = RNA_enum_from_value(items, sproject_settings->active_section);
     /* Enum value not found: File is from the future. */
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index bc9163bf490..ef16a91fef5 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -2316,13 +2316,17 @@ void WM_OT_read_factory_userpref(wmOperatorType *ot)
 /** \name Write Project Settings Operator
  * \{ */
 
+static bool wm_save_project_settings_poll(bContext *C)
+{
+  const BlenderProject *active_project = CTX_wm_project();
+  CTX_wm_operator_poll_msg_set(C, TIP_("No active project loaded"));
+  return active_project != NULL;
+}
+
 /* Only save the prefs block. operator entry */
 static int wm_save_project_settings_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
 {
   BlenderProject *active_project = CTX_wm_project();
-  if (!active_project) {
-    return OPERATOR_CANCELLED;
-  }
 
   if (!BKE_project_settings_save(active_project)) {
     return OPERATOR_CANCELLED;
@@ -2338,6 +2342,7 @@ void WM_OT_save_project_settings(wmOperatorType *ot)
   ot->description = "Make the current changes to the project settings permanent";
 
   ot->invoke = WM_operator_confirm;
+  ot->poll = wm_save_project_settings_poll;
   ot->exec = wm_save_project_settings_exec;
 }



More information about the Bf-blender-cvs mailing list