diff --git a/ui/presets.py b/ui/presets.py index 8f9f750ad9..44e44f65a8 100644 --- a/ui/presets.py +++ b/ui/presets.py @@ -58,28 +58,30 @@ def get_presets_directory(category=None, mkdir=True, standard=False): if standard: presets = join(get_sverchok_directory(), path_partial) else: - presets = join(bpy.utils.user_resource('DATAFILES', path=path_partial, create=mkdir)) + presets = join(bpy.utils.user_resource('DATAFILES', path=path_partial, create=False)) if not os.path.exists(presets) and mkdir and not standard: os.makedirs(presets) return presets -def get_category_names(mkdir=True): +def get_category_names(mkdir=True, include_empty=False): standard = get_presets_directory(standard=True) user = get_presets_directory(standard=False, mkdir=mkdir) categories = [] for base in [standard, user]: for path in sorted(glob(join(base, "*"))): - if isdir(path) and os.listdir(path): - name = basename(path) - if name not in categories: - categories.append(name) + if isdir(path): + is_empty = len(os.listdir(path)) == 0 + if include_empty or not is_empty: + name = basename(path) + if name not in categories: + categories.append(name) return categories -def get_category_items(self, context): +def get_category_items(self, context, include_empty=False): category_items = None category_items = [(GENERAL, "General", "Uncategorized presets", 0)] node_category_items = [] - for idx, category in enumerate(get_category_names()): + for idx, category in enumerate(get_category_names(include_empty=include_empty)): node_class = get_node_class_reference(category) if node_class and hasattr(node_class, 'bl_label'): title = "/Node/ {}".format(node_class.bl_label) @@ -92,6 +94,12 @@ def get_category_items(self, context): category_items = category_items + [None] + node_category_items return category_items +def get_category_items_all(self, context): + return get_category_items(self, context, include_empty=True) + +def get_category_items_nonempty(self, context): + return get_category_items(self, context, include_empty=False) + def get_preset_path(name, category=None, standard=False, mkdir=True): presets = get_presets_directory(category, standard=standard, mkdir=mkdir) return join(presets, name + ".json") @@ -387,7 +395,7 @@ class SvUserPresetsPanelProps(bpy.types.PropertyGroup): category : EnumProperty( name = "Category", description = "Select presets category", - items = get_category_items) + items = get_category_items_nonempty) search_text : StringProperty( name = "Search", @@ -464,7 +472,7 @@ class SvPresetProps(bpy.types.Operator): bl_options = {'INTERNAL'} old_category: StringProperty(name="Old category", description="Preset category") - new_category: EnumProperty(name="Category", description="New preset category", items = get_category_items) + new_category: EnumProperty(name="Category", description="New preset category", items = get_category_items_all) allow_change_category : BoolProperty(default = True) include_node_categories : BoolProperty(default = False) @@ -720,7 +728,7 @@ class SvPresetFromGist(bpy.types.Operator): category : EnumProperty( name = "Category", description = "Select presets category", - items = get_category_items) + items = get_category_items_all) def execute(self, context): if not self.preset_name: