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