- enhancement: create template

This commit is contained in:
Roy Qu 2022-08-07 21:41:57 +08:00
parent 810520c2cd
commit 92d7370903
15 changed files with 2724 additions and 2031 deletions

View File

@ -3,6 +3,7 @@ Red Panda C++ Version 1.2
- enhancement: Portuguese Translation ( Thanks for crcpucmg@github) - enhancement: Portuguese Translation ( Thanks for crcpucmg@github)
- fix: files in network drive is opened in readonly mode - fix: files in network drive is opened in readonly mode
- change: organization structure of templates - change: organization structure of templates
- enhancement: create template
Red Panda C++ Version 1.1.6 Red Panda C++ Version 1.1.6

View File

@ -191,6 +191,7 @@ SOURCES += \
widgets/newheaderdialog.cpp \ widgets/newheaderdialog.cpp \
widgets/newprojectdialog.cpp \ widgets/newprojectdialog.cpp \
widgets/newprojectunitdialog.cpp \ widgets/newprojectunitdialog.cpp \
widgets/newtemplatedialog.cpp \
widgets/ojproblempropertywidget.cpp \ widgets/ojproblempropertywidget.cpp \
widgets/ojproblemsetmodel.cpp \ widgets/ojproblemsetmodel.cpp \
widgets/qconsole.cpp \ widgets/qconsole.cpp \
@ -341,6 +342,7 @@ HEADERS += \
widgets/newheaderdialog.h \ widgets/newheaderdialog.h \
widgets/newprojectdialog.h \ widgets/newprojectdialog.h \
widgets/newprojectunitdialog.h \ widgets/newprojectunitdialog.h \
widgets/newtemplatedialog.h \
widgets/ojproblempropertywidget.h \ widgets/ojproblempropertywidget.h \
widgets/ojproblemsetmodel.h \ widgets/ojproblemsetmodel.h \
widgets/qconsole.h \ widgets/qconsole.h \
@ -406,6 +408,7 @@ FORMS += \
widgets/newheaderdialog.ui \ widgets/newheaderdialog.ui \
widgets/newprojectdialog.ui \ widgets/newprojectdialog.ui \
widgets/newprojectunitdialog.ui \ widgets/newprojectunitdialog.ui \
widgets/newtemplatedialog.ui \
widgets/ojproblempropertywidget.ui \ widgets/ojproblempropertywidget.ui \
widgets/searchdialog.ui \ widgets/searchdialog.ui \
widgets/signalmessagedialog.ui widgets/signalmessagedialog.ui

View File

@ -47,6 +47,7 @@
#include "vcs/gitremotedialog.h" #include "vcs/gitremotedialog.h"
#include "vcs/gituserconfigdialog.h" #include "vcs/gituserconfigdialog.h"
#include "widgets/infomessagebox.h" #include "widgets/infomessagebox.h"
#include "widgets/newtemplatedialog.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QComboBox> #include <QComboBox>
@ -186,6 +187,8 @@ MainWindow::MainWindow(QWidget *parent)
mMenuNew->addAction(ui->actionNew); mMenuNew->addAction(ui->actionNew);
mMenuNew->addAction(ui->actionNew_Project); mMenuNew->addAction(ui->actionNew_Project);
mMenuNew->addSeparator(); mMenuNew->addSeparator();
mMenuNew->addAction(ui->actionNew_Template);
mMenuNew->addSeparator();
mMenuNew->addAction(ui->actionNew_Class); mMenuNew->addAction(ui->actionNew_Class);
mMenuNew->addAction(ui->actionNew_Header); mMenuNew->addAction(ui->actionNew_Header);
@ -519,6 +522,7 @@ void MainWindow::updateEditorActions()
void MainWindow::updateProjectActions() void MainWindow::updateProjectActions()
{ {
bool hasProject = (mProject != nullptr); bool hasProject = (mProject != nullptr);
ui->actionNew_Template->setEnabled(hasProject);
ui->actionView_Makefile->setEnabled(hasProject); ui->actionView_Makefile->setEnabled(hasProject);
ui->actionProject_New_File->setEnabled(hasProject); ui->actionProject_New_File->setEnabled(hasProject);
ui->actionAdd_to_project->setEnabled(hasProject); ui->actionAdd_to_project->setEnabled(hasProject);
@ -8055,3 +8059,33 @@ void MainWindow::on_actionGo_to_Line_triggered()
} }
} }
void MainWindow::on_actionNew_Template_triggered()
{
if (!mProject)
return;
NewTemplateDialog dialog(this);
if (dialog.exec()==QDialog::Accepted) {
QDir folder(
includeTrailingPathDelimiter(
pSettings->dirs().config(Settings::Dirs::DataType::Template))
+dialog.getName());
if (folder.exists()) {
if (QMessageBox::warning(this,
tr("Template Exists"),
tr("Template %1 already exists. Do you want to overwrite?").arg(dialog.getName()),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No
)!=QMessageBox::Yes)
return;
}
mProject->saveAsTemplate(
folder.absolutePath(),
dialog.getName(),
dialog.getDescription(),
dialog.getCategory()
);
}
}

