* work save

This commit is contained in:
royqh1979 2021-06-20 09:27:37 +08:00
parent 6d7bfcd62a
commit 9390545641
18 changed files with 294 additions and 157 deletions

View File

@ -113,7 +113,8 @@ RESOURCES += \
themes/dark/dark.qrc \
themes/light/light.qrc \
themes/dracula/dracula.qrc \
icons.qrc
icons.qrc \
translations.qrc
#win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../QScintilla/src/release/ -lqscintilla2_qt5d
#else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../QScintilla/src/debug/ -lqscintilla2_qt5d

Binary file not shown.

View File

@ -1011,7 +1011,7 @@ Are you really want to continue?</source>
<message>
<location filename="colorscheme.cpp" line="52"/>
<source>Can&apos;t parse json file &apos;%1&apos; at offset %2! Error Code: %3</source>
<translation>JSON文件&quot;%1&quot;&quot;%2&quot;</translation>
<translation type="unfinished">JSON文件&quot;%1&quot;&quot;%2&quot;%3</translation>
</message>
<message>
<location filename="colorscheme.cpp" line="56"/>

View File

@ -43,18 +43,19 @@ PColorScheme ColorScheme::load(const QString &filename)
{
QFile file(filename);
if (!file.open(QFile::ReadOnly)) {
throw new FileError(QObject::tr("Can't open file '%1' for read").arg(file.fileName()));
qDebug()<<QObject::tr("Can't open file '%1' for read").arg(file.fileName());
return PColorScheme();
}
QByteArray content = file.readAll();
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(content,&error);
if (error.error!=QJsonParseError::NoError) {
throw new FileError(QObject::tr("Can't parse json file '%1' at offset %2! Error Code: %3")
.arg(file.fileName()).arg(error.offset).arg(error.error));
qDebug()<<QObject::tr("Can't parse json file '%1' at offset %2! Error Code: %3")
.arg(file.fileName()).arg(error.offset).arg(error.error);
}
if (!doc.isObject()) {
throw new FileError(QObject::tr("Can't parse json file '%1' is not a color schema config file!")
.arg(file.fileName()));
qDebug()<<QObject::tr("Can't parse json file '%1' is not a color schema config file!")
.arg(file.fileName());
}
return ColorScheme::fromJson(doc.object());
}

View File

@ -188,8 +188,8 @@ const QByteArray& Editor::encodingOption() const noexcept{
}
void Editor::setEncodingOption(const QByteArray& encoding) noexcept{
mEncodingOption = encoding;
if (!this->isNew())
this->loadFile();
if (!isNew())
loadFile();
else
pMainWindow->updateForEncodingInfo();
}

View File

@ -52,48 +52,36 @@ int main(int argc, char *argv[])
qRegisterMetaType<PCompileIssue>("PCompileIssue");
qRegisterMetaType<PCompileIssue>("PCompileIssue&");
//load translations
QTranslator trans;
trans.load(("RedPandaIDE_zh_CN"));
app.installTranslator(&trans);
try {
SystemConsts systemConsts;
pSystemConsts = &systemConsts;
SystemConsts systemConsts;
pSystemConsts = &systemConsts;
pSettings = createAppSettings();
if (pSettings == nullptr) {
return -1;
//load settings
pSettings = createAppSettings();
if (pSettings == nullptr) {
return -1;
}
auto settings = std::unique_ptr<Settings>(pSettings);
settings->compilerSets().loadSets();
settings->editor().load();
settings->environment().load();
pColorManager = new ColorManager();
//load translations
QTranslator trans;
trans.load("RedPandaIDE_"+pSettings->environment().language(),":/translations");
app.installTranslator(&trans);
MainWindow mainWindow;
pMainWindow = &mainWindow;
mainWindow.show();
int retCode = app.exec();
// save settings
// settings->compilerSets().saveSets();
return retCode;
} catch (BaseError e) {
QMessageBox::information(nullptr,QApplication::tr("Error"),e.reason());
}
auto settings = std::unique_ptr<Settings>(pSettings);
settings->compilerSets().loadSets();
settings->editor().load();
settings->environment().load();
pColorManager = new ColorManager();
//settings->compilerSets().addSets("e:/workspace/contributes/Dev-CPP/MinGW32_GCC92");
// settings->compilerSets().findSets();
// settings->compilerSets().saveSets();
// qDebug() << settings->compilerSets().defaultSet()->binDirs();
// settings->compilerSets().loadSets();
// qDebug() << settings->compilerSets().defaultSet()->defines();
// qDebug() << settings->compilerSets().defaultSet()->CCompiler();
// qDebug()<<settings->compilerSets().size();
// qDebug()<<settings->compilerSets().list().at(0)->binDirs();
// load theme
// QFile cssFile("dracula.css");
// if (cssFile.open(QFile::ReadOnly)) {
// QString qss = QLatin1String(cssFile.readAll());
// app.setStyleSheet(qss);
// }
MainWindow mainWindow;
pMainWindow = &mainWindow;
mainWindow.show();
int retCode = app.exec();
// save settings
// settings->compilerSets().saveSets();
return retCode;
}

