From 6c3c479906a6edaaea3725f374002bf179cafdb4 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Thu, 8 Apr 2021 10:16:06 +0200 Subject: [PATCH] Move BrowserColumn into BrowserColumns message --- pylib/anki/collection.py | 4 +++- rslib/backend.proto | 19 +++++++++---------- rslib/src/backend/search/browser_table.rs | 6 +++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index a0819f29a..0074b0967 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -1143,7 +1143,9 @@ def _build_sort_mode( return _pb.SortOrder(builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse)) -def _column_data(column: _pb.BrowserColumn) -> Tuple[str, str, bool, bool, bool, bool]: +def _column_data( + column: _pb.BrowserColumns.Column, +) -> Tuple[str, str, bool, bool, bool, bool]: return ( column.key, column.label, diff --git a/rslib/backend.proto b/rslib/backend.proto index 0d5b2cb55..ddddb0175 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -1055,16 +1055,15 @@ message FindAndReplaceIn { } message BrowserColumns { - repeated BrowserColumn columns = 1; -} - -message BrowserColumn { - string key = 1; - string label = 2; - bool is_sortable = 3; - bool sorts_reversed = 4; - bool uses_cell_font = 5; - bool aligns_centered = 6; + message Column { + string key = 1; + string label = 2; + bool is_sortable = 3; + bool sorts_reversed = 4; + bool uses_cell_font = 5; + bool aligns_centered = 6; + } + repeated Column columns = 1; } message BrowserRow { diff --git a/rslib/src/backend/search/browser_table.rs b/rslib/src/backend/search/browser_table.rs index f53c57845..d500fcc9c 100644 --- a/rslib/src/backend/search/browser_table.rs +++ b/rslib/src/backend/search/browser_table.rs @@ -47,7 +47,7 @@ impl Collection { } fn to_pb_columns(&self, columns: &[browser_table::Column]) -> pb::BrowserColumns { - let mut columns: Vec = + let mut columns: Vec = columns.iter().map(|c| c.to_pb_column(&self.tr)).collect(); columns.sort_by(|c1, c2| c1.label.cmp(&c2.label)); pb::BrowserColumns { columns } @@ -55,8 +55,8 @@ impl Collection { } impl browser_table::Column { - fn to_pb_column(self, i18n: &I18n) -> pb::BrowserColumn { - pb::BrowserColumn { + fn to_pb_column(self, i18n: &I18n) -> pb::browser_columns::Column { + pb::browser_columns::Column { key: self.to_string(), label: self.localized_label(i18n), is_sortable: self.is_sortable(),