mirror of
https://github.com/PCSX2/pcsx2.git
synced 2025-12-16 04:08:48 +00:00
Qt: Support macOS file open events
This commit is contained in:
parent
0e649bc70b
commit
fe71fc6a30
@ -2168,57 +2168,56 @@ void MainWindow::dragEnterEvent(QDragEnterEvent* event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::dropEvent(QDropEvent* event)
|
void MainWindow::dropEvent(QDropEvent* event)
|
||||||
|
{
|
||||||
|
if (startFile(getFilenameFromMimeData(event->mimeData())))
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::startFile(const QString& filename)
|
||||||
{
|
{
|
||||||
const auto mcLock = pauseAndLockVM();
|
const auto mcLock = pauseAndLockVM();
|
||||||
|
|
||||||
// Check if memcard is busy, deny request if so
|
// Check if memcard is busy, deny request if so
|
||||||
if (shouldAbortForMemcardBusy(mcLock))
|
if (shouldAbortForMemcardBusy(mcLock))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString filename(getFilenameFromMimeData(event->mimeData()));
|
std::string filename_str = filename.toStdString();
|
||||||
const std::string filename_str(filename.toStdString());
|
|
||||||
if (VMManager::IsSaveStateFileName(filename_str))
|
if (VMManager::IsSaveStateFileName(filename_str))
|
||||||
{
|
{
|
||||||
event->acceptProposedAction();
|
|
||||||
|
|
||||||
// can't load a save state without a current VM
|
// can't load a save state without a current VM
|
||||||
if (s_vm_valid)
|
if (s_vm_valid)
|
||||||
g_emu_thread->loadState(filename);
|
g_emu_thread->loadState(filename);
|
||||||
else
|
else
|
||||||
QMessageBox::critical(this, tr("Load State Failed"), tr("Cannot load a save state without a running VM."));
|
QMessageBox::critical(this, tr("Load State Failed"), tr("Cannot load a save state without a running VM."));
|
||||||
|
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!VMManager::IsLoadableFileName(filename_str))
|
if (!VMManager::IsLoadableFileName(filename_str))
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
// if we're already running, do a disc change, otherwise start
|
// if we're already running, do a disc change, otherwise start
|
||||||
if (!s_vm_valid)
|
if (!s_vm_valid)
|
||||||
{
|
{
|
||||||
event->acceptProposedAction();
|
|
||||||
doStartFile(std::nullopt, filename);
|
doStartFile(std::nullopt, filename);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VMManager::IsDiscFileName(filename_str) || VMManager::IsBlockDumpFileName(filename_str))
|
if (VMManager::IsDiscFileName(filename_str) || VMManager::IsBlockDumpFileName(filename_str))
|
||||||
{
|
{
|
||||||
event->acceptProposedAction();
|
|
||||||
doDiscChange(CDVD_SourceType::Iso, filename);
|
doDiscChange(CDVD_SourceType::Iso, filename);
|
||||||
}
|
}
|
||||||
else if (VMManager::IsElfFileName(filename_str))
|
else if (VMManager::IsElfFileName(filename_str))
|
||||||
{
|
{
|
||||||
const auto lock = pauseAndLockVM();
|
const auto lock = pauseAndLockVM();
|
||||||
|
|
||||||
event->acceptProposedAction();
|
if (QMessageBox::Yes != QMessageBox::question(this, tr("Confirm Reset"),
|
||||||
|
tr("The new ELF cannot be loaded without resetting the virtual machine. Do you want to reset the virtual machine now?")))
|
||||||
if (QMessageBox::question(this, tr("Confirm Reset"),
|
|
||||||
tr("The new ELF cannot be loaded without resetting the virtual machine. Do you want to reset the virtual machine now?")) !=
|
|
||||||
QMessageBox::Yes)
|
|
||||||
{
|
{
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_emu_thread->setELFOverride(filename);
|
g_emu_thread->setELFOverride(filename);
|
||||||
@ -2226,17 +2225,15 @@ void MainWindow::dropEvent(QDropEvent* event)
|
|||||||
}
|
}
|
||||||
else if (VMManager::IsGSDumpFileName(filename_str))
|
else if (VMManager::IsGSDumpFileName(filename_str))
|
||||||
{
|
{
|
||||||
event->acceptProposedAction();
|
|
||||||
|
|
||||||
if (!GSDumpReplayer::IsReplayingDump())
|
if (!GSDumpReplayer::IsReplayingDump())
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Cannot change from game to GS dump without shutting down first."));
|
QMessageBox::critical(this, tr("Error"), tr("Cannot change from game to GS dump without shutting down first."));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_emu_thread->changeGSDump(filename);
|
g_emu_thread->changeGSDump(filename);
|
||||||
switchToEmulationView();
|
switchToEmulationView();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::moveEvent(QMoveEvent* event)
|
void MainWindow::moveEvent(QMoveEvent* event)
|
||||||
|
|||||||
@ -103,6 +103,9 @@ public:
|
|||||||
/// Rescans a single file. NOTE: Happens on UI thread.
|
/// Rescans a single file. NOTE: Happens on UI thread.
|
||||||
void rescanFile(const std::string& path);
|
void rescanFile(const std::string& path);
|
||||||
|
|
||||||
|
/// Start a file from a user action (e.g. dragging a file onto the main window or with macOS open with)
|
||||||
|
bool startFile(const QString& path);
|
||||||
|
|
||||||
void doSettings(const char* category = nullptr);
|
void doSettings(const char* category = nullptr);
|
||||||
void doGameSettings(const char* category = nullptr);
|
void doGameSettings(const char* category = nullptr);
|
||||||
|
|
||||||
|
|||||||
@ -2327,6 +2327,24 @@ bool QtHost::RunSetupWizard()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PCSX2MainApplication : public QApplication {
|
||||||
|
public:
|
||||||
|
using QApplication::QApplication;
|
||||||
|
|
||||||
|
bool event(QEvent* event) override {
|
||||||
|
if (event->type() == QEvent::FileOpen)
|
||||||
|
{
|
||||||
|
QFileOpenEvent* open = static_cast<QFileOpenEvent*>(event);
|
||||||
|
const QUrl url = open->url();
|
||||||
|
if (url.isLocalFile())
|
||||||
|
return g_main_window->startFile(url.toLocalFile());
|
||||||
|
else
|
||||||
|
return false; // No URL schemas currently supported
|
||||||
|
}
|
||||||
|
return QApplication::event(event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
CrashHandler::Install();
|
CrashHandler::Install();
|
||||||
@ -2336,7 +2354,7 @@ int main(int argc, char* argv[])
|
|||||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||||
QtHost::RegisterTypes();
|
QtHost::RegisterTypes();
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
PCSX2MainApplication app(argc, argv);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (!PerformEarlyHardwareChecks())
|
if (!PerformEarlyHardwareChecks())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user