Add enum for column sorting
This commit is contained in:
parent
d8a0aa922c
commit
8a131da9a2
@ -375,15 +375,15 @@ class Table:
|
||||
def _on_sort_column_changed(self, section: int, order: int) -> None:
|
||||
order = bool(order)
|
||||
column = self._model.column_at_section(section)
|
||||
if column.is_sortable:
|
||||
sort_key = column.key
|
||||
else:
|
||||
if column.sorting == Columns.SORTING_NONE:
|
||||
showInfo(tr.browsing_sorting_on_this_column_is_not())
|
||||
sort_key = self._state.sort_column
|
||||
else:
|
||||
sort_key = column.key
|
||||
if self._state.sort_column != sort_key:
|
||||
self._state.sort_column = sort_key
|
||||
# default to descending for non-text fields
|
||||
if column.sorts_reversed:
|
||||
if column.sorting == Columns.SORTING_REVERSED:
|
||||
order = not order
|
||||
self._state.sort_backwards = order
|
||||
self.browser.search()
|
||||
@ -1094,8 +1094,7 @@ def addon_column_fillin(key: str) -> Column:
|
||||
return Column(
|
||||
key=key,
|
||||
label=tr.browsing_addon(),
|
||||
is_sortable=False,
|
||||
sorts_reversed=False,
|
||||
sorting=Columns.SORTING_NONE,
|
||||
uses_cell_font=False,
|
||||
alignment=Columns.ALIGNMENT_CENTER,
|
||||
)
|
||||
|
@ -1055,6 +1055,11 @@ message FindAndReplaceIn {
|
||||
}
|
||||
|
||||
message BrowserColumns {
|
||||
enum Sorting {
|
||||
SORTING_NONE = 0;
|
||||
SORTING_NORMAL = 1;
|
||||
SORTING_REVERSED = 2;
|
||||
}
|
||||
enum Alignment {
|
||||
ALIGNMENT_START = 0;
|
||||
ALIGNMENT_CENTER = 1;
|
||||
@ -1062,8 +1067,7 @@ message BrowserColumns {
|
||||
message Column {
|
||||
string key = 1;
|
||||
string label = 2;
|
||||
bool is_sortable = 3;
|
||||
bool sorts_reversed = 4;
|
||||
Sorting sorting = 3;
|
||||
bool uses_cell_font = 5;
|
||||
Alignment alignment = 6;
|
||||
}
|
||||
|
@ -59,15 +59,18 @@ impl browser_table::Column {
|
||||
pb::browser_columns::Column {
|
||||
key: self.to_string(),
|
||||
label: self.localized_label(i18n),
|
||||
is_sortable: self.is_sortable(),
|
||||
sorts_reversed: self == browser_table::Column::NoteField,
|
||||
sorting: self.sorting() as i32,
|
||||
uses_cell_font: self.uses_cell_font(),
|
||||
alignment: self.alignment() as i32,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_sortable(self) -> bool {
|
||||
!matches!(self, Self::Question | Self::Answer | Self::Custom)
|
||||
fn sorting(self) -> pb::browser_columns::Sorting {
|
||||
match self {
|
||||
Self::Question | Self::Answer | Self::Custom => pb::browser_columns::Sorting::None,
|
||||
Self::NoteField => pb::browser_columns::Sorting::Reversed,
|
||||
_ => pb::browser_columns::Sorting::Normal,
|
||||
}
|
||||
}
|
||||
|
||||
fn uses_cell_font(self) -> bool {
|
||||
|
Loading…
Reference in New Issue
Block a user