Skip to content

Commit 3dc7205

Browse files
committed
Fix file open handling on macOS
1 parent 73fc10b commit 3dc7205

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <QApplication>
99
#include <QDirIterator>
10-
#include <QFileOpenEvent>
1110
#include <QFontDatabase>
1211
#include <QImageReader>
1312
#include <QLoggingCategory>
@@ -22,6 +21,7 @@
2221
#include <QThread>
2322
#include <QTimer>
2423

24+
#include <CoreApi/FileOpenEventSource.h>
2525
#include <CoreApi/applicationinfo.h>
2626
#include <CoreApi/runtimeinterface.h>
2727
#include <CoreApi/settingcatalog.h>
@@ -190,7 +190,6 @@ namespace Core::Internal {
190190

191191
initializeSingletons();
192192
CoreInterface::fileOpenDispatcher()->setReady(false);
193-
qApp->installEventFilter(this);
194193
initializeBehaviorPreference();
195194
initializeActions();
196195
initializeSettings();
@@ -219,6 +218,18 @@ namespace Core::Internal {
219218
checkLastRun();
220219
checkPlugins();
221220
CoreInterface::fileOpenDispatcher()->registerHandler(new ProjectFileOpenHandler(this));
221+
222+
auto fileOpenEventSource = RuntimeInterface::fileOpenEventSource();
223+
const auto openPendingFiles = [fileOpenEventSource] {
224+
const auto filePaths = fileOpenEventSource->takePendingFiles();
225+
if (filePaths.isEmpty()) {
226+
return;
227+
}
228+
auto firstWindow = CoreInterface::windowSystem()->firstWindow();
229+
CoreInterface::fileOpenDispatcher()->openFiles(filePaths, firstWindow ? firstWindow->window() : nullptr);
230+
};
231+
connect(fileOpenEventSource, &FileOpenEventSource::filesAvailable, this, openPendingFiles);
232+
openPendingFiles();
222233
}
223234

224235
bool CorePlugin::delayedInitialize() {
@@ -257,18 +268,6 @@ namespace Core::Internal {
257268
return nullptr;
258269
}
259270

260-
bool CorePlugin::eventFilter(QObject *obj, QEvent *event) {
261-
if (obj == qApp && event->type() == QEvent::FileOpen) {
262-
const auto filePath = static_cast<QFileOpenEvent *>(event)->file();
263-
if (!filePath.isEmpty()) {
264-
auto firstWindow = CoreInterface::windowSystem()->firstWindow();
265-
CoreInterface::fileOpenDispatcher()->openFiles({filePath}, firstWindow ? firstWindow->window() : nullptr);
266-
}
267-
return true;
268-
}
269-
return QObject::eventFilter(obj, event);
270-
}
271-
272271
void CorePlugin::initializeSingletons() {
273272
new CoreInterface(this);
274273
new BehaviorPreference(this);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ namespace Core::Internal {
2121

2222
QObject *remoteCommand(const QStringList &options, const QString &workingDirectory, const QStringList &args) override;
2323

24-
protected:
25-
bool eventFilter(QObject *obj, QEvent *event) override;
26-
2724
private:
2825
void initializeSingletons();
2926
void initializeActions();

0 commit comments

Comments
 (0)