View File

@ -699,6 +699,8 @@ private slots:
void on_actionGo_to_Line_triggered(); void on_actionGo_to_Line_triggered();
void on_actionNew_Template_triggered();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -3187,6 +3187,14 @@
<string>Go to Line...</string> <string>Go to Line...</string>
</property> </property>
</action> </action>
<action name="actionNew_Template">
<property name="text">
<string>New Template...</string>
</property>
<property name="toolTip">
<string>New Template from Project</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -645,20 +645,6 @@ bool Project::saveUnits()
return true; return true;
} }
void Project::saveAsTemplate(const QString &/*filename*/,
const QString &name,
const QString &description,
const QString &category)
{
SimpleIni ini;
ini.SetValue("Template", "Icon", "");
ini.SetValue("Template", "Category",toByteArray(category));
ini.SetValue("Template", "Name",toByteArray(name));
ini.SetValue("Template", "Description", toByteArray(description));
ini.SetValue("Project", "Icon", toByteArray(options().icon));
//todo: save to template
}
PProjectUnit Project::findUnitByFilename(const QString &filename) PProjectUnit Project::findUnitByFilename(const QString &filename)
{ {
foreach(PProjectUnit unit, mUnits) { foreach(PProjectUnit unit, mUnits) {
@ -854,6 +840,121 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
return true; return true;
} }
bool Project::saveAsTemplate(const QString &templateFolder,
const QString& name,
const QString& description,
const QString& category)
{
QDir dir(templateFolder);
if (!dir.mkpath(templateFolder)) {
QMessageBox::critical(nullptr,
tr("Error"),
tr("Can't create folder %1 ").arg(templateFolder),
QMessageBox::Ok);
return false;
}
QString fileName = dir.absoluteFilePath(TEMPLATE_INFO_FILE);
PSimpleIni ini = std::make_shared<SimpleIni>();
ini->SetLongValue("Template","Ver",3);
// template info
ini->SetValue("Template", "Name", name.toUtf8());
ini->SetValue("Template", "Category", category.toUtf8());
ini->SetValue("Template", "Description", description.toUtf8());
if (fileExists(mOptions.icon)) {
QString iconName = extractFileName(mOptions.icon);
if (dir.exists(iconName))
dir.remove(iconName);
QFile::copy(mOptions.icon, dir.absoluteFilePath(iconName));
if (dir.exists(iconName))
ini->SetValue("Template", "Icon", iconName.toUtf8());
}
ini->SetLongValue("Project", "Type", static_cast<int>(mOptions.type));
if (!mOptions.objFiles.isEmpty())
ini->SetValue("Project", "ObjFiles", mOptions.objFiles.join(";").toUtf8());
if (!mOptions.includeDirs.isEmpty())
ini->SetValue("Project", "Includes", mOptions.includeDirs.join(";").toUtf8());
if (!mOptions.resourceIncludes.isEmpty())
ini->SetValue("Project", "ResourceIncludes", mOptions.resourceIncludes.join(";").toUtf8());
if (!mOptions.binDirs.isEmpty())
ini->SetValue("Project", "Bins", mOptions.binDirs.join(";").toUtf8());
if (!mOptions.libDirs.isEmpty())
ini->SetValue("Project", "Libs", mOptions.libDirs.join(";").toUtf8());
if (!mOptions.compilerCmd.isEmpty())
ini->SetValue("Project", "Compiler", mOptions.compilerCmd.toUtf8());
if (!mOptions.cppCompilerCmd.isEmpty())
ini->SetValue("Project", "CppCompiler", mOptions.cppCompilerCmd.toUtf8());
if (!mOptions.linkerCmd.isEmpty())
ini->SetValue("Project", "Linker",mOptions.linkerCmd.toUtf8());
ini->SetBoolValue("Project", "IsCpp", mOptions.isCpp);
if (mOptions.includeVersionInfo)
ini->SetBoolValue("Project", "IncludeVersionInfo", true);
if (mOptions.supportXPThemes)
ini->SetBoolValue("Project", "SupportXPThemes", true);
if (!mOptions.exeOutput.isEmpty())
ini->SetValue("Project", "ExeOutput", mOptions.exeOutput.toUtf8());
if (!mOptions.objectOutput.isEmpty())
ini->SetValue("Project", "ObjectOutput", mOptions.objectOutput.toUtf8());
if (!mOptions.logOutput.isEmpty())
ini->SetValue("Project", "LogOutput", mOptions.logOutput.toUtf8());
if (mOptions.execEncoding!=ENCODING_SYSTEM_DEFAULT)
ini->SetValue("Project","ExecEncoding", mOptions.execEncoding);
if (!mOptions.staticLink)
ini->SetBoolValue("Project", "StaticLink",false);
if (!mOptions.addCharset)
ini->SetBoolValue("Project", "AddCharset",false);
if (mOptions.encoding!=ENCODING_AUTO_DETECT)
ini->SetValue("Project","Encoding",mOptions.encoding.toUtf8());
if (mOptions.modelType!=ProjectModelType::FileSystem)
ini->SetLongValue("Project", "ModelType", (int)mOptions.modelType);
for (int i=0;i<mUnits.count();i++) {
const PProjectUnit& unit=mUnits[i];
QString unitName = extractFileName(unit->fileName());
QByteArray section = toByteArray(QString("Unit%1").arg(i));
if (dir.exists(unitName))
dir.remove(unitName);
if (!QFile::copy(unit->fileName(), dir.absoluteFilePath(unitName))) {
QMessageBox::warning(nullptr,
tr("Warning"),
tr("Can't save file %1").arg(dir.absoluteFilePath(unitName)),
QMessageBox::Ok);
}
switch(getFileType(unit->fileName())) {
case FileType::CSource:
ini->SetValue(section,"C", unitName.toUtf8());
ini->SetValue(section,"CName", unitName.toUtf8());
break;
case FileType::CppSource:
ini->SetValue(section,"Cpp", unitName.toUtf8());
ini->SetValue(section,"CppName", unitName.toUtf8());
break;
case FileType::CHeader:
case FileType::CppHeader:
ini->SetValue(section,"C", unitName.toUtf8());
ini->SetValue(section,"CName", unitName.toUtf8());
ini->SetValue(section,"Cpp", unitName.toUtf8());
ini->SetValue(section,"CppName", unitName.toUtf8());
break;
default:
ini->SetValue(section,"Source", unitName.toUtf8());
ini->SetValue(section,"Target", unitName.toUtf8());
}
}
ini->SetLongValue("Project","UnitCount",mUnits.count());
if (ini->SaveFile(fileName.toLocal8Bit())!=SI_OK) {
QMessageBox::critical(nullptr,
tr("Error"),
tr("Can't save file %1").arg(fileName),
QMessageBox::Ok);
return false;
}
return true;
}
void Project::saveOptions() void Project::saveOptions()
{ {
SimpleIni ini; SimpleIni ini;

View File

@ -205,12 +205,9 @@ public:
void saveUnitAs(int i, const QString& sFileName, bool syncEditor = true); // save single [UnitX] void saveUnitAs(int i, const QString& sFileName, bool syncEditor = true); // save single [UnitX]
bool saveUnits(); bool saveUnits();
void saveAsTemplate(const QString &filename, const QString &name, const QString &description,
const QString &category);
PProjectUnit findUnitByFilename(const QString& filename); PProjectUnit findUnitByFilename(const QString& filename);
void associateEditor(Editor* editor); void associateEditor(Editor* editor);
void associateEditorToUnit(Editor* editor, PProjectUnit unit); void associateEditorToUnit(Editor* editor, PProjectUnit unit);
// bool setCompileOption(const QString &key, int valIndex);
bool setCompileOption(const QString &key, const QString &value); bool setCompileOption(const QString &key, const QString &value);
QString getCompileOption(const QString &key) const; QString getCompileOption(const QString &key) const;
@ -218,9 +215,11 @@ public:
void updateNodeIndexes(); void updateNodeIndexes();
void setCompilerSet(int compilerSetIndex); void setCompilerSet(int compilerSetIndex);
//void showOptions();
bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, bool useCpp); bool assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, bool useCpp);
//void saveToLog(); bool saveAsTemplate(const QString& templateFolder,
const QString& name,
const QString& description,
const QString& category);
std::shared_ptr<CppParser> cppParser(); std::shared_ptr<CppParser> cppParser();
const QString &filename() const; const QString &filename() const;

View File

@ -52,31 +52,6 @@ PTemplateUnit ProjectTemplate::unit(int index)
return unit; return unit;
} }
void ProjectTemplate::setUnit(int index, PTemplateUnit newUnit)
{
if (!mIni || mVersion<=0)
return;
QByteArray section = toByteArray(QString("Unit%1").arg(index));
mIni->SetValue(section,"C", toByteArray(newUnit->CText));
mIni->SetValue(section,"Cpp", toByteArray(newUnit->CppText));
mIni->SetValue(section,"CName", toByteArray(newUnit->CName));
mIni->SetValue(section,"CppName", toByteArray(newUnit->CppName));
mIni->SetValue(section,"Source", toByteArray(newUnit->Source));
mIni->SetValue(section,"Target", toByteArray(newUnit->Target));
}
int ProjectTemplate::addUnit()
{
if (!mIni || mVersion<=0)
return -1;
int count = unitCount() +1;
QByteArray section = toByteArray(QString("Unit%1").arg(count-1));
mIni->SetValue(section, "C", "");
mIni->SetValue(section, "Cpp", "");
mIni->SetLongValue("Project", "UnitCount", count);
return count;
}
void ProjectTemplate::readTemplateFile(const QString &fileName) void ProjectTemplate::readTemplateFile(const QString &fileName)
{ {
if (mIni) if (mIni)
@ -267,3 +242,8 @@ int ProjectTemplate::version() const
return mVersion; return mVersion;
} }
void ProjectTemplate::setVersion(int newVersion)
{
mVersion = newVersion;
}

