mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00

* Update to latest Node LTS * Add sveltekit * Split tslib into separate @generated and @tslib components SvelteKit's path aliases don't support multiple locations, so our old approach of using @tslib to refer to both ts/lib and out/ts/lib will no longer work. Instead, all generated sources and their includes are placed in a separate out/ts/generated folder, and imported via @generated instead. This also allows us to generate .ts files, instead of needing to output separate .d.ts and .js files. * Switch package.json to module type * Avoid usage of baseUrl Incompatible with SvelteKit * Move sass into ts; use relative links SvelteKit's default sass support doesn't allow overriding loadPaths * jest->vitest, graphs example working with yarn dev * most pages working in dev mode * Some fixes after rebasing * Fix/silence some svelte-check errors * Get image-occlusion working with Fabric types * Post-rebase lock changes * Editor is now checked * SvelteKit build integrated into ninja * Use the new SvelteKit entrypoint for pages like congrats/deck options/etc * Run eslint once for ts/**; fix some tests * Fix a bunch of issues introduced when rebasing over latest main * Run eslint fix * Fix remaining eslint+pylint issues; tests now all pass * Fix some issues with a clean build * Latest bufbuild no longer requires @__PURE__ hack * Add a few missed dependencies * Add yarn.bat to fix Windows build * Fix pages failing to show when ANKI_API_PORT not defined * Fix svelte-check and vitest on Windows * Set node path in ./yarn * Move svelte-kit output to ts/.svelte-kit Sadly, I couldn't figure out a way to store it in out/ if out/ is a symlink, as it breaks module resolution when SvelteKit is run. * Allow HMR inside Anki * Skip SvelteKit build when HMR is defined * Fix some post-rebase issues I should have done a normal merge instead.
111 lines
3.5 KiB
Python
111 lines
3.5 KiB
Python
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
from __future__ import annotations
|
|
|
|
import aqt
|
|
import aqt.deckconf
|
|
import aqt.main
|
|
from anki.cards import Card
|
|
from anki.decks import DeckDict, DeckId
|
|
from anki.lang import without_unicode_isolation
|
|
from aqt import gui_hooks
|
|
from aqt.qt import *
|
|
from aqt.utils import (
|
|
KeyboardModifiersPressed,
|
|
addCloseShortcut,
|
|
disable_help_button,
|
|
restoreGeom,
|
|
saveGeom,
|
|
tr,
|
|
)
|
|
from aqt.webview import AnkiWebView, AnkiWebViewKind
|
|
|
|
|
|
class DeckOptionsDialog(QDialog):
|
|
"The new deck configuration screen."
|
|
|
|
TITLE = "deckOptions"
|
|
silentlyClose = True
|
|
|
|
def __init__(self, mw: aqt.main.AnkiQt, deck: DeckDict) -> None:
|
|
QDialog.__init__(self, mw, Qt.WindowType.Window)
|
|
self.mw = mw
|
|
self._deck = deck
|
|
self._setup_ui()
|
|
|
|
def _setup_ui(self) -> None:
|
|
self.setWindowModality(Qt.WindowModality.ApplicationModal)
|
|
self.mw.garbage_collect_on_dialog_finish(self)
|
|
self.setMinimumWidth(400)
|
|
disable_help_button(self)
|
|
restoreGeom(self, self.TITLE, default_size=(800, 800))
|
|
addCloseShortcut(self)
|
|
|
|
self.web = AnkiWebView(kind=AnkiWebViewKind.DECK_OPTIONS)
|
|
self.web.load_sveltekit_page(f"deck-options/{self._deck['id']}")
|
|
layout = QVBoxLayout()
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
layout.addWidget(self.web)
|
|
self.setLayout(layout)
|
|
self.show()
|
|
self.web.hide_while_preserving_layout()
|
|
self.setWindowTitle(
|
|
without_unicode_isolation(tr.actions_options_for(val=self._deck["name"]))
|
|
)
|
|
gui_hooks.deck_options_did_load(self)
|
|
|
|
def reject(self) -> None:
|
|
self.mw.col.set_wants_abort()
|
|
self.web.cleanup()
|
|
self.web = None
|
|
saveGeom(self, self.TITLE)
|
|
QDialog.reject(self)
|
|
|
|
|
|
def confirm_deck_then_display_options(active_card: Card | None = None) -> None:
|
|
decks = [aqt.mw.col.decks.current()]
|
|
if card := active_card:
|
|
if card.odid and card.odid != decks[0]["id"]:
|
|
decks.append(aqt.mw.col.decks.get(card.odid))
|
|
|
|
if not any(d["id"] == card.did for d in decks):
|
|
decks.append(aqt.mw.col.decks.get(card.did))
|
|
|
|
if len(decks) == 1:
|
|
display_options_for_deck(decks[0])
|
|
else:
|
|
decks.sort(key=lambda x: x["dyn"])
|
|
_deck_prompt_dialog(decks)
|
|
|
|
|
|
def _deck_prompt_dialog(decks: list[DeckDict]) -> None:
|
|
diag = QDialog(aqt.mw.app.activeWindow())
|
|
diag.setWindowTitle("Anki")
|
|
box = QVBoxLayout()
|
|
box.addWidget(QLabel(tr.deck_config_which_deck()))
|
|
for deck in decks:
|
|
button = QPushButton(deck["name"])
|
|
qconnect(button.clicked, diag.close)
|
|
qconnect(button.clicked, lambda _, deck=deck: display_options_for_deck(deck))
|
|
box.addWidget(button)
|
|
button = QPushButton(tr.actions_cancel())
|
|
qconnect(button.clicked, diag.close)
|
|
box.addWidget(button)
|
|
diag.setLayout(box)
|
|
diag.open()
|
|
|
|
|
|
def display_options_for_deck_id(deck_id: DeckId) -> None:
|
|
display_options_for_deck(aqt.mw.col.decks.get(deck_id))
|
|
|
|
|
|
def display_options_for_deck(deck: DeckDict) -> None:
|
|
if not deck["dyn"]:
|
|
if KeyboardModifiersPressed().shift or not aqt.mw.col.v3_scheduler():
|
|
deck_legacy = aqt.mw.col.decks.get(DeckId(deck["id"]))
|
|
aqt.deckconf.DeckConf(aqt.mw, deck_legacy)
|
|
else:
|
|
DeckOptionsDialog(aqt.mw, deck)
|
|
else:
|
|
aqt.dialogs.open("FilteredDeckConfigDialog", aqt.mw, deck_id=deck["id"])
|