From a066cee3269b061a8a07ce4ee1d98c9be71b758f Mon Sep 17 00:00:00 2001 From: Benjamin K Date: Thu, 4 Mar 2021 19:39:43 +0100 Subject: [PATCH 1/3] The old delimiter is now kept, when cancel button is clicked --- qt/aqt/importing.py | 53 +++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/qt/aqt/importing.py b/qt/aqt/importing.py index d1cecc330..005143ac9 100644 --- a/qt/aqt/importing.py +++ b/qt/aqt/importing.py @@ -10,6 +10,8 @@ import zipfile from concurrent.futures import Future from typing import Any, Dict, Optional +from qt.aqt.utils import getText + import anki.importing as importing import aqt.deckchooser import aqt.forms @@ -82,6 +84,8 @@ class ChangeMap(QDialog): class ImportDialog(QDialog): + _DEFAULT_FILE_DELIMITER = "\t" + def __init__(self, mw: AnkiQt, importer: Any) -> None: QDialog.__init__(self, mw, Qt.Window) self.mw = mw @@ -122,28 +126,39 @@ class ImportDialog(QDialog): self.showMapping() def onDelimiter(self) -> None: - str = ( - getOnlyText( - tr(TR.IMPORTING_BY_DEFAULT_ANKI_WILL_DETECT_THE), - self, - help=HelpPage.IMPORTING, - ) - or "\t" + + # 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), + self, + help=HelpPage.IMPORTING, ) - str = str.replace("\\t", "\t") - if len(str) > 1: - showWarning( - tr(TR.IMPORTING_MULTICHARACTER_SEPARATORS_ARE_NOT_SUPPORTED_PLEASE) - ) - return - self.hideMapping() - def updateDelim() -> None: - self.importer.delimiter = str - self.importer.updateDelimiter() + # If the modal dialog has been confirmed, update the delimiter + if ok: + # 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 - self.showMapping(hook=updateDelim) - self.updateDelimiterButtonText() + delim = delim if len(delim) > 0 else self._DEFAULT_FILE_DELIMITER + delim = delim.replace("\\t", "\t") # un-escape it + if len(delim) > 1: + showWarning( + tr(TR.IMPORTING_MULTICHARACTER_SEPARATORS_ARE_NOT_SUPPORTED_PLEASE) + ) + return + self.hideMapping() + + def updateDelim() -> None: + self.importer.delimiter = delim + self.importer.updateDelimiter() + self.updateDelimiterButtonText() + + self.showMapping(hook=updateDelim) + + else: + # If the operation has been canceled, do not do anything + pass def updateDelimiterButtonText(self) -> None: if not self.importer.needDelimiter: From 5d880f6e31a354a7061135edefaffa4161ed3758 Mon Sep 17 00:00:00 2001 From: Benjamin K Date: Thu, 4 Mar 2021 19:55:35 +0100 Subject: [PATCH 2/3] Clean up imports --- qt/aqt/importing.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qt/aqt/importing.py b/qt/aqt/importing.py index 005143ac9..2d00fbcde 100644 --- a/qt/aqt/importing.py +++ b/qt/aqt/importing.py @@ -10,8 +10,6 @@ import zipfile from concurrent.futures import Future from typing import Any, Dict, Optional -from qt.aqt.utils import getText - import anki.importing as importing import aqt.deckchooser import aqt.forms @@ -25,7 +23,7 @@ from aqt.utils import ( askUser, disable_help_button, getFile, - getOnlyText, + getText, openHelp, showInfo, showText, From 0452ed0241169b27ee64a7c209583c18bed6276d Mon Sep 17 00:00:00 2001 From: Benjamin K Date: Sun, 7 Mar 2021 11:05:41 +0100 Subject: [PATCH 3/3] Update CONTRIBUTORS --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 083e82d3e..c443d2878 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -75,6 +75,7 @@ Meredith Derecho Daniel Wallgren Kerrick Staley Maksim Abramchuk +Benjamin Kulnik ********************