Cloze notetype merges (#2912)
* Abort when trying to match notetypes of different kinds * Skip merging templates if target is cloze
This commit is contained in:
parent
6608baa9da
commit
be89ec8892
@ -7,6 +7,9 @@ importing-anki-files-are-from-a-very = .anki files are from a very old version o
|
||||
importing-anki2-files-are-not-directly-importable = .anki2 files are not directly importable - please import the .apkg or .zip file you have received instead.
|
||||
importing-appeared-twice-in-file = Appeared twice in file: { $val }
|
||||
importing-by-default-anki-will-detect-the = By default, Anki will detect the character between fields, such as a tab, comma, and so on. If Anki is detecting the character incorrectly, you can enter it here. Use \t to represent tab.
|
||||
importing-cannot-merge-notetypes-of-different-kinds =
|
||||
Cloze notetypes cannot be merged with regular notetypes.
|
||||
You may still import the file with '{ importing-merge-notetypes }' disabled.
|
||||
importing-change = Change
|
||||
importing-colon = Colon
|
||||
importing-comma = Comma
|
||||
|
@ -62,9 +62,14 @@ impl Note {
|
||||
pub enum ImportError {
|
||||
Corrupt,
|
||||
TooNew,
|
||||
MediaImportFailed { info: String },
|
||||
MediaImportFailed {
|
||||
info: String,
|
||||
},
|
||||
NoFieldColumn,
|
||||
EmptyFile,
|
||||
/// Two notetypes could not be merged because one was a regular one and the
|
||||
/// other one a cloze notetype.
|
||||
NotetypeKindMergeConflict,
|
||||
}
|
||||
|
||||
impl ImportError {
|
||||
@ -77,6 +82,9 @@ impl ImportError {
|
||||
}
|
||||
ImportError::NoFieldColumn => tr.importing_file_must_contain_field_column(),
|
||||
ImportError::EmptyFile => tr.importing_file_empty(),
|
||||
ImportError::NotetypeKindMergeConflict => {
|
||||
tr.importing_cannot_merge_notetypes_of_different_kinds()
|
||||
}
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use super::Context;
|
||||
use super::TemplateMap;
|
||||
use crate::import_export::package::media::safe_normalized_file_name;
|
||||
use crate::import_export::package::UpdateCondition;
|
||||
use crate::import_export::ImportError;
|
||||
use crate::import_export::ImportProgress;
|
||||
use crate::import_export::NoteLog;
|
||||
use crate::notetype::ChangeNotetypeInput;
|
||||
@ -229,6 +230,10 @@ impl<'n> NoteContext<'n> {
|
||||
incoming: &mut Notetype,
|
||||
mut existing: Notetype,
|
||||
) -> Result<()> {
|
||||
if existing.is_cloze() != incoming.is_cloze() {
|
||||
return Err(ImportError::NotetypeKindMergeConflict.into());
|
||||
}
|
||||
|
||||
let original_existing = existing.clone();
|
||||
// get and merge duplicated notetypes from previous no-merge imports
|
||||
let mut siblings = self.get_sibling_notetypes(existing.id);
|
||||
@ -367,6 +372,10 @@ impl<'n> NoteContext<'n> {
|
||||
.get_notetype(incoming_ntid)?
|
||||
.or_not_found(incoming_ntid)?;
|
||||
|
||||
if existing.is_cloze() != incoming.is_cloze() {
|
||||
return Err(ImportError::NotetypeKindMergeConflict.into());
|
||||
}
|
||||
|
||||
existing.merge(&incoming);
|
||||
incoming.merge(&existing);
|
||||
self.record_remapped_ords(&incoming);
|
||||
|
@ -9,7 +9,9 @@ impl Notetype {
|
||||
/// Inserts not yet existing fields ands templates from `other`.
|
||||
pub(crate) fn merge(&mut self, other: &Self) {
|
||||
self.merge_fields(other);
|
||||
self.merge_templates(other);
|
||||
if !self.is_cloze() {
|
||||
self.merge_templates(other);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn merge_all<'a>(&mut self, others: impl IntoIterator<Item = &'a Self>) {
|
||||
|
Loading…
Reference in New Issue
Block a user