mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
use strum for config keys
This commit is contained in:
parent
265e91c13f
commit
b67947cfbc
1 changed files with 37 additions and 57 deletions
|
@ -13,6 +13,7 @@ use serde_derive::Deserialize;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use slog::warn;
|
use slog::warn;
|
||||||
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
/// These items are expected to exist in schema 11. When adding
|
/// These items are expected to exist in schema 11. When adding
|
||||||
/// new config variables, you do not need to add them here -
|
/// new config variables, you do not need to add them here -
|
||||||
|
@ -38,10 +39,9 @@ pub(crate) fn schema11_config_as_string() -> String {
|
||||||
serde_json::to_string(&obj).unwrap()
|
serde_json::to_string(&obj).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(IntoStaticStr)]
|
||||||
|
#[strum(serialize_all = "camelCase")]
|
||||||
pub(crate) enum ConfigKey {
|
pub(crate) enum ConfigKey {
|
||||||
AnswerTimeLimitSecs,
|
|
||||||
BrowserSortKind,
|
|
||||||
BrowserSortReverse,
|
|
||||||
CardCountsSeparateInactive,
|
CardCountsSeparateInactive,
|
||||||
CollapseCardState,
|
CollapseCardState,
|
||||||
CollapseDecks,
|
CollapseDecks,
|
||||||
|
@ -51,69 +51,43 @@ pub(crate) enum ConfigKey {
|
||||||
CollapseTags,
|
CollapseTags,
|
||||||
CollapseToday,
|
CollapseToday,
|
||||||
CreationOffset,
|
CreationOffset,
|
||||||
CurrentDeckID,
|
|
||||||
CurrentNoteTypeID,
|
|
||||||
FirstDayOfWeek,
|
FirstDayOfWeek,
|
||||||
FutureDueShowBacklog,
|
FutureDueShowBacklog,
|
||||||
LastUnburiedDay,
|
|
||||||
LearnAheadSecs,
|
|
||||||
LocalOffset,
|
LocalOffset,
|
||||||
NewReviewMix,
|
|
||||||
NextNewCardPosition,
|
|
||||||
NormalizeNoteText,
|
|
||||||
PreviewBothSides,
|
PreviewBothSides,
|
||||||
Rollover,
|
Rollover,
|
||||||
Sched2021,
|
Sched2021,
|
||||||
SchedulerVersion,
|
|
||||||
SetDueBrowser,
|
SetDueBrowser,
|
||||||
SetDueReviewer,
|
SetDueReviewer,
|
||||||
ShowDayLearningCardsFirst,
|
|
||||||
ShowIntervalsAboveAnswerButtons,
|
|
||||||
ShowRemainingDueCountsInStudy,
|
|
||||||
}
|
|
||||||
#[derive(PartialEq, Serialize_repr, Deserialize_repr, Clone, Copy, Debug)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub(crate) enum SchedulerVersion {
|
|
||||||
V1 = 1,
|
|
||||||
V2 = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ConfigKey> for &'static str {
|
#[strum(to_string = "timeLim")]
|
||||||
fn from(c: ConfigKey) -> Self {
|
AnswerTimeLimitSecs,
|
||||||
match c {
|
#[strum(to_string = "sortType")]
|
||||||
ConfigKey::AnswerTimeLimitSecs => "timeLim",
|
BrowserSortKind,
|
||||||
ConfigKey::BrowserSortKind => "sortType",
|
#[strum(to_string = "sortBackwards")]
|
||||||
ConfigKey::BrowserSortReverse => "sortBackwards",
|
BrowserSortReverse,
|
||||||
ConfigKey::CardCountsSeparateInactive => "cardCountsSeparateInactive",
|
#[strum(to_string = "curDeck")]
|
||||||
ConfigKey::CollapseCardState => "collapseCardState",
|
CurrentDeckID,
|
||||||
ConfigKey::CollapseDecks => "collapseDecks",
|
#[strum(to_string = "curModel")]
|
||||||
ConfigKey::CollapseFlags => "collapseFlags",
|
CurrentNoteTypeID,
|
||||||
ConfigKey::CollapseNotetypes => "collapseNotetypes",
|
#[strum(to_string = "lastUnburied")]
|
||||||
ConfigKey::CollapseSavedSearches => "collapseSavedSearches",
|
LastUnburiedDay,
|
||||||
ConfigKey::CollapseTags => "collapseTags",
|
#[strum(to_string = "collapseTime")]
|
||||||
ConfigKey::CollapseToday => "collapseToday",
|
LearnAheadSecs,
|
||||||
ConfigKey::CreationOffset => "creationOffset",
|
#[strum(to_string = "newSpread")]
|
||||||
ConfigKey::CurrentDeckID => "curDeck",
|
NewReviewMix,
|
||||||
ConfigKey::CurrentNoteTypeID => "curModel",
|
#[strum(to_string = "nextPos")]
|
||||||
ConfigKey::FirstDayOfWeek => "firstDayOfWeek",
|
NextNewCardPosition,
|
||||||
ConfigKey::FutureDueShowBacklog => "futureDueShowBacklog",
|
#[strum(to_string = "normalize_note_text")]
|
||||||
ConfigKey::LastUnburiedDay => "lastUnburied",
|
NormalizeNoteText,
|
||||||
ConfigKey::LearnAheadSecs => "collapseTime",
|
#[strum(to_string = "schedVer")]
|
||||||
ConfigKey::LocalOffset => "localOffset",
|
SchedulerVersion,
|
||||||
ConfigKey::NewReviewMix => "newSpread",
|
#[strum(to_string = "dayLearnFirst")]
|
||||||
ConfigKey::NextNewCardPosition => "nextPos",
|
ShowDayLearningCardsFirst,
|
||||||
ConfigKey::NormalizeNoteText => "normalize_note_text",
|
#[strum(to_string = "estTimes")]
|
||||||
ConfigKey::PreviewBothSides => "previewBothSides",
|
ShowIntervalsAboveAnswerButtons,
|
||||||
ConfigKey::Rollover => "rollover",
|
#[strum(to_string = "dueCounts")]
|
||||||
ConfigKey::Sched2021 => "sched2021",
|
ShowRemainingDueCountsInStudy,
|
||||||
ConfigKey::SchedulerVersion => "schedVer",
|
|
||||||
ConfigKey::SetDueBrowser => "setDueBrowser",
|
|
||||||
ConfigKey::SetDueReviewer => "setDueReviewer",
|
|
||||||
ConfigKey::ShowDayLearningCardsFirst => "dayLearnFirst",
|
|
||||||
ConfigKey::ShowIntervalsAboveAnswerButtons => "estTimes",
|
|
||||||
ConfigKey::ShowRemainingDueCountsInStudy => "dueCounts",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BoolKey> for ConfigKey {
|
impl From<BoolKey> for ConfigKey {
|
||||||
|
@ -142,6 +116,12 @@ impl From<StringKey> for ConfigKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Serialize_repr, Deserialize_repr, Clone, Copy, Debug)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub(crate) enum SchedulerVersion {
|
||||||
|
V1 = 1,
|
||||||
|
V2 = 2,
|
||||||
|
}
|
||||||
/// This is a workaround for old clients that used ints to represent boolean
|
/// This is a workaround for old clients that used ints to represent boolean
|
||||||
/// values. For new config items, prefer using a bool directly.
|
/// values. For new config items, prefer using a bool directly.
|
||||||
#[derive(Deserialize, Default)]
|
#[derive(Deserialize, Default)]
|
||||||
|
|
Loading…
Reference in a new issue