Rename browser_rows to browser_table

Reflects the addition of column handling.
This commit is contained in:
RumovZ 2021-03-30 12:08:35 +02:00
parent ffe77b1291
commit da156cd759
6 changed files with 78 additions and 78 deletions

View file

@ -1,71 +0,0 @@
// 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, browser_rows};
impl From<pb::StringList> for Vec<browser_rows::Column> {
fn from(input: pb::StringList) -> Self {
input.vals.into_iter().map(Into::into).collect()
}
}
impl From<String> for browser_rows::Column {
fn from(text: String) -> Self {
match text.as_str() {
"question" => browser_rows::Column::Question,
"answer" => browser_rows::Column::Answer,
"deck" => browser_rows::Column::CardDeck,
"cardDue" => browser_rows::Column::CardDue,
"cardEase" => browser_rows::Column::CardEase,
"cardLapses" => browser_rows::Column::CardLapses,
"cardIvl" => browser_rows::Column::CardInterval,
"cardMod" => browser_rows::Column::CardMod,
"cardReps" => browser_rows::Column::CardReps,
"template" => browser_rows::Column::CardTemplate,
"noteCards" => browser_rows::Column::NoteCards,
"noteCrt" => browser_rows::Column::NoteCreation,
"noteEase" => browser_rows::Column::NoteEase,
"noteFld" => browser_rows::Column::NoteField,
"noteLapses" => browser_rows::Column::NoteLapses,
"noteMod" => browser_rows::Column::NoteMod,
"noteReps" => browser_rows::Column::NoteReps,
"noteTags" => browser_rows::Column::NoteTags,
"note" => browser_rows::Column::Notetype,
_ => browser_rows::Column::Custom,
}
}
}
impl From<browser_rows::Row> for pb::BrowserRow {
fn from(row: browser_rows::Row) -> Self {
pb::BrowserRow {
cells: row.cells.into_iter().map(Into::into).collect(),
color: row.color.into(),
font_name: row.font.name,
font_size: row.font.size,
}
}
}
impl From<browser_rows::Cell> for pb::browser_row::Cell {
fn from(cell: browser_rows::Cell) -> Self {
pb::browser_row::Cell {
text: cell.text,
is_rtl: cell.is_rtl,
}
}
}
impl From<browser_rows::Color> for i32 {
fn from(color: browser_rows::Color) -> Self {
match color {
browser_rows::Color::Default => pb::browser_row::Color::Default as i32,
browser_rows::Color::Marked => pb::browser_row::Color::Marked as i32,
browser_rows::Color::Suspended => pb::browser_row::Color::Suspended as i32,
browser_rows::Color::FlagRed => pb::browser_row::Color::FlagRed as i32,
browser_rows::Color::FlagOrange => pb::browser_row::Color::FlagOrange as i32,
browser_rows::Color::FlagGreen => pb::browser_row::Color::FlagGreen as i32,
browser_rows::Color::FlagBlue => pb::browser_row::Color::FlagBlue as i32,
}
}
}

View file

