mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
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:
parent
73c97de5d0
commit
77fb0fb708
6 changed files with 51 additions and 10 deletions
|
@ -187,7 +187,7 @@ Christian Donat <https://github.com/cdonat2>
|
||||||
Asuka Minato <https://asukaminato.eu.org>
|
Asuka Minato <https://asukaminato.eu.org>
|
||||||
Dillon Baldwin <https://github.com/DillBal>
|
Dillon Baldwin <https://github.com/DillBal>
|
||||||
Voczi <https://github.com/voczi>
|
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>
|
Themis Demetriades <themis100@outlook.com>
|
||||||
Gregory Abrasaldo <degeemon@gmail.com>
|
Gregory Abrasaldo <degeemon@gmail.com>
|
||||||
Taylor Obyen <https://github.com/taylorobyen>
|
Taylor Obyen <https://github.com/taylorobyen>
|
||||||
|
|
|
@ -173,8 +173,16 @@ message BrowserColumns {
|
||||||
|
|
||||||
message BrowserRow {
|
message BrowserRow {
|
||||||
message Cell {
|
message Cell {
|
||||||
|
enum TextElideMode {
|
||||||
|
ElideLeft = 0;
|
||||||
|
ElideRight = 1;
|
||||||
|
ElideMiddle = 2;
|
||||||
|
ElideNone = 3;
|
||||||
|
}
|
||||||
|
|
||||||
string text = 1;
|
string text = 1;
|
||||||
bool is_rtl = 2;
|
bool is_rtl = 2;
|
||||||
|
TextElideMode elide_mode = 3;
|
||||||
}
|
}
|
||||||
enum Color {
|
enum Color {
|
||||||
COLOR_DEFAULT = 0;
|
COLOR_DEFAULT = 0;
|
||||||
|
|
|
@ -861,12 +861,15 @@ class Collection(DeprecatedNamesMixin):
|
||||||
return column
|
return column
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def browser_row_for_id(
|
def browser_row_for_id(self, id_: int) -> tuple[
|
||||||
self, id_: int
|
Generator[tuple[str, bool, BrowserRow.Cell.TextElideMode.V], None, None],
|
||||||
) -> tuple[Generator[tuple[str, bool], None, None], BrowserRow.Color.V, str, int]:
|
BrowserRow.Color.V,
|
||||||
|
str,
|
||||||
|
int,
|
||||||
|
]:
|
||||||
row = self._backend.browser_row_for_id(id_)
|
row = self._backend.browser_row_for_id(id_)
|
||||||
return (
|
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.color,
|
||||||
row.font_name,
|
row.font_name,
|
||||||
row.font_size,
|
row.font_size,
|
||||||
|
|
|
@ -33,10 +33,15 @@ class SearchContext:
|
||||||
ids: Sequence[ItemId] | None = None
|
ids: Sequence[ItemId] | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Cell:
|
class Cell:
|
||||||
text: str
|
def __init__(
|
||||||
is_rtl: bool
|
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:
|
class CellRow:
|
||||||
|
@ -44,7 +49,7 @@ class CellRow:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
cells: Generator[tuple[str, bool], None, None],
|
cells: Generator[tuple[str, bool, BrowserRow.Cell.TextElideMode.V], None, None],
|
||||||
color: BrowserRow.Color.V,
|
color: BrowserRow.Color.V,
|
||||||
font_name: str,
|
font_name: str,
|
||||||
font_size: int,
|
font_size: int,
|
||||||
|
@ -61,7 +66,7 @@ class CellRow:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generic(length: int, cell_text: str) -> CellRow:
|
def generic(length: int, cell_text: str) -> CellRow:
|
||||||
return 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,
|
BrowserRow.COLOR_DEFAULT,
|
||||||
"arial",
|
"arial",
|
||||||
12,
|
12,
|
||||||
|
@ -78,6 +83,18 @@ class CellRow:
|
||||||
return row
|
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:
|
def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> dict[str, str] | None:
|
||||||
temp_color = None
|
temp_color = None
|
||||||
|
|
||||||
|
|
|
@ -643,6 +643,7 @@ class StatusDelegate(QItemDelegate):
|
||||||
def paint(
|
def paint(
|
||||||
self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex
|
self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex
|
||||||
) -> None:
|
) -> None:
|
||||||
|
option.textElideMode = self._model.get_cell(index).elide_mode
|
||||||
if self._model.get_cell(index).is_rtl:
|
if self._model.get_cell(index).is_rtl:
|
||||||
option.direction = Qt.LayoutDirection.RightToLeft
|
option.direction = Qt.LayoutDirection.RightToLeft
|
||||||
if row_color := self._model.get_row(index).color:
|
if row_color := self._model.get_row(index).color:
|
||||||
|
|
|
@ -413,6 +413,7 @@ impl RowContext {
|
||||||
Ok(anki_proto::search::browser_row::Cell {
|
Ok(anki_proto::search::browser_row::Cell {
|
||||||
text: self.get_cell_text(column)?,
|
text: self.get_cell_text(column)?,
|
||||||
is_rtl: self.get_is_rtl(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> {
|
fn template(&self) -> Result<&CardTemplate> {
|
||||||
self.notetype.get_template(self.cards[0].template_idx)
|
self.notetype.get_template(self.cards[0].template_idx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue