i18n: update ts files

This commit is contained in:
2026-02-01 17:18:31 +08:00
parent 85d94afc99
commit ed2f047452
3 changed files with 51 additions and 20 deletions

View File

@@ -194,13 +194,7 @@ void DocumentManager::setDocumentContent(int docId, const QString &content)
{
if (m_documents.contains(docId)) {
DocumentInfo &doc = m_documents[docId];
if (doc.content != content) {
doc.content = content;
if (!doc.modified) {
doc.modified = true;
emit documentModified(docId, true);
}
}
}
}

View File

@@ -27,9 +27,6 @@ TabWidget::TabWidget(DocumentManager *documentManager, QWidget *parent)
this, &TabWidget::onDocumentModified);
connect(m_documentManager, &DocumentManager::documentTitleChanged,
this, &TabWidget::onDocumentTitleChanged);
// 创建第一个文档
newDocument();
}
TabWidget::~TabWidget()
@@ -44,6 +41,8 @@ int TabWidget::newDocument()
}
SciEdit *editor = createEditor();
editor->emptyUndoBuffer();
editor->setSavePoint();
m_editors[docId] = editor;
// 连接信号
@@ -76,7 +75,12 @@ int TabWidget::openDocument(const QString &filePath)
// 设置编辑器内容
QString content = m_documentManager->getDocumentContent(docId);
editor->setText(content.toUtf8().constData());
const QByteArray contentBytes = content.toUtf8();
editor->setUndoCollection(false);
editor->setText(contentBytes.constData());
editor->setUndoCollection(true);
editor->emptyUndoBuffer();
editor->setSavePoint();
editor->setTabWidth(AppSettings::tabWidth());
editor->setEditorFont(AppSettings::editorFont());
editor->applyTheme(AppSettings::editorDarkTheme());
@@ -123,7 +127,11 @@ bool TabWidget::saveCurrentDocument()
return saveCurrentDocumentAs();
}
return m_documentManager->saveDocument(docId);
const bool saved = m_documentManager->saveDocument(docId);
if (saved) {
editor->setSavePoint();
}
return saved;
}
bool TabWidget::saveCurrentDocumentAs()
@@ -160,6 +168,7 @@ bool TabWidget::saveCurrentDocumentAs()
Scintilla::ILexer5 *lexer = CreateLexer(lexerName.toStdString().c_str());
editor->setLexer(lexer);
}
editor->setSavePoint();
}
return saved;
}
@@ -220,6 +229,10 @@ bool TabWidget::closeTab(int index)
if (!saved) {
return false; // 保存失败,不关闭标签页
}
if (editor) {
editor->setSavePoint();
}
} else if (ret == QMessageBox::Cancel) {
return false; // 取消关闭
}
@@ -321,6 +334,21 @@ int TabWidget::findTabByDocumentId(int docId) const
return m_documentIdToTab.value(docId, -1);
}
int TabWidget::documentIdForEditor(SciEdit *editor) const
{
if (!editor) {
return -1;
}
for (auto it = m_editors.begin(); it != m_editors.end(); ++it) {
if (it.value() == editor) {
return it.key();
}
}
return -1;
}
void TabWidget::onCurrentChanged(int index)
{
SciEdit *editor = editorAt(index);
@@ -357,13 +385,7 @@ void TabWidget::onEditorTextChanged()
}
// 找到对应的文档ID
int docId = -1;
for (auto it = m_editors.begin(); it != m_editors.end(); ++it) {
if (it.value() == editor) {
docId = it.key();
break;
}
}
const int docId = documentIdForEditor(editor);
if (docId != -1) {
QByteArray content = editor->getText(editor->textLength());
@@ -371,6 +393,17 @@ void TabWidget::onEditorTextChanged()
}
}
void TabWidget::onEditorSavePointChanged(bool dirty)
{
SciEdit *editor = qobject_cast<SciEdit*>(sender());
const int docId = documentIdForEditor(editor);
if (docId < 0) {
return;
}
m_documentManager->setDocumentModified(docId, dirty);
}
SciEdit *TabWidget::createEditor()
{
SciEdit *editor = new SciEdit(this);
@@ -399,6 +432,7 @@ void TabWidget::connectEditorSignals(SciEdit *editor)
{
if (editor) {
connect(editor, &SciEdit::textChanged, this, &TabWidget::onEditorTextChanged);
connect(editor, &ScintillaEditBase::savePointChanged, this, &TabWidget::onEditorSavePointChanged);
}
}
@@ -406,5 +440,6 @@ void TabWidget::disconnectEditorSignals(SciEdit *editor)
{
if (editor) {
disconnect(editor, &SciEdit::textChanged, this, &TabWidget::onEditorTextChanged);
disconnect(editor, &ScintillaEditBase::savePointChanged, this, &TabWidget::onEditorSavePointChanged);
}
}

View File

@@ -42,6 +42,7 @@ private slots:
void onDocumentModified(int docId, bool modified);
void onDocumentTitleChanged(int docId, const QString &title);
void onEditorTextChanged();
void onEditorSavePointChanged(bool dirty);
private:
DocumentManager *m_documentManager;
@@ -49,6 +50,7 @@ private:
QHash<int, int> m_documentIdToTab; // document id -> tab index
QHash<int, SciEdit*> m_editors; // document id -> editor
int documentIdForEditor(SciEdit *editor) const;
SciEdit *createEditor();
void updateTabTitle(int tabIndex);
void connectEditorSignals(SciEdit *editor);