Skip to content

Commit ce025e0

Browse files
committed
Supports opening files with command line args
1 parent af78b3a commit ce025e0

1 file changed

Lines changed: 33 additions & 16 deletions

File tree

‎src/plugins/coreplugin/internal/CorePlugin.cpp‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,43 @@ namespace Core::Internal {
133133
static constexpr char kNewProjectArg[] = "--new";
134134

135135
static ActionWindowInterfaceBase *initializeGui(const QStringList &options, const QString &workingDirectory, const QStringList &args) {
136+
qCDebug(lcCorePlugin) << "Initializing GUI" << options << args;
136137
if (options.contains(kOpenSettingsArg)) {
137138
qCInfo(lcCorePlugin) << "Open settings dialog with command line args";
138139
CoreInterface::execSettingsDialog("", nullptr);
139140
}
140-
ActionWindowInterfaceBase *windowInterface;
141-
if (options.contains(kNewProjectArg) || (BehaviorPreference::startupBehavior() & BehaviorPreference::SB_CreateNewProject)) {
142-
qCInfo(lcCorePlugin) << "Create new project on startup";
143-
windowInterface = CoreInterface::newFile();
144-
} else {
145-
qCInfo(lcCorePlugin) << "Open home window on startup";
146-
CoreInterface::showHome();
147-
windowInterface = HomeWindowInterface::instance();
148-
}
149-
auto win = windowInterface->window();
150-
if (win->visibility() == QWindow::Minimized) {
151-
win->showNormal();
141+
QList<ActionWindowInterfaceBase *> windowInterfaceList;
142+
do {
143+
if (!args.isEmpty()) {
144+
for (const auto &arg : args) {
145+
auto filePath = QDir(workingDirectory).absoluteFilePath(arg);
146+
auto windowInterface = CoreInterface::openFile(filePath);
147+
if (windowInterface) {
148+
windowInterfaceList.append(windowInterface);
149+
}
150+
}
151+
if (!windowInterfaceList.isEmpty()) {
152+
break;
153+
}
154+
}
155+
if (options.contains(kNewProjectArg) || (BehaviorPreference::startupBehavior() & BehaviorPreference::SB_CreateNewProject)) {
156+
qCInfo(lcCorePlugin) << "Create new project on startup";
157+
windowInterfaceList.append(CoreInterface::newFile());
158+
} else {
159+
qCInfo(lcCorePlugin) << "Open home window on startup";
160+
CoreInterface::showHome();
161+
windowInterfaceList.append(HomeWindowInterface::instance());
162+
}
163+
} while (false);
164+
for (auto windowInterface : windowInterfaceList) {
165+
auto win = windowInterface->window();
166+
if (win->visibility() == QWindow::Minimized) {
167+
win->showNormal();
168+
}
169+
win->raise();
170+
win->requestActivate();
152171
}
153-
win->raise();
154-
win->requestActivate();
155-
return windowInterface;
172+
return windowInterfaceList.first();
156173
}
157174

158175
bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) {
@@ -189,7 +206,7 @@ namespace Core::Internal {
189206
qCInfo(lcCorePlugin) << "Initializing GUI";
190207
// TODO plugin arguments
191208
auto args = QApplication::arguments();
192-
auto windowInterface = initializeGui(args, QDir::currentPath(), args);
209+
auto windowInterface = initializeGui(args, QDir::currentPath(), ExtensionSystem::PluginManager::arguments());
193210
auto win = windowInterface->window();
194211
class ExposedListener : public QObject {
195212
public:

0 commit comments

Comments
 (0)