Possible to show “last” subdeck name in Browser? (#3387)

* elide middle of deck names

* Update CONTRIBUTORS

* made elide mode enum

* add elide mode field

* fix enum number

* remove dataclass decorator

* Update CONTRIBUTORS

* format rust code

* Update CONTRIBUTORS

* formatting

* Update CONTRIBUTORS

* fix type hint

* Update CONTRIBUTORS
This commit is contained in:
Ben Nguyen 2024-09-20 03:33:28 -07:00 committed by GitHub
parent 73c97de5d0
commit 77fb0fb708
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 51 additions and 10 deletions

View file

@ -187,7 +187,7 @@ Christian Donat <https://github.com/cdonat2>
Asuka Minato <https://asukaminato.eu.org>
Dillon Baldwin <https://github.com/DillBal>
Voczi <https://github.com/voczi>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Themis Demetriades <themis100@outlook.com>
Gregory Abrasaldo <degeemon@gmail.com>
Taylor Obyen <https://github.com/taylorobyen>

View file

@ -173,8 +173,16 @@ message BrowserColumns {
message BrowserRow {
message Cell {
enum TextElideMode {
ElideLeft = 0;
ElideRight = 1;
ElideMiddle = 2;
ElideNone = 3;
}
string text = 1;
bool is_rtl = 2;
TextElideMode elide_mode = 3;
}
enum Color {
COLOR_DEFAULT = 0;

View file

@ -861,12 +861,15 @@ class Collection(DeprecatedNamesMixin):
return column
return None
def browser_row_for_id(
self, id_: int
) -> tuple[Generator[tuple[str, bool], None, None], BrowserRow.Color.V, str, int]:
def browser_row_for_id(self, id_: int) -> tuple[
Generator[tuple[str, bool, BrowserRow.Cell.TextElideMode.V], None, None],
BrowserRow.Color.V,
str,
int,
]:
row = self._backend.browser_row_for_id(id_)
return (
((cell.text, cell.is_rtl) for cell in row.cells),
((cell.text, cell.is_rtl, cell.elide_mode) for cell in row.cells),
row.color,
row.font_name,
row.font_size,

View file

@ -33,10 +33,15 @@ class SearchContext:
ids: Sequence[ItemId] | None = None
@dataclass
class Cell:
text: str
is_rtl: bool
def __init__(
self, text: str, is_rtl: bool, elide_mode: BrowserRow.Cell.TextElideMode.V
) -> None:
self.text: str = text
self.is_rtl: bool = is_rtl
self.elide_mode: aqt.Qt.TextElideMode = backend_elide_mode_to_aqt_elide_mode(
elide_mode
)
class CellRow:
@ -44,7 +49,7 @@ class CellRow:
def __init__(
self,
cells: Generator[tuple[str, bool], None, None],
cells: Generator[tuple[str, bool, BrowserRow.Cell.TextElideMode.V], None, None],
color: BrowserRow.Color.V,
font_name: str,
font_size: int,
@ -61,7 +66,7 @@ class CellRow:
@staticmethod
def generic(length: int, cell_text: str) -> CellRow:
return CellRow(
((cell_text, False) for cell in range(length)),
((cell_text, False, BrowserRow.Cell.ElideRight) for cell in range(length)),
BrowserRow.COLOR_DEFAULT,
"arial",
12,
@ -78,6 +83,18 @@ class CellRow:
return row
def backend_elide_mode_to_aqt_elide_mode(
elide_mode: BrowserRow.Cell.TextElideMode.V,
) -> aqt.Qt.TextElideMode:
if elide_mode == BrowserRow.Cell.ElideLeft:
return aqt.Qt.TextElideMode.ElideLeft
if elide_mode == BrowserRow.Cell.ElideMiddle:
return aqt.Qt.TextElideMode.ElideMiddle
if elide_mode == BrowserRow.Cell.ElideNone:
return aqt.Qt.TextElideMode.ElideNone
return aqt.Qt.TextElideMode.ElideRight
def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> dict[str, str] | None:
temp_color = None

View file

@ -643,6 +643,7 @@ class StatusDelegate(QItemDelegate):
def paint(
self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex
) -> None:
option.textElideMode = self._model.get_cell(index).elide_mode
if self._model.get_cell(index).is_rtl:
option.direction = Qt.LayoutDirection.RightToLeft
if row_color := self._model.get_row(index).color:

View file

@ -413,6 +413,7 @@ impl RowContext {
Ok(anki_proto::search::browser_row::Cell {
text: self.get_cell_text(column)?,
is_rtl: self.get_is_rtl(column),
elide_mode: self.get_elide_mode(column) as i32,
})
}
@ -461,6 +462,17 @@ impl RowContext {
}
}
fn get_elide_mode(
&self,
column: Column,
) -> anki_proto::search::browser_row::cell::TextElideMode {
use anki_proto::search::browser_row::cell::TextElideMode;
match column {
Column::Deck => TextElideMode::ElideMiddle,
_ => TextElideMode::ElideRight,
}
}
fn template(&self) -> Result<&CardTemplate> {
self.notetype.get_template(self.cards[0].template_idx)
}