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