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()
cur = self.table.len()
tr_title = (
tr.browsing_window_title
if self.table.is_card_state()
else tr.browsing_window_title_notes
tr.browsing_window_title_notes
if self.table.is_notes_mode()
else tr.browsing_window_title
)
self.setWindowTitle(
without_unicode_isolation(tr_title(total=cur, selected=selected))
@ -377,7 +377,7 @@ class Browser(QMainWindow):
self.table = Table(self)
self.table.set_view(self.form.tableView)
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)
self.form.gridLayout.addWidget(switch, 0, 0)

View file

@ -9,7 +9,7 @@ from aqt.theme import theme_manager
class Switch(QAbstractButton):
"""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
@ -23,7 +23,7 @@ class Switch(QAbstractButton):
) -> None:
super().__init__(parent=parent)
self.setCheckable(True)
super().setChecked(True)
super().setChecked(False)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self._left_label = left_label
self._right_label = right_label
@ -43,15 +43,15 @@ class Switch(QAbstractButton):
@property
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
@property
def end_position(self) -> int:
return self._right_position if self.isChecked() else self._left_position
@property
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:
return QSize(

View file

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