[Bf-blender-cvs] [1ad1ecf1c93] master: Fix T79822: Custom preset casing not preserved

Ankur Deria noreply at git.blender.org
Thu Feb 4 01:51:26 CET 2021


Commit: 1ad1ecf1c93d375aae623eff6bab8cbb7d33a63a
Author: Ankur Deria
Date:   Wed Feb 3 17:32:31 2021 -0700
Branches: master
https://developer.blender.org/rB1ad1ecf1c93d375aae623eff6bab8cbb7d33a63a

Fix T79822: Custom preset casing not preserved

When adding a new preset the name would be converted to lower case and
then displayed in the interface in title case. This was confusing
because the name didn't reflect what was typed, and there are many cases
when the name shouldn't be forced into title case (like 8K UHDTV for
example).

This commit leaves the custom preset names in the original casing, and
removes the conversion of filenames to title case for preset lists.

Differential Revision: https://developer.blender.org/D10224

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

M	release/scripts/modules/bpy/path.py
M	release/scripts/modules/bpy/utils/__init__.py
M	release/scripts/modules/bpy_types.py
M	release/scripts/startup/bl_operators/presets.py

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

diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py
index 3860445233d..fad52eae84a 100644
--- a/release/scripts/modules/bpy/path.py
+++ b/release/scripts/modules/bpy/path.py
@@ -201,12 +201,13 @@ _display_name_literals = {
 }
 
 
-def display_name(name, *, has_ext=True):
+def display_name(name, *, has_ext=True, title_case=True):
     """
     Creates a display string from name to be used menus and the user interface.
-    Capitalize the first letter in all lowercase names,
-    mixed case names are kept as is. Intended for use with
-    filenames and module names.
+    Intended for use with filenames and module names.
+
+    :arg has_ext: Remove file extension from name
+    :arg title_case: Convert lowercase names to title case
     """
 
     if has_ext:
@@ -220,7 +221,7 @@ def display_name(name, *, has_ext=True):
     # (when paths can't start with numbers for eg).
     name = name.replace("_", " ").lstrip(" ")
 
-    if name.islower():
+    if title_case and name.islower():
         name = name.lower().title()
 
     name = _clean_utf8(name)
diff --git a/release/scripts/modules/bpy/utils/__init__.py b/release/scripts/modules/bpy/utils/__init__.py
index c81aac8fdeb..7f39cc5d422 100644
--- a/release/scripts/modules/bpy/utils/__init__.py
+++ b/release/scripts/modules/bpy/utils/__init__.py
@@ -606,7 +606,7 @@ def preset_find(name, preset_path, display_name=False, ext=".py"):
         if display_name:
             filename = ""
             for fn in _os.listdir(directory):
-                if fn.endswith(ext) and name == _bpy.path.display_name(fn):
+                if fn.endswith(ext) and name == _bpy.path.display_name(fn, title_case=False):
                     filename = fn
                     break
         else:
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index d863778a9c2..5d89763f34b 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -982,6 +982,7 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta):
             props_default=props_default,
             filter_ext=lambda ext: ext.lower() in ext_valid,
             add_operator=add_operator,
+            display_name=lambda name: bpy.path.display_name(name, title_case=False)
         )
 
     @classmethod
diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 793a8648ee4..5132b358f5e 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -77,7 +77,7 @@ class AddPresetBase:
                 setattr(cls, attr, trans)
             return trans
 
-        name = name.lower().strip()
+        name = name.strip()
         name = bpy.path.display_name_to_filepath(name)
         trans = maketrans_init()
         # Strip surrounding "_" as they are displayed as spaces.
@@ -249,7 +249,7 @@ class ExecutePreset(Operator):
 
         # change the menu title to the most recently chosen option
         preset_class = getattr(bpy.types, self.menu_idname)
-        preset_class.bl_label = bpy.path.display_name(basename(filepath))
+        preset_class.bl_label = bpy.path.display_name(basename(filepath), title_case=False)
 
         ext = splitext(filepath)[1].lower()



More information about the Bf-blender-cvs mailing list