2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-08-30 17:10:46 +08:00
|
|
|
#include "editormiscwidget.h"
|
|
|
|
#include "ui_editormiscwidget.h"
|
2021-08-30 18:07:55 +08:00
|
|
|
#include "../settings.h"
|
2022-09-26 12:01:45 +08:00
|
|
|
#include "qt_utils/charsetinfo.h"
|
2022-03-20 18:10:53 +08:00
|
|
|
#include "../mainwindow.h"
|
2021-08-30 17:10:46 +08:00
|
|
|
|
|
|
|
EditorMiscWidget::EditorMiscWidget(const QString& name, const QString& group,
|
|
|
|
QWidget *parent) :
|
|
|
|
SettingsWidget(name,group,parent),
|
|
|
|
ui(new Ui::EditorMiscWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorMiscWidget::~EditorMiscWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorMiscWidget::doLoad()
|
|
|
|
{
|
2021-08-30 18:36:44 +08:00
|
|
|
ui->chkReadonlySystemHeaders->setChecked(pSettings->editor().readOnlySytemHeader());
|
|
|
|
ui->chkLoadLastFiles->setChecked(pSettings->editor().autoLoadLastFiles());
|
2021-08-30 23:05:08 +08:00
|
|
|
if (pSettings->editor().defaultFileCpp()) {
|
|
|
|
ui->rbCppFile->setChecked(true);
|
|
|
|
} else {
|
|
|
|
ui->rbCFile->setChecked(true);
|
|
|
|
}
|
2022-03-12 17:37:53 +08:00
|
|
|
ui->chkAutoDetectFileEncoding->setChecked(pSettings->editor().autoDetectFileEncoding());
|
|
|
|
|
|
|
|
QByteArray defaultEncoding = pSettings->editor().defaultEncoding();
|
|
|
|
if (defaultEncoding == ENCODING_AUTO_DETECT
|
|
|
|
|| defaultEncoding == ENCODING_SYSTEM_DEFAULT
|
2022-05-06 15:23:41 +08:00
|
|
|
|| defaultEncoding == ENCODING_UTF8
|
|
|
|
|| defaultEncoding == ENCODING_UTF8_BOM) {
|
2022-03-12 17:37:53 +08:00
|
|
|
int index =ui->cbEncoding->findData(defaultEncoding);
|
|
|
|
ui->cbEncoding->setCurrentIndex(index);
|
|
|
|
ui->cbEncodingDetail->clear();
|
|
|
|
ui->cbEncodingDetail->setVisible(false);
|
|
|
|
} else {
|
|
|
|
QString language = pCharsetInfoManager->findLanguageByCharsetName(defaultEncoding);
|
|
|
|
ui->cbEncoding->setCurrentText(language);
|
|
|
|
ui->cbEncodingDetail->setVisible(true);
|
|
|
|
ui->cbEncodingDetail->clear();
|
|
|
|
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(language);
|
|
|
|
foreach (const PCharsetInfo& info, infos) {
|
|
|
|
ui->cbEncodingDetail->addItem(info->name);
|
|
|
|
}
|
|
|
|
ui->cbEncodingDetail->setCurrentText(defaultEncoding);
|
|
|
|
}
|
2022-03-20 18:10:53 +08:00
|
|
|
ui->spinMaxUndo->setValue(pSettings->editor().undoLimit());
|
2022-10-11 22:33:09 +08:00
|
|
|
ui->spinMaxUndoMemory->setValue(pSettings->editor().undoMemoryUsage());
|
2022-12-16 01:03:57 +08:00
|
|
|
if (pSettings->editor().removeTrailingSpacesWhenSaved())
|
|
|
|
ui->rbRemoveTrailingSpaces->setChecked(true);
|
|
|
|
else if (pSettings->editor().autoFormatWhenSaved())
|
|
|
|
ui->rbAutoReformat->setChecked(true);
|
|
|
|
else
|
|
|
|
ui->rbNone->setChecked(true);
|
|
|
|
|
2022-11-07 21:44:12 +08:00
|
|
|
ui->chkParseTodos->setChecked(pSettings->editor().parseTodos());
|
2021-08-30 17:10:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorMiscWidget::doSave()
|
|
|
|
{
|
2021-08-30 18:36:44 +08:00
|
|
|
pSettings->editor().setReadOnlySytemHeader(ui->chkReadonlySystemHeaders->isChecked());
|
|
|
|
pSettings->editor().setAutoLoadLastFiles(ui->chkLoadLastFiles->isChecked());
|
|
|
|
pSettings->editor().setDefaultFileCpp(ui->rbCppFile->isChecked());
|
2022-03-12 17:37:53 +08:00
|
|
|
pSettings->editor().setAutoDetectFileEncoding(ui->chkAutoDetectFileEncoding->isChecked());
|
|
|
|
|
|
|
|
if (ui->cbEncodingDetail->isVisible()) {
|
2022-03-12 21:42:32 +08:00
|
|
|
pSettings->editor().setDefaultEncoding(ui->cbEncodingDetail->currentText().toLocal8Bit());
|
2022-03-12 17:37:53 +08:00
|
|
|
} else {
|
|
|
|
pSettings->editor().setDefaultEncoding(ui->cbEncoding->currentData().toByteArray());
|
|
|
|
}
|
2022-03-20 18:10:53 +08:00
|
|
|
pSettings->editor().setUndoLimit(ui->spinMaxUndo->value());
|
2022-10-11 22:33:09 +08:00
|
|
|
pSettings->editor().setUndoMemoryUsage(ui->spinMaxUndoMemory->value());
|
2022-12-16 01:03:57 +08:00
|
|
|
pSettings->editor().setAutoFormatWhenSaved(ui->rbAutoReformat->isChecked());
|
|
|
|
pSettings->editor().setRemoveTrailingSpacesWhenSaved(ui->rbRemoveTrailingSpaces->isChecked());
|
2022-11-07 21:44:12 +08:00
|
|
|
pSettings->editor().setParseTodos(ui->chkParseTodos->isChecked());
|
|
|
|
|
2022-10-25 10:13:51 +08:00
|
|
|
|
2021-08-30 17:10:46 +08:00
|
|
|
pSettings->editor().save();
|
2022-03-20 18:10:53 +08:00
|
|
|
pMainWindow->updateEditorSettings();
|
2021-08-30 17:10:46 +08:00
|
|
|
}
|
2022-03-12 17:37:53 +08:00
|
|
|
|
|
|
|
void EditorMiscWidget::init()
|
|
|
|
{
|
|
|
|
ui->cbEncodingDetail->setVisible(false);
|
|
|
|
ui->cbEncoding->clear();
|
|
|
|
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
|
|
|
|
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
|
2022-05-06 15:23:41 +08:00
|
|
|
ui->cbEncoding->addItem(tr("UTF-8 BOM"),ENCODING_UTF8_BOM);
|
2022-03-12 17:37:53 +08:00
|
|
|
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
|
|
|
|
ui->cbEncoding->addItem(langName,langName);
|
|
|
|
}
|
|
|
|
SettingsWidget::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorMiscWidget::on_cbEncoding_currentTextChanged(const QString &/*arg1*/)
|
|
|
|
{
|
|
|
|
QString userData = ui->cbEncoding->currentData().toString();
|
|
|
|
if (userData == ENCODING_AUTO_DETECT
|
|
|
|
|| userData == ENCODING_SYSTEM_DEFAULT
|
2022-05-06 15:23:41 +08:00
|
|
|
|| userData == ENCODING_UTF8
|
|
|
|
|| userData == ENCODING_UTF8_BOM) {
|
2022-03-12 17:37:53 +08:00
|
|
|
ui->cbEncodingDetail->setVisible(false);
|
|
|
|
ui->cbEncodingDetail->clear();
|
|
|
|
} else {
|
|
|
|
ui->cbEncodingDetail->setVisible(true);
|
|
|
|
ui->cbEncodingDetail->clear();
|
|
|
|
QList<PCharsetInfo> infos = pCharsetInfoManager->findCharsetsByLanguageName(userData);
|
|
|
|
foreach (const PCharsetInfo& info, infos) {
|
|
|
|
ui->cbEncodingDetail->addItem(info->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|