Add option for default tree expanded depth.

This commit is contained in:
Sj-Si 2024-05-03 19:20:47 -04:00
parent b497467436
commit fbefe7f4fe
3 changed files with 22 additions and 14 deletions

View file

@ -68,7 +68,8 @@ class ExtraNetworksClusterize extends Clusterize {
await this.initData();
// can't use super class' sort since it relies on setup being run first.
// but we do need to make sure to sort the new data before continuing.
await this.setMaxItems(Object.keys(this.data_obj).length);
const max_items = Object.keys(this.data_obj).filter(k => this.data_obj[k].visible).length;
await this.setMaxItems(max_items);
await this.refresh(true);
await this.options.callbacks.sortData();
}

View file

@ -253,6 +253,7 @@ options_templates.update(options_section(('extra_networks', "Extra Networks", "s
"extra_networks_show_hidden_directories_buttons": OptionInfo(False, "Show buttons for hidden directories in the directory and tree views.").info("a directory is hidden if its name starts with a period (\".\").").needs_reload_ui(),
"extra_networks_show_hidden_models_cards": OptionInfo("Never", "Show cards for models in hidden directories", gr.Radio, {"choices": ["Always", "When searched", "Never"]}).info("\"When searched\" will only show cards when the search string has 4 characters or more and the search string matches either the model name or the hidden directory name (or any of its subdirectories).").needs_reload_ui(),
"extra_networks_show_hidden_models_in_tree_view": OptionInfo(False, "Show entries for models inside hidden directories in the tree view.").info("This option only applies if the \"Show buttons for hidden directories\" option is enabled.").needs_reload_ui(),
"extra_networks_tree_view_expand_depth_default": OptionInfo(1, "Expand the tree view to this folder depth by default.").needs_reload_ui(),
"extra_networks_default_multiplier": OptionInfo(1.0, "Default multiplier for extra networks", gr.Slider, {"minimum": 0.0, "maximum": 2.0, "step": 0.01}),
"extra_networks_card_width": OptionInfo(0, "Card width for Extra Networks").info("in pixels"),
"extra_networks_card_height": OptionInfo(0, "Card height for Extra Networks").info("in pixels"),

View file

@ -600,6 +600,7 @@ class ExtraNetworksPage:
show_hidden_dirs = shared.opts.extra_networks_show_hidden_directories_buttons
show_hidden_models = shared.opts.extra_networks_show_hidden_models_in_tree_view
expand_depth = int(shared.opts.extra_networks_tree_view_expand_depth_default)
for node in self.nodes.values():
if node.is_hidden and node.is_dir and not show_hidden_dirs:
continue
@ -608,13 +609,11 @@ class ExtraNetworksPage:
continue
tree_item = TreeListItem(node.id, "")
# If root node, expand and set visible.
if node.parent is None:
tree_item.expanded = True
tree_item.visible = True
# If direct child of root node, set visible.
if node.parent is not None and node.parent.parent is None:
if node.depth <= expand_depth:
tree_item.expanded = True
if node.depth <= expand_depth + 1:
tree_item.visible = True
tree_item.node = node
@ -639,12 +638,19 @@ class ExtraNetworksPage:
dir_is_empty = all(not x.is_dir for x in node.children)
if not dir_is_empty:
if show_files and show_hidden_models:
children = [x.id for x in tree_item.node.children]
elif show_files and not show_hidden_models:
children = [x.id for x in tree_item.node.children if x.is_dir or (not x.is_dir and not x.is_hidden)]
else:
children = [x.id for x in tree_item.node.children if x.is_dir]
for child in tree_item.node.children:
if child.is_dir:
if child.is_hidden:
if show_hidden_dirs:
children.append(child.id)
else:
children.append(child.id)
elif show_files:
if child.is_hidden:
if show_hidden_dirs and show_hidden_models:
children.append(child.id)
else:
children.append(child.id)
data_attributes = {
"data-div-id": f'"{node.id}"',
@ -652,7 +658,7 @@ class ExtraNetworksPage:
"data-tree-entry-type": "dir",
"data-depth": node.depth,
"data-path": f'"{node.relpath}"',
"data-expanded": node.parent is None, # Expand root directories
"data-expanded": tree_item.expanded,
}
if node.is_hidden: