Make a few minor improvements, including fixing #1495
This commit is contained in:
@@ -512,8 +512,7 @@ def sha256sum(path: str | Path) -> str | None:
|
||||
# =============================================================================================== #
|
||||
|
||||
def getGuiItem(objName: str) -> QWidget | None:
|
||||
"""Returns a QtWidget based on its objectName.
|
||||
"""
|
||||
"""Returns a QtWidget based on its objectName."""
|
||||
for qWidget in qApp.topLevelWidgets():
|
||||
if qWidget.objectName() == objName:
|
||||
return qWidget
|
||||
|
||||
@@ -160,7 +160,7 @@ class NWProject(QObject):
|
||||
"""Add a new file with a given label and parent item."""
|
||||
return self._tree.create(label, parent, nwItemType.FILE)
|
||||
|
||||
def writeNewFile(self, tHandle: str, hLevel: int, isDocument: bool, addText: str = "") -> bool:
|
||||
def writeNewFile(self, tHandle: str, hLevel: int, isDocument: bool, text: str = "") -> bool:
|
||||
"""Write content to a new document after it is created. This
|
||||
will not run if the file exists and is not empty.
|
||||
"""
|
||||
@@ -175,7 +175,7 @@ class NWProject(QObject):
|
||||
return False
|
||||
|
||||
hshText = "#"*minmax(hLevel, 1, 4)
|
||||
newText = f"{hshText} {tItem.itemName}\n\n{addText}"
|
||||
newText = f"{hshText} {tItem.itemName}\n\n{text}"
|
||||
if tItem.isNovelLike() and isDocument:
|
||||
tItem.setLayout(nwItemLayout.DOCUMENT)
|
||||
else:
|
||||
@@ -503,7 +503,7 @@ class NWProject(QObject):
|
||||
order has been altered, or a file is orphaned, this function is
|
||||
capable of handling it.
|
||||
"""
|
||||
sentItems = []
|
||||
sentItems = set()
|
||||
iterItems = self._tree.handles()
|
||||
n = 0
|
||||
nMax = min(len(iterItems), 10000)
|
||||
@@ -515,13 +515,12 @@ class NWProject(QObject):
|
||||
# Technically a bug
|
||||
continue
|
||||
elif tItem.itemParent is None:
|
||||
# Item is a root, or already been identified as an
|
||||
# orphaned item
|
||||
sentItems.append(tHandle)
|
||||
# Item is a root, or already been identified as orphaned
|
||||
sentItems.add(tHandle)
|
||||
yield tItem
|
||||
elif tItem.itemParent in sentItems:
|
||||
# Item's parent has been sent, so all is fine
|
||||
sentItems.append(tHandle)
|
||||
sentItems.add(tHandle)
|
||||
yield tItem
|
||||
elif tItem.itemParent in iterItems:
|
||||
# Item's parent exists, but hasn't been sent yet, so add
|
||||
|
||||
@@ -213,15 +213,15 @@ class UserDictionary:
|
||||
def load(self) -> None:
|
||||
"""Load the user's dictionary."""
|
||||
self._path = self._project.storage.getMetaFile(nwFiles.DICT_FILE)
|
||||
if not isinstance(self._path, Path):
|
||||
return
|
||||
try:
|
||||
with open(self._path, mode="r", encoding="utf-8") as fObj:
|
||||
data = json.load(fObj)
|
||||
self._words = set(data.get("novelWriter.userDict", []))
|
||||
except Exception:
|
||||
logger.error("Failed to load user dictionary")
|
||||
logException()
|
||||
self._words = set()
|
||||
if isinstance(self._path, Path) and self._path.is_file():
|
||||
try:
|
||||
with open(self._path, mode="r", encoding="utf-8") as fObj:
|
||||
data = json.load(fObj)
|
||||
self._words = set(data.get("novelWriter.userDict", []))
|
||||
except Exception:
|
||||
logger.error("Failed to load user dictionary")
|
||||
logException()
|
||||
return
|
||||
|
||||
def save(self) -> None:
|
||||
|
||||
@@ -448,6 +448,7 @@ class GuiMain(QMainWindow):
|
||||
self._changeView(nwView.PROJECT)
|
||||
|
||||
# Try to open the project
|
||||
tStart = time()
|
||||
if not SHARED.openProject(projFile):
|
||||
# The project open failed.
|
||||
lockStatus = SHARED.projectLock
|
||||
@@ -522,7 +523,7 @@ class GuiMain(QMainWindow):
|
||||
self.docEditor.setDocumentChanged(False)
|
||||
SHARED.project.setProjectChanged(False)
|
||||
|
||||
logger.debug("Project load complete")
|
||||
logger.debug("Project loaded in %.3f ms", (time() - tStart)*1000)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user