utility: loading project via commanlineargument
loading a project via commanline with --project or -p argument
This commit is contained in:
@@ -5,6 +5,9 @@ add_files(
|
||||
platform_includes/includesMac.h
|
||||
platform_includes/includesWindows.h
|
||||
|
||||
qt/commandline/QtCommandLineParser.cpp
|
||||
qt/commandline/QtCommandLineParser.h
|
||||
|
||||
qt/element/QtAutocompletionList.cpp
|
||||
qt/element/QtAutocompletionList.h
|
||||
qt/element/QtCodeArea.cpp
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "qt/commandline/QtCommandLineParser.h"
|
||||
|
||||
#include "utility/ConfigManager.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
|
||||
QtCommandLineParser::QtCommandLineParser()
|
||||
{
|
||||
}
|
||||
|
||||
QtCommandLineParser::~QtCommandLineParser()
|
||||
{
|
||||
}
|
||||
|
||||
void QtCommandLineParser::setup()
|
||||
{
|
||||
|
||||
setApplicationDescription("Coati helper");
|
||||
addVersionOption();
|
||||
addHelpOption();
|
||||
|
||||
QCommandLineOption projectOption(QStringList() << "p" << "project",
|
||||
QCoreApplication::translate("main", "Load Coati with the a Coatiprojectfile <CoatiProject>."),
|
||||
QCoreApplication::translate("main", "CoatiProject"));
|
||||
addOption(projectOption);
|
||||
}
|
||||
|
||||
void QtCommandLineParser::parseCommandline()
|
||||
{
|
||||
|
||||
if(isSet("project"))
|
||||
{
|
||||
QString projectfilename = value("project") ;
|
||||
FilePath projectfile(projectfilename.toStdString());
|
||||
bool isValidProjectfile = true;
|
||||
std::stringstream errorstring("Provided Projectfile is not valid: ");
|
||||
errorstring << "Provided Projectfile('" << projectfile.fileName() << ") ";
|
||||
if(!projectfile.exists())
|
||||
{
|
||||
errorstring << "does not exist";
|
||||
isValidProjectfile = false;
|
||||
}
|
||||
|
||||
if(projectfile.extension() != ".coatiproject")
|
||||
{
|
||||
errorstring << "has a wrong fileending";
|
||||
isValidProjectfile = false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ConfigManager> configManager = ConfigManager::createEmpty();
|
||||
if(!configManager->load(TextAccess::createFromFile(projectfile.str())))
|
||||
{
|
||||
errorstring << "could not be loaded";
|
||||
isValidProjectfile = false;
|
||||
}
|
||||
|
||||
if(isValidProjectfile)
|
||||
{
|
||||
MessageLoadProject(projectfile.str()).dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageStatus(errorstring.str(), true).dispatch();
|
||||
LOG_ERROR(errorstring.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef QTCOMMANDLINEPARSER_H
|
||||
#define QTCOMMANDLINEPARSER_H
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include "Application.h"
|
||||
|
||||
class QtCommandLineParser : public QCommandLineParser
|
||||
{
|
||||
public:
|
||||
QtCommandLineParser();
|
||||
~QtCommandLineParser();
|
||||
void setup();
|
||||
void parseCommandline();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif //QTCOMMANDLINEPARSER_H
|
||||
Reference in New Issue
Block a user