i18n: update ts files
This commit is contained in:
@@ -194,13 +194,7 @@ void DocumentManager::setDocumentContent(int docId, const QString &content)
|
|||||||
{
|
{
|
||||||
if (m_documents.contains(docId)) {
|
if (m_documents.contains(docId)) {
|
||||||
DocumentInfo &doc = m_documents[docId];
|
DocumentInfo &doc = m_documents[docId];
|
||||||
if (doc.content != content) {
|
doc.content = content;
|
||||||
doc.content = content;
|
|
||||||
if (!doc.modified) {
|
|
||||||
doc.modified = true;
|
|
||||||
emit documentModified(docId, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ TabWidget::TabWidget(DocumentManager *documentManager, QWidget *parent)
|
|||||||
this, &TabWidget::onDocumentModified);
|
this, &TabWidget::onDocumentModified);
|
||||||
connect(m_documentManager, &DocumentManager::documentTitleChanged,
|
connect(m_documentManager, &DocumentManager::documentTitleChanged,
|
||||||
this, &TabWidget::onDocumentTitleChanged);
|
this, &TabWidget::onDocumentTitleChanged);
|
||||||
|
|
||||||
// 创建第一个文档
|
|
||||||
newDocument();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TabWidget::~TabWidget()
|
TabWidget::~TabWidget()
|
||||||
@@ -44,6 +41,8 @@ int TabWidget::newDocument()
|
|||||||
}
|
}
|
||||||
|
|
||||||
SciEdit *editor = createEditor();
|
SciEdit *editor = createEditor();
|
||||||
|
editor->emptyUndoBuffer();
|
||||||
|
editor->setSavePoint();
|
||||||
m_editors[docId] = editor;
|
m_editors[docId] = editor;
|
||||||
|
|
||||||
// 连接信号
|
// 连接信号
|
||||||
@@ -76,7 +75,12 @@ int TabWidget::openDocument(const QString &filePath)
|
|||||||
|
|
||||||
// 设置编辑器内容
|
// 设置编辑器内容
|
||||||
QString content = m_documentManager->getDocumentContent(docId);
|
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->setTabWidth(AppSettings::tabWidth());
|
||||||
editor->setEditorFont(AppSettings::editorFont());
|
editor->setEditorFont(AppSettings::editorFont());
|
||||||
editor->applyTheme(AppSettings::editorDarkTheme());
|
editor->applyTheme(AppSettings::editorDarkTheme());
|
||||||
@@ -123,7 +127,11 @@ bool TabWidget::saveCurrentDocument()
|
|||||||
return saveCurrentDocumentAs();
|
return saveCurrentDocumentAs();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_documentManager->saveDocument(docId);
|
const bool saved = m_documentManager->saveDocument(docId);
|
||||||
|
if (saved) {
|
||||||
|
editor->setSavePoint();
|
||||||
|
}
|
||||||
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TabWidget::saveCurrentDocumentAs()
|
bool TabWidget::saveCurrentDocumentAs()
|
||||||
@@ -160,6 +168,7 @@ bool TabWidget::saveCurrentDocumentAs()
|
|||||||
Scintilla::ILexer5 *lexer = CreateLexer(lexerName.toStdString().c_str());
|
Scintilla::ILexer5 *lexer = CreateLexer(lexerName.toStdString().c_str());
|
||||||
editor->setLexer(lexer);
|
editor->setLexer(lexer);
|
||||||
}
|
}
|
||||||
|
editor->setSavePoint();
|
||||||
}
|
}
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
@@ -220,6 +229,10 @@ bool TabWidget::closeTab(int index)
|
|||||||
if (!saved) {
|
if (!saved) {
|
||||||
return false; // 保存失败,不关闭标签页
|
return false; // 保存失败,不关闭标签页
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (editor) {
|
||||||
|
editor->setSavePoint();
|
||||||
|
}
|
||||||
} else if (ret == QMessageBox::Cancel) {
|
} else if (ret == QMessageBox::Cancel) {
|
||||||
return false; // 取消关闭
|
return false; // 取消关闭
|
||||||
}
|
}
|
||||||
@@ -321,6 +334,21 @@ int TabWidget::findTabByDocumentId(int docId) const
|
|||||||
return m_documentIdToTab.value(docId, -1);
|
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)
|
void TabWidget::onCurrentChanged(int index)
|
||||||
{
|
{
|
||||||
SciEdit *editor = editorAt(index);
|
SciEdit *editor = editorAt(index);
|
||||||
@@ -357,13 +385,7 @@ void TabWidget::onEditorTextChanged()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 找到对应的文档ID
|
// 找到对应的文档ID
|
||||||
int docId = -1;
|
const int docId = documentIdForEditor(editor);
|
||||||
for (auto it = m_editors.begin(); it != m_editors.end(); ++it) {
|
|
||||||
if (it.value() == editor) {
|
|
||||||
docId = it.key();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (docId != -1) {
|
if (docId != -1) {
|
||||||
QByteArray content = editor->getText(editor->textLength());
|
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 *TabWidget::createEditor()
|
||||||
{
|
{
|
||||||
SciEdit *editor = new SciEdit(this);
|
SciEdit *editor = new SciEdit(this);
|
||||||
@@ -399,6 +432,7 @@ void TabWidget::connectEditorSignals(SciEdit *editor)
|
|||||||
{
|
{
|
||||||
if (editor) {
|
if (editor) {
|
||||||
connect(editor, &SciEdit::textChanged, this, &TabWidget::onEditorTextChanged);
|
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) {
|
if (editor) {
|
||||||
disconnect(editor, &SciEdit::textChanged, this, &TabWidget::onEditorTextChanged);
|
disconnect(editor, &SciEdit::textChanged, this, &TabWidget::onEditorTextChanged);
|
||||||
|
disconnect(editor, &ScintillaEditBase::savePointChanged, this, &TabWidget::onEditorSavePointChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ private slots:
|
|||||||
void onDocumentModified(int docId, bool modified);
|
void onDocumentModified(int docId, bool modified);
|
||||||
void onDocumentTitleChanged(int docId, const QString &title);
|
void onDocumentTitleChanged(int docId, const QString &title);
|
||||||
void onEditorTextChanged();
|
void onEditorTextChanged();
|
||||||
|
void onEditorSavePointChanged(bool dirty);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DocumentManager *m_documentManager;
|
DocumentManager *m_documentManager;
|
||||||
@@ -49,6 +50,7 @@ private:
|
|||||||
QHash<int, int> m_documentIdToTab; // document id -> tab index
|
QHash<int, int> m_documentIdToTab; // document id -> tab index
|
||||||
QHash<int, SciEdit*> m_editors; // document id -> editor
|
QHash<int, SciEdit*> m_editors; // document id -> editor
|
||||||
|
|
||||||
|
int documentIdForEditor(SciEdit *editor) const;
|
||||||
SciEdit *createEditor();
|
SciEdit *createEditor();
|
||||||
void updateTabTitle(int tabIndex);
|
void updateTabTitle(int tabIndex);
|
||||||
void connectEditorSignals(SciEdit *editor);
|
void connectEditorSignals(SciEdit *editor);
|
||||||
|
|||||||
Reference in New Issue
Block a user