line number, symtax highlight, initial dark theme
This commit is contained in:
@@ -1,11 +1,41 @@
|
||||
#include "tabwidget.h"
|
||||
#include "sciedit.h"
|
||||
#include "documentmanager.h"
|
||||
#include "appsettings.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
||||
#include <ILexer.h>
|
||||
#include <Lexilla.h>
|
||||
|
||||
static QString lexerNameForDocumentLanguage(const QString &language)
|
||||
{
|
||||
if (language == QStringLiteral("C++") ||
|
||||
language == QStringLiteral("C") ||
|
||||
language == QStringLiteral("C/C++ Header")) {
|
||||
return QStringLiteral("cpp");
|
||||
}
|
||||
if (language == QStringLiteral("Python")) {
|
||||
return QStringLiteral("python");
|
||||
}
|
||||
if (language == QStringLiteral("HTML")) {
|
||||
return QStringLiteral("hypertext");
|
||||
}
|
||||
if (language == QStringLiteral("XML")) {
|
||||
return QStringLiteral("xml");
|
||||
}
|
||||
if (language == QStringLiteral("JSON")) {
|
||||
return QStringLiteral("json");
|
||||
}
|
||||
if (language == QStringLiteral("CSS")) {
|
||||
return QStringLiteral("css");
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
TabWidget::TabWidget(DocumentManager *documentManager, QWidget *parent)
|
||||
: QTabWidget(parent)
|
||||
, m_documentManager(documentManager)
|
||||
@@ -73,6 +103,17 @@ int TabWidget::openDocument(const QString &filePath)
|
||||
// 设置编辑器内容
|
||||
QString content = m_documentManager->getDocumentContent(docId);
|
||||
editor->setText(content.toUtf8().constData());
|
||||
editor->setTabWidth(AppSettings::tabWidth());
|
||||
editor->setEditorFont(AppSettings::editorFont());
|
||||
editor->applyTheme(AppSettings::editorDarkTheme());
|
||||
|
||||
const QString lexerName = lexerNameForDocumentLanguage(m_documentManager->getDocumentLanguage(docId));
|
||||
if (lexerName.isEmpty()) {
|
||||
editor->setLexer(nullptr);
|
||||
} else {
|
||||
Scintilla::ILexer5 *lexer = CreateLexer(lexerName.toStdString().c_str());
|
||||
editor->setLexer(lexer);
|
||||
}
|
||||
|
||||
// 重新连接信号
|
||||
connectEditorSignals(editor);
|
||||
@@ -136,7 +177,17 @@ bool TabWidget::saveCurrentDocumentAs()
|
||||
QByteArray content = editor->getText(editor->textLength());
|
||||
m_documentManager->setDocumentContent(docId, QString::fromUtf8(content));
|
||||
|
||||
return m_documentManager->saveDocumentAs(docId, fileName);
|
||||
const bool saved = m_documentManager->saveDocumentAs(docId, fileName);
|
||||
if (saved) {
|
||||
const QString lexerName = lexerNameForDocumentLanguage(m_documentManager->getDocumentLanguage(docId));
|
||||
if (lexerName.isEmpty()) {
|
||||
editor->setLexer(nullptr);
|
||||
} else {
|
||||
Scintilla::ILexer5 *lexer = CreateLexer(lexerName.toStdString().c_str());
|
||||
editor->setLexer(lexer);
|
||||
}
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
void TabWidget::closeCurrentTab()
|
||||
@@ -349,6 +400,9 @@ void TabWidget::onEditorTextChanged()
|
||||
SciEdit *TabWidget::createEditor()
|
||||
{
|
||||
SciEdit *editor = new SciEdit(this);
|
||||
editor->setTabWidth(AppSettings::tabWidth());
|
||||
editor->setEditorFont(AppSettings::editorFont());
|
||||
editor->applyTheme(AppSettings::editorDarkTheme());
|
||||
return editor;
|
||||
}
|
||||
|
||||
@@ -379,4 +433,4 @@ void TabWidget::disconnectEditorSignals(SciEdit *editor)
|
||||
if (editor) {
|
||||
disconnect(editor, &SciEdit::textChanged, this, &TabWidget::onEditorTextChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user