Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions qt/aqt/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@
)

_html = """
<style>
:root {
--bg-color: %s;
}
</style>
<div>
<div id="editorToolbar"></div>
<div id="fields">
Expand Down Expand Up @@ -135,10 +130,9 @@ def setupWeb(self) -> None:
self.web.set_bridge_command(self.onBridgeCmd, self)
self.outerLayout.addWidget(self.web, 1)

bgcol = self.mw.app.palette().window().color().name() # type: ignore
# then load page
self.web.stdHtml(
_html % (bgcol, tr.editing_show_duplicates()),
_html % tr.editing_show_duplicates(),
css=[
"css/editor.css",
],
Expand Down
2 changes: 2 additions & 0 deletions ts/deckoptions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ts_library(
"lib.ts",
"steps.ts",
"textInputModal.ts",
"optionsDropdown.ts",
],
module_name = "deckoptions",
deps = [
Expand Down Expand Up @@ -97,6 +98,7 @@ esbuild(
"@npm//bootstrap",
":base_css",
"//ts/sveltelib",
"//ts/sveltelib:svelte_components",
] + svelte_names,
)

Expand Down
50 changes: 8 additions & 42 deletions ts/deckoptions/ConfigSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import * as tr from "lib/i18n";
import type { DeckOptionsState, ConfigListEntry } from "./lib";
import OptionsDropdown from "./OptionsDropdown.svelte";
import type { DeckOptionsState } from "./lib";

import StickyBar from "sveltelib/StickyBar.svelte";
import { getOptionsDropdown } from "./optionsDropdown";

export let state: DeckOptionsState;
let configList = state.configList;

function configLabel(entry: ConfigListEntry): string {
const count = tr.deckConfigUsedByDecks({ decks: entry.useCount });
return `${entry.name} (${count})`;
}

function blur(this: HTMLSelectElement) {
state.setCurrentIndex(parseInt(this.value));
}
$: optionsDropdown = getOptionsDropdown(state, $configList);
</script>

<style lang="scss">
.sticky-bar {
position: sticky;
z-index: 1;
top: 0;
color: var(--text-fg);
background: var(--window-bg);
padding-bottom: 0.5em;
padding-top: 0.5em;
}

.selector-grid {
display: grid;
grid-template-columns: 6fr 1fr;
grid-column-gap: 0.5em;
padding-right: 0.5em;
}
</style>

<div class="sticky-bar">
<StickyBar>
<div>{tr.actionsOptionsFor({ val: state.currentDeck.name })}</div>

<div class="selector-grid">
<!-- svelte-ignore a11y-no-onchange -->
<select class="form-select" on:change={blur}>
{#each $configList as entry}
<option value={entry.idx} selected={entry.current}>
{configLabel(entry)}
</option>
{/each}
</select>

<OptionsDropdown {state} />
</div>
</div>
<svelte:component this={optionsDropdown.component} {...optionsDropdown} />
</StickyBar>
8 changes: 6 additions & 2 deletions ts/deckoptions/DeckOptionsPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import ConfigSelector from "./ConfigSelector.svelte";
import ConfigEditor from "./ConfigEditor.svelte";
import type { DeckOptionsState } from "./lib";
import { onMount, onDestroy } from "svelte";
import { onMount, onDestroy, setContext } from "svelte";
import { registerShortcut } from "lib/shortcuts";
import type { Writable } from "svelte/store";
import HtmlAddon from "./HtmlAddon.svelte";
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponents";
import { nightModeKey } from "sveltelib/contextKeys";

export let state: DeckOptionsState;
let addons = state.addonComponents;

export let nightMode: boolean;
setContext(nightModeKey, nightMode);

export function auxData(): Writable<Record<string, unknown>> {
return state.currentAuxData;
}
Expand Down
97 changes: 0 additions & 97 deletions ts/deckoptions/OptionsDropdown.svelte

This file was deleted.

1 change: 1 addition & 0 deletions ts/deckoptions/deckoptions-base.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@use "ts/sass/vars";
@use "ts/sass/scrollbar";
@use "ts/sass/bootstrap-dark";

Expand Down
4 changes: 2 additions & 2 deletions ts/deckoptions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export async function deckOptions(
target: HTMLDivElement,
deckId: number
): Promise<DeckOptionsPage> {
checkNightMode();
const nightMode = checkNightMode();
await setupI18n({
modules: [ModuleName.SCHEDULING, ModuleName.ACTIONS, ModuleName.DECK_CONFIG],
});
const info = await getDeckOptionsInfo(deckId);
const state = new DeckOptionsState(deckId, info);
return new DeckOptionsPage({
target,
props: { state },
props: { state, nightMode },
});
}

Expand Down
2 changes: 1 addition & 1 deletion ts/deckoptions/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { postRequest } from "lib/postrequest";
import { Writable, writable, get, Readable, readable } from "svelte/store";
import { isEqual, cloneDeep } from "lodash-es";
import * as tr from "lib/i18n";
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponents";

export async function getDeckOptionsInfo(
deckId: number
Expand Down
136 changes: 136 additions & 0 deletions ts/deckoptions/optionsDropdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import * as tr from "lib/i18n";
import { textInputModal } from "./textInputModal";
import type { DeckOptionsState, ConfigListEntry } from "./lib";
import {
DynamicSvelteComponent,
labelButton,
buttonGroup,
dropdownMenu,
dropdownItem,
dropdownDivider,
selectButton,
} from "sveltelib/dynamicComponents";

function configLabel(entry: ConfigListEntry): string {
const count = tr.deckConfigUsedByDecks({ decks: entry.useCount });
return `${entry.name} (${count})`;
}

export function getOptionsDropdown(
state: DeckOptionsState,
configList: ConfigListEntry[]
): DynamicSvelteComponent {
function addConfig(): void {
textInputModal({
title: "Add Config",
prompt: "Name:",
onOk: (text: string) => {
const trimmed = text.trim();
if (trimmed.length) {
state.addConfig(trimmed);
}
},
});
}

function renameConfig(): void {
textInputModal({
title: "Rename Config",
prompt: "Name:",
startingValue: state.getCurrentName(),
onOk: (text: string) => {
state.setCurrentName(text);
},
});
}

function removeConfig(): void {
// show pop-up after dropdown has gone away
setTimeout(() => {
if (state.defaultConfigSelected()) {
alert(tr.schedulingTheDefaultConfigurationCantBeRemoved());
return;
}
// fixme: move tr.qt_misc schema mod msg into core
// fixme: include name of deck in msg
const msg = state.removalWilLForceFullSync()
? "This will require a one-way sync. Are you sure?"
: "Are you sure?";
if (confirm(msg)) {
try {
state.removeCurrentConfig();
} catch (err) {
alert(err);
}
}
}, 100);
}

function save(applyToChildDecks: boolean): void {
state.save(applyToChildDecks);
}

function blur(this: HTMLSelectElement) {
state.setCurrentIndex(parseInt(this.value));
}

const options = configList.map((entry) => ({
value: entry.idx,
selected: entry.current,
label: configLabel(entry),
}));

return buttonGroup({
id: "configSelector",
className: "justify-content-between",
size: 35,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the height of the toolbar, maybe we could rename it to 'height'?

Copy link
Contributor Author

@hgiesel hgiesel Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also affects the width of buttons / font-weight, so height seems to be a bit deceiving.

items: [
buttonGroup({
className: "flex-basis-75",
items: [
selectButton({
options,
className: "flex-basis-100",
onChange: blur,
}),
],
}),
buttonGroup({
id: "optionsDropdown",
items: [
labelButton({
label: "Save",
theme: "primary",
onClick: () => save(false),
}),
labelButton({
dropdownToggle: true,
}),
dropdownMenu({
items: [
dropdownItem({
label: "Add Config",
onClick: addConfig,
}),
dropdownItem({
label: "Rename Config",
onClick: renameConfig,
}),
dropdownItem({
label: "Remove Config",
onClick: removeConfig,
}),
dropdownDivider({}),
dropdownItem({
label: "Save to All Children",
onClick: () => save(true),
}),
],
}),
],
}),
],
});
}
2 changes: 1 addition & 1 deletion ts/editor-toolbar/ButtonDropdown.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { ToolbarItem } from "./types";
import type { ToolbarItem } from "sveltelib/types";

export interface ButtonDropdownProps {
id: string;
Expand Down
Loading