Remove document size constraint

This commit is contained in:
Veronica Berglyd Olsen
2023-09-06 20:35:48 +02:00
parent 0ef46ef0ea
commit 915b9da5d0
6 changed files with 93 additions and 161 deletions
-4
View File
@@ -40,10 +40,6 @@ class nwConst:
FMT_FSTAMP = "%Y-%m-%d %H.%M.%S" # FileName safe format
FMT_DSTAMP = "%Y-%m-%d" # Date only format
# Various Hard Limits
MAX_DOCSIZE = 5000000 # Maximum size of a single document
MAX_BUILDSIZE = 10000000 # Maximum size of a project build
# URLs
URL_WEB = "https://novelwriter.io"
URL_DOCS = "https://docs.novelwriter.io"
+1 -9
View File
@@ -38,7 +38,7 @@ from PyQt5.QtCore import QCoreApplication, QRegularExpression
from novelwriter.enum import nwItemLayout
from novelwriter.common import formatTimeStamp, numberToRoman, checkInt
from novelwriter.constants import nwConst, nwHeadFmt, nwRegEx, nwUnicode
from novelwriter.constants import nwHeadFmt, nwRegEx, nwUnicode
from novelwriter.core.project import NWProject
logger = logging.getLogger(__name__)
@@ -349,14 +349,6 @@ class Tokenizer(ABC):
self._text = text
docSize = len(self._text)
if docSize > nwConst.MAX_DOCSIZE:
errVal = self.tr("Document '{0}' is too big ({1} MB). Skipping.").format(
self._nwItem.itemName, f"{docSize/1.0e6:.2f}"
)
self._text = "# {0}\n\n{1}\n\n".format(self.tr("ERROR"), errVal)
self._errData.append(errVal)
self._isNone = self._nwItem.itemLayout == nwItemLayout.NO_LAYOUT
self._isNovel = self._nwItem.itemLayout == nwItemLayout.DOCUMENT
self._isNote = self._nwItem.itemLayout == nwItemLayout.NOTE
+10 -46
View File
@@ -53,7 +53,7 @@ from PyQt5.QtWidgets import (
from novelwriter import CONFIG, SHARED
from novelwriter.enum import nwDocAction, nwDocInsert, nwDocMode, nwItemClass
from novelwriter.common import minmax, transferCase
from novelwriter.constants import nwConst, nwKeyWords, nwUnicode
from novelwriter.constants import nwKeyWords, nwUnicode
from novelwriter.core.index import countWords
from novelwriter.gui.dochighlight import GuiDocHighlighter
from novelwriter.extensions.wheeleventfilter import WheelEventFilter
@@ -358,7 +358,7 @@ class GuiDocEditor(QPlainTextEdit):
return
def loadText(self, tHandle, tLine=None) -> bool:
"""Load text from a document into the editor. If we have an io
"""Load text from a document into the editor. If we have an I/O
error, we must handle this and clear the editor so that we don't
risk overwriting the file if it exists. This can for instance
happen of the file contains binary elements or an encoding that
@@ -371,20 +371,7 @@ class GuiDocEditor(QPlainTextEdit):
docText = self._nwDocument.readDocument()
if docText is None:
# There was an io error
self.clearEditor()
return False
docSize = len(docText)
if docSize > nwConst.MAX_DOCSIZE:
SHARED.error(self.tr(
"The document you are trying to open is too big. "
"The document size is {0} MB. "
"The maximum size allowed is {1} MB."
).format(
f"{docSize/1.0e6:.2f}",
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
))
# There was an I/O error
self.clearEditor()
return False
@@ -416,17 +403,17 @@ class GuiDocEditor(QPlainTextEdit):
self.docFooter.updateLineCount()
qApp.processEvents()
self.document().clearUndoRedoStacks()
self.setDocumentChanged(False)
qApp.restoreOverrideCursor()
# This is a hack to fix invisible cursor on an empty document
if self.document().characterCount() <= 1:
self.setPlainText("\n")
self.setPlainText("")
self.setCursorPosition(0)
qApp.processEvents()
self.document().clearUndoRedoStacks()
self.setDocumentChanged(False)
qApp.restoreOverrideCursor()
# Update the status bar
if self._nwItem is not None:
self.statusMessage.emit(self.tr("Opened Document: {0}").format(self._nwItem.itemName))
@@ -444,29 +431,16 @@ class GuiDocEditor(QPlainTextEdit):
self.updateDocMargins()
return
def replaceText(self, text: str) -> bool:
def replaceText(self, text: str) -> None:
"""Replace the text of the current document with the provided
text. This also clears undo history.
"""
docSize = len(text)
if docSize > nwConst.MAX_DOCSIZE:
SHARED.error(self.tr(
"The text you are trying to add is too big. "
"The text size is {0} MB. "
"The maximum size allowed is {1} MB."
).format(
f"{docSize/1.0e6:.2f}",
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
))
return False
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
self.setPlainText(text)
self.updateDocMargins()
self.setDocumentChanged(True)
qApp.restoreOverrideCursor()
return True
return
def saveText(self) -> bool:
"""Save the text currently in the editor to the NWDocument
@@ -1013,16 +987,6 @@ class GuiDocEditor(QPlainTextEdit):
self._lastEdit = time()
self._lastFind = None
if self.document().characterCount() > nwConst.MAX_DOCSIZE:
SHARED.error(self.tr(
"The document has grown too big and you cannot add more text to it. "
"The maximum size of a single novelWriter document is {0} MB."
).format(
f"{nwConst.MAX_DOCSIZE/1.0e6:.2f}"
))
self.undo()
return
if not self._docChanged:
self.setDocumentChanged(removed != 0 or added != 0)
+3
View File
@@ -340,6 +340,7 @@ class GuiMain(QMainWindow):
def postLaunchTasks(self, cmdOpen: str | None) -> None:
"""Process tasks after the main window has been created."""
if cmdOpen:
qApp.processEvents()
logger.info("Command line path: %s", cmdOpen)
self.openProject(cmdOpen)
@@ -513,10 +514,12 @@ class GuiMain(QMainWindow):
break
if lastEdited is not None:
qApp.processEvents()
self.openDocument(lastEdited, doScroll=True)
lastViewed = SHARED.project.data.getLastHandle("viewer")
if lastViewed is not None:
qApp.processEvents()
self.viewDocument(lastViewed)
# Check if we need to rebuild the index