add option to clone current config
This commit is contained in:
parent
57ec4cc7b5
commit
5b5b654c33
@ -40,38 +40,52 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
}
|
||||
}
|
||||
|
||||
function onCloneConfig(text: string): void {
|
||||
const trimmed = text.trim();
|
||||
if (trimmed.length) {
|
||||
state.cloneConfig(trimmed);
|
||||
}
|
||||
}
|
||||
|
||||
function onRenameConfig(text: string): void {
|
||||
state.setCurrentName(text);
|
||||
}
|
||||
|
||||
const modals = getContext<Map<string, Modal>>(modalsKey);
|
||||
|
||||
let addModalKey: string;
|
||||
let renameModalKey: string;
|
||||
let oldName = "";
|
||||
let modalKey: string;
|
||||
let modalStartingValue = "";
|
||||
let modalTitle = "";
|
||||
let modalSuccess = (_text: string) => {};
|
||||
|
||||
function onAdd() {
|
||||
modals.get(addModalKey)!.show();
|
||||
function promptToAdd() {
|
||||
modalTitle = "Add Config";
|
||||
modalSuccess = onAddConfig;
|
||||
modalStartingValue = "";
|
||||
modals.get(modalKey)!.show();
|
||||
}
|
||||
|
||||
function onRename() {
|
||||
oldName = state.getCurrentName();
|
||||
modals.get(renameModalKey)!.show();
|
||||
function promptToClone() {
|
||||
modalTitle = "Clone Config";
|
||||
modalSuccess = onCloneConfig;
|
||||
modalStartingValue = state.getCurrentName();
|
||||
modals.get(modalKey)!.show();
|
||||
}
|
||||
|
||||
function promptToRename() {
|
||||
modalTitle = "Rename Config";
|
||||
modalSuccess = onRenameConfig;
|
||||
modalStartingValue = state.getCurrentName();
|
||||
modals.get(modalKey)!.show();
|
||||
}
|
||||
</script>
|
||||
|
||||
<TextInputModal
|
||||
title="Add Config"
|
||||
title={modalTitle}
|
||||
prompt="Name"
|
||||
onOk={onAddConfig}
|
||||
bind:modalKey={addModalKey}
|
||||
/>
|
||||
<TextInputModal
|
||||
title="Rename Config"
|
||||
prompt="Name"
|
||||
onOk={onRenameConfig}
|
||||
value={oldName}
|
||||
bind:modalKey={renameModalKey}
|
||||
value={modalStartingValue}
|
||||
onOk={modalSuccess}
|
||||
bind:modalKey
|
||||
/>
|
||||
|
||||
<StickyBar>
|
||||
@ -95,7 +109,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
</ButtonToolbarItem>
|
||||
|
||||
<ButtonToolbarItem>
|
||||
<SaveButton {state} on:add={onAdd} on:rename={onRename} />
|
||||
<SaveButton
|
||||
{state}
|
||||
on:add={promptToAdd}
|
||||
on:clone={promptToClone}
|
||||
on:rename={promptToRename}
|
||||
/>
|
||||
</ButtonToolbarItem>
|
||||
</ButtonToolbar>
|
||||
</WithTheming>
|
||||
|
@ -57,6 +57,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
<LabelButton on:mount={createDropdown} on:click={activateDropdown} />
|
||||
<DropdownMenu id={menuId}>
|
||||
<DropdownItem on:click={() => dispatch("add")}>Add Config</DropdownItem>
|
||||
<DropdownItem on:click={() => dispatch("clone")}
|
||||
>Clone Config</DropdownItem
|
||||
>
|
||||
<DropdownItem on:click={() => dispatch("rename")}>
|
||||
Rename Config
|
||||
</DropdownItem>
|
||||
|
@ -140,11 +140,24 @@ export class DeckOptionsState {
|
||||
|
||||
/// Adds a new config, making it current.
|
||||
addConfig(name: string): void {
|
||||
this.addConfigFrom(name, this.defaults);
|
||||
}
|
||||
|
||||
/// Clone the current config, making it current.
|
||||
cloneConfig(name: string): void {
|
||||
this.addConfigFrom(name, this.configs[this.selectedIdx].config.config!);
|
||||
}
|
||||
|
||||
/// Clone the current config, making it current.
|
||||
private addConfigFrom(
|
||||
name: string,
|
||||
source: pb.BackendProto.DeckConfig.IConfig
|
||||
): void {
|
||||
const uniqueName = this.ensureNewNameUnique(name);
|
||||
const config = pb.BackendProto.DeckConfig.create({
|
||||
id: 0,
|
||||
name: uniqueName,
|
||||
config: cloneDeep(this.defaults),
|
||||
config: cloneDeep(source),
|
||||
});
|
||||
const configWithCount = { config, useCount: 0 };
|
||||
this.configs.push(configWithCount);
|
||||
|
Loading…
Reference in New Issue
Block a user