View File

@ -9,6 +9,7 @@
#include <QComboBox>
#include <QFileDialog>
#include <QLabel>
#include <QTranslator>
#include "settingsdialog/settingsdialog.h"
#include "compiler/compilermanager.h"
@ -161,7 +162,9 @@ void MainWindow::applySettings()
changeTheme(pSettings->environment().theme());
QFont font(pSettings->environment().interfaceFont(),
pSettings->environment().interfaceFontSize());
dynamic_cast<QApplication*>(QApplication::instance())->setFont(font);
font.setStyleStrategy(QFont::PreferAntialias);
QApplication * app = dynamic_cast<QApplication*>(QApplication::instance());
app->setFont(font);
}
void MainWindow::updateStatusbarForLineCol()
@ -243,9 +246,13 @@ void MainWindow::updateCompilerSet()
void MainWindow::on_actionNew_triggered()
{
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
editor->activate();
updateForEncodingInfo();
try {
Editor * editor=mEditorList->newEditor("",ENCODING_AUTO_DETECT,false,true);
editor->activate();
updateForEncodingInfo();
} catch (FileError e) {
QMessageBox::information(this,tr("Error"),e.reason());
}
}
void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
@ -256,11 +263,15 @@ void MainWindow::on_EditorTabsLeft_tabCloseRequested(int index)
void MainWindow::on_actionOpen_triggered()
{
QString selectedFileFilter = pSystemConsts->defaultFileFilter();
QStringList files = QFileDialog::getOpenFileNames(pMainWindow,
tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
&selectedFileFilter);
openFiles(files);
try {
QString selectedFileFilter = pSystemConsts->defaultFileFilter();
QStringList files = QFileDialog::getOpenFileNames(pMainWindow,
tr("Open"), QString(), pSystemConsts->defaultFileFilters().join(";;"),
&selectedFileFilter);
openFiles(files);
} catch (FileError e) {
QMessageBox::information(this,tr("Error"),e.reason());
}
}
void MainWindow::closeEvent(QCloseEvent *event) {
@ -278,15 +289,23 @@ void MainWindow::on_actionSave_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL) {
editor->save();
}
try {
editor->save();
} catch(FileError e) {
QMessageBox::information(this,tr("Error"),e.reason());
}
}
}
void MainWindow::on_actionSaveAs_triggered()
{
Editor * editor = mEditorList->getEditor();
if (editor != NULL) {
editor->saveAs();
try {
editor->saveAs();
} catch(FileError e) {
QMessageBox::information(this,tr("Error"),e.reason());
}
}
}
@ -440,7 +459,11 @@ void MainWindow::on_actionEncode_in_ANSI_triggered()
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
editor->setEncodingOption(ENCODING_SYSTEM_DEFAULT);
try {
editor->setEncodingOption(ENCODING_SYSTEM_DEFAULT);
} catch(FileError e) {
QMessageBox::information(this,tr("Error"),e.reason());
}
}
void MainWindow::on_actionEncode_in_UTF_8_triggered()
@ -448,7 +471,11 @@ void MainWindow::on_actionEncode_in_UTF_8_triggered()
Editor * editor = mEditorList->getEditor();
if (editor == nullptr)
return;
editor->setEncodingOption(ENCODING_UTF8);
try {
editor->setEncodingOption(ENCODING_UTF8);
} catch(FileError e) {
QMessageBox::information(this,tr("Error"),e.reason());
}
}
void MainWindow::on_actionAuto_Detect_triggered()

