mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-18 11:52:25 +12:00
Trying to optimize things a bit
This commit is contained in:
parent
a14351956b
commit
ce445500d3
|
@ -100,7 +100,7 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
|
|||
highlighting=True,
|
||||
autoResize=True)
|
||||
edt.setFrameShape(QFrame.NoFrame)
|
||||
edt.setStatusTip(itm.path())
|
||||
edt.setStatusTip("{} ({})".format(itm.path(), itm.type()))
|
||||
self.toggledSpellcheck.connect(edt.toggleSpellcheck, AUC)
|
||||
self.dictChanged.connect(edt.setDict, AUC)
|
||||
#edt.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
||||
|
|
|
@ -10,6 +10,7 @@ class metadataView(QWidget, Ui_metadataView):
|
|||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self)
|
||||
self.setupUi(self)
|
||||
self._lastIndexes = None
|
||||
self.txtSummarySentance.setColumn(Outline.summarySentance.value)
|
||||
self.txtSummaryFull.setColumn(Outline.summaryFull.value)
|
||||
self.txtNotes.setColumn(Outline.notes.value)
|
||||
|
@ -34,9 +35,11 @@ class metadataView(QWidget, Ui_metadataView):
|
|||
return indexes
|
||||
|
||||
def selectionChanged(self, sourceView):
|
||||
|
||||
indexes = self.getIndexes(sourceView)
|
||||
|
||||
if self._lastIndexes == indexes:
|
||||
return
|
||||
|
||||
if len(indexes) == 0:
|
||||
self.setEnabled(False)
|
||||
|
||||
|
@ -55,6 +58,8 @@ class metadataView(QWidget, Ui_metadataView):
|
|||
|
||||
self.properties.selectionChanged(sourceView)
|
||||
|
||||
self._lastIndexes = indexes
|
||||
|
||||
def setDict(self, d):
|
||||
self.txtNotes.setDict(d)
|
||||
self.txtSummaryFull.setDict(d)
|
||||
|
|
|
@ -26,6 +26,7 @@ class textEditView(QTextEdit):
|
|||
self._updating = False
|
||||
self._item = None
|
||||
self._highlighting = highlighting
|
||||
self._textFormat = "text"
|
||||
self.setAcceptRichText(False)
|
||||
|
||||
self.spellcheck = spellcheck
|
||||
|
@ -45,7 +46,9 @@ class textEditView(QTextEdit):
|
|||
self.updateTimer.setInterval(500)
|
||||
self.updateTimer.setSingleShot(True)
|
||||
self.updateTimer.timeout.connect(self.submit)
|
||||
self.updateTimer.stop()
|
||||
self.document().contentsChanged.connect(self.updateTimer.start, AUC)
|
||||
#self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))
|
||||
|
||||
if index:
|
||||
self.setCurrentModelIndex(index)
|
||||
|
@ -96,10 +99,10 @@ class textEditView(QTextEdit):
|
|||
except TypeError:
|
||||
pass
|
||||
|
||||
self.setupEditorForIndex(self._index)
|
||||
#self.document().contentsChanged.connect(self.submit, AUC)
|
||||
self.updateText()
|
||||
|
||||
self.setupEditorForIndex(self._index)
|
||||
|
||||
else:
|
||||
self._index = QModelIndex()
|
||||
|
@ -112,6 +115,24 @@ class textEditView(QTextEdit):
|
|||
self.setPlainText("")
|
||||
|
||||
def setupEditorForIndex(self, index):
|
||||
|
||||
# what type of text are we editing?
|
||||
if type(index.model()) != outlineModel:
|
||||
self._textFormat = "text"
|
||||
return
|
||||
|
||||
if self._column != Outline.text.value:
|
||||
self._textFormat = "text"
|
||||
return
|
||||
|
||||
item = index.internalPointer()
|
||||
if item.isHTML():
|
||||
self._textFormat = "html"
|
||||
elif item.isT2T():
|
||||
self._textFormat = "t2t"
|
||||
else:
|
||||
self._textFormat = "text"
|
||||
|
||||
# Setting highlighter
|
||||
if self._highlighting:
|
||||
item = index.internalPointer()
|
||||
|
@ -123,10 +144,10 @@ class textEditView(QTextEdit):
|
|||
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
|
||||
|
||||
# Accept richtext maybe
|
||||
if self.indexIsHtml(index):
|
||||
if self._textFormat == "html":
|
||||
self.setAcceptRichText(True)
|
||||
else:
|
||||
self.setAcceptRichText(False)
|
||||
self.setAcceptRichText
|
||||
|
||||
def setCurrentModelIndexes(self, indexes):
|
||||
self._index = None
|
||||
|
@ -164,6 +185,15 @@ class textEditView(QTextEdit):
|
|||
if update:
|
||||
self.updateText()
|
||||
|
||||
def disconnectDocument(self):
|
||||
try:
|
||||
self.document().contentsChanged.disconnect(self.updateTimer.start)
|
||||
except:
|
||||
pass
|
||||
|
||||
def reconnectDocument(self):
|
||||
self.document().contentsChanged.connect(self.updateTimer.start, AUC)
|
||||
|
||||
def updateText(self):
|
||||
|
||||
if self._updating:
|
||||
|
@ -171,13 +201,15 @@ class textEditView(QTextEdit):
|
|||
|
||||
self._updating = True
|
||||
if self._index:
|
||||
if self.indexIsHtml(self._index):
|
||||
self.disconnectDocument()
|
||||
if self._textFormat == "html":
|
||||
if self.toHtml() != toString(self._model.data(self._index)):
|
||||
self.document().setHtml(toString(self._model.data(self._index)))
|
||||
else:
|
||||
if self.toPlainText() != toString(self._model.data(self._index)):
|
||||
self.document().setPlainText(toString(self._model.data(self._index)))
|
||||
|
||||
self.reconnectDocument()
|
||||
|
||||
elif self._indexes:
|
||||
t = []
|
||||
same = True
|
||||
|
@ -208,7 +240,7 @@ class textEditView(QTextEdit):
|
|||
|
||||
if self._index:
|
||||
item = self._index.internalPointer()
|
||||
if self.indexIsHtml(self._index):
|
||||
if self._textFormat == "html":
|
||||
if self.toHtml() != self._model.data(self._index):
|
||||
self._updating = True
|
||||
self._model.setData(self._index, self.toHtml())
|
||||
|
@ -227,19 +259,6 @@ class textEditView(QTextEdit):
|
|||
self._model.setData(i, self.toPlainText())
|
||||
self._updating = False
|
||||
|
||||
def indexIsHtml(self, index):
|
||||
if not index.isValid():
|
||||
return False
|
||||
|
||||
if type(index.model()) != outlineModel:
|
||||
return False
|
||||
|
||||
item = index.internalPointer()
|
||||
if item.isHTML():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------
|
||||
# Resize stuff
|
||||
|
||||
|
|
Loading…
Reference in a new issue