Merge pull request #267 from vkbo/bugfixes

Bugfixes
This commit is contained in:
Veronica K. Berglyd Olsen
2020-05-30 15:43:47 +02:00
committed by GitHub
6 changed files with 64 additions and 24 deletions
+7 -1
View File
@@ -71,6 +71,9 @@ class NWDoc():
"""Open a document from handle, capturing potential file system """Open a document from handle, capturing potential file system
errors and parse meta data. errors and parse meta data.
""" """
if not isHandle(tHandle):
return None
# Always clear first, since the object will often be reused. # Always clear first, since the object will often be reused.
self.clearDocument() self.clearDocument()
@@ -170,7 +173,10 @@ class NWDoc():
"""Permanently delete a document source file and its backups """Permanently delete a document source file and its backups
from the project data folder. from the project data folder.
""" """
docFile = self.docHandle+".nwd" if not isHandle(tHandle):
return False
docFile = tHandle+".nwd"
chkList = [] chkList = []
chkList.append(path.join(self.theProject.projContent, docFile)) chkList.append(path.join(self.theProject.projContent, docFile))
+24 -8
View File
@@ -152,15 +152,19 @@ class NWProject():
self.projTree.append(None, pHandle, newItem) self.projTree.append(None, pHandle, newItem)
return newItem.itemHandle return newItem.itemHandle
def addTrash(self): def trashFolder(self):
"""Add the special trash root folder to the project. """Add the special trash root folder to the project.
""" """
newItem = NWItem(self) trashHandle = self.projTree.trashRoot()
newItem.setName("Trash") if trashHandle is None:
newItem.setType(nwItemType.TRASH) newItem = NWItem(self)
newItem.setClass(nwItemClass.TRASH) newItem.setName("Trash")
self.projTree.append(None, None, newItem) newItem.setType(nwItemType.TRASH)
return newItem.itemHandle newItem.setClass(nwItemClass.TRASH)
self.projTree.append(None, None, newItem)
return newItem.itemHandle
return trashHandle
## ##
# Project Methods # Project Methods
@@ -179,6 +183,7 @@ class NWProject():
hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt) hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt)
self.projOpened = time() self.projOpened = time()
self.setProjectChanged(True) self.setProjectChanged(True)
self.saveProject(autoSave=True)
return True return True
def clearProject(self): def clearProject(self):
@@ -674,7 +679,7 @@ class NWProject():
# Setters # Setters
## ##
def setProjectPath(self, projPath): def setProjectPath(self, projPath, newProject=False):
"""Set the project storage path, and also expand ~ to the user """Set the project storage path, and also expand ~ to the user
directory using the path library. directory using the path library.
""" """
@@ -684,7 +689,18 @@ class NWProject():
if projPath.startswith("~"): if projPath.startswith("~"):
projPath = path.expanduser(projPath) projPath = path.expanduser(projPath)
self.projPath = path.abspath(projPath) self.projPath = path.abspath(projPath)
if newProject and self.mainConf.showGUI:
if listdir(self.projPath):
self.theParent.makeAlert((
"New project folder is not empty. "
"Each project requires a dedicated project folder."
), nwAlert.ERROR)
return False
self.ensureFolderStructure()
self.setProjectChanged(True) self.setProjectChanged(True)
return True return True
def setProjectName(self, projName): def setProjectName(self, projName):
+6 -6
View File
@@ -200,8 +200,8 @@ class GuiDocTree(QTreeWidget):
def revealTreeItem(self, tHandle): def revealTreeItem(self, tHandle):
"""Reveal a newly added project item in the project tree. """Reveal a newly added project item in the project tree.
""" """
nwItem = self.theProject.projTree[tHandle] nwItem = self.theProject.projTree[tHandle]
trItem = self._addTreeItem(nwItem) trItem = self._addTreeItem(nwItem)
pHandle = nwItem.parHandle pHandle = nwItem.parHandle
if pHandle is not None and pHandle in self.theMap.keys(): if pHandle is not None and pHandle in self.theMap.keys():
self.theMap[pHandle].setExpanded(True) self.theMap[pHandle].setExpanded(True)
@@ -608,15 +608,15 @@ class GuiDocTree(QTreeWidget):
"""Adds the trash root folder if it doesn't already exist in the """Adds the trash root folder if it doesn't already exist in the
project tree. project tree.
""" """
trashHandle = self.theProject.projTree.trashRoot() trashHandle = self.theProject.trashFolder()
if trashHandle is None: if trashHandle is None:
self.theProject.addTrash() return None
trItem = self._getTreeItem(trashHandle)
if trItem is None:
trItem = self._addTreeItem( trItem = self._addTreeItem(
self.theProject.projTree[trashHandle] self.theProject.projTree[trashHandle]
) )
trItem.setExpanded(True) trItem.setExpanded(True)
else:
trItem = self._getTreeItem(trashHandle)
return trItem return trItem
def _addOrphanedRoot(self): def _addOrphanedRoot(self):
+8 -6
View File
@@ -294,12 +294,14 @@ class GuiMain(QMainWindow):
return False return False
logger.info("Creating new project") logger.info("Creating new project")
self.theProject.newProject() if self.theProject.setProjectPath(projPath, newProject=True):
self.theProject.setProjectPath(projPath) self.theProject.newProject()
self.rebuildTree() self.rebuildTree()
self.saveProject() self.saveProject()
self.hasProject = True self.hasProject = True
self.statusBar.setRefTime(self.theProject.projOpened) self.statusBar.setRefTime(self.theProject.projOpened)
else:
return False
return True return True
+10 -3
View File
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="0.7.0rc1" hexVersion="0x000700c1" fileVersion="1.1" saveCount="4" autoCount="0" timeStamp="2020-05-29 23:06:02"> <novelWriterXML appVersion="0.7.0rc1" hexVersion="0x000700c1" fileVersion="1.1" saveCount="4" autoCount="1" timeStamp="2020-05-30 15:31:30" editTime="12">
<project> <project>
<name>New Project</name> <name>New Project</name>
<title></title> <title></title>
@@ -9,7 +9,7 @@
<spellCheck>True</spellCheck> <spellCheck>True</spellCheck>
<autoOutline>True</autoOutline> <autoOutline>True</autoOutline>
<lastEdited>31489056e0916</lastEdited> <lastEdited>31489056e0916</lastEdited>
<lastViewed>31489056e0916</lastViewed> <lastViewed>None</lastViewed>
<lastWordCount>86</lastWordCount> <lastWordCount>86</lastWordCount>
<autoReplace/> <autoReplace/>
<titleFormat> <titleFormat>
@@ -35,7 +35,7 @@
<entry blue="0" green="200" red="50">Main</entry> <entry blue="0" green="200" red="50">Main</entry>
</importance> </importance>
</settings> </settings>
<content count="9"> <content count="10">
<item handle="73475cb40a568" order="0" parent="None"> <item handle="73475cb40a568" order="0" parent="None">
<name>Novel</name> <name>Novel</name>
<type>ROOT</type> <type>ROOT</type>
@@ -119,5 +119,12 @@
<paraCount>1</paraCount> <paraCount>1</paraCount>
<cursorPos>68</cursorPos> <cursorPos>68</cursorPos>
</item> </item>
<item handle="41cfc0d1f2d12" order="4" parent="None">
<name>Trash</name>
<type>TRASH</type>
<class>TRASH</class>
<status>None</status>
<expanded>True</expanded>
</item>
</content> </content>
</novelWriterXML> </novelWriterXML>
+9
View File
@@ -235,6 +235,15 @@ def testMainWindows(qtbot, nwTempGUI, nwRef, nwTemp):
assert nwGUI.closeDocViewer() assert nwGUI.closeDocViewer()
qtbot.wait(stepDelay) qtbot.wait(stepDelay)
# Check a Quick Create and Delete
assert nwGUI.treeView.newTreeItem(nwItemType.FILE, None)
newHandle = nwGUI.treeView.getSelectedHandle()
assert nwGUI.theProject.projTree["031b4af5197ec"] is not None
assert nwGUI.treeView.deleteItem()
assert nwGUI.treeView.setSelectedHandle(newHandle)
assert nwGUI.treeView.deleteItem()
assert nwGUI.saveProject()
# Check the files # Check the files
refFile = path.join(nwTempGUI, "nwProject.nwx") refFile = path.join(nwTempGUI, "nwProject.nwx")
assert cmpFiles(refFile, path.join(nwRef, "gui", "1_nwProject.nwx"), [2]) assert cmpFiles(refFile, path.join(nwRef, "gui", "1_nwProject.nwx"), [2])