View File

@ -456,8 +456,6 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB
{
if (!file.open(QFile::ReadOnly))
throw FileError(tr("Can't open file '%1' for read!").arg(file.fileName()));
// if (!file.canReadLine())
// throw FileError(tr("Can't read from file '%1'!").arg(file.fileName()));
beginUpdate();
auto action = finally([this]{
endUpdate();

View File

@ -846,8 +846,10 @@ void SynEditTextPainter::PaintLines()
break;
sToken = edit->mHighlighter->getToken();
// Maybe should also test whether GetTokenPos changed...
if (sToken.isEmpty())
if (sToken.isEmpty()) {
qDebug()<<SynEdit::tr("The highlighter seems to be in an infinite loop");
throw BaseError(SynEdit::tr("The highlighter seems to be in an infinite loop"));
}
}
nTokenColumnsBefore = edit->charToColumn(vLine,edit->mHighlighter->getTokenPos()+1)-1;
nTokenColumnLen = edit->stringColumns(sToken, nTokenColumnsBefore);

View File

@ -1819,7 +1819,8 @@ void Settings::Environment::doLoad()
//Appearence
mTheme = stringValue("theme","default");
mInterfaceFont = stringValue("interface font","Segoe UI");
mInterfaceFontSize = intValue("interface font size",11);
mInterfaceFontSize = intValue("interface font size",10);
mLanguage = stringValue("language", QLocale::system().name());
}
int Settings::Environment::interfaceFontSize() const
@ -1832,12 +1833,23 @@ void Settings::Environment::setInterfaceFontSize(int interfaceFontSize)
mInterfaceFontSize = interfaceFontSize;
}
QString Settings::Environment::language() const
{
return mLanguage;
}
void Settings::Environment::setLanguage(const QString &language)
{
mLanguage = language;
}
void Settings::Environment::doSave()
{
//Appearence
saveValue("theme", mTheme);
saveValue("interface font", mInterfaceFont);
saveValue("interface font size", mInterfaceFontSize);
saveValue("language", mLanguage);
}
QString Settings::Environment::interfaceFont() const

View File

@ -289,12 +289,16 @@ public:
int interfaceFontSize() const;
void setInterfaceFontSize(int interfaceFontSize);
QString language() const;
void setLanguage(const QString &language);
private:
//Appearence
QString mTheme;
QString mInterfaceFont;
int mInterfaceFontSize;
QString mLanguage;
// _Base interface
protected:
void doSave() override;

View File

