[Bf-blender-cvs] [84f21c170dd] blender2.8: Application Templates: make templates more prominent in the UI.

Brecht Van Lommel noreply at git.blender.org
Tue Sep 18 19:39:06 CEST 2018


Commit: 84f21c170dda9e503de440c20bc2753002987901
Author: Brecht Van Lommel
Date:   Tue Aug 28 15:12:14 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB84f21c170dda9e503de440c20bc2753002987901

Application Templates: make templates more prominent in the UI.

The goal here is to make app templates usable for default templates
that we can ship with Blender. These only have a custom startup.blend
currently and so are quite limited compared to app templates that fully
customize Blender.

But still it seems like the same kind of concept where we should be
sharing the code and UI. It is useful to be able to save a startup.blend
per template, and I can imagine some scripting being useful in the future
as well.

Changes made:

* File > New and Ctrl+N now list the templates, replacing a separate
  Application Templates menu that was not as easy to discover.
* File menu now shows name of active template above Save Startup File
  and Load Factory Settings to indicate these are saved/loaded per
  template.
* The "Default" template was renamed to "General".
* Workspaces can now be added from any of the template startup.blend
  files when clicking the (+) button in the topbar.

* User preferences are now fully shared between app templates, unless
  the template includes a custom userpref.blend. I think this will be
  useful in general, not all app templates need their own keymaps for
  example.
* Previously Save User Preferences would save the current app template
  and then Blender would start using that template by default. I've
  disabled this, to me it seems it was unintentional, or at least not
  clear at all that saving user preferences also makes the current

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

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

M	release/scripts/startup/bl_ui/space_topbar.py
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/BKE_appdir.h
M	source/blender/blenkernel/intern/appdir.c
M	source/blender/blenlib/BLI_path_util.h
M	source/blender/blenlib/intern/path_util.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/screen/workspace_edit.c
M	source/blender/makesrna/intern/rna_ui_api.c
M	source/blender/windowmanager/intern/wm_files.c

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

diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index ce4a1ad8c74..80a7215f90b 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -47,7 +47,7 @@ class TOPBAR_HT_upper_bar(Header):
         if not screen.show_fullscreen:
             layout.template_ID_tabs(
                 window, "workspace",
-                new="workspace.add_menu",
+                new="workspace.add",
                 menu="TOPBAR_MT_workspace_menu",
             )
         else:
@@ -287,7 +287,7 @@ class TOPBAR_MT_file(Menu):
         layout = self.layout
 
         layout.operator_context = 'INVOKE_AREA'
-        layout.operator("wm.read_homefile", text="New", icon='NEW')
+        layout.menu("TOPBAR_MT_file_new", text="New", icon='NEW')
         layout.operator("wm.open_mainfile", text="Open...", icon='FILE_FOLDER')
         layout.menu("TOPBAR_MT_file_open_recent")
         layout.operator("wm.revert_mainfile")
@@ -305,10 +305,27 @@ class TOPBAR_MT_file(Menu):
         layout.operator("wm.save_as_mainfile", text="Save Copy...").copy = True
 
         layout.separator()
-
         layout.operator_context = 'INVOKE_AREA'
-        layout.operator("wm.save_homefile")
-        layout.operator("wm.read_factory_settings")
+
+        if any(bpy.utils.app_template_paths()):
+            app_template = context.user_preferences.app_template
+        else:
+            app_template = None
+
+        if app_template:
+            layout.label(text=bpy.path.display_name(app_template))
+            layout.operator("wm.save_homefile")
+            layout.operator(
+                "wm.read_factory_settings",
+                text="Load Factory Settings",
+            ).app_template = app_template
+        else:
+            layout.operator("wm.save_homefile")
+            layout.operator("wm.read_factory_settings")
+
+        layout.separator()
+
+        layout.operator("wm.app_template_install", text="Install Application Template...")
 
         layout.separator()
 
@@ -334,6 +351,49 @@ class TOPBAR_MT_file(Menu):
         layout.operator("wm.quit_blender", text="Quit", icon='QUIT')
 
 
