mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
Merge pull request #1052 from tqml/fix/import-delimiter-change
Import Dialog: Do not change delimiter if cancel button is pressed
This commit is contained in:
commit
e1bf19b6ee
2 changed files with 34 additions and 20 deletions
|
@ -75,6 +75,7 @@ Meredith Derecho <meredithderecho@gmail.com>
|
||||||
Daniel Wallgren <github.com/wallgrenen>
|
Daniel Wallgren <github.com/wallgrenen>
|
||||||
Kerrick Staley <kerrick@kerrickstaley.com>
|
Kerrick Staley <kerrick@kerrickstaley.com>
|
||||||
Maksim Abramchuk <maximabramchuck@gmail.com>
|
Maksim Abramchuk <maximabramchuck@gmail.com>
|
||||||
|
Benjamin Kulnik <benjamin.kulnik@student.tuwien.ac.at>
|
||||||
|
|
||||||
********************
|
********************
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ from aqt.utils import (
|
||||||
askUser,
|
askUser,
|
||||||
disable_help_button,
|
disable_help_button,
|
||||||
getFile,
|
getFile,
|
||||||
getOnlyText,
|
getText,
|
||||||
openHelp,
|
openHelp,
|
||||||
showInfo,
|
showInfo,
|
||||||
showText,
|
showText,
|
||||||
|
@ -82,6 +82,8 @@ class ChangeMap(QDialog):
|
||||||
|
|
||||||
|
|
||||||
class ImportDialog(QDialog):
|
class ImportDialog(QDialog):
|
||||||
|
_DEFAULT_FILE_DELIMITER = "\t"
|
||||||
|
|
||||||
def __init__(self, mw: AnkiQt, importer: Any) -> None:
|
def __init__(self, mw: AnkiQt, importer: Any) -> None:
|
||||||
QDialog.__init__(self, mw, Qt.Window)
|
QDialog.__init__(self, mw, Qt.Window)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
|
@ -122,16 +124,23 @@ class ImportDialog(QDialog):
|
||||||
self.showMapping()
|
self.showMapping()
|
||||||
|
|
||||||
def onDelimiter(self) -> None:
|
def onDelimiter(self) -> None:
|
||||||
str = (
|
|
||||||
getOnlyText(
|
# Open a modal dialog to enter an delimiter
|
||||||
|
# Todo/Idea Constrain the maximum width, so it doesnt take up that much screen space
|
||||||
|
delim, ok = getText(
|
||||||
tr(TR.IMPORTING_BY_DEFAULT_ANKI_WILL_DETECT_THE),
|
tr(TR.IMPORTING_BY_DEFAULT_ANKI_WILL_DETECT_THE),
|
||||||
self,
|
self,
|
||||||
help=HelpPage.IMPORTING,
|
help=HelpPage.IMPORTING,
|
||||||
)
|
)
|
||||||
or "\t"
|
|
||||||
)
|
# If the modal dialog has been confirmed, update the delimiter
|
||||||
str = str.replace("\\t", "\t")
|
if ok:
|
||||||
if len(str) > 1:
|
# Check if the entered value is valid and if not fallback to default
|
||||||
|
# at the moment every single character entry as well as '\t' is valid
|
||||||
|
|
||||||
|
delim = delim if len(delim) > 0 else self._DEFAULT_FILE_DELIMITER
|
||||||
|
delim = delim.replace("\\t", "\t") # un-escape it
|
||||||
|
if len(delim) > 1:
|
||||||
showWarning(
|
showWarning(
|
||||||
tr(TR.IMPORTING_MULTICHARACTER_SEPARATORS_ARE_NOT_SUPPORTED_PLEASE)
|
tr(TR.IMPORTING_MULTICHARACTER_SEPARATORS_ARE_NOT_SUPPORTED_PLEASE)
|
||||||
)
|
)
|
||||||
|
@ -139,11 +148,15 @@ class ImportDialog(QDialog):
|
||||||
self.hideMapping()
|
self.hideMapping()
|
||||||
|
|
||||||
def updateDelim() -> None:
|
def updateDelim() -> None:
|
||||||
self.importer.delimiter = str
|
self.importer.delimiter = delim
|
||||||
self.importer.updateDelimiter()
|
self.importer.updateDelimiter()
|
||||||
|
self.updateDelimiterButtonText()
|
||||||
|
|
||||||
self.showMapping(hook=updateDelim)
|
self.showMapping(hook=updateDelim)
|
||||||
self.updateDelimiterButtonText()
|
|
||||||
|
else:
|
||||||
|
# If the operation has been canceled, do not do anything
|
||||||
|
pass
|
||||||
|
|
||||||
def updateDelimiterButtonText(self) -> None:
|
def updateDelimiterButtonText(self) -> None:
|
||||||
if not self.importer.needDelimiter:
|
if not self.importer.needDelimiter:
|
||||||
|
|
Loading…
Reference in a new issue