mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Move Column logic into main rslib
This commit is contained in:
parent
055a5e8a04
commit
f04ea5a2c7
2 changed files with 76 additions and 75 deletions
|
@ -3,23 +3,10 @@
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use strum::IntoEnumIterator;
|
use crate::{backend_proto as pb, browser_table, i18n::I18n};
|
||||||
|
|
||||||
use crate::{backend_proto as pb, browser_table, collection::Collection, i18n::I18n};
|
|
||||||
|
|
||||||
impl Collection {
|
|
||||||
pub(crate) fn all_browser_columns(&self) -> pb::BrowserColumns {
|
|
||||||
let mut columns: Vec<pb::browser_columns::Column> = browser_table::Column::iter()
|
|
||||||
.filter(|&c| c != browser_table::Column::Custom)
|
|
||||||
.map(|c| c.to_pb_column(&self.tr))
|
|
||||||
.collect();
|
|
||||||
columns.sort_by(|c1, c2| c1.label.cmp(&c2.label));
|
|
||||||
pb::BrowserColumns { columns }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl browser_table::Column {
|
impl browser_table::Column {
|
||||||
fn to_pb_column(self, i18n: &I18n) -> pb::browser_columns::Column {
|
pub fn to_pb_column(self, i18n: &I18n) -> pb::browser_columns::Column {
|
||||||
pb::browser_columns::Column {
|
pb::browser_columns::Column {
|
||||||
key: self.to_string(),
|
key: self.to_string(),
|
||||||
label: self.localized_label(i18n),
|
label: self.localized_label(i18n),
|
||||||
|
@ -29,65 +16,6 @@ impl browser_table::Column {
|
||||||
alignment: self.alignment() as i32,
|
alignment: self.alignment() as i32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sorting(self) -> pb::browser_columns::Sorting {
|
|
||||||
match self {
|
|
||||||
Self::Question | Self::Answer | Self::Custom => pb::browser_columns::Sorting::None,
|
|
||||||
Self::SortField => pb::browser_columns::Sorting::Reversed,
|
|
||||||
_ => pb::browser_columns::Sorting::Normal,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn uses_cell_font(self) -> bool {
|
|
||||||
matches!(self, Self::Question | Self::Answer | Self::SortField)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn alignment(self) -> pb::browser_columns::Alignment {
|
|
||||||
match self {
|
|
||||||
Self::Question
|
|
||||||
| Self::Answer
|
|
||||||
| Self::Cards
|
|
||||||
| Self::Deck
|
|
||||||
| Self::SortField
|
|
||||||
| Self::Notetype
|
|
||||||
| Self::Tags => pb::browser_columns::Alignment::Start,
|
|
||||||
_ => pb::browser_columns::Alignment::Center,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn localized_label(self, i18n: &I18n) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Answer => i18n.browsing_answer(),
|
|
||||||
Self::CardMod => i18n.search_card_modified(),
|
|
||||||
Self::Cards => i18n.browsing_card(),
|
|
||||||
Self::Deck => i18n.decks_deck(),
|
|
||||||
Self::Due => i18n.statistics_due_date(),
|
|
||||||
Self::Custom => i18n.browsing_addon(),
|
|
||||||
Self::Ease => i18n.browsing_ease(),
|
|
||||||
Self::Interval => i18n.browsing_interval(),
|
|
||||||
Self::Lapses => i18n.scheduling_lapses(),
|
|
||||||
Self::NoteCreation => i18n.browsing_created(),
|
|
||||||
Self::NoteMod => i18n.search_note_modified(),
|
|
||||||
Self::Notetype => i18n.browsing_note(),
|
|
||||||
Self::Question => i18n.browsing_question(),
|
|
||||||
Self::Reps => i18n.scheduling_reviews(),
|
|
||||||
Self::SortField => i18n.browsing_sort_field(),
|
|
||||||
Self::Tags => i18n.editing_tags(),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn localized_notes_label(self, i18n: &I18n) -> String {
|
|
||||||
match self {
|
|
||||||
Self::CardMod => i18n.search_card_modified(),
|
|
||||||
Self::Cards => i18n.editing_cards(),
|
|
||||||
Self::Ease => i18n.browsing_average_ease(),
|
|
||||||
Self::Interval => i18n.browsing_average_interval(),
|
|
||||||
Self::Reps => i18n.scheduling_reviews(),
|
|
||||||
_ => return self.localized_label(i18n),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<pb::StringList> for Vec<browser_table::Column> {
|
impl From<pb::StringList> for Vec<browser_table::Column> {
|
||||||
|
|
|
@ -5,11 +5,12 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{Display, EnumIter, EnumString};
|
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
|
||||||
|
|
||||||
use crate::error::{AnkiError, Result};
|
use crate::error::{AnkiError, Result};
|
||||||
use crate::i18n::I18n;
|
use crate::i18n::I18n;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
backend_proto as pb,
|
||||||
card::{Card, CardId, CardQueue, CardType},
|
card::{Card, CardId, CardQueue, CardType},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
config::BoolKey,
|
config::BoolKey,
|
||||||
|
@ -170,7 +171,79 @@ impl Note {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Column {
|
||||||
|
pub fn localized_label(self, i18n: &I18n) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Answer => i18n.browsing_answer(),
|
||||||
|
Self::CardMod => i18n.search_card_modified(),
|
||||||
|
Self::Cards => i18n.browsing_card(),
|
||||||
|
Self::Deck => i18n.decks_deck(),
|
||||||
|
Self::Due => i18n.statistics_due_date(),
|
||||||
|
Self::Custom => i18n.browsing_addon(),
|
||||||
|
Self::Ease => i18n.browsing_ease(),
|
||||||
|
Self::Interval => i18n.browsing_interval(),
|
||||||
|
Self::Lapses => i18n.scheduling_lapses(),
|
||||||
|
Self::NoteCreation => i18n.browsing_created(),
|
||||||
|
Self::NoteMod => i18n.search_note_modified(),
|
||||||
|
Self::Notetype => i18n.browsing_note(),
|
||||||
|
Self::Question => i18n.browsing_question(),
|
||||||
|
Self::Reps => i18n.scheduling_reviews(),
|
||||||
|
Self::SortField => i18n.browsing_sort_field(),
|
||||||
|
Self::Tags => i18n.editing_tags(),
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn localized_notes_label(self, i18n: &I18n) -> String {
|
||||||
|
match self {
|
||||||
|
Self::CardMod => i18n.search_card_modified(),
|
||||||
|
Self::Cards => i18n.editing_cards(),
|
||||||
|
Self::Ease => i18n.browsing_average_ease(),
|
||||||
|
Self::Interval => i18n.browsing_average_interval(),
|
||||||
|
Self::Reps => i18n.scheduling_reviews(),
|
||||||
|
_ => return self.localized_label(i18n),
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sorting(self) -> pb::browser_columns::Sorting {
|
||||||
|
use pb::browser_columns::Sorting;
|
||||||
|
match self {
|
||||||
|
Self::Question | Self::Answer | Self::Custom => Sorting::None,
|
||||||
|
Self::SortField => Sorting::Reversed,
|
||||||
|
_ => Sorting::Normal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uses_cell_font(self) -> bool {
|
||||||
|
matches!(self, Self::Question | Self::Answer | Self::SortField)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn alignment(self) -> pb::browser_columns::Alignment {
|
||||||
|
use pb::browser_columns::Alignment;
|
||||||
|
match self {
|
||||||
|
Self::Question
|
||||||
|
| Self::Answer
|
||||||
|
| Self::Cards
|
||||||
|
| Self::Deck
|
||||||
|
| Self::SortField
|
||||||
|
| Self::Notetype
|
||||||
|
| Self::Tags => Alignment::Start,
|
||||||
|
_ => Alignment::Center,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
|
pub fn all_browser_columns(&self) -> pb::BrowserColumns {
|
||||||
|
let mut columns: Vec<pb::browser_columns::Column> = Column::iter()
|
||||||
|
.filter(|&c| c != Column::Custom)
|
||||||
|
.map(|c| c.to_pb_column(&self.tr))
|
||||||
|
.collect();
|
||||||
|
columns.sort_by(|c1, c2| c1.label.cmp(&c2.label));
|
||||||
|
pb::BrowserColumns { columns }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn browser_row_for_id(&mut self, id: i64) -> Result<Row> {
|
pub fn browser_row_for_id(&mut self, id: i64) -> Result<Row> {
|
||||||
let notes_mode = self.get_bool(BoolKey::BrowserTableShowNotesMode);
|
let notes_mode = self.get_bool(BoolKey::BrowserTableShowNotesMode);
|
||||||
let columns = if notes_mode {
|
let columns = if notes_mode {
|
||||||
|
|
Loading…
Reference in a new issue