[Bf-blender-cvs] [483a70eeb5f] blender-projects-basics: Support changing project name in Project Settings UI + show location
Julian Eisel
noreply at git.blender.org
Thu Oct 6 15:58:51 CEST 2022
Commit: 483a70eeb5f94361c0807b4b1e1bf1c1681db71e
Author: Julian Eisel
Date: Thu Oct 6 15:53:04 2022 +0200
Branches: blender-projects-basics
https://developer.blender.org/rB483a70eeb5f94361c0807b4b1e1bf1c1681db71e
Support changing project name in Project Settings UI + show location
Adds basic access to the active project and its properties to BPY
(`context.project`).
===================================================================
M release/scripts/startup/bl_ui/space_project_settings.py
M source/blender/blenkernel/BKE_blender_project.h
M source/blender/blenkernel/BKE_blender_project.hh
M source/blender/blenkernel/intern/blender_project.cc
M source/blender/editors/space_project_settings/space_project_settings.cc
M source/blender/makesrna/intern/CMakeLists.txt
M source/blender/makesrna/intern/makesrna.c
A source/blender/makesrna/intern/rna_blender_project.c
M source/blender/makesrna/intern/rna_context.c
M source/blender/makesrna/intern/rna_internal.h
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/intern/wm_draw.c
M source/blender/windowmanager/intern/wm_files.c
M source/blender/windowmanager/intern/wm_window.c
M source/blender/windowmanager/wm_window.h
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_project_settings.py b/release/scripts/startup/bl_ui/space_project_settings.py
index b2a543e9e07..fcc1d51be8d 100644
--- a/release/scripts/startup/bl_ui/space_project_settings.py
+++ b/release/scripts/startup/bl_ui/space_project_settings.py
@@ -105,7 +105,14 @@ class PROJECTSETTINGS_PT_setup(CenterAlignMixIn, Panel):
bl_options = {'HIDE_HEADER'}
def draw_centered(self, context, layout):
- layout.label(text="Testing")
+ 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")
classes = (
diff --git a/source/blender/blenkernel/BKE_blender_project.h b/source/blender/blenkernel/BKE_blender_project.h
index eff87d4aef5..2451e2d9f29 100644
--- a/source/blender/blenkernel/BKE_blender_project.h
+++ b/source/blender/blenkernel/BKE_blender_project.h
@@ -40,6 +40,10 @@ bool BKE_project_settings_save(const BlenderProject *project) ATTR_NONNULL();
const char *BKE_project_root_path_get(const BlenderProject *project) ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL();
+/**
+ * \param name The new name to set, expected to be 0 terminated.
+ */
+void BKE_project_name_set(const BlenderProject *project_handle, const char *name) ATTR_NONNULL();
const char *BKE_project_name_get(const BlenderProject *project) ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL();
diff --git a/source/blender/blenkernel/BKE_blender_project.hh b/source/blender/blenkernel/BKE_blender_project.hh
index 9ddecdfc729..bc93af92129 100644
--- a/source/blender/blenkernel/BKE_blender_project.hh
+++ b/source/blender/blenkernel/BKE_blender_project.hh
@@ -81,6 +81,7 @@ class ProjectSettings {
explicit ProjectSettings(StringRef project_root_path);
auto project_root_path [[nodiscard]] () const -> StringRefNull;
+ void project_name(StringRef new_name);
auto project_name [[nodiscard]] () const -> StringRefNull;
private:
diff --git a/source/blender/blenkernel/intern/blender_project.cc b/source/blender/blenkernel/intern/blender_project.cc
index 429980774e4..452bc950db2 100644
--- a/source/blender/blenkernel/intern/blender_project.cc
+++ b/source/blender/blenkernel/intern/blender_project.cc
@@ -257,6 +257,11 @@ StringRefNull ProjectSettings::project_root_path() const
return project_root_path_;
}
+void ProjectSettings::project_name(StringRef new_name)
+{
+ project_name_ = new_name;
+}
+
StringRefNull ProjectSettings::project_name() const
{
return project_name_;
@@ -319,6 +324,13 @@ const char *BKE_project_root_path_get(const BlenderProject *project_handle)
return project->get_settings().project_root_path().c_str();
}
+void BKE_project_name_set(const BlenderProject *project_handle, const char *name)
+{
+ const bke::BlenderProject *project = reinterpret_cast<const bke::BlenderProject *>(
+ project_handle);
+ project->get_settings().project_name(name);
+}
+
const char *BKE_project_name_get(const BlenderProject *project_handle)
{
const bke::BlenderProject *project = reinterpret_cast<const bke::BlenderProject *>(
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 ec70a0a2721..f58c600977b 100644
--- a/source/blender/editors/space_project_settings/space_project_settings.cc
+++ b/source/blender/editors/space_project_settings/space_project_settings.cc
@@ -85,6 +85,18 @@ static SpaceLink *project_settings_duplicate(SpaceLink *sl)
return reinterpret_cast<SpaceLink *>(sproject_settings_new);
}
+static void project_settings_listener(const wmSpaceTypeListenerParams *params)
+{
+ const wmNotifier *wmn = params->notifier;
+ ScrArea *area = params->area;
+
+ switch (wmn->category) {
+ case NC_PROJECT:
+ ED_area_tag_redraw(area);
+ break;
+ }
+}
+
static void project_settings_operatortypes(void)
{
}
@@ -187,6 +199,7 @@ void ED_spacetype_project_settings()
st->free = project_settings_free;
st->init = project_settings_init;
st->duplicate = project_settings_duplicate;
+ st->listener = project_settings_listener;
st->operatortypes = project_settings_operatortypes;
st->keymap = project_settings_keymap;
st->blend_write = project_settings_blend_write;
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index 2b06daf34e3..0a17ae637bc 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -20,6 +20,7 @@ set(DEFSRC
rna_armature.c
rna_asset.c
rna_attribute.c
+ rna_blender_project.c
rna_boid.c
rna_brush.c
rna_cachefile.c
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 9cb501a6403..dc6aea870a6 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -4494,6 +4494,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
{"rna_attribute.c", NULL, RNA_def_attribute},
{"rna_asset.c", NULL, RNA_def_asset},
+ {"rna_blender_project.c", NULL, RNA_def_blender_project},
{"rna_boid.c", NULL, RNA_def_boid},
{"rna_brush.c", NULL, RNA_def_brush},
{"rna_cachefile.c", NULL, RNA_def_cachefile},
diff --git a/source/blender/makesrna/intern/rna_blender_project.c b/source/blender/makesrna/intern/rna_blender_project.c
new file mode 100644
index 00000000000..2da9e40e2fa
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_blender_project.c
@@ -0,0 +1,122 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup RNA
+ */
+
+#include "RNA_define.h"
+
+#include "rna_internal.h"
+
+#ifdef RNA_RUNTIME
+
+# include "BKE_blender_project.h"
+
+# include "BLT_translation.h"
+
+# include "WM_api.h"
+
+static void rna_BlenderProject_update(Main *UNUSED(bmain),
+ Scene *UNUSED(scene),
+ PointerRNA *UNUSED(ptr))
+{
+ /* TODO evaluate which props should send which notifiers. */
+ /* Force full redraw of all windows. */
+ WM_main_add_notifier(NC_WINDOW, NULL);
+}
+
+static void rna_BlenderProject_name_get(PointerRNA *ptr, char *value)
+{
+ BlenderProject *project = ptr->data;
+ if (!project) {
+ value[0] = '\0';
+ return;
+ }
+
+ strcpy(value, BKE_project_name_get(project));
+}
+
+static int rna_BlenderProject_name_length(PointerRNA *ptr)
+{
+ BlenderProject *project = ptr->data;
+ if (!project) {
+ return 0;
+ }
+
+ return strlen(BKE_project_name_get(project));
+}
+
+static void rna_BlenderProject_name_set(PointerRNA *ptr, const char *value)
+{
+ BlenderProject *project = ptr->data;
+
+ if (!project) {
+ return;
+ }
+
+ BKE_project_name_set(project, value);
+}
+
+static void rna_BlenderProject_root_path_get(PointerRNA *ptr, char *value)
+{
+ BlenderProject *project = ptr->data;
+ if (!project) {
+ value[0] = '\0';
+ return;
+ }
+
+ strcpy(value, BKE_project_root_path_get(project));
+}
+
+static int rna_BlenderProject_root_path_length(PointerRNA *ptr)
+{
+ BlenderProject *project = ptr->data;
+ if (!project) {
+ return 0;
+ }
+
+ return strlen(BKE_project_root_path_get(project));
+}
+
+static void rna_BlenderProject_root_path_set(PointerRNA *UNUSED(ptr), const char *UNUSED(value))
+{
+ /* Property is not editable, see #rna_BlenderProject_root_path_editable(). */
+ BLI_assert_unreachable();
+}
+
+static int rna_BlenderProject_root_path_editable(PointerRNA *UNUSED(ptr), const char **r_info)
+{
+ /* Path is never editable (setting up a project is an operation), but return a nicer disabled
+ * hint. */
+ *r_info = N_("Project location cannot be changed, displayed for informal purposes only");
+ return 0;
+}
+
+#else
+
+void RNA_def_blender_project(BlenderRNA *brna)
+{
+ StructRNA *srna = RNA_def_struct(brna, "BlenderProject", NULL);
+ RNA_def_struct_ui_text(srna, "Blender Project", "");
+
+ PropertyRNA *prop;
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop,
+ "rna_BlenderProject_name_get",
+ "rna_BlenderProject_name_length",
+ "rna_BlenderProject_name_set");
+ RNA_def_property_ui_text(prop, "Name", "The identifier for the project");
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_update(prop, 0, "rna_BlenderProject_update");
+
+ prop = RNA_def_property(srna, "root_path", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop,
+ "rna_BlenderProject_root_path_get",
+ "rna_BlenderProject_root_path_length",
+ "rna_BlenderProject_root_path_set");
+ RNA_def_property_editable_func(prop, "rna_BlenderProject_root_path_editable");
+ RNA_def_property_ui_text(prop, "Location", "The location of the project on disk");
+}
+
+#endif
diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c
index e723be2ab71..2b910a9eaac 100644
--- a/source/blender/makesrna/intern/rna_context.c
+++ b/source/blender/makesrna/intern/rna_context.c
@@ -203,6 +203,15 @@ static PointerRNA rna_Context_preferences_get(PointerRNA *UNUSED(ptr))
return newptr;
}
+static PointerRNA rna_Context_project_get(PointerRNA *UNUSED(ptr))
+{
+ struct BlenderProject *project = CTX_wm_project();
+
+ PointerRNA newptr;
+ RNA_pointer_create(NULL, &RNA_BlenderProject, project, &newptr);
+ return newptr;
+}
+
static int rna_Context_mode_get(PointerRNA *ptr)
{
bContext *C = (bContext *)ptr->data;
@@ -338,6 +347,11 @@ void RNA_def_context(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "Preferences");
RNA_def_property_pointer_funcs(prop, "rna_Context_preferences_get", NULL, NULL, NULL);
+ prop = RNA_def_property(srna, "project", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "BlenderProject");
+ RNA_def_property_point
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list