Anki/rslib/src/config/deck.rs
Damien Elmes f3e81c8a95 Move custom study tag and limit gathering+saving into the backend
Ideally this would have been in beta 6 :-) No add-ons appear to be
using customstudy.py/taglimit.py though, so it should hopefully not be
disruptive.

In the earlier custom study changes, we didn't get around to addressing
issue #1136. Now instead of trying to determine the maximum increase
to allow (which doesn't work correctly with nested decks), we just
present the total available to the user again, and let them decide. There's
plenty of room for improvement here still, but further work here might
be better done once we look into decoupling deck limits from deck presets.

Tags and available cards are fetched prior to showing the dialog now,
and will show a progress dialog if things take a while.

Tags are stored in an aux var now, so they don't inflate the deck
object size.
2022-03-10 16:23:03 +10:00

45 lines
1.3 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use strum::IntoStaticStr;
use crate::prelude::*;
/// Auxillary deck state, stored in the config table.
#[derive(Debug, Clone, Copy, IntoStaticStr)]
#[strum(serialize_all = "camelCase")]
pub enum DeckConfigKey {
LastNotetype,
CustomStudyIncludeTags,
CustomStudyExcludeTags,
}
impl DeckConfigKey {
pub fn for_deck(self, did: DeckId) -> String {
build_aux_deck_key(did, <&'static str>::from(self))
}
}
impl Collection {
pub(crate) fn clear_aux_config_for_deck(&mut self, ntid: DeckId) -> Result<()> {
self.remove_config_prefix(&build_aux_deck_key(ntid, ""))
}
pub(crate) fn get_last_notetype_for_deck(&self, id: DeckId) -> Option<NotetypeId> {
let key = DeckConfigKey::LastNotetype.for_deck(id);
self.get_config_optional(key.as_str())
}
pub(crate) fn set_last_notetype_for_deck(
&mut self,
did: DeckId,
ntid: NotetypeId,
) -> Result<bool> {
let key = DeckConfigKey::LastNotetype.for_deck(did);
self.set_config(key.as_str(), &ntid)
}
}
fn build_aux_deck_key(deck: DeckId, key: &str) -> String {
format!("_deck_{deck}_{key}", deck = deck, key = key)
}