2021-04-12 06:18:30 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2021-04-16 15:29:21 +02:00
|
|
|
<script lang="ts">
|
2021-04-22 19:55:26 +02:00
|
|
|
import * as tr from "lib/i18n";
|
2021-05-25 19:18:25 +02:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2021-04-25 10:40:02 +02:00
|
|
|
import type { DeckOptionsState } from "./lib";
|
2021-04-16 15:29:21 +02:00
|
|
|
|
2021-05-18 16:32:29 +02:00
|
|
|
import ButtonGroup from "components/ButtonGroup.svelte";
|
|
|
|
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
|
|
|
|
|
|
|
|
import LabelButton from "components/LabelButton.svelte";
|
|
|
|
import DropdownMenu from "components/DropdownMenu.svelte";
|
|
|
|
import DropdownItem from "components/DropdownItem.svelte";
|
|
|
|
import DropdownDivider from "components/DropdownDivider.svelte";
|
|
|
|
import WithDropdownMenu from "components/WithDropdownMenu.svelte";
|
2021-06-01 07:54:07 +02:00
|
|
|
import WithShortcut from "components/WithShortcut.svelte";
|
2021-05-18 16:32:29 +02:00
|
|
|
|
2021-05-25 19:18:25 +02:00
|
|
|
const dispatch = createEventDispatcher();
|
2021-04-16 15:29:21 +02:00
|
|
|
|
2021-05-25 19:18:25 +02:00
|
|
|
export let state: DeckOptionsState;
|
2021-04-16 15:29:21 +02:00
|
|
|
|
2021-06-01 07:54:07 +02:00
|
|
|
function commitEditing(): void {
|
|
|
|
if (document.activeElement instanceof HTMLElement) {
|
|
|
|
document.activeElement.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-16 15:29:21 +02:00
|
|
|
function removeConfig(): void {
|
2021-04-18 03:56:41 +02:00
|
|
|
// show pop-up after dropdown has gone away
|
2021-04-16 15:29:21 +02:00
|
|
|
setTimeout(() => {
|
2021-04-18 03:56:41 +02:00
|
|
|
if (state.defaultConfigSelected()) {
|
|
|
|
alert(tr.schedulingTheDefaultConfigurationCantBeRemoved());
|
|
|
|
return;
|
|
|
|
}
|
2021-05-26 06:41:18 +02:00
|
|
|
const msg =
|
|
|
|
(state.removalWilLForceFullSync()
|
|
|
|
? tr.deckConfigWillRequireFullSync() + " "
|
|
|
|
: "") +
|
|
|
|
tr.deckConfigConfirmRemoveName({ name: state.getCurrentName() });
|
|
|
|
if (confirm(tr.i18n.withCollapsedWhitespace(msg))) {
|
2021-04-16 15:29:21 +02:00
|
|
|
try {
|
|
|
|
state.removeCurrentConfig();
|
|
|
|
} catch (err) {
|
|
|
|
alert(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
2021-04-20 11:50:05 +02:00
|
|
|
|
|
|
|
function save(applyToChildDecks: boolean): void {
|
2021-06-01 07:54:07 +02:00
|
|
|
commitEditing();
|
2021-04-20 11:50:05 +02:00
|
|
|
state.save(applyToChildDecks);
|
|
|
|
}
|
2021-04-16 15:29:21 +02:00
|
|
|
</script>
|
|
|
|
|
2021-05-18 16:32:29 +02:00
|
|
|
<ButtonGroup>
|
|
|
|
<ButtonGroupItem>
|
2021-06-01 07:54:07 +02:00
|
|
|
<WithShortcut shortcut={"Control+Enter"} let:createShortcut let:shortcutLabel>
|
|
|
|
<LabelButton
|
|
|
|
theme="primary"
|
|
|
|
on:click={() => save(false)}
|
|
|
|
tooltip={shortcutLabel}
|
|
|
|
on:mount={createShortcut}>{tr.deckConfigSaveButton()}</LabelButton
|
|
|
|
>
|
|
|
|
</WithShortcut>
|
2021-05-18 16:32:29 +02:00
|
|
|
</ButtonGroupItem>
|
2021-04-12 06:18:30 +02:00
|
|
|
|
2021-05-18 16:32:29 +02:00
|
|
|
<ButtonGroupItem>
|
2021-05-18 18:55:22 +02:00
|
|
|
<WithDropdownMenu let:createDropdown let:activateDropdown let:menuId>
|
2021-06-21 19:11:10 +02:00
|
|
|
<LabelButton
|
|
|
|
on:mount={(event) => createDropdown(event.detail.button)}
|
|
|
|
on:click={activateDropdown}
|
|
|
|
/>
|
2021-05-18 16:32:29 +02:00
|
|
|
<DropdownMenu id={menuId}>
|
2021-05-26 06:41:18 +02:00
|
|
|
<DropdownItem on:click={() => dispatch("add")}
|
|
|
|
>{tr.deckConfigAddGroup()}</DropdownItem
|
|
|
|
>
|
2021-05-26 05:20:24 +02:00
|
|
|
<DropdownItem on:click={() => dispatch("clone")}
|
2021-05-26 06:41:18 +02:00
|
|
|
>{tr.deckConfigCloneGroup()}</DropdownItem
|
2021-05-26 05:20:24 +02:00
|
|
|
>
|
2021-05-26 01:21:33 +02:00
|
|
|
<DropdownItem on:click={() => dispatch("rename")}>
|
2021-05-26 06:41:18 +02:00
|
|
|
{tr.deckConfigRenameGroup()}
|
2021-05-25 19:18:25 +02:00
|
|
|
</DropdownItem>
|
2021-05-26 06:41:18 +02:00
|
|
|
<DropdownItem on:click={removeConfig}
|
|
|
|
>{tr.deckConfigRemoveGroup()}</DropdownItem
|
|
|
|
>
|
2021-05-18 16:32:29 +02:00
|
|
|
<DropdownDivider />
|
|
|
|
<DropdownItem on:click={() => save(true)}>
|
2021-05-26 06:41:18 +02:00
|
|
|
{tr.deckConfigSaveToAllSubdecks()}
|
2021-05-18 16:32:29 +02:00
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</WithDropdownMenu>
|
|
|
|
</ButtonGroupItem>
|
|
|
|
</ButtonGroup>
|