Block document action if editor does not have focus
This commit is contained in:
@@ -646,6 +646,10 @@ class GuiDocEditor(QTextEdit):
|
|||||||
this class when calling these actions from other classes.
|
this class when calling these actions from other classes.
|
||||||
"""
|
"""
|
||||||
logger.verbose("Requesting action: %s" % theAction.name)
|
logger.verbose("Requesting action: %s" % theAction.name)
|
||||||
|
if not self.hasFocus():
|
||||||
|
logger.verbose("Editor does not have focus")
|
||||||
|
return False
|
||||||
|
|
||||||
if self.theHandle is None:
|
if self.theHandle is None:
|
||||||
logger.error("No document open")
|
logger.error("No document open")
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from PyQt5.QtCore import Qt
|
|||||||
from PyQt5.QtGui import QTextCursor
|
from PyQt5.QtGui import QTextCursor
|
||||||
from PyQt5.QtWidgets import QAction, QMessageBox
|
from PyQt5.QtWidgets import QAction, QMessageBox
|
||||||
|
|
||||||
|
from nw.gui.doceditor import GuiDocEditor
|
||||||
from nw.gui.projtree import GuiProjectTree
|
from nw.gui.projtree import GuiProjectTree
|
||||||
from nw.constants import nwItemType, nwDocAction
|
from nw.constants import nwItemType, nwDocAction
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ def testGuiEditor_Main(qtbot, monkeypatch, nwGUI, fncDir, fncProj, refDir, outDi
|
|||||||
# Block message box
|
# Block message box
|
||||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||||
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *args: True)
|
monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *args: True)
|
||||||
|
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *args: True)
|
||||||
|
|
||||||
# Create new, save, close project
|
# Create new, save, close project
|
||||||
nwGUI.theProject.projTree.setSeed(42)
|
nwGUI.theProject.projTree.setSeed(42)
|
||||||
@@ -353,6 +355,7 @@ def testGuiEditor_Search(qtbot, monkeypatch, nwGUI, nwLipsum):
|
|||||||
"""
|
"""
|
||||||
# Block message box
|
# Block message box
|
||||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||||
|
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *args: True)
|
||||||
|
|
||||||
nwGUI.theProject.projTree.setSeed(42)
|
nwGUI.theProject.projTree.setSeed(42)
|
||||||
assert nwGUI.openProject(nwLipsum)
|
assert nwGUI.openProject(nwLipsum)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ from PyQt5.QtCore import Qt
|
|||||||
from PyQt5.QtGui import QTextCursor, QTextBlock
|
from PyQt5.QtGui import QTextCursor, QTextBlock
|
||||||
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
|
from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
|
||||||
|
|
||||||
|
from nw.gui.doceditor import GuiDocEditor
|
||||||
from nw.constants import nwUnicode, nwDocAction, nwDocInsert, nwKeyWords
|
from nw.constants import nwUnicode, nwDocAction, nwDocInsert, nwKeyWords
|
||||||
|
|
||||||
keyDelay = 2
|
keyDelay = 2
|
||||||
@@ -39,6 +40,7 @@ def testGuiMenu_EditFormat(qtbot, monkeypatch, nwGUI, nwLipsum):
|
|||||||
"""
|
"""
|
||||||
# Block message box
|
# Block message box
|
||||||
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
|
||||||
|
monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *args: True)
|
||||||
|
|
||||||
# Test Document Action with No Project
|
# Test Document Action with No Project
|
||||||
assert not nwGUI.docEditor.docAction(nwDocAction.COPY)
|
assert not nwGUI.docEditor.docAction(nwDocAction.COPY)
|
||||||
|
|||||||
Reference in New Issue
Block a user