strip html option on import, and option to customize deck import location

This commit is contained in:
Damien Elmes 2012-10-25 00:24:26 +09:00
parent b0c28d33b2
commit 8ec9572265
2 changed files with 18 additions and 1 deletions

View file

@ -139,6 +139,7 @@ you can enter it here. Use \\t to represent tab."""),
_("The first field of the note type must be mapped.")) _("The first field of the note type must be mapped."))
return return
self.importer.importMode = self.frm.importMode.currentIndex() self.importer.importMode = self.frm.importMode.currentIndex()
self.importer.allowHTML = self.frm.allowHTML.isChecked()
did = self.deck.selectedId() did = self.deck.selectedId()
if did != self.importer.model['did']: if did != self.importer.model['did']:
self.importer.model['did'] = did self.importer.model['did'] = did
@ -291,6 +292,13 @@ backup, please see the 'Backups' section of the user manual."""))
if importer.__class__.__name__ == "AnkiPackageImporter": if importer.__class__.__name__ == "AnkiPackageImporter":
if not setupApkgImport(mw, importer): if not setupApkgImport(mw, importer):
return return
def prepareImportPrefix(name):
mw.progress.finish()
new = getOnlyText(_("""\
Deck to import into (if blank, will import into current deck):"""), default=name)
mw.progress.start()
return new or mw.col.decks.current()['name']
addHook("prepareImportPrefix", prepareImportPrefix)
mw.progress.start(immediate=True) mw.progress.start(immediate=True)
try: try:
importer.run() importer.run()
@ -316,12 +324,14 @@ Unable to import from a read-only file."""))
showText(log) showText(log)
finally: finally:
mw.progress.finish() mw.progress.finish()
remHook("prepareImportPrefix", prepareImportPrefix)
mw.reset() mw.reset()
def setupApkgImport(mw, importer): def setupApkgImport(mw, importer):
base = os.path.basename(importer.file).lower() base = os.path.basename(importer.file).lower()
full = (base == "collection.apkg") or re.match("backup-\d+.apkg", base) full = (base == "collection.apkg") or re.match("backup-\d+.apkg", base)
if not full: if not full:
# adding
return True return True
if not askUser(_("""\ if not askUser(_("""\
This will delete your existing collection and replace it with the data in \ This will delete your existing collection and replace it with the data in \

View file

@ -70,6 +70,13 @@
</item> </item>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="allowHTML">
<property name="text">
<string>Allow HTML in fields</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -127,7 +134,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>402</width> <width>402</width>
<height>229</height> <height>206</height>
</rect> </rect>
</property> </property>
</widget> </widget>