View File

@ -39,8 +39,6 @@ public:
explicit ProjectTemplate(QObject *parent = nullptr); explicit ProjectTemplate(QObject *parent = nullptr);
int unitCount(); int unitCount();
PTemplateUnit unit(int index); PTemplateUnit unit(int index);
void setUnit(int index, PTemplateUnit newUnit);
int addUnit();
void readTemplateFile(const QString& fileName); void readTemplateFile(const QString& fileName);
bool save(); bool save();
const QString &category() const; const QString &category() const;
@ -65,6 +63,8 @@ public:
int version() const; int version() const;
void setVersion(int newVersion);
private: private:
QString mFileName; QString mFileName;
ProjectOptions mOptions; ProjectOptions mOptions;

View File

@ -287,6 +287,18 @@
<source>Ok</source> <source>Ok</source>
<translation>Ok</translation> <translation>Ok</translation>
</message> </message>
<message>
<source>Default Language:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>C</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>C++</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>CodeSnippetsManager</name> <name>CodeSnippetsManager</name>
@ -1041,7 +1053,7 @@
</message> </message>
<message> <message>
<source>Enable code completion</source> <source>Enable code completion</source>
<translation>Habilitar complementação de código</translation> <translation type="vanished">Habilitar complementação de código</translation>
</message> </message>
<message> <message>
<source>Minimum id length to show completion </source> <source>Minimum id length to show completion </source>
@ -1111,6 +1123,10 @@
<source>Completion suggestion window height:</source> <source>Completion suggestion window height:</source>
<translation>Altura da janela com sugestão para complementação</translation> <translation>Altura da janela com sugestão para complementação</translation>
</message> </message>
<message>
<source>Enable code competion</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>EditorColorSchemeWidget</name> <name>EditorColorSchemeWidget</name>
@ -1547,7 +1563,7 @@
</message> </message>
<message> <message>
<source>Independent Red Panda C++ applications</source> <source>Independent Red Panda C++ applications</source>
<translation>Aplicativos independentes do Red Panda C++</translation> <translation type="vanished">Aplicativos independentes do Red Panda C++</translation>
</message> </message>
<message> <message>
<source>The same Red Panda C++ application</source> <source>The same Red Panda C++ application</source>
@ -1561,6 +1577,10 @@
<source>Just check or uncheck for which file types Red Panda C++ wil be registered as the default application to open them ... </source> <source>Just check or uncheck for which file types Red Panda C++ wil be registered as the default application to open them ... </source>
<translation>Basta marcar ou desmarcar quais tipos de arquivos o Red Panda C++ irá registrar como aplicativos padrões para abrí-los ...</translation> <translation>Basta marcar ou desmarcar quais tipos de arquivos o Red Panda C++ irá registrar como aplicativos padrões para abrí-los ...</translation>
</message> </message>
<message>
<source>Independant Red Panda C++ applications</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>EnvironmentFoldersWidget</name> <name>EnvironmentFoldersWidget</name>
@ -2060,7 +2080,7 @@
</message> </message>
<message> <message>
<source>Insert empty lines around unrelated blocks</source> <source>Insert empty lines around unrelated blocks</source>
<translation>Inserir linhas em branco em torno de blocos não relacionados</translation> <translation type="vanished">Inserir linhas em branco em torno de blocos não relacionados</translation>
</message> </message>
<message> <message>
<source>Insert empty lines around all blocks</source> <source>Insert empty lines around all blocks</source>
@ -2164,7 +2184,7 @@
</message> </message>
<message> <message>
<source>Don&apos;t break multiple statements residing on one line</source> <source>Don&apos;t break multiple statements residing on one line</source>
<translation>Não separar instruções múltiplas que estejam em uma mesma linha</translation> <translation type="vanished">Não separar instruções múltiplas que estejam em uma mesma linha</translation>
</message> </message>
<message> <message>
<source>Break return type from the function name in its declaration</source> <source>Break return type from the function name in its declaration</source>
@ -2198,6 +2218,14 @@
<source>Place the logical conditional to the last on the previous line, when break lines</source> <source>Place the logical conditional to the last on the previous line, when break lines</source>
<translation>Colocar a condição lógica por último na linha anterior, ao separar linhas</translation> <translation>Colocar a condição lógica por último na linha anterior, ao separar linhas</translation>
</message> </message>
<message>
<source>Insert empty lines arround unrelated blocks</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Don&apos;t break multimple statements residing on one line</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>FormatterPathWidget</name> <name>FormatterPathWidget</name>
@ -2417,7 +2445,7 @@
</message> </message>
<message> <message>
<source>Not Specified</source> <source>Not Specified</source>
<translation>Não especificado</translation> <translation type="vanished">Não especificado</translation>
</message> </message>
<message> <message>
<source>Create New Branch</source> <source>Create New Branch</source>
@ -2443,6 +2471,10 @@
<source>Cancel</source> <source>Cancel</source>
<translation>Cancelar</translation> <translation>Cancelar</translation>
</message> </message>
<message>
<source>Not Specifiied</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>GitFetchDialog</name> <name>GitFetchDialog</name>
@ -2703,12 +2735,16 @@
</message> </message>
<message> <message>
<source>User name:</source> <source>User name:</source>
<translation>User name:</translation> <translation type="vanished">User name:</translation>
</message> </message>
<message> <message>
<source>Git needs the following info to commit</source> <source>Git needs the following info to commit</source>
<translation>Git needs the following info to commit</translation> <translation>Git needs the following info to commit</translation>
</message> </message>
<message>
<source>User Name:</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>InfoMessageBox</name> <name>InfoMessageBox</name>
@ -2958,7 +2994,7 @@
</message> </message>
<message> <message>
<source>Add Problem Case</source> <source>Add Problem Case</source>
<translation>Acrescentar caso de problema</translation> <translation type="vanished">Acrescentar caso de problema</translation>
</message> </message>
<message> <message>
<source>Remove Problem Case</source> <source>Remove Problem Case</source>
@ -2966,7 +3002,7 @@
</message> </message>
<message> <message>
<source>Open Answer Source File</source> <source>Open Answer Source File</source>
<translation>Abrir arquivo de respostas</translation> <translation type="vanished">Abrir arquivo de respostas</translation>
</message> </message>
<message> <message>
<source>Run All Cases</source> <source>Run All Cases</source>
@ -3878,7 +3914,7 @@
</message> </message>
<message> <message>
<source>Host application missing</source> <source>Host application missing</source>
<translation>Falta aplicativo hospedeiro</translation> <translation type="vanished">Falta aplicativo hospedeiro</translation>
</message> </message>
<message> <message>
<source>DLL project needs a host application to run.</source> <source>DLL project needs a host application to run.</source>
@ -4532,6 +4568,34 @@
<source>Line</source> <source>Line</source>
<translation>Linha</translation> <translation>Linha</translation>
</message> </message>
<message>
<source>Add Probem Case</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open Anwser Source File</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Host applcation missing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>New Template...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>New Template from Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Template Exists</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Template %1 already exists. Do you want to overwrite?</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>NewClassDialog</name> <name>NewClassDialog</name>
@ -4689,6 +4753,37 @@
<translation>Escolher pasta</translation> <translation>Escolher pasta</translation>
</message> </message>
</context> </context>
<context>
<name>NewTemplateDialog</name>
<message>
<source>Dialog</source>
<translation type="obsolete">Diálogo</translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished">Descrição</translation>
</message>
<message>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Create</source>
<translation type="unfinished">Criar</translation>
</message>
<message>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Create Template From Project</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OJProblemCasesRunner</name> <name>OJProblemCasesRunner</name>
<message> <message>
@ -4828,6 +4923,22 @@
<source>Developed using the Red Panda C++ IDE</source> <source>Developed using the Red Panda C++ IDE</source>
<translation>Desenvolvido com uso da IDE Red Panda C++</translation> <translation>Desenvolvido com uso da IDE Red Panda C++</translation>
</message> </message>
<message>
<source>Error</source>
<translation type="unfinished">Erro</translation>
</message>
<message>
<source>Can&apos;t create folder %1 </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Warning</source>
<translation type="unfinished">Aviso</translation>
</message>
<message>
<source>Can&apos;t save file %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProjectCompileParamatersWidget</name> <name>ProjectCompileParamatersWidget</name>
@ -5289,7 +5400,7 @@
</message> </message>
<message> <message>
<source>Release</source> <source>Release</source>
<translation>Release</translation> <translation type="vanished">Release</translation>
</message> </message>
<message> <message>
<source>Build</source> <source>Build</source>
@ -5343,6 +5454,10 @@
<source>Legal copyright</source> <source>Legal copyright</source>
<translation>Direitos autorais reservados</translation> <translation>Direitos autorais reservados</translation>
</message> </message>
<message>
<source>Rlease</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>QApplication</name> <name>QApplication</name>
@ -5415,7 +5530,7 @@
</message> </message>
<message> <message>
<source>Global Variable</source> <source>Global Variable</source>
<translation>Variável global</translation> <translation type="vanished">Variável global</translation>
</message> </message>
<message> <message>
<source>Hexadecimal Integer</source> <source>Hexadecimal Integer</source>
@ -5747,7 +5862,7 @@
</message> </message>
<message> <message>
<source>Do not assemble, compile and generate the assembly code (-S)</source> <source>Do not assemble, compile and generate the assembly code (-S)</source>
<translation>Não montar, compilar e gerar código em assembly (-S)</translation> <translation type="vanished">Não montar, compilar e gerar código em assembly (-S)</translation>
</message> </message>
<message> <message>
<source>Use pipes instead of temporary files during compilation (-pipe)</source> <source>Use pipes instead of temporary files during compilation (-pipe)</source>
@ -5767,7 +5882,7 @@
</message> </message>
<message> <message>
<source>Compiler set not configured.</source> <source>Compiler set not configured.</source>
<translation>Compilador não configurado.</translation> <translation type="vanished">Compilador não configurado.</translation>
</message> </message>
<message> <message>
<source>Would you like Red Panda C++ to search for compilers in the following locations: &lt;BR /&gt;&apos;%1&apos;&lt;BR /&gt;&apos;%2&apos;? </source> <source>Would you like Red Panda C++ to search for compilers in the following locations: &lt;BR /&gt;&apos;%1&apos;&lt;BR /&gt;&apos;%2&apos;? </source>
@ -5857,6 +5972,18 @@
<source>Leaving those directories will lead to problems during compilation.</source> <source>Leaving those directories will lead to problems during compilation.</source>
<translation>Deixar essas pastas resultará em problemas durante a compilação.</translation> <translation>Deixar essas pastas resultará em problemas durante a compilação.</translation>
</message> </message>
<message>
<source>Gloabal Variable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Do not assemble, compile and generate the assemble code (-S)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Compiler set not configuared.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>RegisterModel</name> <name>RegisterModel</name>
@ -6221,7 +6348,11 @@
</message> </message>
<message> <message>
<source>There are changes in the settings, do you want to save them before switch to other page?</source> <source>There are changes in the settings, do you want to save them before switch to other page?</source>
<translation>Alteradas nas configurações, quer salvá-las antes de mudar para outra página?</translation> <translation type="vanished">Alteradas nas configurações, quer salvá-las antes de mudar para outra página?</translation>
</message>
<message>
<source>There are changes in the settings, do you want to save them before swtich to other page?</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