+class TOPBAR_MT_file_new(Menu):
+    bl_label = "New File"
+
+    @staticmethod
+    def app_template_paths():
+        import os
+
+        template_paths = bpy.utils.app_template_paths()
+
+        # expand template paths
+        app_templates = []
+        for path in template_paths:
+            for d in os.listdir(path):
+                if d.startswith(("__", ".")):
+                    continue
+                template = os.path.join(path, d)
+                if os.path.isdir(template):
+                    # template_paths_expand.append(template)
+                    app_templates.append(d)
+
+        return sorted(app_templates)
+
+    def draw_ex(self, context, *, use_splash=False, use_default=False):
+        layout = self.layout
+
+        # now draw the presets
+        layout.operator_context = 'EXEC_DEFAULT'
+
+        if use_default:
+            props = layout.operator("wm.read_homefile", text="General")
+            props.app_template = ""
+
+        for d in TOPBAR_MT_file_new.app_template_paths():
+            props = layout.operator(
+                "wm.read_homefile",
+                text=bpy.path.display_name(d),
+            )
+            props.app_template = d
+
+    def draw(self, context):
+        self.draw_ex(context, use_splash=False, use_default=True)
+
+
 class TOPBAR_MT_file_import(Menu):
     bl_idname = "TOPBAR_MT_file_import"
     bl_label = "Import"