@ -89,6 +89,11 @@ PColorSchemeItem EditorColorSchemeWidget::getCurrentItem()
return pColorManager->getItem(ui->cbScheme->currentText(), name);
}
PColorScheme EditorColorSchemeWidget::getCurrentScheme()
{
return pColorManager->get(ui->cbScheme->currentText());
}
EditorColorSchemeWidget::~EditorColorSchemeWidget()
{
delete ui;
@ -164,6 +169,10 @@ void EditorColorSchemeWidget::onForegroundChanged()
} else {
item->setForeground(QColor());
}
PColorScheme scheme = getCurrentScheme();
if (scheme) {
scheme->setCustomed(true);
}
}
void EditorColorSchemeWidget::onBackgroundChanged()
@ -176,7 +185,10 @@ void EditorColorSchemeWidget::onBackgroundChanged()
} else {
item->setBackground(QColor());
}
PColorScheme scheme = getCurrentScheme();
if (scheme) {
scheme->setCustomed(true);
}
}
void EditorColorSchemeWidget::onFontStyleChanged()
@ -188,6 +200,10 @@ void EditorColorSchemeWidget::onFontStyleChanged()
item->setItalic(ui->cbItalic->isChecked());
item->setStrikeout(ui->cbStrikeout->isChecked());
item->setUnderlined(ui->cbUnderlined->isChecked());
PColorScheme scheme = getCurrentScheme();
if (scheme) {
scheme->setCustomed(true);
}
}
void EditorColorSchemeWidget::doLoad()

View File

@ -31,6 +31,7 @@ public slots:
private:
void addDefine(const QString& name, PColorSchemeItemDefine define);
PColorSchemeItem getCurrentItem();
PColorScheme getCurrentScheme();
private:
Ui::EditorColorSchemeWidget *ui;

View File

@ -87,16 +87,28 @@
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="widget_3" native="true">
<property name="enabled">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
@ -131,6 +143,18 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QCheckBox" name="cbBackground">
<property name="text">
@ -145,19 +169,6 @@
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="ColorEdit" name="colorForeground">
<property name="frameShape">
@ -168,18 +179,15 @@
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="0" column="2">
<widget class="ColorEdit" name="colorBackground">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</spacer>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QGroupBox" name="grpFontStyles">
@ -215,18 +223,34 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="0" column="2">
<widget class="ColorEdit" name="colorBackground">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
</layout>
</widget>

View File

@ -19,6 +19,8 @@ EnvironmentAppearenceWidget::EnvironmentAppearenceWidget(const QString& name, co
for (QString name:factory.keys()) {
ui->cbTheme->addItem(name);
}
ui->cbLanguage->addItem("English","en");
ui->cbLanguage->addItem("简体中文","zh_CN");
}
EnvironmentAppearenceWidget::~EnvironmentAppearenceWidget()
@ -31,6 +33,13 @@ void EnvironmentAppearenceWidget::doLoad()
ui->cbTheme->setCurrentText(pSettings->environment().theme());
ui->cbFont->setCurrentFont(QFont(pSettings->environment().interfaceFont()));
ui->spinFontSize->setValue(pSettings->environment().interfaceFontSize());
for (int i=0;i<ui->cbLanguage->count();i++) {
if (ui->cbLanguage->itemData(i) == pSettings->environment().language()) {
ui->cbLanguage->setCurrentIndex(i);
break;
}
}
}
void EnvironmentAppearenceWidget::doSave()
@ -38,6 +47,7 @@ void EnvironmentAppearenceWidget::doSave()
pSettings->environment().setTheme(ui->cbTheme->currentText());
pSettings->environment().setInterfaceFont(ui->cbFont->currentFont().family());
pSettings->environment().setInterfaceFontSize(ui->spinFontSize->value());
pSettings->environment().setLanguage(ui->cbLanguage->currentData().toString());
pSettings->environment().save();
pMainWindow->applySettings();

View File

@ -14,40 +14,26 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFont"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Font Size:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -62,27 +48,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Font Size:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<item row="0" column="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
@ -116,7 +82,41 @@
</layout>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="2">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFont"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="2">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
@ -150,6 +150,54 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="cbLanguage"/>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>*Needs restart</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>

View File

@ -104,7 +104,7 @@
<x>0</x>
<y>0</y>
<width>683</width>
<height>535</height>
<height>533</height>
</rect>
</property>
</widget>
@ -119,7 +119,7 @@
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/translations">
<file>RedPandaIDE_zh_CN.qm</file>
</qresource>
</RCC>