Make note state equate to False as on backend

This commit is contained in:
RumovZ 2021-03-29 15:51:34 +02:00
parent ad7ac06398
commit 18e33f24d3
3 changed files with 25 additions and 25 deletions

View file

@ -330,9 +330,9 @@ class Browser(QMainWindow):
selected = self.table.len_selection() selected = self.table.len_selection()
cur = self.table.len() cur = self.table.len()
tr_title = ( tr_title = (
tr.browsing_window_title tr.browsing_window_title_notes
if self.table.is_card_state() if self.table.is_notes_mode()
else tr.browsing_window_title_notes else tr.browsing_window_title
) )
self.setWindowTitle( self.setWindowTitle(
without_unicode_isolation(tr_title(total=cur, selected=selected)) without_unicode_isolation(tr_title(total=cur, selected=selected))
@ -377,7 +377,7 @@ class Browser(QMainWindow):
self.table = Table(self) self.table = Table(self)
self.table.set_view(self.form.tableView) self.table.set_view(self.form.tableView)
switch = Switch(11, tr.browsing_card_initial(), tr.browsing_note_initial()) switch = Switch(11, tr.browsing_card_initial(), tr.browsing_note_initial())
switch.setChecked(self.table.is_card_state()) switch.setChecked(self.table.is_notes_mode())
qconnect(switch.toggled, self.on_table_state_changed) qconnect(switch.toggled, self.on_table_state_changed)
self.form.gridLayout.addWidget(switch, 0, 0) self.form.gridLayout.addWidget(switch, 0, 0)

View file

@ -9,7 +9,7 @@ from aqt.theme import theme_manager
class Switch(QAbstractButton): class Switch(QAbstractButton):
"""A horizontal slider to toggle between two states which can be denoted by short strings. """A horizontal slider to toggle between two states which can be denoted by short strings.
The left state is the default and corresponds to isChecked=True. The left state is the default and corresponds to isChecked=False.
""" """
_margin: int = 2 _margin: int = 2
@ -23,7 +23,7 @@ class Switch(QAbstractButton):
) -> None: ) -> None:
super().__init__(parent=parent) super().__init__(parent=parent)
self.setCheckable(True) self.setCheckable(True)
super().setChecked(True) super().setChecked(False)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self._left_label = left_label self._left_label = left_label
self._right_label = right_label self._right_label = right_label
@ -43,15 +43,15 @@ class Switch(QAbstractButton):
@property @property
def start_position(self) -> int: def start_position(self) -> int:
return self._right_position if self.isChecked() else self._left_position
@property
def end_position(self) -> int:
return self._left_position if self.isChecked() else self._right_position return self._left_position if self.isChecked() else self._right_position
@property
def end_position(self) -> int:
return self._right_position if self.isChecked() else self._left_position
@property @property
def label(self) -> str: def label(self) -> str:
return self._left_label if self.isChecked() else self._right_label return self._right_label if self.isChecked() else self._left_label
def sizeHint(self) -> QSize: def sizeHint(self) -> QSize:
return QSize( return QSize(

View file

@ -93,8 +93,8 @@ class Table:
def has_next(self) -> bool: def has_next(self) -> bool:
return self.has_current() and self._current().row() < self.len() - 1 return self.has_current() and self._current().row() < self.len() - 1
def is_card_state(self) -> bool: def is_notes_mode(self) -> bool:
return self._state.is_card_state() return self._state.is_notes_mode()
# Get objects # Get objects
@ -193,15 +193,15 @@ class Table:
self._model.search(SearchContext(search=txt, browser=self.browser)) self._model.search(SearchContext(search=txt, browser=self.browser))
self._restore_selection(self._intersected_selection) self._restore_selection(self._intersected_selection)
def toggle_state(self, is_card_state: bool, last_search: str) -> None: def toggle_state(self, is_notes_mode: bool, last_search: str) -> None:
if is_card_state == self.is_card_state(): if is_notes_mode == self.is_notes_mode():
return return
self._save_selection() self._save_selection()
self._state = self._model.toggle_state( self._state = self._model.toggle_state(
SearchContext(search=last_search, browser=self.browser) SearchContext(search=last_search, browser=self.browser)
) )
self.col.set_config_bool( self.col.set_config_bool(
Config.Bool.BROWSER_TABLE_SHOW_NOTES_MODE, not self.is_card_state() Config.Bool.BROWSER_TABLE_SHOW_NOTES_MODE, self.is_notes_mode()
) )
self._set_sort_indicator() self._set_sort_indicator()
self._set_column_sizes() self._set_column_sizes()
@ -327,14 +327,14 @@ class Table:
def _on_context_menu(self, _point: QPoint) -> None: def _on_context_menu(self, _point: QPoint) -> None:
menu = QMenu() menu = QMenu()
if self.is_card_state(): if self.is_notes_mode():
main = self.browser.form.menu_Cards
other = self.browser.form.menu_Notes
other_name = tr.qt_accel_notes()
else:
main = self.browser.form.menu_Notes main = self.browser.form.menu_Notes
other = self.browser.form.menu_Cards other = self.browser.form.menu_Cards
other_name = tr.qt_accel_cards() other_name = tr.qt_accel_cards()
else:
main = self.browser.form.menu_Cards
other = self.browser.form.menu_Notes
other_name = tr.qt_accel_notes()
for action in main.actions(): for action in main.actions():
menu.addAction(action) menu.addAction(action)
menu.addSeparator() menu.addSeparator()
@ -529,9 +529,9 @@ class ItemState(ABC):
def __init__(self, col: Collection) -> None: def __init__(self, col: Collection) -> None:
self.col = col self.col = col
def is_card_state(self) -> bool: def is_notes_mode(self) -> bool:
"""Return True if the state is a CardState.""" """Return True if the state is a NoteState."""
return isinstance(self, CardState) return isinstance(self, NoteState)
# Stateless Helpers # Stateless Helpers
@ -901,7 +901,7 @@ class DataModel(QAbstractTableModel):
return CellRow.generic(self.len_columns(), str(e)) return CellRow.generic(self.len_columns(), str(e))
gui_hooks.browser_did_fetch_row( gui_hooks.browser_did_fetch_row(
item, not self._state.is_card_state(), row, self._state.active_columns item, self._state.is_notes_mode(), row, self._state.active_columns
) )
return row return row