Populate the add button menu in the project widget
This commit is contained in:
+17
-13
@@ -1,5 +1,5 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="1.7-beta1" hexVersion="0x010700b1" fileVersion="1.4" timeStamp="2022-05-21 17:08:21">
|
||||
<novelWriterXML appVersion="1.7-beta1" hexVersion="0x010700b1" fileVersion="1.4" timeStamp="2022-06-06 21:17:27">
|
||||
<project>
|
||||
<name>New Project</name>
|
||||
<title>New Novel</title>
|
||||
@@ -16,9 +16,9 @@
|
||||
<autoOutline>True</autoOutline>
|
||||
<lastEdited>None</lastEdited>
|
||||
<lastViewed>None</lastViewed>
|
||||
<lastWordCount>0</lastWordCount>
|
||||
<novelWordCount>0</novelWordCount>
|
||||
<notesWordCount>0</notesWordCount>
|
||||
<lastWordCount>2</lastWordCount>
|
||||
<novelWordCount>1</novelWordCount>
|
||||
<notesWordCount>1</notesWordCount>
|
||||
<autoReplace/>
|
||||
<titleFormat>
|
||||
<title>%title%</title>
|
||||
@@ -28,19 +28,19 @@
|
||||
<section></section>
|
||||
</titleFormat>
|
||||
<status>
|
||||
<entry key="s000008" count="5" red="100" green="100" blue="100">New</entry>
|
||||
<entry key="s000008" count="7" red="100" green="100" blue="100">New</entry>
|
||||
<entry key="s000009" count="0" red="200" green="50" blue="0">Note</entry>
|
||||
<entry key="s00000a" count="0" red="200" green="150" blue="0">Draft</entry>
|
||||
<entry key="s00000b" count="0" red="50" green="200" blue="0">Finished</entry>
|
||||
</status>
|
||||
<importance>
|
||||
<entry key="i00000c" count="3" red="100" green="100" blue="100">New</entry>
|
||||
<entry key="i00000c" count="4" red="100" green="100" blue="100">New</entry>
|
||||
<entry key="i00000d" count="0" red="200" green="50" blue="0">Minor</entry>
|
||||
<entry key="i00000e" count="0" red="200" green="150" blue="0">Major</entry>
|
||||
<entry key="i00000f" count="0" red="50" green="200" blue="0">Main</entry>
|
||||
</importance>
|
||||
</settings>
|
||||
<content count="10">
|
||||
<content count="11">
|
||||
<item handle="0000000000010" parent="None" root="0000000000010" order="0" type="ROOT" class="NOVEL">
|
||||
<meta expanded="False"/>
|
||||
<name status="s000008" import="i00000c">Novel</name>
|
||||
@@ -73,13 +73,17 @@
|
||||
<meta expanded="False" charCount="0" wordCount="0" paraCount="0" cursorPos="0"/>
|
||||
<name status="s000008" import="i00000c" exported="True">New Scene</name>
|
||||
</item>
|
||||
<item handle="0000000000028" parent="31489056e0916" root="None" order="0" type="FILE" class="NO_CLASS" layout="NO_LAYOUT">
|
||||
<meta expanded="False" charCount="0" wordCount="0" paraCount="0" cursorPos="0"/>
|
||||
<name status="None" import="None" exported="True">Hello</name>
|
||||
<item handle="0000000000028" parent="0000000000015" root="0000000000010" order="0" type="FOLDER" class="NOVEL">
|
||||
<meta expanded="False"/>
|
||||
<name status="s000008" import="i00000c">Stuff</name>
|
||||
</item>
|
||||
<item handle="0000000000029" parent="71ee45a3c0db9" root="None" order="0" type="FILE" class="NO_CLASS" layout="NO_LAYOUT">
|
||||
<meta expanded="False" charCount="0" wordCount="0" paraCount="0" cursorPos="0"/>
|
||||
<name status="None" import="None" exported="True">Jane</name>
|
||||
<item handle="0000000000029" parent="0000000000015" root="0000000000010" order="0" type="FILE" class="NOVEL" layout="DOCUMENT">
|
||||
<meta expanded="False" charCount="5" wordCount="1" paraCount="0" cursorPos="0"/>
|
||||
<name status="s000008" import="i00000c" exported="True">Hello</name>
|
||||
</item>
|
||||
<item handle="000000000002a" parent="0000000000012" root="0000000000012" order="0" type="FILE" class="CHARACTER" layout="NOTE">
|
||||
<meta expanded="False" charCount="4" wordCount="1" paraCount="0" cursorPos="0"/>
|
||||
<name status="s000008" import="i00000c" exported="True">Jane</name>
|
||||
</item>
|
||||
</content>
|
||||
</novelWriterXML>
|
||||
@@ -232,9 +232,6 @@ def testCoreIndex_CheckThese(mockGUI, fncDir, mockRnd):
|
||||
|
||||
assert theIndex.getHandleHeaderLevel(cHandle) == "H1"
|
||||
assert theIndex.getHandleHeaderLevel(nHandle) == "H1"
|
||||
assert theIndex.getHandleHeaderIntLevel(cHandle) == 1
|
||||
assert theIndex.getHandleHeaderIntLevel(nHandle) == 1
|
||||
assert theIndex.getHandleHeaderIntLevel("stuff") == 0
|
||||
|
||||
# Zero Items
|
||||
assert theIndex.checkThese([], cItem) == []
|
||||
|
||||
@@ -25,7 +25,7 @@ import pytest
|
||||
from mock import causeOSError
|
||||
from tools import getGuiItem, readFile, writeFile, buildTestProject
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog, QInputDialog
|
||||
|
||||
from novelwriter.enum import nwItemType, nwWidget
|
||||
from novelwriter.dialogs import GuiDocMerge, GuiItemEditor
|
||||
@@ -39,6 +39,7 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
|
||||
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
|
||||
|
||||
# Create a new project
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
|
||||
@@ -25,7 +25,7 @@ import pytest
|
||||
from mock import causeOSError
|
||||
from tools import getGuiItem, readFile, writeFile, buildTestProject
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox, QDialog, QInputDialog
|
||||
|
||||
from novelwriter.enum import nwItemType, nwWidget
|
||||
from novelwriter.dialogs import GuiDocSplit, GuiItemEditor
|
||||
@@ -40,6 +40,7 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok)
|
||||
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
|
||||
|
||||
# Create a new project
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
|
||||
@@ -23,7 +23,7 @@ import pytest
|
||||
|
||||
from tools import getGuiItem, buildTestProject
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QDialog, QMessageBox
|
||||
from PyQt5.QtWidgets import QAction, QDialog, QMessageBox, QInputDialog
|
||||
|
||||
from novelwriter.enum import nwItemLayout, nwItemType
|
||||
from novelwriter.dialogs import GuiItemEditor
|
||||
@@ -154,6 +154,7 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
# Block message box
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
|
||||
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
|
||||
|
||||
# Create Project and Open Document
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
@@ -165,7 +166,7 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, mockRnd):
|
||||
# Create Note
|
||||
nwGUI.treeView.projTree.clearSelection()
|
||||
nwGUI.treeView.projTree._getTreeItem("000000000000a").setSelected(True)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
|
||||
|
||||
# Open Note
|
||||
assert nwGUI.openDocument("0000000000010")
|
||||
|
||||
@@ -26,7 +26,7 @@ from shutil import copyfile
|
||||
from tools import cmpFiles, buildTestProject, XML_IGNORE, writeFile
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox, QDialog
|
||||
from PyQt5.QtWidgets import QMessageBox, QDialog, QInputDialog
|
||||
|
||||
from novelwriter.gui import GuiDocEditor, GuiNovelTree, GuiOutline
|
||||
from novelwriter.enum import nwItemType, nwWidget
|
||||
@@ -173,6 +173,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
monkeypatch.setattr(GuiItemEditor, "result", lambda *a: QDialog.Accepted)
|
||||
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
|
||||
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True)
|
||||
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
|
||||
|
||||
# Create new, save, close project
|
||||
buildTestProject(nwGUI, fncProj)
|
||||
@@ -241,7 +242,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
nwGUI.switchFocus(nwWidget.TREE)
|
||||
nwGUI.treeView.projTree.clearSelection()
|
||||
nwGUI.treeView.projTree._getTreeItem("000000000000a").setSelected(True)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
|
||||
assert nwGUI.openSelectedItem()
|
||||
|
||||
# Type something into the document
|
||||
@@ -263,7 +264,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
nwGUI.switchFocus(nwWidget.TREE)
|
||||
nwGUI.treeView.projTree.clearSelection()
|
||||
nwGUI.treeView.projTree._getTreeItem("0000000000009").setSelected(True)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
|
||||
assert nwGUI.openSelectedItem()
|
||||
|
||||
# Type something into the document
|
||||
@@ -285,7 +286,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock
|
||||
nwGUI.switchFocus(nwWidget.TREE)
|
||||
nwGUI.treeView.projTree.clearSelection()
|
||||
nwGUI.treeView.projTree._getTreeItem("000000000000b").setSelected(True)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None)
|
||||
nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
|
||||
assert nwGUI.openSelectedItem()
|
||||
|
||||
# Add Some Text
|
||||
|
||||
@@ -24,9 +24,8 @@ import os
|
||||
|
||||
from tools import buildTestProject
|
||||
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox
|
||||
from PyQt5.QtWidgets import QAction, QMessageBox, QInputDialog
|
||||
|
||||
from novelwriter.guimain import GuiMain
|
||||
from novelwriter.gui.projtree import GuiProjectTree
|
||||
from novelwriter.enum import nwItemType, nwItemClass
|
||||
|
||||
@@ -40,7 +39,7 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd)
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiMain, "editItem", lambda *a: None)
|
||||
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
|
||||
|
||||
nwTree = nwGUI.treeView
|
||||
|
||||
@@ -89,22 +88,31 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd)
|
||||
assert nwGUI.theProject.tree["0000000000012"].itemRoot == "0000000000008"
|
||||
assert nwGUI.theProject.tree["0000000000012"].itemClass == nwItemClass.NOVEL
|
||||
|
||||
# Add a new file next to the other new file
|
||||
# Add a new chapter next to the other new file
|
||||
nwTree.setSelectedHandle("0000000000012")
|
||||
assert nwTree.newTreeItem(nwItemType.FILE) is True
|
||||
assert nwTree.newTreeItem(nwItemType.FILE, hLevel=2) is True
|
||||
assert nwGUI.theProject.tree["0000000000013"].itemParent == "0000000000011"
|
||||
assert nwGUI.theProject.tree["0000000000013"].itemRoot == "0000000000008"
|
||||
assert nwGUI.theProject.tree["0000000000013"].itemClass == nwItemClass.NOVEL
|
||||
assert nwGUI.openDocument("0000000000013")
|
||||
assert nwGUI.docEditor.getText() == "## New Document\n\n"
|
||||
assert nwGUI.docEditor.getText() == "## New Chapter\n\n"
|
||||
|
||||
# Add a new scene next to the other new file
|
||||
nwTree.setSelectedHandle("0000000000012")
|
||||
assert nwTree.newTreeItem(nwItemType.FILE, hLevel=3) is True
|
||||
assert nwGUI.theProject.tree["0000000000014"].itemParent == "0000000000011"
|
||||
assert nwGUI.theProject.tree["0000000000014"].itemRoot == "0000000000008"
|
||||
assert nwGUI.theProject.tree["0000000000014"].itemClass == nwItemClass.NOVEL
|
||||
assert nwGUI.openDocument("0000000000014")
|
||||
assert nwGUI.docEditor.getText() == "### New Scene\n\n"
|
||||
|
||||
# Add a new file to the characters folder
|
||||
nwTree.setSelectedHandle("000000000000a")
|
||||
assert nwTree.newTreeItem(nwItemType.FILE) is True
|
||||
assert nwGUI.theProject.tree["0000000000014"].itemParent == "000000000000a"
|
||||
assert nwGUI.theProject.tree["0000000000014"].itemRoot == "000000000000a"
|
||||
assert nwGUI.theProject.tree["0000000000014"].itemClass == nwItemClass.CHARACTER
|
||||
assert nwGUI.openDocument("0000000000014")
|
||||
assert nwTree.newTreeItem(nwItemType.FILE, hLevel=1, isNote=True) is True
|
||||
assert nwGUI.theProject.tree["0000000000015"].itemParent == "000000000000a"
|
||||
assert nwGUI.theProject.tree["0000000000015"].itemRoot == "000000000000a"
|
||||
assert nwGUI.theProject.tree["0000000000015"].itemClass == nwItemClass.CHARACTER
|
||||
assert nwGUI.openDocument("0000000000015")
|
||||
assert nwGUI.docEditor.getText() == "# New Note\n\n"
|
||||
|
||||
# Make sure the sibling folder bug trap works
|
||||
@@ -115,6 +123,12 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd)
|
||||
assert "Internal error" in caplog.text
|
||||
nwGUI.theProject.tree["0000000000013"].setParent("0000000000011")
|
||||
|
||||
# Cancel during creation
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(QInputDialog, "getText", lambda *a, **k: ("", False))
|
||||
nwTree.setSelectedHandle("0000000000013")
|
||||
assert nwTree.newTreeItem(nwItemType.FILE) is False
|
||||
|
||||
# Get the trash folder
|
||||
nwTree.projTree._addTrashRoot()
|
||||
trashHandle = nwGUI.theProject.trashFolder()
|
||||
@@ -148,7 +162,7 @@ def testGuiProjTree_MoveItems(qtbot, monkeypatch, nwGUI, fncDir, mockRnd):
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiMain, "editItem", lambda *a: None)
|
||||
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
|
||||
|
||||
nwTree = nwGUI.treeView
|
||||
|
||||
@@ -272,7 +286,7 @@ def testGuiProjTree_DeleteItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockR
|
||||
monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes)
|
||||
monkeypatch.setattr(GuiMain, "editItem", lambda *a: None)
|
||||
monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True))
|
||||
|
||||
nwTree = nwGUI.treeView
|
||||
|
||||
|
||||
Reference in New Issue
Block a user