Merge pull request #830 from ogmaresca/sort-models

Sort models alphabetically
This commit is contained in:
cmdr2 2023-02-10 17:42:24 +05:30 committed by GitHub
commit f7b8e000c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -171,10 +171,10 @@ def getModels():
"Raised when picklescan reports a problem with a model"
pass
def scan_directory(directory, suffixes):
def scan_directory(directory, suffixes, directoriesFirst:bool=True):
nonlocal models_scanned
tree = []
for entry in os.scandir(directory):
for entry in sorted(os.scandir(directory), key = lambda entry: (entry.is_file() == directoriesFirst, entry.name.lower())):
if entry.is_file():
matching_suffix = list(filter(lambda s: entry.name.endswith(s), suffixes))
if len(matching_suffix) == 0: continue
@ -189,7 +189,8 @@ def getModels():
known_models[entry.path] = mtime
tree.append(entry.name[:-len(matching_suffix)])
elif entry.is_dir():
scan=scan_directory(entry.path, suffixes)
scan=scan_directory(entry.path, suffixes, directoriesFirst=False)
if len(scan) != 0:
tree.append( (entry.name, scan ) )
return tree

View File

@ -1344,9 +1344,12 @@ async function getModels() {
}
modelField.appendChild(modelOption)
} else {
const modelGroup = document.createElement('optgroup')
modelGroup.label = path + modelName[0]
modelField.appendChild(modelGroup)
// Since <optgroup/>s can't be nested, don't show empty groups
if (modelName[1].some(child => typeof(child) == 'string')) {
const modelGroup = document.createElement('optgroup')
modelGroup.label = path + modelName[0]
modelField.appendChild(modelGroup)
}
modelName[1].forEach( createModelOptions(modelField, selectedModel, path + modelName[0] + "/" ) )
}
}