mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
macOS: handle file open event requested by Finder
This commit is contained in:
parent
a9005bef23
commit
280144f4eb
23
src/application.cpp
Normal file
23
src/application.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "application.h"
|
||||||
|
|
||||||
|
#include <QFileOpenEvent>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
using namespace vnotex;
|
||||||
|
|
||||||
|
Application::Application(int &p_argc, char **p_argv)
|
||||||
|
: QApplication(p_argc, p_argv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::event(QEvent *p_event)
|
||||||
|
{
|
||||||
|
// On macOS, we need this to open file from Finder.
|
||||||
|
if (p_event->type() == QEvent::FileOpen) {
|
||||||
|
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(p_event);
|
||||||
|
qDebug() << "request to open file" << openEvent->file();
|
||||||
|
emit openFileRequested(openEvent->file());
|
||||||
|
}
|
||||||
|
|
||||||
|
return QApplication::event(p_event);
|
||||||
|
}
|
22
src/application.h
Normal file
22
src/application.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef APPLICATION_H
|
||||||
|
#define APPLICATION_H
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
namespace vnotex
|
||||||
|
{
|
||||||
|
class Application : public QApplication
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Application(int &p_argc, char **p_argv);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void openFileRequested(const QString &p_filePath);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool event(QEvent *p_event) Q_DECL_OVERRIDE;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // APPLICATION_H
|
@ -1,4 +1,3 @@
|
|||||||
#include <QApplication>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QSslSocket>
|
#include <QSslSocket>
|
||||||
@ -22,6 +21,7 @@
|
|||||||
#include <core/exception.h>
|
#include <core/exception.h>
|
||||||
#include <widgets/messageboxhelper.h>
|
#include <widgets/messageboxhelper.h>
|
||||||
#include "commandlineoptions.h"
|
#include "commandlineoptions.h"
|
||||||
|
#include "application.h"
|
||||||
|
|
||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
Application app(argc, argv);
|
||||||
|
|
||||||
initWebEngineSettings();
|
initWebEngineSettings();
|
||||||
|
|
||||||
@ -162,6 +162,11 @@ int main(int argc, char *argv[])
|
|||||||
QObject::connect(&guard, &SingleInstanceGuard::openFilesRequested,
|
QObject::connect(&guard, &SingleInstanceGuard::openFilesRequested,
|
||||||
&window, &MainWindow::openFiles);
|
&window, &MainWindow::openFiles);
|
||||||
|
|
||||||
|
QObject::connect(&app, &Application::openFileRequested,
|
||||||
|
&window, [&window](const QString &p_filePath) {
|
||||||
|
window.openFiles(QStringList() << p_filePath);
|
||||||
|
});
|
||||||
|
|
||||||
window.kickOffOnStart(cmdOptions.m_pathsToOpen);
|
window.kickOffOnStart(cmdOptions.m_pathsToOpen);
|
||||||
|
|
||||||
int ret = app.exec();
|
int ret = app.exec();
|
||||||
|
@ -32,6 +32,7 @@ TRANSLATIONS += \
|
|||||||
data/core/translations/vnote_ja.ts
|
data/core/translations/vnote_ja.ts
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
application.cpp \
|
||||||
commandlineoptions.cpp \
|
commandlineoptions.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
@ -148,4 +149,5 @@ unix:!macx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
application.h \
|
||||||
commandlineoptions.h
|
commandlineoptions.h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user