From ba9f4716958e4297bb1578e01b184fd069ee61c9 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sun, 17 Nov 2019 22:10:33 +0100 Subject: [PATCH] Fixed a minor issue when insert from file was cancelled. --- nw/gui/elements/doceditor.py | 8 ++++++++ nw/guimain.py | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index 7cc4a186..a0baeb74 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -229,6 +229,14 @@ class GuiDocEditor(QTextEdit): return True + def replaceText(self, theText): + """Replaces the text of the current document with the provided + text. This also clears undo history. + """ + self.setPlainText(theText) + self.setDocumentChanged(True) + return + def saveText(self): if self.nwDocument.theItem is None: diff --git a/nw/guimain.py b/nw/guimain.py index 0a3a87fc..8f658ce0 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -415,17 +415,20 @@ class GuiMain(QMainWindow): ) if inPath: loadFile = inPath[0] - self.mainConf.setLastPath(loadFile) else: return False + if loadFile.strip() == "": + return False + theText = None try: with open(loadFile,mode="rt",encoding="utf8") as inFile: theText = inFile.read() + self.mainConf.setLastPath(loadFile) except Exception as e: self.makeAlert( - ["Could not read file. The file cannot be a binary file.",str(e)], + ["Could not read file. The file must be an existing text file.",str(e)], nwAlert.ERROR ) return False @@ -449,7 +452,7 @@ class GuiMain(QMainWindow): else: return False - self.docEditor.setText(theText) + self.docEditor.replaceText(theText) return True