@@ -647,6 +707,7 @@ classes = (
     TOPBAR_MT_workspace_menu,
     TOPBAR_MT_editor_menus,
     TOPBAR_MT_file,
+    TOPBAR_MT_file_new,
     TOPBAR_MT_file_import,
     TOPBAR_MT_file_export,
     TOPBAR_MT_file_external_data,
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index ee2bd2645fc..b1604489605 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -81,60 +81,12 @@ class USERPREF_MT_interaction_presets(Menu):
     draw = Menu.draw_preset
 
 
-class USERPREF_MT_app_templates(Menu):
-    bl_label = "Application Templates"
-    preset_subdir = "app_templates"
-
-    def draw_ex(self, context, *, use_splash=False, use_default=False, use_install=False):
-        import os
-
-        layout = self.layout
-
-        # now draw the presets
-        layout.operator_context = 'EXEC_DEFAULT'
-
-        if use_default:
-            props = layout.operator("wm.read_homefile", text="Default")
-            props.use_splash = True
-            props.app_template = ""
-            layout.separator()
-
-        template_paths = bpy.utils.app_template_paths()
-
-        # expand template paths
-        app_templates = []
-        for path in template_paths:
-            for d in os.listdir(path):
-                if d.startswith(("__", ".")):
-                    continue
-                template = os.path.join(path, d)
-                if os.path.isdir(template):
-                    # template_paths_expand.append(template)
-                    app_templates.append(d)
-
-        for d in sorted(app_templates):
-            props = layout.operator(
-                "wm.read_homefile",
-                text=bpy.path.display_name(d),
-            )
-            props.use_splash = True
-            props.app_template = d
-
-        if use_install:
-            layout.separator()
-            layout.operator_context = 'INVOKE_DEFAULT'
-            props = layout.operator("wm.app_template_install")
-
-    def draw(self, context):
-        self.draw_ex(context, use_splash=False, use_default=True, use_install=True)
-
-
 class USERPREF_MT_templates_splash(Menu):
     bl_label = "Startup Templates"
     preset_subdir = "templates"
 
     def draw(self, context):
-        USERPREF_MT_app_templates.draw_ex(self, context, use_splash=True, use_default=True)
+        bpy.types.TOPBAR_MT_file_new.draw_ex(self, context, use_splash=True, use_default=True)
 
 
 class USERPREF_MT_appconfigs(Menu):
@@ -1650,7 +1602,6 @@ classes = (
     USERPREF_PT_tabs,
     USERPREF_MT_interaction_presets,
     USERPREF_MT_templates_splash,
-    USERPREF_MT_app_templates,
     USERPREF_MT_appconfigs,
     USERPREF_MT_splash,
     USERPREF_MT_splash_footer,
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h
index ac8f861fa56..6162c7b6bf6 100644
--- a/source/blender/blenkernel/BKE_appdir.h
+++ b/source/blender/blenkernel/BKE_appdir.h
@@ -23,6 +23,7 @@
 /** \file BKE_appdir.h
  *  \ingroup bli
  */
+struct ListBase;
 
 /* note on naming: typical _get() suffix is omitted here,
  * since its the main purpose of the API. */
@@ -35,6 +36,7 @@ const char *BKE_appdir_folder_id_version(const int folder_id, const int ver, con
 
 bool BKE_appdir_app_template_any(void);
 bool BKE_appdir_app_template_id_search(const char *app_template, char *path, size_t path_len);
+void BKE_appdir_app_templates(struct ListBase *templates);
 
 /* Initialize path to program executable */
 void        BKE_appdir_program_path_init(const char *argv0);
diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c
index 46f25815481..2848c245553 100644
--- a/source/blender/blenkernel/intern/appdir.c
+++ b/source/blender/blenkernel/intern/appdir.c
@@ -28,9 +28,11 @@
 #include <stdio.h>
 
 #include "BLI_utildefines.h"
-#include "BLI_string.h"
 #include "BLI_fileops.h"
+#include "BLI_fileops_types.h"
+#include "BLI_listbase.h"
 #include "BLI_path_util.h"
+#include "BLI_string.h"
 
 #include "BKE_blender_version.h"
 #include "BKE_appdir.h"  /* own include */
@@ -738,6 +740,32 @@ bool BKE_appdir_app_template_id_search(const char *app_template, char *path, siz
 	return false;
 }
 
+void BKE_appdir_app_templates(ListBase *templates)
+{
+	BLI_listbase_clear(templates);
+
+	for (int i = 0; i < 2; i++) {
+		char subdir[FILE_MAX];
+		if (!BKE_appdir_folder_id_ex(
+		        app_template_directory_id[i], app_template_directory_search[i],
+		        subdir, sizeof(subdir)))
+		{
+			continue;
+		}
+
+		struct direntry *dir;
+		uint totfile = BLI_filelist_dir_contents(subdir, &dir);
+		for (int f = 0; f < totfile; f++) {
+			if (!FILENAME_IS_CURRPAR(dir[f].relname) && S_ISDIR(dir[f].type)) {
+				char *template = BLI_strdup(dir[f].relname);
+				BLI_addtail(templates, BLI_genericNodeN(template));
+			}
+		}
+
+		BLI_filelist_free(dir, totfile);
+	}
+}
+
 /**
  * Gets the temp directory when blender first runs.
  * If the default path is not found, use try $TEMP
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index e434e83416b..dcfb2c9cbc9 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -108,6 +108,8 @@ void BLI_path_rel(char *file, const char *relfile) ATTR_NONNULL();
 bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 bool BLI_path_is_unc(const char *path);
 
+void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) ATTR_NONNULL();
+
 #if defined(WIN32)
 void BLI_cleanup_unc_16(wchar_t *path_16);
 void BLI_cleanup_unc(char *path_16, int maxlen);
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 10ca0fa6cbf..b3ab33312ba 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -927,6 +927,48 @@ bool BLI_path_frame_check_chars(const char *path)
 	return stringframe_chars(path, &ch_sta, &ch_end);
 }
 
+/**
+ * Creates a display string from path to be used menus and the user interface.
+ * Like bpy.path.display_name().
+ */
+void BLI_path_to_display_name(char *display_name, int maxlen, const char *name)
+{
+	/* Strip leading underscores and spaces. */
+	int strip_offset = 0;
+	while (ELEM(name[strip_offset], '_', ' ')) {
+		strip_offset++;
+	}
+
+	BLI_strncpy(display_name, name + strip_offset, maxlen);
+
+	/* Replace underscores with spaces. */
+	BLI_str_replace_char(display_name, '_', ' ');
+
+	/* Strip extension. */
+	BLI_path_extension

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list