Add SD style deletion

This commit is contained in:
Cohee
2024-05-29 23:44:11 +03:00
parent 283bb2fa89
commit e007fe7529

View File

@ -534,6 +534,42 @@ function onStyleSelect() {
saveSettingsDebounced();
}
async function onDeleteStyleClick() {
const selectedStyle = String($('#sd_style').find(':selected').val());
const styleObject = extension_settings.sd.styles.find(x => x.name === selectedStyle);
if (!styleObject) {
return;
}
const confirmed = await callPopup(`Are you sure you want to delete the style "${selectedStyle}"?`, 'confirm', '', { okButton: 'Delete' });
if (!confirmed) {
return;
}
const index = extension_settings.sd.styles.indexOf(styleObject);
if (index === -1) {
return;
}
extension_settings.sd.styles.splice(index, 1);
$('#sd_style').find(`option[value="${selectedStyle}"]`).remove();
if (extension_settings.sd.styles.length > 0) {
extension_settings.sd.style = extension_settings.sd.styles[0].name;
$('#sd_style').val(extension_settings.sd.style).trigger('change');
} else {
extension_settings.sd.style = '';
$('#sd_prompt_prefix').val('').trigger('input');
$('#sd_negative_prompt').val('').trigger('input');
$('#sd_style').val('');
}
saveSettingsDebounced();
}
async function onSaveStyleClick() {
const userInput = await callPopup('Enter style name:', 'input', '', { okButton: 'Save' });
@ -3223,6 +3259,7 @@ jQuery(async () => {
$('#sd_expand').on('input', onExpandInput);
$('#sd_style').on('change', onStyleSelect);
$('#sd_save_style').on('click', onSaveStyleClick);
$('#sd_delete_style').on('click', onDeleteStyleClick);
$('#sd_character_prompt_block').hide();
$('#sd_interactive_mode').on('input', onInteractiveModeInput);
$('#sd_openai_style').on('change', onOpenAiStyleSelect);