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.
This commit is contained in:
Julian Eisel 2022-10-06 16:58:57 +02:00
parent 871bdb5d1f
commit 525f24f1ba
3 changed files with 36 additions and 9 deletions

View File

@ -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,
)

View File

@ -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. */

View File

@ -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;
}