Apply open document shortcuts to the tree that has focus (#945)
* Better handling of Enter/Return on GUI trees, resolves #913 * Update test * Generalise open selected handle functions * Improve test coverage * Update docstring
This commit is contained in:
committed by
GitHub
parent
7024254960
commit
b0f939af32
@@ -28,16 +28,104 @@ from tools import cmpFiles
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QMessageBox, QDialog
|
||||
|
||||
from novelwriter.dialogs.itemeditor import GuiItemEditor
|
||||
from novelwriter.gui.doceditor import GuiDocEditor
|
||||
from novelwriter.gui.projtree import GuiProjectTree
|
||||
from novelwriter.gui import (
|
||||
GuiDocEditor, GuiProjectTree, GuiNovelTree, GuiOutline
|
||||
)
|
||||
from novelwriter.enum import nwItemType, nwWidget
|
||||
from novelwriter.dialogs.itemeditor import GuiItemEditor
|
||||
|
||||
keyDelay = 2
|
||||
typeDelay = 1
|
||||
stepDelay = 20
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_ProjectBlocker(monkeypatch, nwGUI):
|
||||
"""Test the blocking of features when there's no project open.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
# Test no-project blocking
|
||||
assert nwGUI.closeProject() is True
|
||||
assert nwGUI.saveProject() is False
|
||||
assert nwGUI.closeDocument() is False
|
||||
assert nwGUI.openDocument(None) is False
|
||||
assert nwGUI.openNextDocument(None) is False
|
||||
assert nwGUI.saveDocument() is False
|
||||
assert nwGUI.viewDocument(None) is False
|
||||
assert nwGUI.importDocument() is False
|
||||
assert nwGUI.mergeDocuments() is False
|
||||
assert nwGUI.splitDocument() is False
|
||||
assert nwGUI.openSelectedItem() is False
|
||||
assert nwGUI.editItem() is False
|
||||
assert nwGUI.requestNovelTreeRefresh() is False
|
||||
assert nwGUI.rebuildIndex() is False
|
||||
assert nwGUI.rebuildOutline() is False
|
||||
assert nwGUI.showProjectSettingsDialog() is False
|
||||
assert nwGUI.showProjectDetailsDialog() is False
|
||||
assert nwGUI.showBuildProjectDialog() is False
|
||||
assert nwGUI.showProjectWordListDialog() is False
|
||||
assert nwGUI.showWritingStatsDialog() is False
|
||||
|
||||
# END Test testGuiMain_NoProject
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, fncProj):
|
||||
"""Test handling of project tree items based on GUI focus states.
|
||||
"""
|
||||
monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes)
|
||||
|
||||
nwGUI.theProject.projTree.setSeed(42)
|
||||
assert nwGUI.newProject({"projPath": fncProj}) is True
|
||||
assert nwGUI.saveProject() is True
|
||||
|
||||
sHandle = "0e17daca5f3e1"
|
||||
assert nwGUI.openSelectedItem() is False
|
||||
|
||||
# Project Tree has focus
|
||||
nwGUI.switchFocus(nwWidget.TREE)
|
||||
nwGUI.projTabs.setCurrentIndex(0)
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(GuiProjectTree, "hasFocus", lambda *a: True)
|
||||
assert nwGUI.docEditor.docHandle() is None
|
||||
nwGUI.treeView._getTreeItem(sHandle).setSelected(True)
|
||||
nwGUI._keyPressReturn()
|
||||
assert nwGUI.docEditor.docHandle() == sHandle
|
||||
assert nwGUI.closeDocument() is True
|
||||
|
||||
# Novel Tree has focus
|
||||
nwGUI.projTabs.setCurrentIndex(1)
|
||||
nwGUI.novelView.refreshTree(True)
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(GuiNovelTree, "hasFocus", lambda *a: True)
|
||||
assert nwGUI.docEditor.docHandle() is None
|
||||
actItem = nwGUI.novelView.topLevelItem(0)
|
||||
chpItem = actItem.child(0)
|
||||
selItem = chpItem.child(0)
|
||||
nwGUI.novelView.setCurrentItem(selItem)
|
||||
nwGUI._keyPressReturn()
|
||||
assert nwGUI.docEditor.docHandle() == sHandle
|
||||
assert nwGUI.closeDocument() is True
|
||||
|
||||
# Project Outline has focus
|
||||
nwGUI.switchFocus(nwWidget.OUTLINE)
|
||||
with monkeypatch.context() as mp:
|
||||
mp.setattr(GuiOutline, "hasFocus", lambda *a: True)
|
||||
assert nwGUI.docEditor.docHandle() is None
|
||||
actItem = nwGUI.projView.topLevelItem(0)
|
||||
chpItem = actItem.child(0)
|
||||
selItem = chpItem.child(0)
|
||||
nwGUI.projView.setCurrentItem(selItem)
|
||||
nwGUI._keyPressReturn()
|
||||
assert nwGUI.docEditor.docHandle() == sHandle
|
||||
assert nwGUI.closeDocument() is True
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiMain_ProjectTreeItems
|
||||
|
||||
|
||||
@pytest.mark.gui
|
||||
def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir):
|
||||
"""Test the document editor.
|
||||
|
||||
@@ -29,7 +29,7 @@ from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
|
||||
from tools import writeFile
|
||||
|
||||
from novelwriter.gui.doceditor import GuiDocEditor
|
||||
from novelwriter.enum import nwDocAction, nwDocInsert, nwWidget
|
||||
from novelwriter.enum import nwDocAction, nwDocInsert
|
||||
from novelwriter.constants import nwKeyWords, nwUnicode
|
||||
|
||||
keyDelay = 2
|
||||
@@ -471,11 +471,7 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncDir, fncProj):
|
||||
assert nwGUI.newProject({"projPath": fncProj})
|
||||
|
||||
assert nwGUI.treeView._getTreeItem("0e17daca5f3e1") is not None
|
||||
|
||||
nwGUI.switchFocus(nwWidget.TREE)
|
||||
nwGUI.treeView.clearSelection()
|
||||
nwGUI.treeView._getTreeItem("0e17daca5f3e1").setSelected(True)
|
||||
assert nwGUI.openSelectedItem()
|
||||
assert nwGUI.openDocument("0e17daca5f3e1") is True
|
||||
nwGUI.docEditor.clear()
|
||||
|
||||
# Test Faulty Inserts
|
||||
|
||||
@@ -74,7 +74,7 @@ def testGuiNovelTree_TreeItems(qtbot, monkeypatch, nwGUI, nwMinimal):
|
||||
assert not topItem.isSelected()
|
||||
topItem.setSelected(True)
|
||||
assert nwTree.selectedItems()[0] == topItem
|
||||
assert nwTree.getSelectedHandle() == "a35baf2e93843"
|
||||
assert nwTree.getSelectedHandle() == ("a35baf2e93843", 0)
|
||||
|
||||
nwTree.refreshTree()
|
||||
assert nwTree.topLevelItem(0).isSelected()
|
||||
|
||||
@@ -77,6 +77,10 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, nwLipsum):
|
||||
selItem = chpItem.child(0)
|
||||
|
||||
nwGUI.projView.setCurrentItem(selItem)
|
||||
tHandle, tLine = nwGUI.projView.getSelectedHandle()
|
||||
assert tHandle == "88243afbe5ed8"
|
||||
assert tLine == 0
|
||||
|
||||
assert nwGUI.projMeta.titleLabel.text() == "<b>Scene</b>"
|
||||
assert nwGUI.projMeta.titleValue.text() == "Scene One"
|
||||
assert nwGUI.projMeta.fileValue.text() == "Scene One"
|
||||
@@ -87,6 +91,25 @@ def testGuiOutline_Main(qtbot, monkeypatch, nwGUI, nwLipsum):
|
||||
nwGUI.projMeta._tagClicked("#pov=Bod")
|
||||
assert nwGUI.docViewer.docHandle() == "4c4f28287af27"
|
||||
|
||||
# Scene One, Section Two
|
||||
actItem = nwGUI.projView.topLevelItem(1)
|
||||
chpItem = actItem.child(0)
|
||||
scnItem = chpItem.child(0)
|
||||
selItem = scnItem.child(0)
|
||||
|
||||
nwGUI.projView.setCurrentItem(selItem)
|
||||
tHandle, tLine = nwGUI.projView.getSelectedHandle()
|
||||
assert tHandle == "88243afbe5ed8"
|
||||
assert tLine == 12
|
||||
|
||||
assert nwGUI.projMeta.titleLabel.text() == "<b>Section</b>"
|
||||
assert nwGUI.projMeta.titleValue.text() == "Scene One, Section Two"
|
||||
assert nwGUI.projMeta.fileValue.text() == "Scene One"
|
||||
assert nwGUI.projMeta.itemValue.text() == "Finished"
|
||||
|
||||
nwGUI.projView._treeDoubleClick(selItem, 0)
|
||||
assert nwGUI.docEditor.docHandle() == "88243afbe5ed8"
|
||||
|
||||
# qtbot.stopForInteraction()
|
||||
|
||||
# END Test testGuiOutline_Main
|
||||
|
||||
Reference in New Issue
Block a user