Merge pull request #149 from vkbo/insert_from_file_fix
Fixed a minor issue when insert from file was cancelled.
This commit is contained in:
@@ -229,6 +229,14 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
return True
|
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):
|
def saveText(self):
|
||||||
|
|
||||||
if self.nwDocument.theItem is None:
|
if self.nwDocument.theItem is None:
|
||||||
|
|||||||
+6
-3
@@ -415,17 +415,20 @@ class GuiMain(QMainWindow):
|
|||||||
)
|
)
|
||||||
if inPath:
|
if inPath:
|
||||||
loadFile = inPath[0]
|
loadFile = inPath[0]
|
||||||
self.mainConf.setLastPath(loadFile)
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if loadFile.strip() == "":
|
||||||
|
return False
|
||||||
|
|
||||||
theText = None
|
theText = None
|
||||||
try:
|
try:
|
||||||
with open(loadFile,mode="rt",encoding="utf8") as inFile:
|
with open(loadFile,mode="rt",encoding="utf8") as inFile:
|
||||||
theText = inFile.read()
|
theText = inFile.read()
|
||||||
|
self.mainConf.setLastPath(loadFile)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.makeAlert(
|
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
|
nwAlert.ERROR
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
@@ -449,7 +452,7 @@ class GuiMain(QMainWindow):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.docEditor.setText(theText)
|
self.docEditor.replaceText(theText)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user