tidy signal handling
This commit is contained in:
2
main.cpp
2
main.cpp
@@ -18,7 +18,7 @@ int main(int argc, char *argv[])
|
|||||||
KLocalizedString::setApplicationDomain(QByteArrayLiteral("pineapple-notepad"));
|
KLocalizedString::setApplicationDomain(QByteArrayLiteral("pineapple-notepad"));
|
||||||
|
|
||||||
KAboutData aboutData(QStringLiteral("pineapple-notepad"),
|
KAboutData aboutData(QStringLiteral("pineapple-notepad"),
|
||||||
"Pineapple Notepad(迫真)",
|
"Pineapple Notepad",
|
||||||
QStringLiteral("0.1"),
|
QStringLiteral("0.1"),
|
||||||
"A Scintilla-based Text Editor",
|
"A Scintilla-based Text Editor",
|
||||||
KAboutLicense::Unknown,
|
KAboutLicense::Unknown,
|
||||||
|
|||||||
@@ -70,9 +70,6 @@ int TabWidget::openDocument(const QString &filePath)
|
|||||||
SciEdit *editor = createEditor();
|
SciEdit *editor = createEditor();
|
||||||
m_editors[docId] = editor;
|
m_editors[docId] = editor;
|
||||||
|
|
||||||
// 临时断开信号连接,避免setText触发textChanged导致文档被标记为已修改
|
|
||||||
disconnectEditorSignals(editor);
|
|
||||||
|
|
||||||
// 设置编辑器内容
|
// 设置编辑器内容
|
||||||
QString content = m_documentManager->getDocumentContent(docId);
|
QString content = m_documentManager->getDocumentContent(docId);
|
||||||
const QByteArray contentBytes = content.toUtf8();
|
const QByteArray contentBytes = content.toUtf8();
|
||||||
@@ -243,7 +240,6 @@ bool TabWidget::closeTab(int index)
|
|||||||
// 清理编辑器和文档
|
// 清理编辑器和文档
|
||||||
if (m_editors.contains(docId)) {
|
if (m_editors.contains(docId)) {
|
||||||
SciEdit *editor = m_editors[docId];
|
SciEdit *editor = m_editors[docId];
|
||||||
disconnectEditorSignals(editor);
|
|
||||||
m_editors.remove(docId);
|
m_editors.remove(docId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,11 +431,3 @@ void TabWidget::connectEditorSignals(SciEdit *editor)
|
|||||||
connect(editor, &ScintillaEditBase::savePointChanged, this, &TabWidget::onEditorSavePointChanged);
|
connect(editor, &ScintillaEditBase::savePointChanged, this, &TabWidget::onEditorSavePointChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabWidget::disconnectEditorSignals(SciEdit *editor)
|
|
||||||
{
|
|
||||||
if (editor) {
|
|
||||||
disconnect(editor, &SciEdit::textChanged, this, &TabWidget::onEditorTextChanged);
|
|
||||||
disconnect(editor, &ScintillaEditBase::savePointChanged, this, &TabWidget::onEditorSavePointChanged);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -54,5 +54,4 @@ private:
|
|||||||
SciEdit *createEditor();
|
SciEdit *createEditor();
|
||||||
void updateTabTitle(int tabIndex);
|
void updateTabTitle(int tabIndex);
|
||||||
void connectEditorSignals(SciEdit *editor);
|
void connectEditorSignals(SciEdit *editor);
|
||||||
void disconnectEditorSignals(SciEdit *editor);
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user