File diff suppressed because it is too large Load Diff

View File

@ -4540,6 +4540,22 @@
<source>Line</source> <source>Line</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>New Template...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>New Template from Project</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Template Exists</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Template %1 already exists. Do you want to overwrite?</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>NewClassDialog</name> <name>NewClassDialog</name>
@ -4697,6 +4713,33 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>NewTemplateDialog</name>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Category</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Create</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Create Template From Project</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OJProblemCasesRunner</name> <name>OJProblemCasesRunner</name>
<message> <message>
@ -4836,6 +4879,22 @@
<source>Developed using the Red Panda C++ IDE</source> <source>Developed using the Red Panda C++ IDE</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t create folder %1 </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Warning</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Can&apos;t save file %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProjectCompileParamatersWidget</name> <name>ProjectCompileParamatersWidget</name>

View File

@ -0,0 +1,118 @@
#include "newtemplatedialog.h"
#include "ui_newtemplatedialog.h"
#include "../settings.h"
#include "../projecttemplate.h"
#include "../systemconsts.h"
#include <QFile>
#include <QDir>
#include <QFileInfo>
NewTemplateDialog::NewTemplateDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewTemplateDialog)
{
ui->setupUi(this);
QStringList categories = findCategories();
ui->cbCategory->addItems(categories);
updateCreateState();
}
NewTemplateDialog::~NewTemplateDialog()
{
delete ui;
}
QString NewTemplateDialog::getName() const
{
return ui->txtName->text();
}
QString NewTemplateDialog::getDescription() const
{
return ui->txtDescription->toPlainText();
}
QString NewTemplateDialog::getCategory() const
{
return ui->cbCategory->currentText();
}
QStringList NewTemplateDialog::findCategories()
{
QSet<QString> categories;
readTemplateCategory(":/templates/empty.template",categories);
readTemplateCategoriesInDir(pSettings->dirs().data(Settings::Dirs::DataType::Template),categories);
readTemplateCategoriesInDir(pSettings->dirs().config(Settings::Dirs::DataType::Template),categories);
QStringList result;
foreach(const QString& s, categories)
result.append(s);
result.sort();
return result;
}
void NewTemplateDialog::readTemplateCategory(const QString &filename, QSet<QString> &categories)
{
if (!QFile(filename).exists())
return;
PProjectTemplate t = std::make_shared<ProjectTemplate>();
t->readTemplateFile(filename);
if (!t->category().isEmpty())
categories.insert(t->category());
}
void NewTemplateDialog::readTemplateCategoriesInDir(const QString &folderPath, QSet<QString> &categories)
{
QString templateExt(".");
templateExt += TEMPLATE_EXT;
QDir dir(folderPath);
if (!dir.exists())
return;
foreach (const QFileInfo& fileInfo,dir.entryInfoList()) {
if (fileInfo.isFile()
&& fileInfo.fileName().endsWith(templateExt)) {
readTemplateCategory(fileInfo.absoluteFilePath(),categories);
} else if (fileInfo.isDir()) {
QDir subDir(fileInfo.absoluteFilePath());
readTemplateCategory(subDir.absoluteFilePath(TEMPLATE_INFO_FILE),categories);
}
}
}
void NewTemplateDialog::updateCreateState()
{
ui->btnCreate->setEnabled(
!ui->txtName->text().isEmpty()
&& !ui->cbCategory->currentText().isEmpty()
);
}
void NewTemplateDialog::closeEvent(QCloseEvent */*event*/)
{
reject();
}
void NewTemplateDialog::on_btnCreate_clicked()
{
accept();
}
void NewTemplateDialog::on_btnCancel_clicked()
{
reject();
}
void NewTemplateDialog::on_txtName_textChanged(const QString &/*arg1*/)
{
updateCreateState();
}
void NewTemplateDialog::on_cbCategory_currentTextChanged(const QString &/*arg1*/)
{
updateCreateState();
}

View File

@ -0,0 +1,43 @@
#ifndef NEWTEMPLATEDIALOG_H
#define NEWTEMPLATEDIALOG_H
#include <QDialog>
#include <QSet>
namespace Ui {
class NewTemplateDialog;
}
class NewTemplateDialog : public QDialog
{
Q_OBJECT
public:
explicit NewTemplateDialog(QWidget *parent = nullptr);
~NewTemplateDialog();
QString getName() const;
QString getDescription() const;
QString getCategory() const;
private slots:
void on_btnCreate_clicked();
void on_btnCancel_clicked();
void on_txtName_textChanged(const QString &arg1);
void on_cbCategory_currentTextChanged(const QString &arg1);
private:
QStringList findCategories();
void readTemplateCategory(const QString& filename, QSet<QString>& categories);
void readTemplateCategoriesInDir(const QString& folderPath, QSet<QString>& categories);
void updateCreateState();
private:
Ui::NewTemplateDialog *ui;
// QWidget interface
protected:
void closeEvent(QCloseEvent *event) override;
};
#endif // NEWTEMPLATEDIALOG_H

View File

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewTemplateDialog</class>
<widget class="QDialog" name="NewTemplateDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>553</width>
<height>519</height>
</rect>
</property>
<property name="windowTitle">
<string>Create Template From Project</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="widget_2" native="true">
<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="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Category</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtName"/>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cbCategory">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPlainTextEdit" name="txtDescription"/>
</item>
</layout>
</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>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>332</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnCreate">
<property name="text">
<string>Create</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>