Skip to content

Commit

Permalink
feat: support open projcet by terminal
Browse files Browse the repository at this point in the history
Log: as title
  • Loading branch information
LiHua000 committed Aug 1, 2024
1 parent 78e2399 commit 571fb21
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ void voidMessageOutput(QtMsgType type, const QMessageLogContext &context, const
// not ouput qt log when in command mode.
}

void openProject(const QString &path)
{
project.openProjectByPath(path);
}

int main(int argc, char *argv[])
{
// some platform opengl drive with wrong,so use OpenGLES instead.
Expand Down Expand Up @@ -144,5 +149,12 @@ int main(int argc, char *argv[])
abort();
}

if (!CommandParser::instance().projectDirectory().isEmpty()) {
auto directory = CommandParser::instance().projectDirectory().first(); // only process first argument
QObject::connect(&dpf::Listener::instance(), &dpf::Listener::pluginsStarted, &a, [directory]() {
QTimer::singleShot(100, [directory](){ openProject(directory); });
});
}

return a.exec();
}
21 changes: 21 additions & 0 deletions src/common/util/commandparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QCommandLineOption>
#include <QDebug>
#include <QDir>
#include <QFileInfo>

#include <iostream>

Expand All @@ -24,6 +25,24 @@ bool CommandParser::isSet(const QString &name) const
return commandParser->isSet(name);
}

QStringList CommandParser::projectDirectory() const
{
if (positionalArguments().isEmpty())
return {};

QStringList projectList;
for (auto arg : positionalArguments()) {
if (arg == ".") {
projectList.append(QDir::currentPath());
continue;
}
QFileInfo fileInfo(arg);
if (fileInfo.exists() && fileInfo.isDir())
projectList.append(arg);
}
return projectList;
}

QString CommandParser::value(const QString &name) const
{
return commandParser->value(name);
Expand Down Expand Up @@ -98,6 +117,8 @@ void CommandParser::initOptions()
addOption(kitOption);
addOption(argsOption);
addOption(addTagOption);

commandParser->addPositionalArgument("address", tr("Project directory"));
}

void CommandParser::addOption(const QCommandLineOption &option)
Expand Down
1 change: 1 addition & 0 deletions src/common/util/commandparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CommandParser : public QObject

bool isSet(const QString &name) const;
QString value(const QString &name) const;
QStringList projectDirectory() const;
void process();
void process(const QStringList &arguments);
void setModel(CommandModel model);
Expand Down
1 change: 1 addition & 0 deletions src/common/util/eventdefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ OPI_OBJECT(recent,
OPI_OBJECT(project,
// in
OPI_INTERFACE(openProject, "kitName", "language", "workspace")
OPI_INTERFACE(openProjectByPath, "directory")
OPI_INTERFACE(activeProject, "kitName", "language", "workspace")
// out
OPI_INTERFACE(activatedProject, "projectInfo")
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/project/projectcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ bool ProjectCore::start()
QObject::connect(&dpf::Listener::instance(), &dpf::Listener::pluginsStarted,
this, &ProjectCore::pluginsStartedMain, Qt::DirectConnection);

connect(ProjectProxy::instance(), &ProjectProxy::openProject, this, [=](const QString &directory) {
confirmProjectKit(directory);
},
Qt::DirectConnection);

initProject(ctx);
initLocator(ctx);

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/project/transceiver/projectcorereceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@ void ProjectCoreReceiver::eventProcess(const dpf::Event &event)
} else if (event.data() == uiController.modeRaised.name) {
auto mode = event.property("mode").toString();
emit ProjectProxy::instance()->modeRaised(mode);
} else if (event.data() == project.openProjectByPath.name) {
auto directory = event.property("directory").toString();
emit ProjectProxy::instance()->openProject(directory);
}
}
1 change: 1 addition & 0 deletions src/plugins/project/transceiver/projectcorereceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ProjectProxy : public QObject
}
signals:
void modeRaised(const QString &mode);
void openProject(const QString &path);
void projectActivated(const dpfservice::ProjectInfo prjInfo);
void switchedFile(const QString &file);
};
Expand Down

0 comments on commit 571fb21

Please sign in to comment.