@ -0,0 +1,71 @@
// 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, browser_table};
impl From<pb::StringList> for Vec<browser_table::Column> {
fn from(input: pb::StringList) -> Self {
input.vals.into_iter().map(Into::into).collect()
}
}
impl From<String> for browser_table::Column {
fn from(text: String) -> Self {
match text.as_str() {
"question" => browser_table::Column::Question,
"answer" => browser_table::Column::Answer,
"deck" => browser_table::Column::CardDeck,
"cardDue" => browser_table::Column::CardDue,
"cardEase" => browser_table::Column::CardEase,
"cardLapses" => browser_table::Column::CardLapses,
"cardIvl" => browser_table::Column::CardInterval,
"cardMod" => browser_table::Column::CardMod,
"cardReps" => browser_table::Column::CardReps,
"template" => browser_table::Column::CardTemplate,
"noteCards" => browser_table::Column::NoteCards,
"noteCrt" => browser_table::Column::NoteCreation,
"noteEase" => browser_table::Column::NoteEase,
"noteFld" => browser_table::Column::NoteField,
"noteLapses" => browser_table::Column::NoteLapses,
"noteMod" => browser_table::Column::NoteMod,
"noteReps" => browser_table::Column::NoteReps,
"noteTags" => browser_table::Column::NoteTags,
"note" => browser_table::Column::Notetype,
_ => browser_table::Column::Custom,
}
}
}
impl From<browser_table::Row> for pb::BrowserRow {
fn from(row: browser_table::Row) -> Self {
pb::BrowserRow {
cells: row.cells.into_iter().map(Into::into).collect(),
color: row.color.into(),
font_name: row.font.name,
font_size: row.font.size,
}
}
}
impl From<browser_table::Cell> for pb::browser_row::Cell {
fn from(cell: browser_table::Cell) -> Self {
pb::browser_row::Cell {
text: cell.text,
is_rtl: cell.is_rtl,
}
}
}
impl From<browser_table::Color> for i32 {
fn from(color: browser_table::Color) -> Self {
match color {
browser_table::Color::Default => pb::browser_row::Color::Default as i32,
browser_table::Color::Marked => pb::browser_row::Color::Marked as i32,
browser_table::Color::Suspended => pb::browser_row::Color::Suspended as i32,
browser_table::Color::FlagRed => pb::browser_row::Color::FlagRed as i32,
browser_table::Color::FlagOrange => pb::browser_row::Color::FlagOrange as i32,
browser_table::Color::FlagGreen => pb::browser_row::Color::FlagGreen as i32,
browser_table::Color::FlagBlue => pb::browser_row::Color::FlagBlue as i32,
}
}
}

View file

@ -1,7 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors // Copyright: Ankitects Pty Ltd and contributors
// 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 browser_row; mod browser_table;
mod search_node; mod search_node;
use std::convert::TryInto; use std::convert::TryInto;

View file

@ -9,7 +9,7 @@ mod string;
pub(crate) mod undo; pub(crate) mod undo;
pub use self::{bool::BoolKey, string::StringKey}; pub use self::{bool::BoolKey, string::StringKey};
use crate::browser_rows; use crate::browser_table;
use crate::prelude::*; use crate::prelude::*;
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use serde_derive::Deserialize; use serde_derive::Deserialize;
@ -139,24 +139,24 @@ impl Collection {
self.get_config_default(ConfigKey::BrowserNoteSortKind) self.get_config_default(ConfigKey::BrowserNoteSortKind)
} }
pub(crate) fn get_desktop_browser_card_columns(&self) -> Option<Vec<browser_rows::Column>> { pub(crate) fn get_desktop_browser_card_columns(&self) -> Option<Vec<browser_table::Column>> {
self.get_config_optional(ConfigKey::DesktopBrowserCardColumns) self.get_config_optional(ConfigKey::DesktopBrowserCardColumns)
} }
pub(crate) fn set_desktop_browser_card_columns( pub(crate) fn set_desktop_browser_card_columns(
&mut self, &mut self,
columns: Vec<browser_rows::Column>, columns: Vec<browser_table::Column>,
) -> Result<()> { ) -> Result<()> {
self.set_config(ConfigKey::DesktopBrowserCardColumns, &columns) self.set_config(ConfigKey::DesktopBrowserCardColumns, &columns)
} }
pub(crate) fn get_desktop_browser_note_columns(&self) -> Option<Vec<browser_rows::Column>> { pub(crate) fn get_desktop_browser_note_columns(&self) -> Option<Vec<browser_table::Column>> {
self.get_config_optional(ConfigKey::DesktopBrowserNoteColumns) self.get_config_optional(ConfigKey::DesktopBrowserNoteColumns)
} }
pub(crate) fn set_desktop_browser_note_columns( pub(crate) fn set_desktop_browser_note_columns(
&mut self, &mut self,
columns: Vec<browser_rows::Column>, columns: Vec<browser_table::Column>,
) -> Result<()> { ) -> Result<()> {
self.set_config(ConfigKey::DesktopBrowserNoteColumns, &columns) self.set_config(ConfigKey::DesktopBrowserNoteColumns, &columns)
} }

View file

@ -6,7 +6,7 @@
pub mod adding; pub mod adding;
pub mod backend; pub mod backend;
mod backend_proto; mod backend_proto;
pub mod browser_rows; pub mod browser_table;
pub mod card; pub mod card;
pub mod cloze; pub mod cloze;
pub mod collection; pub mod collection;