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-09-14 17:33:47 +08:00
|
|
|
#include "projectfileswidget.h"
|
|
|
|
#include "ui_projectfileswidget.h"
|
2021-09-14 23:56:08 +08:00
|
|
|
#include "../mainwindow.h"
|
|
|
|
#include "../systemconsts.h"
|
2022-09-26 14:54:28 +08:00
|
|
|
#include <qt_utils/charsetinfo.h>
|
2021-09-14 17:33:47 +08:00
|
|
|
|
2021-09-14 23:56:08 +08:00
|
|
|
ProjectFilesWidget::ProjectFilesWidget(const QString &name, const QString &group, QWidget *parent) :
|
|
|
|
SettingsWidget(name,group,parent),
|
2021-09-14 17:33:47 +08:00
|
|
|
ui(new Ui::ProjectFilesWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectFilesWidget::~ProjectFilesWidget()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2021-09-14 23:56:08 +08:00
|
|
|
|
|
|
|
void ProjectFilesWidget::doLoad()
|
|
|
|
{
|
|
|
|
std::shared_ptr<Project> project = pMainWindow->project();
|
|
|
|
if (!project)
|
|
|
|
return;
|
2021-09-15 07:53:35 +08:00
|
|
|
copyUnits();
|
2022-10-10 18:05:18 +08:00
|
|
|
QItemSelectionModel *m=ui->treeProject->selectionModel();
|
2021-09-14 23:56:08 +08:00
|
|
|
ui->treeProject->setModel(project->model());
|
2022-10-10 18:05:18 +08:00
|
|
|
delete m;
|
2021-09-14 23:56:08 +08:00
|
|
|
ui->treeProject->expandAll();
|
|
|
|
ui->grpFileOptions->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectFilesWidget::doSave()
|
|
|
|
{
|
|
|
|
for (int i=0;i<mUnits.count();i++) {
|
|
|
|
PProjectUnit unitCopy = mUnits[i];
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectUnit unit = pMainWindow->project()->findUnit(unitCopy->fileName());
|
2021-09-14 23:56:08 +08:00
|
|
|
unit->setPriority(unitCopy->priority());
|
|
|
|
unit->setCompile(unitCopy->compile());
|
|
|
|
unit->setLink(unitCopy->link());
|
|
|
|
unit->setCompileCpp(unitCopy->compileCpp());
|
|
|
|
unit->setOverrideBuildCmd(unitCopy->overrideBuildCmd());
|
|
|
|
unit->setBuildCmd(unitCopy->buildCmd());
|
|
|
|
unit->setEncoding(unitCopy->encoding());
|
|
|
|
}
|
|
|
|
pMainWindow->project()->saveUnits();
|
2021-09-15 07:53:35 +08:00
|
|
|
copyUnits();
|
2021-09-15 12:19:09 +08:00
|
|
|
ui->treeProject->expandAll();
|
2021-09-15 07:53:35 +08:00
|
|
|
ui->treeProject->clicked(ui->treeProject->currentIndex());
|
2021-09-14 23:56:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
PProjectUnit ProjectFilesWidget::currentUnit()
|
|
|
|
{
|
|
|
|
QModelIndex index = ui->treeProject->currentIndex();
|
|
|
|
if (!index.isValid())
|
|
|
|
return PProjectUnit();
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* node = static_cast<ProjectModelNode*>(index.internalPointer());
|
2021-09-14 23:56:08 +08:00
|
|
|
if (!node)
|
|
|
|
return PProjectUnit();
|
2022-10-08 23:30:30 +08:00
|
|
|
if (!node->isUnit)
|
|
|
|
return PProjectUnit();
|
|
|
|
PProjectUnit unit=node->pUnit.lock();
|
|
|
|
if (unit) {
|
|
|
|
foreach (PProjectUnit tmpUnit, mUnits) {
|
|
|
|
if (tmpUnit->fileName() == unit->fileName())
|
|
|
|
return tmpUnit;
|
2022-10-01 08:54:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PProjectUnit();
|
2021-09-14 23:56:08 +08:00
|
|
|
}
|
|
|
|
|
2021-09-15 07:53:35 +08:00
|
|
|
void ProjectFilesWidget::copyUnits()
|
|
|
|
{
|
|
|
|
std::shared_ptr<Project> project = pMainWindow->project();
|
|
|
|
if (!project)
|
|
|
|
return;
|
|
|
|
mUnits.clear();
|
2022-10-01 08:54:44 +08:00
|
|
|
foreach (const PProjectUnit& unit, project->unitList()) {
|
2021-09-15 07:53:35 +08:00
|
|
|
PProjectUnit unitCopy = std::make_shared<ProjectUnit>(project.get());
|
|
|
|
unitCopy->setPriority(unit->priority());
|
|
|
|
unitCopy->setCompile(unit->compile());
|
|
|
|
unitCopy->setLink(unit->link());
|
|
|
|
unitCopy->setCompileCpp(unit->compileCpp());
|
|
|
|
unitCopy->setOverrideBuildCmd(unit->overrideBuildCmd());
|
|
|
|
unitCopy->setBuildCmd(unit->buildCmd());
|
|
|
|
unitCopy->setEncoding(unit->encoding());
|
2022-11-06 12:38:53 +08:00
|
|
|
unitCopy->setFileName(unit->fileName());
|
2021-09-15 07:53:35 +08:00
|
|
|
mUnits.append(unitCopy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-15 12:19:09 +08:00
|
|
|
void ProjectFilesWidget::disableFileOptions()
|
|
|
|
{
|
|
|
|
ui->grpFileOptions->setEnabled(false);
|
|
|
|
ui->spinPriority->setValue(0);
|
|
|
|
ui->chkCompile->setChecked(false);
|
|
|
|
ui->chkLink->setChecked(false);
|
|
|
|
ui->chkCompileAsCPP->setChecked(false);
|
|
|
|
ui->chkOverrideBuildCommand->setChecked(false);
|
|
|
|
ui->txtBuildCommand->setPlainText("");
|
|
|
|
}
|
|
|
|
|
2022-01-24 01:08:47 +08:00
|
|
|
void ProjectFilesWidget::loadUnitEncoding(PProjectUnit unit)
|
|
|
|
{
|
2023-01-24 11:31:30 +08:00
|
|
|
if (unit->encoding() == ENCODING_PROJECT
|
2022-01-24 01:08:47 +08:00
|
|
|
|| unit->encoding() == ENCODING_SYSTEM_DEFAULT
|
|
|
|
|| unit->encoding() == ENCODING_UTF8) {
|
2022-03-12 17:37:53 +08:00
|
|
|
int index =ui->cbEncoding->findData(unit->encoding());
|
|
|
|
ui->cbEncoding->setCurrentIndex(index);
|
2022-01-24 01:08:47 +08:00
|
|
|
ui->cbEncodingDetail->clear();
|
|
|
|
ui->cbEncodingDetail->setVisible(false);
|
|
|
|
} else {
|
|
|
|
QString encoding = unit->encoding();
|
|
|
|
QString language = pCharsetInfoManager->findLanguageByCharsetName(encoding);
|
|
|
|
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(encoding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-14 23:56:08 +08:00
|
|
|
void ProjectFilesWidget::on_treeProject_doubleClicked(const QModelIndex &index)
|
|
|
|
{
|
2021-09-15 12:19:09 +08:00
|
|
|
if (!index.isValid()) {
|
|
|
|
disableFileOptions();
|
2021-09-14 23:56:08 +08:00
|
|
|
return ;
|
2021-09-15 12:19:09 +08:00
|
|
|
}
|
2022-02-08 00:24:08 +08:00
|
|
|
ProjectModelNode* node = static_cast<ProjectModelNode*>(index.internalPointer());
|
2021-09-15 12:19:09 +08:00
|
|
|
if (!node) {
|
|
|
|
disableFileOptions();
|
2021-09-14 23:56:08 +08:00
|
|
|
return;
|
2021-09-15 12:19:09 +08:00
|
|
|
}
|
2022-10-08 23:30:30 +08:00
|
|
|
PProjectUnit unit = node->pUnit.lock();
|
|
|
|
if (unit) {
|
2021-09-14 23:56:08 +08:00
|
|
|
ui->grpFileOptions->setEnabled(true);
|
|
|
|
ui->spinPriority->setValue(unit->priority());
|
|
|
|
ui->chkCompile->setChecked(unit->compile());
|
|
|
|
ui->chkLink->setChecked(unit->link());
|
|
|
|
ui->chkCompileAsCPP->setChecked(unit->compileCpp());
|
|
|
|
ui->chkOverrideBuildCommand->setChecked(unit->overrideBuildCmd());
|
|
|
|
ui->txtBuildCommand->setPlainText(unit->buildCmd());
|
|
|
|
ui->txtBuildCommand->setEnabled(ui->chkOverrideBuildCommand->isChecked());
|
2022-01-24 01:08:47 +08:00
|
|
|
loadUnitEncoding(unit);
|
2021-09-14 23:56:08 +08:00
|
|
|
} else {
|
2021-09-15 12:19:09 +08:00
|
|
|
disableFileOptions();
|
2021-09-14 23:56:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_spinPriority_valueChanged(int)
|
|
|
|
{
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
|
|
|
unit->setPriority(ui->spinPriority->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_chkCompile_stateChanged(int)
|
|
|
|
{
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
|
|
|
unit->setCompile(ui->chkCompile->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_chkLink_stateChanged(int)
|
|
|
|
{
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
|
|
|
unit->setLink(ui->chkLink->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_chkCompileAsCPP_stateChanged(int )
|
|
|
|
{
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
|
|
|
unit->setCompileCpp(ui->chkCompileAsCPP->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_chkOverrideBuildCommand_stateChanged(int )
|
|
|
|
{
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
|
|
|
unit->setOverrideBuildCmd(ui->chkOverrideBuildCommand->isChecked());
|
|
|
|
ui->txtBuildCommand->setEnabled(ui->chkOverrideBuildCommand->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_txtBuildCommand_textChanged()
|
|
|
|
{
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
|
|
|
unit->setBuildCmd(ui->txtBuildCommand->toPlainText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_cbEncoding_currentTextChanged(const QString &)
|
|
|
|
{
|
2021-09-29 19:03:22 +08:00
|
|
|
QString userData = ui->cbEncoding->currentData().toString();
|
2023-01-24 11:31:30 +08:00
|
|
|
if (userData == ENCODING_PROJECT
|
2021-09-29 19:03:22 +08:00
|
|
|
|| userData == ENCODING_SYSTEM_DEFAULT
|
|
|
|
|| userData == ENCODING_UTF8) {
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
2022-01-24 01:08:47 +08:00
|
|
|
unit->setEncoding(userData.toUtf8());
|
2021-09-29 19:03:22 +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);
|
|
|
|
}
|
|
|
|
}
|
2021-09-14 23:56:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProjectFilesWidget::on_treeProject_clicked(const QModelIndex &index)
|
|
|
|
{
|
|
|
|
on_treeProject_doubleClicked(index);
|
|
|
|
}
|
|
|
|
|
2021-09-15 11:23:42 +08:00
|
|
|
void ProjectFilesWidget::init()
|
|
|
|
{
|
|
|
|
ui->spinPriority->setMinimum(0);
|
|
|
|
ui->spinPriority->setMaximum(9999);
|
2021-09-29 19:03:22 +08:00
|
|
|
ui->cbEncodingDetail->setVisible(false);
|
2021-09-15 11:23:42 +08:00
|
|
|
ui->cbEncoding->clear();
|
2023-03-07 17:18:35 +08:00
|
|
|
if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) {
|
|
|
|
ui->cbEncoding->addItem(tr("Project(%1)").arg(tr("ANSI"),ENCODING_PROJECT));
|
|
|
|
} else {
|
|
|
|
ui->cbEncoding->addItem(tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding)),ENCODING_PROJECT);
|
|
|
|
}
|
2021-09-29 19:03:22 +08:00
|
|
|
ui->cbEncoding->addItem(tr("ANSI"),ENCODING_SYSTEM_DEFAULT);
|
|
|
|
ui->cbEncoding->addItem(tr("UTF-8"),ENCODING_UTF8);
|
|
|
|
foreach (const QString& langName, pCharsetInfoManager->languageNames()) {
|
|
|
|
ui->cbEncoding->addItem(langName,langName);
|
|
|
|
}
|
2021-09-15 12:19:09 +08:00
|
|
|
SettingsWidget::init();
|
2021-09-15 11:23:42 +08:00
|
|
|
}
|
|
|
|
|
2023-03-07 17:18:35 +08:00
|
|
|
void ProjectFilesWidget::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
if (ui->cbEncoding->count()>0) {
|
|
|
|
if (pMainWindow->project()->options().encoding==ENCODING_SYSTEM_DEFAULT) {
|
|
|
|
ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(tr("ANSI")));
|
|
|
|
} else {
|
|
|
|
ui->cbEncoding->setItemText(0,tr("Project(%1)").arg(QString(pMainWindow->project()->options().encoding)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 19:03:22 +08:00
|
|
|
|
2021-10-20 18:05:43 +08:00
|
|
|
void ProjectFilesWidget::on_cbEncodingDetail_currentTextChanged(const QString &)
|
2021-09-29 19:03:22 +08:00
|
|
|
{
|
|
|
|
PProjectUnit unit = currentUnit();
|
|
|
|
if(!unit)
|
|
|
|
return;
|
2023-01-25 10:28:55 +08:00
|
|
|
if (ui->cbEncodingDetail->currentText().isEmpty())
|
|
|
|
return;
|
2022-01-24 01:08:47 +08:00
|
|
|
unit->setEncoding(ui->cbEncodingDetail->currentText().toUtf8());
|
2021-09-29 19:03:22 +08:00
|
|
|
}
|
|
|
|
|