mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
use native boolkey instead of separate getters/setters
Makes it easier to add new config settings in the future, especially if we don't need to export them via protobuf.
This commit is contained in:
parent
b67947cfbc
commit
1dea8babee
13 changed files with 116 additions and 134 deletions
22
rslib/src/backend/config.rs
Normal file
22
rslib/src/backend/config.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use crate::{backend_proto as pb, config::BoolKey};
|
||||||
|
use pb::config::bool::Key;
|
||||||
|
|
||||||
|
impl From<Key> for BoolKey {
|
||||||
|
fn from(k: Key) -> Self {
|
||||||
|
match k {
|
||||||
|
Key::BrowserSortBackwards => BoolKey::BrowserSortBackwards,
|
||||||
|
Key::PreviewBothSides => BoolKey::PreviewBothSides,
|
||||||
|
Key::CollapseTags => BoolKey::CollapseTags,
|
||||||
|
Key::CollapseNotetypes => BoolKey::CollapseNotetypes,
|
||||||
|
Key::CollapseDecks => BoolKey::CollapseDecks,
|
||||||
|
Key::CollapseSavedSearches => BoolKey::CollapseSavedSearches,
|
||||||
|
Key::CollapseToday => BoolKey::CollapseToday,
|
||||||
|
Key::CollapseCardState => BoolKey::CollapseCardState,
|
||||||
|
Key::CollapseFlags => BoolKey::CollapseFlags,
|
||||||
|
Key::Sched2021 => BoolKey::Sched2021,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
mod card;
|
mod card;
|
||||||
|
mod config;
|
||||||
mod dbproxy;
|
mod dbproxy;
|
||||||
mod generic;
|
mod generic;
|
||||||
mod http_sync_server;
|
mod http_sync_server;
|
||||||
|
@ -1513,13 +1514,13 @@ impl BackendService for Backend {
|
||||||
fn get_config_bool(&self, input: pb::config::Bool) -> BackendResult<pb::Bool> {
|
fn get_config_bool(&self, input: pb::config::Bool) -> BackendResult<pb::Bool> {
|
||||||
self.with_col(|col| {
|
self.with_col(|col| {
|
||||||
Ok(pb::Bool {
|
Ok(pb::Bool {
|
||||||
val: col.get_bool(input),
|
val: col.get_bool(input.key().into()),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_config_bool(&self, input: pb::SetConfigBoolIn) -> BackendResult<pb::Empty> {
|
fn set_config_bool(&self, input: pb::SetConfigBoolIn) -> BackendResult<pb::Empty> {
|
||||||
self.with_col(|col| col.transact(None, |col| col.set_bool(input)))
|
self.with_col(|col| col.transact(None, |col| col.set_bool(input.key().into(), input.value)))
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::{
|
||||||
backend_proto as pb, collection::Collection, decks::DeckID, err::Result, notetype::NoteTypeID,
|
backend_proto as pb, collection::Collection, decks::DeckID, err::Result, notetype::NoteTypeID,
|
||||||
timestamp::TimestampSecs,
|
timestamp::TimestampSecs,
|
||||||
};
|
};
|
||||||
pub use pb::config::bool::Key as BoolKey;
|
|
||||||
pub use pb::config::string::Key as StringKey;
|
pub use pb::config::string::Key as StringKey;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use serde_aux::field_attributes::deserialize_bool_from_anything;
|
use serde_aux::field_attributes::deserialize_bool_from_anything;
|
||||||
|
@ -42,21 +41,10 @@ pub(crate) fn schema11_config_as_string() -> String {
|
||||||
#[derive(IntoStaticStr)]
|
#[derive(IntoStaticStr)]
|
||||||
#[strum(serialize_all = "camelCase")]
|
#[strum(serialize_all = "camelCase")]
|
||||||
pub(crate) enum ConfigKey {
|
pub(crate) enum ConfigKey {
|
||||||
CardCountsSeparateInactive,
|
|
||||||
CollapseCardState,
|
|
||||||
CollapseDecks,
|
|
||||||
CollapseFlags,
|
|
||||||
CollapseNotetypes,
|
|
||||||
CollapseSavedSearches,
|
|
||||||
CollapseTags,
|
|
||||||
CollapseToday,
|
|
||||||
CreationOffset,
|
CreationOffset,
|
||||||
FirstDayOfWeek,
|
FirstDayOfWeek,
|
||||||
FutureDueShowBacklog,
|
|
||||||
LocalOffset,
|
LocalOffset,
|
||||||
PreviewBothSides,
|
|
||||||
Rollover,
|
Rollover,
|
||||||
Sched2021,
|
|
||||||
SetDueBrowser,
|
SetDueBrowser,
|
||||||
SetDueReviewer,
|
SetDueReviewer,
|
||||||
|
|
||||||
|
@ -64,8 +52,6 @@ pub(crate) enum ConfigKey {
|
||||||
AnswerTimeLimitSecs,
|
AnswerTimeLimitSecs,
|
||||||
#[strum(to_string = "sortType")]
|
#[strum(to_string = "sortType")]
|
||||||
BrowserSortKind,
|
BrowserSortKind,
|
||||||
#[strum(to_string = "sortBackwards")]
|
|
||||||
BrowserSortReverse,
|
|
||||||
#[strum(to_string = "curDeck")]
|
#[strum(to_string = "curDeck")]
|
||||||
CurrentDeckID,
|
CurrentDeckID,
|
||||||
#[strum(to_string = "curModel")]
|
#[strum(to_string = "curModel")]
|
||||||
|
@ -78,10 +64,29 @@ pub(crate) enum ConfigKey {
|
||||||
NewReviewMix,
|
NewReviewMix,
|
||||||
#[strum(to_string = "nextPos")]
|
#[strum(to_string = "nextPos")]
|
||||||
NextNewCardPosition,
|
NextNewCardPosition,
|
||||||
#[strum(to_string = "normalize_note_text")]
|
|
||||||
NormalizeNoteText,
|
|
||||||
#[strum(to_string = "schedVer")]
|
#[strum(to_string = "schedVer")]
|
||||||
SchedulerVersion,
|
SchedulerVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
||||||
|
#[strum(serialize_all = "camelCase")]
|
||||||
|
pub enum BoolKey {
|
||||||
|
CardCountsSeparateInactive,
|
||||||
|
CollapseCardState,
|
||||||
|
CollapseDecks,
|
||||||
|
CollapseFlags,
|
||||||
|
CollapseNotetypes,
|
||||||
|
CollapseSavedSearches,
|
||||||
|
CollapseTags,
|
||||||
|
CollapseToday,
|
||||||
|
FutureDueShowBacklog,
|
||||||
|
PreviewBothSides,
|
||||||
|
Sched2021,
|
||||||
|
|
||||||
|
#[strum(to_string = "sortBackwards")]
|
||||||
|
BrowserSortBackwards,
|
||||||
|
#[strum(to_string = "normalize_note_text")]
|
||||||
|
NormalizeNoteText,
|
||||||
#[strum(to_string = "dayLearnFirst")]
|
#[strum(to_string = "dayLearnFirst")]
|
||||||
ShowDayLearningCardsFirst,
|
ShowDayLearningCardsFirst,
|
||||||
#[strum(to_string = "estTimes")]
|
#[strum(to_string = "estTimes")]
|
||||||
|
@ -90,23 +95,6 @@ pub(crate) enum ConfigKey {
|
||||||
ShowRemainingDueCountsInStudy,
|
ShowRemainingDueCountsInStudy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BoolKey> for ConfigKey {
|
|
||||||
fn from(key: BoolKey) -> Self {
|
|
||||||
match key {
|
|
||||||
BoolKey::BrowserSortBackwards => ConfigKey::BrowserSortReverse,
|
|
||||||
BoolKey::CollapseCardState => ConfigKey::CollapseCardState,
|
|
||||||
BoolKey::CollapseDecks => ConfigKey::CollapseDecks,
|
|
||||||
BoolKey::CollapseFlags => ConfigKey::CollapseFlags,
|
|
||||||
BoolKey::CollapseNotetypes => ConfigKey::CollapseNotetypes,
|
|
||||||
BoolKey::CollapseSavedSearches => ConfigKey::CollapseSavedSearches,
|
|
||||||
BoolKey::CollapseTags => ConfigKey::CollapseTags,
|
|
||||||
BoolKey::CollapseToday => ConfigKey::CollapseToday,
|
|
||||||
BoolKey::PreviewBothSides => ConfigKey::PreviewBothSides,
|
|
||||||
BoolKey::Sched2021 => ConfigKey::Sched2021,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StringKey> for ConfigKey {
|
impl From<StringKey> for ConfigKey {
|
||||||
fn from(key: StringKey) -> Self {
|
fn from(key: StringKey) -> Self {
|
||||||
match key {
|
match key {
|
||||||
|
@ -169,13 +157,31 @@ impl Collection {
|
||||||
self.storage.remove_config(key.into())
|
self.storage.remove_config(key.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_browser_sort_kind(&self) -> SortKind {
|
pub(crate) fn get_bool(&self, key: BoolKey) -> bool {
|
||||||
self.get_config_default(ConfigKey::BrowserSortKind)
|
match key {
|
||||||
|
BoolKey::BrowserSortBackwards => {
|
||||||
|
// older clients were storing this as an int
|
||||||
|
self.get_config_default::<BoolLike, _>(BoolKey::BrowserSortBackwards)
|
||||||
|
.0
|
||||||
|
}
|
||||||
|
|
||||||
|
// some keys default to true
|
||||||
|
BoolKey::FutureDueShowBacklog
|
||||||
|
| BoolKey::ShowRemainingDueCountsInStudy
|
||||||
|
| BoolKey::CardCountsSeparateInactive
|
||||||
|
| BoolKey::NormalizeNoteText => self.get_config_optional(key).unwrap_or(true),
|
||||||
|
|
||||||
|
// other options default to false
|
||||||
|
other => self.get_config_default(other),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_browser_sort_reverse(&self) -> bool {
|
pub(crate) fn set_bool(&self, key: BoolKey, value: bool) -> Result<()> {
|
||||||
let b: BoolLike = self.get_config_default(ConfigKey::BrowserSortReverse);
|
self.set_config(key, &value)
|
||||||
b.0
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_browser_sort_kind(&self) -> SortKind {
|
||||||
|
self.get_config_default(ConfigKey::BrowserSortKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_current_deck_id(&self) -> DeckID {
|
pub(crate) fn get_current_deck_id(&self) -> DeckID {
|
||||||
|
@ -256,12 +262,6 @@ impl Collection {
|
||||||
self.set_config(ConfigKey::LearnAheadSecs, &secs)
|
self.set_config(ConfigKey::LearnAheadSecs, &secs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is a stop-gap solution until we can decouple searching from canonical storage.
|
|
||||||
pub(crate) fn normalize_note_text(&self) -> bool {
|
|
||||||
self.get_config_optional(ConfigKey::NormalizeNoteText)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_new_review_mix(&self) -> NewReviewMix {
|
pub(crate) fn get_new_review_mix(&self) -> NewReviewMix {
|
||||||
match self.get_config_default::<u8, _>(ConfigKey::NewReviewMix) {
|
match self.get_config_default::<u8, _>(ConfigKey::NewReviewMix) {
|
||||||
1 => NewReviewMix::ReviewsFirst,
|
1 => NewReviewMix::ReviewsFirst,
|
||||||
|
@ -283,42 +283,6 @@ impl Collection {
|
||||||
self.set_config(ConfigKey::FirstDayOfWeek, &weekday)
|
self.set_config(ConfigKey::FirstDayOfWeek, &weekday)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_card_counts_separate_inactive(&self) -> bool {
|
|
||||||
self.get_config_optional(ConfigKey::CardCountsSeparateInactive)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_card_counts_separate_inactive(&self, separate: bool) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::CardCountsSeparateInactive, &separate)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_future_due_show_backlog(&self) -> bool {
|
|
||||||
self.get_config_optional(ConfigKey::FutureDueShowBacklog)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_future_due_show_backlog(&self, show: bool) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::FutureDueShowBacklog, &show)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_show_due_counts(&self) -> bool {
|
|
||||||
self.get_config_optional(ConfigKey::ShowRemainingDueCountsInStudy)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_show_due_counts(&self, on: bool) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::ShowRemainingDueCountsInStudy, &on)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_show_intervals_above_buttons(&self) -> bool {
|
|
||||||
self.get_config_optional(ConfigKey::ShowIntervalsAboveAnswerButtons)
|
|
||||||
.unwrap_or(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_show_intervals_above_buttons(&self, on: bool) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::ShowIntervalsAboveAnswerButtons, &on)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_answer_time_limit_secs(&self) -> u32 {
|
pub(crate) fn get_answer_time_limit_secs(&self) -> u32 {
|
||||||
self.get_config_optional(ConfigKey::AnswerTimeLimitSecs)
|
self.get_config_optional(ConfigKey::AnswerTimeLimitSecs)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
@ -328,15 +292,6 @@ impl Collection {
|
||||||
self.set_config(ConfigKey::AnswerTimeLimitSecs, &secs)
|
self.set_config(ConfigKey::AnswerTimeLimitSecs, &secs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_day_learn_first(&self) -> bool {
|
|
||||||
self.get_config_optional(ConfigKey::ShowDayLearningCardsFirst)
|
|
||||||
.unwrap_or_default()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_day_learn_first(&self, on: bool) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::ShowDayLearningCardsFirst, &on)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_last_unburied_day(&self) -> u32 {
|
pub(crate) fn get_last_unburied_day(&self) -> u32 {
|
||||||
self.get_config_optional(ConfigKey::LastUnburiedDay)
|
self.get_config_optional(ConfigKey::LastUnburiedDay)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
@ -346,23 +301,6 @@ impl Collection {
|
||||||
self.set_config(ConfigKey::LastUnburiedDay, &day)
|
self.set_config(ConfigKey::LastUnburiedDay, &day)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::match_single_binding)]
|
|
||||||
pub(crate) fn get_bool(&self, config: pb::config::Bool) -> bool {
|
|
||||||
self.get_bool_key(config.key())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::match_single_binding)]
|
|
||||||
pub(crate) fn get_bool_key(&self, key: BoolKey) -> bool {
|
|
||||||
match key {
|
|
||||||
// all options default to false at the moment
|
|
||||||
other => self.get_config_default(ConfigKey::from(other)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_bool(&self, input: pb::SetConfigBoolIn) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::from(input.key()), &input.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_string(&self, config: pb::config::String) -> String {
|
pub(crate) fn get_string(&self, config: pb::config::String) -> String {
|
||||||
let key = config.key();
|
let key = config.key();
|
||||||
let default = match key {
|
let default = match key {
|
||||||
|
|
|
@ -230,7 +230,7 @@ impl Collection {
|
||||||
F: FnMut(DatabaseCheckProgress, bool),
|
F: FnMut(DatabaseCheckProgress, bool),
|
||||||
{
|
{
|
||||||
let nids_by_notetype = self.storage.all_note_ids_by_notetype()?;
|
let nids_by_notetype = self.storage.all_note_ids_by_notetype()?;
|
||||||
let norm = self.normalize_note_text();
|
let norm = self.get_bool(BoolKey::NormalizeNoteText);
|
||||||
let usn = self.usn()?;
|
let usn = self.usn()?;
|
||||||
let stamp = TimestampMillis::now();
|
let stamp = TimestampMillis::now();
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@ impl Collection {
|
||||||
let dconf = self.storage.get_deck_config_map()?;
|
let dconf = self.storage.get_deck_config_map()?;
|
||||||
add_counts(&mut tree, &counts);
|
add_counts(&mut tree, &counts);
|
||||||
if self.scheduler_version() == SchedulerVersion::V2
|
if self.scheduler_version() == SchedulerVersion::V2
|
||||||
&& !self.get_bool_key(BoolKey::Sched2021)
|
&& !self.get_bool(BoolKey::Sched2021)
|
||||||
{
|
{
|
||||||
apply_limits_v2_old(
|
apply_limits_v2_old(
|
||||||
&mut tree,
|
&mut tree,
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crate::{
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
err::{AnkiError, Result},
|
err::{AnkiError, Result},
|
||||||
notes::{NoteID, TransformNoteOutput},
|
notes::{NoteID, TransformNoteOutput},
|
||||||
|
prelude::*,
|
||||||
text::normalize_to_nfc,
|
text::normalize_to_nfc,
|
||||||
};
|
};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
@ -46,7 +47,7 @@ impl Collection {
|
||||||
field_name: Option<String>,
|
field_name: Option<String>,
|
||||||
) -> Result<usize> {
|
) -> Result<usize> {
|
||||||
self.transact(None, |col| {
|
self.transact(None, |col| {
|
||||||
let norm = col.normalize_note_text();
|
let norm = col.get_bool(BoolKey::NormalizeNoteText);
|
||||||
let search = if norm {
|
let search = if norm {
|
||||||
normalize_to_nfc(search_re)
|
normalize_to_nfc(search_re)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -305,7 +305,7 @@ impl Collection {
|
||||||
.get_notetype(note.notetype_id)?
|
.get_notetype(note.notetype_id)?
|
||||||
.ok_or_else(|| AnkiError::invalid_input("missing note type"))?;
|
.ok_or_else(|| AnkiError::invalid_input("missing note type"))?;
|
||||||
let ctx = CardGenContext::new(&nt, col.usn()?);
|
let ctx = CardGenContext::new(&nt, col.usn()?);
|
||||||
let norm = col.normalize_note_text();
|
let norm = col.get_bool(BoolKey::NormalizeNoteText);
|
||||||
col.add_note_inner(&ctx, note, did, norm)
|
col.add_note_inner(&ctx, note, did, norm)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -345,7 +345,7 @@ impl Collection {
|
||||||
.get_notetype(note.notetype_id)?
|
.get_notetype(note.notetype_id)?
|
||||||
.ok_or_else(|| AnkiError::invalid_input("missing note type"))?;
|
.ok_or_else(|| AnkiError::invalid_input("missing note type"))?;
|
||||||
let ctx = CardGenContext::new(&nt, col.usn()?);
|
let ctx = CardGenContext::new(&nt, col.usn()?);
|
||||||
let norm = col.normalize_note_text();
|
let norm = col.get_bool(BoolKey::NormalizeNoteText);
|
||||||
col.update_note_inner_generating_cards(&ctx, note, &existing_note, true, norm)
|
col.update_note_inner_generating_cards(&ctx, note, &existing_note, true, norm)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ impl Collection {
|
||||||
F: FnMut(&mut Note, &NoteType) -> Result<TransformNoteOutput>,
|
F: FnMut(&mut Note, &NoteType) -> Result<TransformNoteOutput>,
|
||||||
{
|
{
|
||||||
let nids_by_notetype = self.storage.note_ids_by_notetype(nids)?;
|
let nids_by_notetype = self.storage.note_ids_by_notetype(nids)?;
|
||||||
let norm = self.normalize_note_text();
|
let norm = self.get_bool(BoolKey::NormalizeNoteText);
|
||||||
let mut changed_notes = 0;
|
let mut changed_notes = 0;
|
||||||
let usn = self.usn()?;
|
let usn = self.usn()?;
|
||||||
|
|
||||||
|
@ -479,7 +479,7 @@ impl Collection {
|
||||||
|
|
||||||
pub(crate) fn note_is_duplicate_or_empty(&self, note: &Note) -> Result<DuplicateState> {
|
pub(crate) fn note_is_duplicate_or_empty(&self, note: &Note) -> Result<DuplicateState> {
|
||||||
if let Some(field1) = note.fields.get(0) {
|
if let Some(field1) = note.fields.get(0) {
|
||||||
let field1 = if self.normalize_note_text() {
|
let field1 = if self.get_bool(BoolKey::NormalizeNoteText) {
|
||||||
normalize_to_nfc(field1)
|
normalize_to_nfc(field1)
|
||||||
} else {
|
} else {
|
||||||
field1.into()
|
field1.into()
|
||||||
|
@ -554,8 +554,8 @@ fn note_differs_from_db(existing_note: &mut Note, note: &mut Note) -> bool {
|
||||||
mod test {
|
mod test {
|
||||||
use super::{anki_base91, field_checksum};
|
use super::{anki_base91, field_checksum};
|
||||||
use crate::{
|
use crate::{
|
||||||
collection::open_test_collection, config::ConfigKey, decks::DeckID, err::Result,
|
collection::open_test_collection, config::BoolKey, decks::DeckID, err::Result, prelude::*,
|
||||||
prelude::*, search::SortMode,
|
search::SortMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -642,8 +642,7 @@ mod test {
|
||||||
// if normalization turned off, note text is entered as-is
|
// if normalization turned off, note text is entered as-is
|
||||||
let mut note = nt.new_note();
|
let mut note = nt.new_note();
|
||||||
note.fields[0] = "\u{fa47}".into();
|
note.fields[0] = "\u{fa47}".into();
|
||||||
col.set_config(ConfigKey::NormalizeNoteText, &false)
|
col.set_config(BoolKey::NormalizeNoteText, &false).unwrap();
|
||||||
.unwrap();
|
|
||||||
col.add_note(&mut note, DeckID(1))?;
|
col.add_note(&mut note, DeckID(1))?;
|
||||||
assert_eq!(note.fields[0], "\u{fa47}");
|
assert_eq!(note.fields[0], "\u{fa47}");
|
||||||
// normalized searches won't match
|
// normalized searches won't match
|
||||||
|
|
|
@ -28,6 +28,7 @@ use crate::{
|
||||||
define_newtype,
|
define_newtype,
|
||||||
err::{AnkiError, Result},
|
err::{AnkiError, Result},
|
||||||
notes::Note,
|
notes::Note,
|
||||||
|
prelude::*,
|
||||||
template::{FieldRequirements, ParsedTemplate},
|
template::{FieldRequirements, ParsedTemplate},
|
||||||
text::ensure_string_in_nfc,
|
text::ensure_string_in_nfc,
|
||||||
timestamp::TimestampSecs,
|
timestamp::TimestampSecs,
|
||||||
|
@ -424,7 +425,7 @@ impl Collection {
|
||||||
/// or fields have been added/removed/reordered.
|
/// or fields have been added/removed/reordered.
|
||||||
pub fn update_notetype(&mut self, nt: &mut NoteType, preserve_usn: bool) -> Result<()> {
|
pub fn update_notetype(&mut self, nt: &mut NoteType, preserve_usn: bool) -> Result<()> {
|
||||||
let existing = self.get_notetype(nt.id)?;
|
let existing = self.get_notetype(nt.id)?;
|
||||||
let norm = self.normalize_note_text();
|
let norm = self.get_bool(BoolKey::NormalizeNoteText);
|
||||||
nt.prepare_for_update(existing.as_ref().map(AsRef::as_ref))?;
|
nt.prepare_for_update(existing.as_ref().map(AsRef::as_ref))?;
|
||||||
self.transact(None, |col| {
|
self.transact(None, |col| {
|
||||||
if let Some(existing_notetype) = existing {
|
if let Some(existing_notetype) = existing {
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
Preferences,
|
Preferences,
|
||||||
},
|
},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
|
config::BoolKey,
|
||||||
err::Result,
|
err::Result,
|
||||||
scheduler::timing::local_minutes_west_for_stamp,
|
scheduler::timing::local_minutes_west_for_stamp,
|
||||||
};
|
};
|
||||||
|
@ -39,11 +40,11 @@ impl Collection {
|
||||||
crate::config::NewReviewMix::ReviewsFirst => NewRevMixPB::ReviewsFirst,
|
crate::config::NewReviewMix::ReviewsFirst => NewRevMixPB::ReviewsFirst,
|
||||||
crate::config::NewReviewMix::NewFirst => NewRevMixPB::NewFirst,
|
crate::config::NewReviewMix::NewFirst => NewRevMixPB::NewFirst,
|
||||||
} as i32,
|
} as i32,
|
||||||
show_remaining_due_counts: self.get_show_due_counts(),
|
show_remaining_due_counts: self.get_bool(BoolKey::ShowRemainingDueCountsInStudy),
|
||||||
show_intervals_on_buttons: self.get_show_intervals_above_buttons(),
|
show_intervals_on_buttons: self.get_bool(BoolKey::ShowIntervalsAboveAnswerButtons),
|
||||||
time_limit_secs: self.get_answer_time_limit_secs(),
|
time_limit_secs: self.get_answer_time_limit_secs(),
|
||||||
new_timezone: self.get_creation_utc_offset().is_some(),
|
new_timezone: self.get_creation_utc_offset().is_some(),
|
||||||
day_learn_first: self.get_day_learn_first(),
|
day_learn_first: self.get_bool(BoolKey::ShowDayLearningCardsFirst),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,10 +54,16 @@ impl Collection {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let s = settings;
|
let s = settings;
|
||||||
|
|
||||||
self.set_day_learn_first(s.day_learn_first)?;
|
self.set_bool(BoolKey::ShowDayLearningCardsFirst, s.day_learn_first)?;
|
||||||
|
self.set_bool(
|
||||||
|
BoolKey::ShowRemainingDueCountsInStudy,
|
||||||
|
s.show_remaining_due_counts,
|
||||||
|
)?;
|
||||||
|
self.set_bool(
|
||||||
|
BoolKey::ShowIntervalsAboveAnswerButtons,
|
||||||
|
s.show_intervals_on_buttons,
|
||||||
|
)?;
|
||||||
self.set_answer_time_limit_secs(s.time_limit_secs)?;
|
self.set_answer_time_limit_secs(s.time_limit_secs)?;
|
||||||
self.set_show_due_counts(s.show_remaining_due_counts)?;
|
|
||||||
self.set_show_intervals_above_buttons(s.show_intervals_on_buttons)?;
|
|
||||||
self.set_learn_ahead_secs(s.learn_ahead_secs)?;
|
self.set_learn_ahead_secs(s.learn_ahead_secs)?;
|
||||||
|
|
||||||
self.set_new_review_mix(match s.new_review_mix() {
|
self.set_new_review_mix(match s.new_review_mix() {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
card::{Card, CardID},
|
card::{Card, CardID},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
|
config::BoolKey,
|
||||||
deckconf::{DeckConf, DeckConfID},
|
deckconf::{DeckConf, DeckConfID},
|
||||||
decks::{Deck, DeckID, DeckKind},
|
decks::{Deck, DeckID, DeckKind},
|
||||||
err::{AnkiError, Result},
|
err::{AnkiError, Result},
|
||||||
|
|
|
@ -6,7 +6,11 @@ use super::{
|
||||||
sqlwriter::{RequiredTable, SqlWriter},
|
sqlwriter::{RequiredTable, SqlWriter},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
card::CardID, card::CardType, collection::Collection, config::SortKind, err::Result,
|
card::CardID,
|
||||||
|
card::CardType,
|
||||||
|
collection::Collection,
|
||||||
|
config::{BoolKey, SortKind},
|
||||||
|
err::Result,
|
||||||
search::parser::parse,
|
search::parser::parse,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -124,7 +128,7 @@ impl Collection {
|
||||||
if mode == &SortMode::FromConfig {
|
if mode == &SortMode::FromConfig {
|
||||||
*mode = SortMode::Builtin {
|
*mode = SortMode::Builtin {
|
||||||
kind: self.get_browser_sort_kind(),
|
kind: self.get_browser_sort_kind(),
|
||||||
reverse: self.get_browser_sort_reverse(),
|
reverse: self.get_bool(BoolKey::BrowserSortBackwards),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use crate::{
|
||||||
err::Result,
|
err::Result,
|
||||||
notes::field_checksum,
|
notes::field_checksum,
|
||||||
notetype::NoteTypeID,
|
notetype::NoteTypeID,
|
||||||
|
prelude::*,
|
||||||
storage::ids_to_string,
|
storage::ids_to_string,
|
||||||
text::{
|
text::{
|
||||||
is_glob, matches_glob, normalize_to_nfc, strip_html_preserving_media_filenames,
|
is_glob, matches_glob, normalize_to_nfc, strip_html_preserving_media_filenames,
|
||||||
|
@ -28,7 +29,7 @@ pub(crate) struct SqlWriter<'a> {
|
||||||
|
|
||||||
impl SqlWriter<'_> {
|
impl SqlWriter<'_> {
|
||||||
pub(crate) fn new(col: &mut Collection) -> SqlWriter<'_> {
|
pub(crate) fn new(col: &mut Collection) -> SqlWriter<'_> {
|
||||||
let normalize_note_text = col.normalize_note_text();
|
let normalize_note_text = col.get_bool(BoolKey::NormalizeNoteText);
|
||||||
let sql = String::new();
|
let sql = String::new();
|
||||||
let args = vec![];
|
let args = vec![];
|
||||||
SqlWriter {
|
SqlWriter {
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb, config::Weekday, prelude::*, revlog::RevlogEntry, search::SortMode,
|
backend_proto as pb,
|
||||||
|
config::{BoolKey, Weekday},
|
||||||
|
prelude::*,
|
||||||
|
revlog::RevlogEntry,
|
||||||
|
search::SortMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
|
@ -50,9 +54,9 @@ impl Collection {
|
||||||
pub(crate) fn get_graph_preferences(&self) -> Result<pb::GraphPreferences> {
|
pub(crate) fn get_graph_preferences(&self) -> Result<pb::GraphPreferences> {
|
||||||
Ok(pb::GraphPreferences {
|
Ok(pb::GraphPreferences {
|
||||||
calendar_first_day_of_week: self.get_first_day_of_week() as i32,
|
calendar_first_day_of_week: self.get_first_day_of_week() as i32,
|
||||||
card_counts_separate_inactive: self.get_card_counts_separate_inactive(),
|
card_counts_separate_inactive: self.get_bool(BoolKey::CardCountsSeparateInactive),
|
||||||
browser_links_supported: true,
|
browser_links_supported: true,
|
||||||
future_due_show_backlog: self.get_future_due_show_backlog(),
|
future_due_show_backlog: self.get_bool(BoolKey::FutureDueShowBacklog),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +67,11 @@ impl Collection {
|
||||||
6 => Weekday::Saturday,
|
6 => Weekday::Saturday,
|
||||||
_ => Weekday::Sunday,
|
_ => Weekday::Sunday,
|
||||||
})?;
|
})?;
|
||||||
self.set_card_counts_separate_inactive(prefs.card_counts_separate_inactive)?;
|
self.set_bool(
|
||||||
self.set_future_due_show_backlog(prefs.future_due_show_backlog)?;
|
BoolKey::CardCountsSeparateInactive,
|
||||||
|
prefs.card_counts_separate_inactive,
|
||||||
|
)?;
|
||||||
|
self.set_bool(BoolKey::FutureDueShowBacklog, prefs.future_due_show_backlog)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue