Remember previous choices in reposition dialog (#1950)

* remember previous choices in reposition dialog

* remember previous choice for randomize option as well

* fix failing test
This commit is contained in:
Sam Penny 2022-07-08 02:28:38 +01:00 committed by GitHub
parent 2bbd1fca2a
commit 9dcceff4af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 15 deletions

View file

@ -47,6 +47,8 @@ message ConfigKey {
RESTORE_POSITION_REVIEWER = 20; RESTORE_POSITION_REVIEWER = 20;
RESET_COUNTS_BROWSER = 21; RESET_COUNTS_BROWSER = 21;
RESET_COUNTS_REVIEWER = 22; RESET_COUNTS_REVIEWER = 22;
RANDOM_ORDER_REPOSITION = 23;
SHIFT_POSITION_OF_EXISTING_CARDS = 24;
} }
enum String { enum String {
SET_DUE_BROWSER = 0; SET_DUE_BROWSER = 0;

View file

@ -44,6 +44,7 @@ service SchedulerService {
rpc CustomStudy(CustomStudyRequest) returns (collection.OpChanges); rpc CustomStudy(CustomStudyRequest) returns (collection.OpChanges);
rpc CustomStudyDefaults(CustomStudyDefaultsRequest) rpc CustomStudyDefaults(CustomStudyDefaultsRequest)
returns (CustomStudyDefaultsResponse); returns (CustomStudyDefaultsResponse);
rpc RepositionDefaults(generic.Empty) returns (RepositionDefaultsResponse);
} }
message SchedulingState { message SchedulingState {
@ -297,3 +298,8 @@ message CustomStudyDefaultsResponse {
uint32 available_new_in_children = 6; uint32 available_new_in_children = 6;
uint32 available_review_in_children = 7; uint32 available_review_in_children = 7;
} }
message RepositionDefaultsResponse {
bool random = 1;
bool shift = 2;
}

View file

@ -19,7 +19,7 @@ CustomStudyDefaults = scheduler_pb2.CustomStudyDefaultsResponse
ScheduleCardsAsNew = scheduler_pb2.ScheduleCardsAsNewRequest ScheduleCardsAsNew = scheduler_pb2.ScheduleCardsAsNewRequest
ScheduleCardsAsNewDefaults = scheduler_pb2.ScheduleCardsAsNewDefaultsResponse ScheduleCardsAsNewDefaults = scheduler_pb2.ScheduleCardsAsNewDefaultsResponse
FilteredDeckForUpdate = decks_pb2.FilteredDeckForUpdate FilteredDeckForUpdate = decks_pb2.FilteredDeckForUpdate
RepositionDefaults = scheduler_pb2.RepositionDefaultsResponse
from typing import Sequence from typing import Sequence
@ -239,6 +239,9 @@ class SchedulerBase(DeprecatedNamesMixin):
shift_existing=shift_existing, shift_existing=shift_existing,
) )
def reposition_defaults(self) -> RepositionDefaults:
return self.col._backend.reposition_defaults()
def randomize_cards(self, did: DeckId) -> None: def randomize_cards(self, did: DeckId) -> None:
self.col._backend.sort_deck(deck_id=did, randomize=True) self.col._backend.sort_deck(deck_id=did, randomize=True)

View file

@ -105,7 +105,9 @@ def forget_cards(
def reposition_new_cards_dialog( def reposition_new_cards_dialog(
*, parent: QWidget, card_ids: Sequence[CardId] *,
parent: QWidget,
card_ids: Sequence[CardId],
) -> CollectionOp[OpChangesWithCount] | None: ) -> CollectionOp[OpChangesWithCount] | None:
from aqt import mw from aqt import mw
@ -120,24 +122,29 @@ def reposition_new_cards_dialog(
min_position = max(min_position or 0, 0) min_position = max(min_position or 0, 0)
max_position = max_position or 0 max_position = max_position or 0
d = QDialog(parent) dialog = QDialog(parent)
disable_help_button(d) disable_help_button(dialog)
d.setWindowModality(Qt.WindowModality.WindowModal) dialog.setWindowModality(Qt.WindowModality.WindowModal)
frm = aqt.forms.reposition.Ui_Dialog() form = aqt.forms.reposition.Ui_Dialog()
frm.setupUi(d) form.setupUi(dialog)
txt = tr.browsing_queue_top(val=min_position) txt = tr.browsing_queue_top(val=min_position)
txt += "\n" + tr.browsing_queue_bottom(val=max_position) txt += "\n" + tr.browsing_queue_bottom(val=max_position)
frm.label.setText(txt) form.label.setText(txt)
frm.start.selectAll() form.start.selectAll()
if not d.exec():
defaults = mw.col.sched.reposition_defaults()
form.randomize.setChecked(defaults.random)
form.shift.setChecked(defaults.shift)
if not dialog.exec():
return None return None
start = frm.start.value() start = form.start.value()
step = frm.step.value() step = form.step.value()
randomize = frm.randomize.isChecked() randomize = form.randomize.isChecked()
shift = frm.shift.isChecked() shift = form.shift.isChecked()
return reposition_new_cards( return reposition_new_cards(
parent=parent, parent=parent,

View file

@ -36,6 +36,8 @@ impl From<BoolKeyProto> for BoolKey {
BoolKeyProto::RestorePositionReviewer => BoolKey::RestorePositionReviewer, BoolKeyProto::RestorePositionReviewer => BoolKey::RestorePositionReviewer,
BoolKeyProto::ResetCountsBrowser => BoolKey::ResetCountsBrowser, BoolKeyProto::ResetCountsBrowser => BoolKey::ResetCountsBrowser,
BoolKeyProto::ResetCountsReviewer => BoolKey::ResetCountsReviewer, BoolKeyProto::ResetCountsReviewer => BoolKey::ResetCountsReviewer,
BoolKeyProto::RandomOrderReposition => BoolKey::RandomOrderReposition,
BoolKeyProto::ShiftPositionOfExistingCards => BoolKey::ShiftPositionOfExistingCards,
} }
} }
} }

View file

@ -157,6 +157,10 @@ impl SchedulerService for Backend {
}) })
} }
fn reposition_defaults(&self, _input: pb::Empty) -> Result<pb::RepositionDefaultsResponse> {
self.with_col(|col| Ok(col.reposition_defaults()))
}
fn sort_deck(&self, input: pb::SortDeckRequest) -> Result<pb::OpChangesWithCount> { fn sort_deck(&self, input: pb::SortDeckRequest) -> Result<pb::OpChangesWithCount> {
self.with_col(|col| { self.with_col(|col| {
col.sort_deck_legacy(input.deck_id.into(), input.randomize) col.sort_deck_legacy(input.deck_id.into(), input.randomize)

View file

@ -31,6 +31,8 @@ pub enum BoolKey {
RestorePositionReviewer, RestorePositionReviewer,
ResetCountsBrowser, ResetCountsBrowser,
ResetCountsReviewer, ResetCountsReviewer,
RandomOrderReposition,
ShiftPositionOfExistingCards,
#[strum(to_string = "normalize_note_text")] #[strum(to_string = "normalize_note_text")]
NormalizeNoteText, NormalizeNoteText,

View file

@ -6,7 +6,7 @@ use std::collections::{HashMap, HashSet};
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
pub use crate::pb::scheduler::{ pub use crate::pb::scheduler::{
schedule_cards_as_new_request::Context as ScheduleAsNewContext, schedule_cards_as_new_request::Context as ScheduleAsNewContext, RepositionDefaultsResponse,
ScheduleCardsAsNewDefaultsResponse, ScheduleCardsAsNewDefaultsResponse,
}; };
use crate::{ use crate::{
@ -212,6 +212,11 @@ impl Collection {
) -> Result<OpOutput<usize>> { ) -> Result<OpOutput<usize>> {
let usn = self.usn()?; let usn = self.usn()?;
self.transact(Op::SortCards, |col| { self.transact(Op::SortCards, |col| {
col.set_config_bool_inner(
BoolKey::RandomOrderReposition,
order == NewCardDueOrder::Random,
)?;
col.set_config_bool_inner(BoolKey::ShiftPositionOfExistingCards, shift)?;
col.sort_cards_inner(cids, starting_from, step, order, shift, usn) col.sort_cards_inner(cids, starting_from, step, order, shift, usn)
}) })
} }
@ -244,6 +249,13 @@ impl Collection {
Ok(count) Ok(count)
} }
pub fn reposition_defaults(&self) -> RepositionDefaultsResponse {
RepositionDefaultsResponse {
random: self.get_config_bool(BoolKey::RandomOrderReposition),
shift: self.get_config_bool(BoolKey::ShiftPositionOfExistingCards),
}
}
/// This is handled by update_deck_configs() now; this function has been kept around /// This is handled by update_deck_configs() now; this function has been kept around
/// for now to support the old deck config screen. /// for now to support the old deck config screen.
pub fn sort_deck_legacy(&mut self, deck: DeckId, random: bool) -> Result<OpOutput<usize>> { pub fn sort_deck_legacy(&mut self, deck: DeckId, random: bool) -> Result<OpOutput<usize>> {