mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Store active browser columns in col state
This commit is contained in:
parent
769b5ac833
commit
d7f7deafd4
6 changed files with 22 additions and 44 deletions
|
@ -717,24 +717,24 @@ class Collection:
|
||||||
columns = self.get_config(
|
columns = self.get_config(
|
||||||
"activeCols", ["noteFld", "template", "cardDue", "deck"]
|
"activeCols", ["noteFld", "template", "cardDue", "deck"]
|
||||||
)
|
)
|
||||||
self._backend.set_desktop_browser_card_columns(columns)
|
self._backend.set_active_browser_columns(columns)
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
def set_browser_card_columns(self, columns: List[str]) -> None:
|
def set_browser_card_columns(self, columns: List[str]) -> None:
|
||||||
self.set_config("activeCols", columns)
|
self.set_config("activeCols", columns)
|
||||||
self._backend.set_desktop_browser_card_columns(columns)
|
self._backend.set_active_browser_columns(columns)
|
||||||
|
|
||||||
def load_browser_note_columns(self) -> List[str]:
|
def load_browser_note_columns(self) -> List[str]:
|
||||||
"""Return the stored note column names and ensure the backend columns are set and in sync."""
|
"""Return the stored note column names and ensure the backend columns are set and in sync."""
|
||||||
columns = self.get_config(
|
columns = self.get_config(
|
||||||
"activeNoteCols", ["noteFld", "note", "noteCards", "noteTags"]
|
"activeNoteCols", ["noteFld", "note", "noteCards", "noteTags"]
|
||||||
)
|
)
|
||||||
self._backend.set_desktop_browser_note_columns(columns)
|
self._backend.set_active_browser_columns(columns)
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
def set_browser_note_columns(self, columns: List[str]) -> None:
|
def set_browser_note_columns(self, columns: List[str]) -> None:
|
||||||
self.set_config("activeNoteCols", columns)
|
self.set_config("activeNoteCols", columns)
|
||||||
self._backend.set_desktop_browser_note_columns(columns)
|
self._backend.set_active_browser_columns(columns)
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -250,8 +250,7 @@ service SearchService {
|
||||||
rpc FindAndReplace(FindAndReplaceIn) returns (OpChangesWithCount);
|
rpc FindAndReplace(FindAndReplaceIn) returns (OpChangesWithCount);
|
||||||
rpc AllBrowserColumns(Empty) returns (BrowserColumns);
|
rpc AllBrowserColumns(Empty) returns (BrowserColumns);
|
||||||
rpc BrowserRowForId(Int64) returns (BrowserRow);
|
rpc BrowserRowForId(Int64) returns (BrowserRow);
|
||||||
rpc SetDesktopBrowserCardColumns(StringList) returns (Empty);
|
rpc SetActiveBrowserColumns(StringList) returns (Empty);
|
||||||
rpc SetDesktopBrowserNoteColumns(StringList) returns (Empty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service StatsService {
|
service StatsService {
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
mod browser_table;
|
mod browser_table;
|
||||||
mod search_node;
|
mod search_node;
|
||||||
|
|
||||||
use std::convert::TryInto;
|
use std::{convert::TryInto, str::FromStr, sync::Arc};
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -92,19 +91,17 @@ impl SearchService for Backend {
|
||||||
self.with_col(|col| Ok(col.all_browser_columns()))
|
self.with_col(|col| Ok(col.all_browser_columns()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_active_browser_columns(&self, input: pb::StringList) -> Result<pb::Empty> {
|
||||||
|
self.with_col(|col| {
|
||||||
|
col.state.active_browser_columns = Some(Arc::new(input.into()));
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.map(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
fn browser_row_for_id(&self, input: pb::Int64) -> Result<pb::BrowserRow> {
|
fn browser_row_for_id(&self, input: pb::Int64) -> Result<pb::BrowserRow> {
|
||||||
self.with_col(|col| col.browser_row_for_id(input.val).map(Into::into))
|
self.with_col(|col| col.browser_row_for_id(input.val).map(Into::into))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_desktop_browser_card_columns(&self, input: pb::StringList) -> Result<pb::Empty> {
|
|
||||||
self.with_col(|col| col.set_desktop_browser_card_columns(input.into()))?;
|
|
||||||
Ok(().into())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_desktop_browser_note_columns(&self, input: pb::StringList) -> Result<pb::Empty> {
|
|
||||||
self.with_col(|col| col.set_desktop_browser_note_columns(input.into()))?;
|
|
||||||
Ok(().into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Option<SortOrderProto>> for SortMode {
|
impl From<Option<SortOrderProto>> for SortMode {
|
||||||
|
|
|
@ -246,13 +246,12 @@ impl Collection {
|
||||||
|
|
||||||
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 = Arc::clone(
|
||||||
self.get_desktop_browser_note_columns()
|
self.state
|
||||||
.ok_or_else(|| AnkiError::invalid_input("Note columns not set."))?
|
.active_browser_columns
|
||||||
} else {
|
.as_ref()
|
||||||
self.get_desktop_browser_card_columns()
|
.ok_or_else(|| AnkiError::invalid_input("Active browser columns not set."))?,
|
||||||
.ok_or_else(|| AnkiError::invalid_input("Card columns not set."))?
|
);
|
||||||
};
|
|
||||||
RowContext::new(self, id, notes_mode, card_render_required(&columns))?.browser_row(&columns)
|
RowContext::new(self, id, notes_mode, card_render_required(&columns))?.browser_row(&columns)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
use crate::types::Usn;
|
use crate::types::Usn;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
browser_table,
|
||||||
decks::{Deck, DeckId},
|
decks::{Deck, DeckId},
|
||||||
notetype::{Notetype, NotetypeId},
|
notetype::{Notetype, NotetypeId},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
@ -66,6 +67,7 @@ pub struct CollectionState {
|
||||||
pub(crate) deck_cache: HashMap<DeckId, Arc<Deck>>,
|
pub(crate) deck_cache: HashMap<DeckId, Arc<Deck>>,
|
||||||
pub(crate) scheduler_info: Option<SchedulerInfo>,
|
pub(crate) scheduler_info: Option<SchedulerInfo>,
|
||||||
pub(crate) card_queues: Option<CardQueues>,
|
pub(crate) card_queues: Option<CardQueues>,
|
||||||
|
pub(crate) active_browser_columns: Option<Arc<Vec<browser_table::Column>>>,
|
||||||
/// True if legacy Python code has executed SQL that has modified the
|
/// True if legacy Python code has executed SQL that has modified the
|
||||||
/// database, requiring modification time to be bumped.
|
/// database, requiring modification time to be bumped.
|
||||||
pub(crate) modified_by_dbproxy: bool,
|
pub(crate) modified_by_dbproxy: bool,
|
||||||
|
|
|
@ -64,9 +64,6 @@ pub(crate) enum ConfigKey {
|
||||||
NextNewCardPosition,
|
NextNewCardPosition,
|
||||||
#[strum(to_string = "schedVer")]
|
#[strum(to_string = "schedVer")]
|
||||||
SchedulerVersion,
|
SchedulerVersion,
|
||||||
|
|
||||||
DesktopBrowserCardColumns,
|
|
||||||
DesktopBrowserNoteColumns,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Serialize_repr, Deserialize_repr, Clone, Copy, Debug)]
|
#[derive(PartialEq, Serialize_repr, Deserialize_repr, Clone, Copy, Debug)]
|
||||||
|
@ -140,22 +137,6 @@ impl Collection {
|
||||||
.unwrap_or(Column::NoteCreation)
|
.unwrap_or(Column::NoteCreation)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_desktop_browser_card_columns(&self) -> Option<Vec<Column>> {
|
|
||||||
self.get_config_optional(ConfigKey::DesktopBrowserCardColumns)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_desktop_browser_card_columns(&mut self, columns: Vec<Column>) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::DesktopBrowserCardColumns, &columns)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_desktop_browser_note_columns(&self) -> Option<Vec<Column>> {
|
|
||||||
self.get_config_optional(ConfigKey::DesktopBrowserNoteColumns)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn set_desktop_browser_note_columns(&mut self, columns: Vec<Column>) -> Result<()> {
|
|
||||||
self.set_config(ConfigKey::DesktopBrowserNoteColumns, &columns)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_creation_utc_offset(&self) -> Option<i32> {
|
pub(crate) fn get_creation_utc_offset(&self) -> Option<i32> {
|
||||||
self.get_config_optional(ConfigKey::CreationOffset)
|
self.get_config_optional(ConfigKey::CreationOffset)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue