Fixes: some Documents menu calls would crash manuskript if in textEdit

This commit is contained in:
Olivier Keshavjee 2017-11-22 09:37:02 +01:00
parent 6cc8864937
commit 550f889251

View file

@ -8,8 +8,7 @@ from PyQt5.QtWidgets import QWidget, QTextEdit, qApp, QAction, QMenu
from manuskript import settings
from manuskript.enums import Outline
from manuskript.functions import AUC, themeIcon
from manuskript.functions import toString
from manuskript import functions as F
from manuskript.models.outlineModel import outlineModel
from manuskript.ui.editors.MDFunctions import MDFormatSelection
from manuskript.ui.editors.MMDHighlighter import MMDHighlighter
@ -50,7 +49,7 @@ class textEditView(QTextEdit):
self.highligtCS = False
self.defaultFontPointSize = qApp.font().pointSize()
self._dict = None
# self.document().contentsChanged.connect(self.submit, AUC)
# self.document().contentsChanged.connect(self.submit, F.AUC)
# Submit text changed only after 500ms without modifications
self.updateTimer = QTimer()
@ -60,7 +59,7 @@ class textEditView(QTextEdit):
# self.updateTimer.timeout.connect(lambda: print("Timeout"))
self.updateTimer.stop()
self.document().contentsChanged.connect(self.updateTimer.start, AUC)
self.document().contentsChanged.connect(self.updateTimer.start, F.AUC)
# self.document().contentsChanged.connect(lambda: print("Document changed"))
# self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))
@ -100,11 +99,11 @@ class textEditView(QTextEdit):
def setModel(self, model):
self._model = model
try:
self._model.dataChanged.connect(self.update, AUC)
self._model.dataChanged.connect(self.update, F.AUC)
except TypeError:
pass
try:
self._model.rowsAboutToBeRemoved.connect(self.rowsAboutToBeRemoved, AUC)
self._model.rowsAboutToBeRemoved.connect(self.rowsAboutToBeRemoved, F.AUC)
except TypeError:
pass
@ -308,7 +307,7 @@ class textEditView(QTextEdit):
pass
def reconnectDocument(self):
self.document().contentsChanged.connect(self.updateTimer.start, AUC)
self.document().contentsChanged.connect(self.updateTimer.start, F.AUC)
def updateText(self):
if self._updating:
@ -317,9 +316,9 @@ class textEditView(QTextEdit):
self._updating = True
if self._index:
self.disconnectDocument()
if self.toPlainText() != toString(self._model.data(self._index)):
if self.toPlainText() != F.toString(self._model.data(self._index)):
# print(" Updating plaintext")
self.document().setPlainText(toString(self._model.data(self._index)))
self.document().setPlainText(F.toString(self._model.data(self._index)))
self.reconnectDocument()
elif self._indexes:
@ -328,7 +327,7 @@ class textEditView(QTextEdit):
same = True
for i in self._indexes:
item = i.internalPointer()
t.append(toString(item.data(self._column)))
t.append(F.toString(item.data(self._column)))
for t2 in t[1:]:
if t2 != t[0]:
@ -364,7 +363,7 @@ class textEditView(QTextEdit):
self._updating = True
for i in self._indexes:
item = i.internalPointer()
if self.toPlainText() != toString(item.data(self._column)):
if self.toPlainText() != F.toString(item.data(self._column)):
print("Submitting many indexes")
self._model.setData(i, self.toPlainText())
self._updating = False
@ -466,7 +465,7 @@ class textEditView(QTextEdit):
selectedWord = cursor.selectedText()
if not valid:
spell_menu = QMenu(self.tr('Spelling Suggestions'), self)
spell_menu.setIcon(themeIcon("spelling"))
spell_menu.setIcon(F.themeIcon("spelling"))
for word in self._dict.suggest(text):
action = self.SpellAction(word, spell_menu)
action.correct.connect(self.correctWord)
@ -553,3 +552,21 @@ class textEditView(QTextEdit):
MDFormatSelection(self, 2)
elif _format == "Clear":
MDFormatSelection(self)
###############################################################################
# KEYBOARD SHORTCUTS
###############################################################################
def callMainTreeView(self, functionName):
"""
The tree view in mainwindow must have same index as the text
edit that has focus. So we can pass it the call for documents
edits like: duplicate, move up, etc.
"""
if self._index and self._column == Outline.text.value:
function = getattr(F.mainWindow().treeRedacOutline, functionName)
function()
def duplicate(self): self.callMainTreeView("duplicate")
def moveUp(self): self.callMainTreeView("moveUp")
def moveDown(self): self.callMainTreeView("moveDown")