Add wrapper function to disable hotkeys for QFileDialog

Previously, if you have "Hotkeys Require Window Focus" disabled, you could repeatedly use the "Open" hotkey, for example, to stack File Open windows over top of each other over and over.

This commit allows the hotkey manager to disable/enable on QFileDialog creation and destruction.
This commit is contained in:
sowens99 2021-10-09 22:28:59 -04:00
parent d90b30ca25
commit 839b04014e
16 changed files with 175 additions and 81 deletions

View File

@ -262,6 +262,8 @@ add_executable(dolphin-emu
NetPlay/NetPlaySetupDialog.h NetPlay/NetPlaySetupDialog.h
NetPlay/PadMappingDialog.cpp NetPlay/PadMappingDialog.cpp
NetPlay/PadMappingDialog.h NetPlay/PadMappingDialog.h
QtUtils/DolphinFileDialog.cpp
QtUtils/DolphinFileDialog.h
QtUtils/DoubleClickEventFilter.cpp QtUtils/DoubleClickEventFilter.cpp
QtUtils/DoubleClickEventFilter.h QtUtils/DoubleClickEventFilter.h
QtUtils/ElidedButton.cpp QtUtils/ElidedButton.cpp

View File

@ -5,7 +5,6 @@
#include <QApplication> #include <QApplication>
#include <QCoreApplication> #include <QCoreApplication>
#include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QHeaderView> #include <QHeaderView>
#include <QMenu> #include <QMenu>
@ -23,6 +22,7 @@
#include "DiscIO/Filesystem.h" #include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/ParallelProgressDialog.h" #include "DolphinQt/QtUtils/ParallelProgressDialog.h"
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
@ -211,7 +211,8 @@ void FilesystemWidget::PopulateDirectory(int partition_id, QStandardItem* root,
QString FilesystemWidget::SelectFolder() QString FilesystemWidget::SelectFolder()
{ {
return QFileDialog::getExistingDirectory(this, QObject::tr("Choose the folder to extract to")); return DolphinFileDialog::getExistingDirectory(this,
QObject::tr("Choose the folder to extract to"));
} }
void FilesystemWidget::ShowContextMenu(const QPoint&) void FilesystemWidget::ShowContextMenu(const QPoint&)
@ -296,7 +297,7 @@ void FilesystemWidget::ShowContextMenu(const QPoint&)
case EntryType::File: case EntryType::File:
menu->addAction(tr("Extract File..."), this, [this, partition, path] { menu->addAction(tr("Extract File..."), this, [this, partition, path] {
auto dest = auto dest =
QFileDialog::getSaveFileName(this, tr("Save File to"), QFileInfo(path).fileName()); DolphinFileDialog::getSaveFileName(this, tr("Save File to"), QFileInfo(path).fileName());
if (!dest.isEmpty()) if (!dest.isEmpty())
ExtractFile(partition, path, dest); ExtractFile(partition, path, dest);

View File

@ -4,7 +4,6 @@
#include <QComboBox> #include <QComboBox>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDir> #include <QDir>
#include <QFileDialog>
#include <QFormLayout> #include <QFormLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
@ -19,6 +18,7 @@
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#include "DolphinQt/Config/InfoWidget.h" #include "DolphinQt/Config/InfoWidget.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ImageConverter.h" #include "DolphinQt/QtUtils/ImageConverter.h"
#include "UICommon/UICommon.h" #include "UICommon/UICommon.h"
@ -190,8 +190,8 @@ QWidget* InfoWidget::CreateBannerGraphic(const QPixmap& image)
void InfoWidget::SaveBanner() void InfoWidget::SaveBanner()
{ {
QString path = QFileDialog::getSaveFileName(this, tr("Select a File"), QDir::currentPath(), QString path = DolphinFileDialog::getSaveFileName(this, tr("Select a File"), QDir::currentPath(),
tr("PNG image file (*.png);; All Files (*)")); tr("PNG image file (*.png);; All Files (*)"));
ToQPixmap(m_game.GetBannerImage()).save(path, "PNG"); ToQPixmap(m_game.GetBannerImage()).save(path, "PNG");
} }

View File

@ -11,7 +11,6 @@
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
#include <QFileDialog>
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
@ -26,6 +25,7 @@
#include "DiscIO/Blob.h" #include "DiscIO/Blob.h"
#include "DiscIO/ScrubbedBlob.h" #include "DiscIO/ScrubbedBlob.h"
#include "DiscIO/WIABlob.h" #include "DiscIO/WIABlob.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/ParallelProgressDialog.h" #include "DolphinQt/QtUtils/ParallelProgressDialog.h"
#include "UICommon/GameFile.h" #include "UICommon/GameFile.h"
@ -374,7 +374,7 @@ void ConvertDialog::Convert()
if (m_files.size() > 1) if (m_files.size() > 1)
{ {
dst_dir = QFileDialog::getExistingDirectory( dst_dir = DolphinFileDialog::getExistingDirectory(
this, tr("Select where you want to save the converted images"), this, tr("Select where you want to save the converted images"),
QFileInfo(QString::fromStdString(m_files[0]->GetFilePath())).dir().absolutePath()); QFileInfo(QString::fromStdString(m_files[0]->GetFilePath())).dir().absolutePath());
@ -383,7 +383,7 @@ void ConvertDialog::Convert()
} }
else else
{ {
dst_path = QFileDialog::getSaveFileName( dst_path = DolphinFileDialog::getSaveFileName(
this, tr("Select where you want to save the converted image"), this, tr("Select where you want to save the converted image"),
QFileInfo(QString::fromStdString(m_files[0]->GetFilePath())) QFileInfo(QString::fromStdString(m_files[0]->GetFilePath()))
.dir() .dir()

View File

@ -164,6 +164,7 @@
<ClCompile Include="NKitWarningDialog.cpp" /> <ClCompile Include="NKitWarningDialog.cpp" />
<ClCompile Include="QtUtils\AspectRatioWidget.cpp" /> <ClCompile Include="QtUtils\AspectRatioWidget.cpp" />
<ClCompile Include="QtUtils\BlockUserInputFilter.cpp" /> <ClCompile Include="QtUtils\BlockUserInputFilter.cpp" />
<ClCompile Include="QtUtils\DolphinFileDialog.cpp" />
<ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" /> <ClCompile Include="QtUtils\DoubleClickEventFilter.cpp" />
<ClCompile Include="QtUtils\ElidedButton.cpp" /> <ClCompile Include="QtUtils\ElidedButton.cpp" />
<ClCompile Include="QtUtils\FileOpenEventFilter.cpp" /> <ClCompile Include="QtUtils\FileOpenEventFilter.cpp" />
@ -217,6 +218,7 @@
<ClInclude Include="Debugger\RegisterColumn.h" /> <ClInclude Include="Debugger\RegisterColumn.h" />
<ClInclude Include="GBAHost.h" /> <ClInclude Include="GBAHost.h" />
<ClInclude Include="QtUtils\ActionHelper.h" /> <ClInclude Include="QtUtils\ActionHelper.h" />
<ClInclude Include="QtUtils\DolphinFileDialog.h" />
<ClInclude Include="QtUtils\FlowLayout.h" /> <ClInclude Include="QtUtils\FlowLayout.h" />
<ClInclude Include="QtUtils\ImageConverter.h" /> <ClInclude Include="QtUtils\ImageConverter.h" />
<ClInclude Include="QtUtils\ModalMessageBox.h" /> <ClInclude Include="QtUtils\ModalMessageBox.h" />

View File

@ -6,7 +6,6 @@
#include <QCheckBox> #include <QCheckBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QEvent> #include <QEvent>
#include <QFileDialog>
#include <QGroupBox> #include <QGroupBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QIcon> #include <QIcon>
@ -27,6 +26,7 @@
#include "Core/FifoPlayer/FifoRecorder.h" #include "Core/FifoPlayer/FifoRecorder.h"
#include "DolphinQt/FIFO/FIFOAnalyzer.h" #include "DolphinQt/FIFO/FIFOAnalyzer.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/QueueOnObject.h" #include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
@ -189,8 +189,8 @@ void FIFOPlayerWindow::ConnectWidgets()
void FIFOPlayerWindow::LoadRecording() void FIFOPlayerWindow::LoadRecording()
{ {
QString path = QFileDialog::getOpenFileName(this, tr("Open FIFO log"), QString(), QString path = DolphinFileDialog::getOpenFileName(this, tr("Open FIFO log"), QString(),
tr("Dolphin FIFO Log (*.dff)")); tr("Dolphin FIFO Log (*.dff)"));
if (path.isEmpty()) if (path.isEmpty())
return; return;
@ -200,8 +200,8 @@ void FIFOPlayerWindow::LoadRecording()
void FIFOPlayerWindow::SaveRecording() void FIFOPlayerWindow::SaveRecording()
{ {
QString path = QFileDialog::getSaveFileName(this, tr("Save FIFO log"), QString(), QString path = DolphinFileDialog::getSaveFileName(this, tr("Save FIFO log"), QString(),
tr("Dolphin FIFO Log (*.dff)")); tr("Dolphin FIFO Log (*.dff)"));
if (path.isEmpty()) if (path.isEmpty())
return; return;

View File

@ -26,6 +26,7 @@
#include "Core/HW/SI/SI_Device.h" #include "Core/HW/SI/SI_Device.h"
#include "Core/Movie.h" #include "Core/Movie.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/Resources.h" #include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
@ -183,7 +184,7 @@ void GBAWidget::UnloadROM()
void GBAWidget::PromptForEReaderCards() void GBAWidget::PromptForEReaderCards()
{ {
const QStringList card_paths = QFileDialog::getOpenFileNames( const QStringList card_paths = DolphinFileDialog::getOpenFileNames(
this, tr("Select e-Reader Cards"), QString(), tr("e-Reader Cards (*.raw);;All Files (*)"), this, tr("Select e-Reader Cards"), QString(), tr("e-Reader Cards (*.raw);;All Files (*)"),
nullptr, QFileDialog::Options()); nullptr, QFileDialog::Options());
@ -205,9 +206,10 @@ void GBAWidget::DoState(bool export_state)
return; return;
QString state_path = QDir::toNativeSeparators( QString state_path = QDir::toNativeSeparators(
(export_state ? QFileDialog::getSaveFileName : QFileDialog::getOpenFileName)( (export_state ? DolphinFileDialog::getSaveFileName : DolphinFileDialog::getOpenFileName)(
this, tr("Select a File"), QString(), this, tr("Select a File"), QString(),
tr("mGBA Save States (*.ss0 *.ss1 *.ss2 *.ss3 *.ss4 *.ss5 *.ss6 *.ss7 *.ss8 *.ss9);;" tr("mGBA Save States (*.ss0 *.ss1 *.ss2 *.ss3 *.ss4 "
"*.ss5 *.ss6 *.ss7 *.ss8 *.ss9);;"
"All Files (*)"), "All Files (*)"),
nullptr, QFileDialog::Options())); nullptr, QFileDialog::Options()));

View File

@ -5,7 +5,6 @@
#include <QComboBox> #include <QComboBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFileDialog>
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
@ -19,6 +18,8 @@
#include "Core/HW/GCMemcard/GCMemcard.h" #include "Core/HW/GCMemcard/GCMemcard.h"
#include "Core/HW/Sram.h" #include "Core/HW/Sram.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
GCMemcardCreateNewDialog::GCMemcardCreateNewDialog(QWidget* parent) : QDialog(parent) GCMemcardCreateNewDialog::GCMemcardCreateNewDialog(QWidget* parent) : QDialog(parent)
{ {
m_combobox_size = new QComboBox(); m_combobox_size = new QComboBox();
@ -69,7 +70,7 @@ bool GCMemcardCreateNewDialog::CreateCard()
const u16 size = static_cast<u16>(m_combobox_size->currentData().toInt()); const u16 size = static_cast<u16>(m_combobox_size->currentData().toInt());
const bool is_shift_jis = m_radio_shiftjis->isChecked(); const bool is_shift_jis = m_radio_shiftjis->isChecked();
const QString path = QFileDialog::getSaveFileName( const QString path = DolphinFileDialog::getSaveFileName(
this, tr("Create New Memory Card"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)), this, tr("Create New Memory Card"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
tr("GameCube Memory Cards (*.raw *.gcp)") + QStringLiteral(";;") + tr("All Files (*)")); tr("GameCube Memory Cards (*.raw *.gcp)") + QStringLiteral(";;") + tr("All Files (*)"));

View File

@ -11,7 +11,6 @@
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QDir> #include <QDir>
#include <QFileDialog>
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QHeaderView> #include <QHeaderView>
@ -40,6 +39,7 @@
#include "Core/HW/GCMemcard/GCMemcardUtils.h" #include "Core/HW/GCMemcard/GCMemcardUtils.h"
#include "DolphinQt/GCMemcardCreateNewDialog.h" #include "DolphinQt/GCMemcardCreateNewDialog.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
constexpr int ROW_HEIGHT = 36; constexpr int ROW_HEIGHT = 36;
@ -339,7 +339,7 @@ void GCMemcardManager::SetSlotFile(int slot, QString path)
void GCMemcardManager::SetSlotFileInteractive(int slot) void GCMemcardManager::SetSlotFileInteractive(int slot)
{ {
QString path = QDir::toNativeSeparators(QFileDialog::getOpenFileName( QString path = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
this, this,
slot == 0 ? tr("Set memory card file for Slot A") : tr("Set memory card file for Slot B"), slot == 0 ? tr("Set memory card file for Slot A") : tr("Set memory card file for Slot B"),
QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
@ -418,7 +418,7 @@ void GCMemcardManager::ExportFiles(Memcard::SavefileFormat format)
const QString qformatdesc = GetFormatDescription(format); const QString qformatdesc = GetFormatDescription(format);
const std::string default_path = const std::string default_path =
fmt::format("{}/{}{}", File::GetUserPath(D_GCUSER_IDX), basename, extension); fmt::format("{}/{}{}", File::GetUserPath(D_GCUSER_IDX), basename, extension);
const QString qfilename = QFileDialog::getSaveFileName( const QString qfilename = DolphinFileDialog::getSaveFileName(
this, tr("Export Save File"), QString::fromStdString(default_path), this, tr("Export Save File"), QString::fromStdString(default_path),
QStringLiteral("%1 (*%2);;%3 (*)") QStringLiteral("%1 (*%2);;%3 (*)")
.arg(qformatdesc, QString::fromStdString(extension), tr("All Files"))); .arg(qformatdesc, QString::fromStdString(extension), tr("All Files")));
@ -435,9 +435,9 @@ void GCMemcardManager::ExportFiles(Memcard::SavefileFormat format)
return; return;
} }
const QString qdirpath = const QString qdirpath = DolphinFileDialog::getExistingDirectory(
QFileDialog::getExistingDirectory(this, QObject::tr("Export Save Files"), this, QObject::tr("Export Save Files"),
QString::fromStdString(File::GetUserPath(D_GCUSER_IDX))); QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)));
if (qdirpath.isEmpty()) if (qdirpath.isEmpty())
return; return;
@ -567,7 +567,7 @@ void GCMemcardManager::ImportFile()
if (!card) if (!card)
return; return;
const QStringList paths = QFileDialog::getOpenFileNames( const QStringList paths = DolphinFileDialog::getOpenFileNames(
this, tr("Import Save File(s)"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)), this, tr("Import Save File(s)"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
QStringLiteral("%1 (*.gci *.gcs *.sav);;%2 (*.gci);;%3 (*.gcs);;%4 (*.sav);;%5 (*)") QStringLiteral("%1 (*.gci *.gcs *.sav);;%2 (*.gci);;%3 (*.gcs);;%4 (*.sav);;%5 (*)")
.arg(tr("Supported file formats"), GetFormatDescription(Memcard::SavefileFormat::GCI), .arg(tr("Supported file formats"), GetFormatDescription(Memcard::SavefileFormat::GCI),

View File

@ -59,6 +59,7 @@
#include "DolphinQt/GameList/GridProxyModel.h" #include "DolphinQt/GameList/GridProxyModel.h"
#include "DolphinQt/GameList/ListProxyModel.h" #include "DolphinQt/GameList/ListProxyModel.h"
#include "DolphinQt/MenuBar.h" #include "DolphinQt/MenuBar.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/DoubleClickEventFilter.h" #include "DolphinQt/QtUtils/DoubleClickEventFilter.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/ParallelProgressDialog.h" #include "DolphinQt/QtUtils/ParallelProgressDialog.h"
@ -254,7 +255,7 @@ void GameList::MakeEmptyView()
m_empty->installEventFilter(event_filter); m_empty->installEventFilter(event_filter);
connect(event_filter, &DoubleClickEventFilter::doubleClicked, [this] { connect(event_filter, &DoubleClickEventFilter::doubleClicked, [this] {
auto current_dir = QDir::currentPath(); auto current_dir = QDir::currentPath();
auto dir = QFileDialog::getExistingDirectory(this, tr("Select a Directory"), current_dir); auto dir = DolphinFileDialog::getExistingDirectory(this, tr("Select a Directory"), current_dir);
if (!dir.isEmpty()) if (!dir.isEmpty())
Settings::Instance().AddPath(dir); Settings::Instance().AddPath(dir);
}); });
@ -489,7 +490,7 @@ void GameList::OpenProperties()
void GameList::ExportWiiSave() void GameList::ExportWiiSave()
{ {
const QString export_dir = QFileDialog::getExistingDirectory( const QString export_dir = DolphinFileDialog::getExistingDirectory(
this, tr("Select Export Directory"), QString::fromStdString(File::GetUserPath(D_USER_IDX)), this, tr("Select Export Directory"), QString::fromStdString(File::GetUserPath(D_USER_IDX)),
QFileDialog::ShowDirsOnly); QFileDialog::ShowDirsOnly);
if (export_dir.isEmpty()) if (export_dir.isEmpty())

View File

@ -7,7 +7,6 @@
#include <QDir> #include <QDir>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDropEvent> #include <QDropEvent>
#include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QIcon> #include <QIcon>
#include <QMimeData> #include <QMimeData>
@ -91,6 +90,7 @@
#include "DolphinQt/NetPlay/NetPlayBrowser.h" #include "DolphinQt/NetPlay/NetPlayBrowser.h"
#include "DolphinQt/NetPlay/NetPlayDialog.h" #include "DolphinQt/NetPlay/NetPlayDialog.h"
#include "DolphinQt/NetPlay/NetPlaySetupDialog.h" #include "DolphinQt/NetPlay/NetPlaySetupDialog.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/FileOpenEventFilter.h" #include "DolphinQt/QtUtils/FileOpenEventFilter.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/ParallelProgressDialog.h" #include "DolphinQt/QtUtils/ParallelProgressDialog.h"
@ -712,7 +712,7 @@ void MainWindow::RefreshGameList()
QStringList MainWindow::PromptFileNames() QStringList MainWindow::PromptFileNames()
{ {
auto& settings = Settings::Instance().GetQSettings(); auto& settings = Settings::Instance().GetQSettings();
QStringList paths = QFileDialog::getOpenFileNames( QStringList paths = DolphinFileDialog::getOpenFileNames(
this, tr("Select a File"), this, tr("Select a File"),
settings.value(QStringLiteral("mainwindow/lastdir"), QString{}).toString(), settings.value(QStringLiteral("mainwindow/lastdir"), QString{}).toString(),
tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wia *.rvz *.wad " tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wia *.rvz *.wad "
@ -1278,15 +1278,17 @@ void MainWindow::ShowFIFOPlayer()
void MainWindow::StateLoad() void MainWindow::StateLoad()
{ {
QString path = QFileDialog::getOpenFileName(this, tr("Select a File"), QDir::currentPath(), QString path =
tr("All Save States (*.sav *.s##);; All Files (*)")); DolphinFileDialog::getOpenFileName(this, tr("Select a File"), QDir::currentPath(),
tr("All Save States (*.sav *.s##);; All Files (*)"));
State::LoadAs(path.toStdString()); State::LoadAs(path.toStdString());
} }
void MainWindow::StateSave() void MainWindow::StateSave()
{ {
QString path = QFileDialog::getSaveFileName(this, tr("Select a File"), QDir::currentPath(), QString path =
tr("All Save States (*.sav *.s##);; All Files (*)")); DolphinFileDialog::getSaveFileName(this, tr("Select a File"), QDir::currentPath(),
tr("All Save States (*.sav *.s##);; All Files (*)"));
State::SaveAs(path.toStdString()); State::SaveAs(path.toStdString());
} }
@ -1612,9 +1614,10 @@ void MainWindow::OnImportNANDBackup()
if (response == QMessageBox::No) if (response == QMessageBox::No)
return; return;
QString file = QFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(), QString file =
tr("BootMii NAND backup file (*.bin);;" DolphinFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(),
"All Files (*)")); tr("BootMii NAND backup file (*.bin);;"
"All Files (*)"));
if (file.isEmpty()) if (file.isEmpty())
return; return;
@ -1637,10 +1640,10 @@ void MainWindow::OnImportNANDBackup()
}, },
[this] { [this] {
std::optional<std::string> keys_file = RunOnObject(this, [this] { std::optional<std::string> keys_file = RunOnObject(this, [this] {
return QFileDialog::getOpenFileName(this, tr("Select the keys file (OTP/SEEPROM dump)"), return DolphinFileDialog::getOpenFileName(
QDir::currentPath(), this, tr("Select the keys file (OTP/SEEPROM dump)"), QDir::currentPath(),
tr("BootMii keys file (*.bin);;" tr("BootMii keys file (*.bin);;"
"All Files (*)")) "All Files (*)"))
.toStdString(); .toStdString();
}); });
if (keys_file) if (keys_file)
@ -1659,8 +1662,8 @@ void MainWindow::OnImportNANDBackup()
void MainWindow::OnPlayRecording() void MainWindow::OnPlayRecording()
{ {
QString dtm_file = QFileDialog::getOpenFileName(this, tr("Select the Recording File to Play"), QString dtm_file = DolphinFileDialog::getOpenFileName(
QString(), tr("Dolphin TAS Movies (*.dtm)")); this, tr("Select the Recording File to Play"), QString(), tr("Dolphin TAS Movies (*.dtm)"));
if (dtm_file.isEmpty()) if (dtm_file.isEmpty())
return; return;
@ -1729,8 +1732,8 @@ void MainWindow::OnStopRecording()
void MainWindow::OnExportRecording() void MainWindow::OnExportRecording()
{ {
Core::RunAsCPUThread([this] { Core::RunAsCPUThread([this] {
QString dtm_file = QFileDialog::getSaveFileName(this, tr("Save Recording File As"), QString(), QString dtm_file = DolphinFileDialog::getSaveFileName(
tr("Dolphin TAS Movies (*.dtm)")); this, tr("Save Recording File As"), QString(), tr("Dolphin TAS Movies (*.dtm)"));
if (!dtm_file.isEmpty()) if (!dtm_file.isEmpty())
Movie::SaveRecording(dtm_file.toStdString()); Movie::SaveRecording(dtm_file.toStdString());
}); });

View File

@ -51,6 +51,7 @@
#include "DolphinQt/AboutDialog.h" #include "DolphinQt/AboutDialog.h"
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/ParallelProgressDialog.h" #include "DolphinQt/QtUtils/ParallelProgressDialog.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
@ -1029,8 +1030,8 @@ void MenuBar::UpdateToolsMenu(bool emulation_started)
void MenuBar::InstallWAD() void MenuBar::InstallWAD()
{ {
QString wad_file = QFileDialog::getOpenFileName(this, tr("Select a title to install to NAND"), QString wad_file = DolphinFileDialog::getOpenFileName(
QString(), tr("WAD files (*.wad)")); this, tr("Select a title to install to NAND"), QString(), tr("WAD files (*.wad)"));
if (wad_file.isEmpty()) if (wad_file.isEmpty())
return; return;
@ -1049,9 +1050,10 @@ void MenuBar::InstallWAD()
void MenuBar::ImportWiiSave() void MenuBar::ImportWiiSave()
{ {
QString file = QFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(), QString file =
tr("Wii save files (*.bin);;" DolphinFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(),
"All Files (*)")); tr("Wii save files (*.bin);;"
"All Files (*)"));
if (file.isEmpty()) if (file.isEmpty())
return; return;
@ -1093,7 +1095,7 @@ void MenuBar::ImportWiiSave()
void MenuBar::ExportWiiSaves() void MenuBar::ExportWiiSaves()
{ {
const QString export_dir = QFileDialog::getExistingDirectory( const QString export_dir = DolphinFileDialog::getExistingDirectory(
this, tr("Select Export Directory"), QString::fromStdString(File::GetUserPath(D_USER_IDX)), this, tr("Select Export Directory"), QString::fromStdString(File::GetUserPath(D_USER_IDX)),
QFileDialog::ShowDirsOnly); QFileDialog::ShowDirsOnly);
if (export_dir.isEmpty()) if (export_dir.isEmpty())
@ -1482,7 +1484,7 @@ void MenuBar::SaveSymbolMap()
void MenuBar::LoadOtherSymbolMap() void MenuBar::LoadOtherSymbolMap()
{ {
const QString file = QFileDialog::getOpenFileName( const QString file = DolphinFileDialog::getOpenFileName(
this, tr("Load map file"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX)), this, tr("Load map file"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX)),
tr("Dolphin Map File (*.map)")); tr("Dolphin Map File (*.map)"));
@ -1498,7 +1500,7 @@ void MenuBar::LoadOtherSymbolMap()
void MenuBar::LoadBadSymbolMap() void MenuBar::LoadBadSymbolMap()
{ {
const QString file = QFileDialog::getOpenFileName( const QString file = DolphinFileDialog::getOpenFileName(
this, tr("Load map file"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX)), this, tr("Load map file"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX)),
tr("Dolphin Map File (*.map)")); tr("Dolphin Map File (*.map)"));
@ -1515,7 +1517,7 @@ void MenuBar::LoadBadSymbolMap()
void MenuBar::SaveSymbolMapAs() void MenuBar::SaveSymbolMapAs()
{ {
const std::string& title_id_str = SConfig::GetInstance().m_debugger_game_id; const std::string& title_id_str = SConfig::GetInstance().m_debugger_game_id;
const QString file = QFileDialog::getSaveFileName( const QString file = DolphinFileDialog::getSaveFileName(
this, tr("Save map file"), this, tr("Save map file"),
QString::fromStdString(File::GetUserPath(D_MAPS_IDX) + "/" + title_id_str + ".map"), QString::fromStdString(File::GetUserPath(D_MAPS_IDX) + "/" + title_id_str + ".map"),
tr("Dolphin Map File (*.map)")); tr("Dolphin Map File (*.map)"));
@ -1568,8 +1570,8 @@ void MenuBar::CreateSignatureFile()
this, tr("Input"), tr("Only export symbols with prefix:\n(Blank for all symbols)"), this, tr("Input"), tr("Only export symbols with prefix:\n(Blank for all symbols)"),
QLineEdit::Normal, QString{}, nullptr, Qt::WindowCloseButtonHint); QLineEdit::Normal, QString{}, nullptr, Qt::WindowCloseButtonHint);
const QString file = QFileDialog::getSaveFileName(this, tr("Save signature file"), const QString file = DolphinFileDialog::getSaveFileName(this, tr("Save signature file"),
QDir::homePath(), GetSignatureSelector()); QDir::homePath(), GetSignatureSelector());
if (file.isEmpty()) if (file.isEmpty())
return; return;
@ -1593,8 +1595,8 @@ void MenuBar::AppendSignatureFile()
this, tr("Input"), tr("Only append symbols with prefix:\n(Blank for all symbols)"), this, tr("Input"), tr("Only append symbols with prefix:\n(Blank for all symbols)"),
QLineEdit::Normal, QString{}, nullptr, Qt::WindowCloseButtonHint); QLineEdit::Normal, QString{}, nullptr, Qt::WindowCloseButtonHint);
const QString file = QFileDialog::getSaveFileName(this, tr("Append signature to"), const QString file = DolphinFileDialog::getSaveFileName(this, tr("Append signature to"),
QDir::homePath(), GetSignatureSelector()); QDir::homePath(), GetSignatureSelector());
if (file.isEmpty()) if (file.isEmpty())
return; return;
@ -1616,8 +1618,8 @@ void MenuBar::AppendSignatureFile()
void MenuBar::ApplySignatureFile() void MenuBar::ApplySignatureFile()
{ {
const QString file = QFileDialog::getOpenFileName(this, tr("Apply signature file"), const QString file = DolphinFileDialog::getOpenFileName(this, tr("Apply signature file"),
QDir::homePath(), GetSignatureSelector()); QDir::homePath(), GetSignatureSelector());
if (file.isEmpty()) if (file.isEmpty())
return; return;
@ -1633,18 +1635,18 @@ void MenuBar::ApplySignatureFile()
void MenuBar::CombineSignatureFiles() void MenuBar::CombineSignatureFiles()
{ {
const QString priorityFile = QFileDialog::getOpenFileName( const QString priorityFile = DolphinFileDialog::getOpenFileName(
this, tr("Choose priority input file"), QDir::homePath(), GetSignatureSelector()); this, tr("Choose priority input file"), QDir::homePath(), GetSignatureSelector());
if (priorityFile.isEmpty()) if (priorityFile.isEmpty())
return; return;
const QString secondaryFile = QFileDialog::getOpenFileName( const QString secondaryFile = DolphinFileDialog::getOpenFileName(
this, tr("Choose secondary input file"), QDir::homePath(), GetSignatureSelector()); this, tr("Choose secondary input file"), QDir::homePath(), GetSignatureSelector());
if (secondaryFile.isEmpty()) if (secondaryFile.isEmpty())
return; return;
const QString saveFile = QFileDialog::getSaveFileName(this, tr("Save combined output file as"), const QString saveFile = DolphinFileDialog::getSaveFileName(
QDir::homePath(), GetSignatureSelector()); this, tr("Save combined output file as"), QDir::homePath(), GetSignatureSelector());
if (saveFile.isEmpty()) if (saveFile.isEmpty())
return; return;

View File

@ -0,0 +1,39 @@
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinFileDialog.h"
#include <QFileDialog>
#include <QObject>
QString DolphinFileDialog::getExistingDirectory(QWidget* parent, const QString& caption,
const QString& dir, QFileDialog::Options options)
{
const HotkeyDisabler disabler;
return QFileDialog::getExistingDirectory(parent, caption, dir, options);
}
QString DolphinFileDialog::getSaveFileName(QWidget* parent, const QString& caption,
const QString& dir, const QString& filter,
QString* selectedFilter, QFileDialog::Options options)
{
const HotkeyDisabler disabler;
return QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options);
}
QString DolphinFileDialog::getOpenFileName(QWidget* parent, const QString& caption,
const QString& dir, const QString& filter,
QString* selectedFilter, QFileDialog::Options options)
{
const HotkeyDisabler disabler;
return QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options);
}
QStringList DolphinFileDialog::getOpenFileNames(QWidget* parent, const QString& caption,
const QString& dir, const QString& filter,
QString* selectedFilter,
QFileDialog::Options options)
{
const HotkeyDisabler disabler;
return QFileDialog::getOpenFileNames(parent, caption, dir, filter, selectedFilter, options);
}

View File

@ -0,0 +1,40 @@
// Copyright 2021 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "Core/HotkeyManager.h"
#include <QFileDialog>
#include <QObject>
#include <QString>
namespace DolphinFileDialog
{
class HotkeyDisabler final
{
public:
HotkeyDisabler() { HotkeyManagerEmu::Enable(false); }
~HotkeyDisabler() { HotkeyManagerEmu::Enable(true); }
};
QString getExistingDirectory(QWidget* parent = nullptr, const QString& caption = QString(),
const QString& dir = QString(),
QFileDialog::Options options = QFileDialog::ShowDirsOnly);
QString getOpenFileName(QWidget* parent = nullptr, const QString& caption = QString(),
const QString& dir = QString(), const QString& filter = QString(),
QString* selectedFilter = nullptr,
QFileDialog::Options options = QFileDialog::Options());
QStringList getOpenFileNames(QWidget* parent = nullptr, const QString& caption = QString(),
const QString& dir = QString(), const QString& filter = QString(),
QString* selectedFilter = nullptr,
QFileDialog::Options options = QFileDialog::Options());
QString getSaveFileName(QWidget* parent = nullptr, const QString& caption = QString(),
const QString& dir = QString(), const QString& filter = QString(),
QString* selectedFilter = nullptr,
QFileDialog::Options options = QFileDialog::Options());
} // namespace DolphinFileDialog

View File

@ -32,6 +32,7 @@
#include "DolphinQt/Config/Mapping/MappingWindow.h" #include "DolphinQt/Config/Mapping/MappingWindow.h"
#include "DolphinQt/GCMemcardManager.h" #include "DolphinQt/GCMemcardManager.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
#include "DolphinQt/Settings/BroadbandAdapterSettingsDialog.h" #include "DolphinQt/Settings/BroadbandAdapterSettingsDialog.h"
@ -292,7 +293,7 @@ void GameCubePane::OnConfigPressed(int slot)
qFatal("unknown settings pressed"); qFatal("unknown settings pressed");
} }
QString filename = QFileDialog::getSaveFileName( QString filename = DolphinFileDialog::getSaveFileName(
this, tr("Choose a file to open"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)), this, tr("Choose a file to open"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
filter, 0, QFileDialog::DontConfirmOverwrite); filter, 0, QFileDialog::DontConfirmOverwrite);
@ -390,7 +391,7 @@ void GameCubePane::OnConfigPressed(int slot)
void GameCubePane::BrowseGBABios() void GameCubePane::BrowseGBABios()
{ {
QString file = QDir::toNativeSeparators(QFileDialog::getOpenFileName( QString file = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
this, tr("Select GBA BIOS"), QString::fromStdString(File::GetUserPath(F_GBABIOS_IDX)), this, tr("Select GBA BIOS"), QString::fromStdString(File::GetUserPath(F_GBABIOS_IDX)),
tr("All Files (*)"))); tr("All Files (*)")));
if (!file.isEmpty()) if (!file.isEmpty())
@ -419,9 +420,9 @@ void GameCubePane::SaveRomPathChanged()
void GameCubePane::BrowseGBASaves() void GameCubePane::BrowseGBASaves()
{ {
QString dir = QDir::toNativeSeparators( QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
QFileDialog::getExistingDirectory(this, tr("Select GBA Saves Path"), this, tr("Select GBA Saves Path"),
QString::fromStdString(File::GetUserPath(D_GBASAVES_IDX)))); QString::fromStdString(File::GetUserPath(D_GBASAVES_IDX))));
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
m_gba_saves_edit->setText(dir); m_gba_saves_edit->setText(dir);
@ -547,7 +548,7 @@ std::string GameCubePane::GetOpenGBARom(std::string_view title)
if (!title.empty()) if (!title.empty())
caption += QStringLiteral(": %1").arg(QString::fromStdString(std::string(title))); caption += QStringLiteral(": %1").arg(QString::fromStdString(std::string(title)));
return QDir::toNativeSeparators( return QDir::toNativeSeparators(
QFileDialog::getOpenFileName( DolphinFileDialog::getOpenFileName(
nullptr, caption, QString(), nullptr, caption, QString(),
tr("Game Boy Advance ROMs (*.gba *.gbc *.gb *.7z *.zip *.agb *.mb *.rom *.bin);;" tr("Game Boy Advance ROMs (*.gba *.gbc *.gb *.7z *.zip *.agb *.mb *.rom *.bin);;"
"All Files (*)"))) "All Files (*)")))

View File

@ -3,7 +3,6 @@
#include <QCheckBox> #include <QCheckBox>
#include <QDir> #include <QDir>
#include <QFileDialog>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
@ -17,6 +16,7 @@
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
#include "Core/Config/UISettings.h" #include "Core/Config/UISettings.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
#include "DolphinQt/Settings/PathPane.h" #include "DolphinQt/Settings/PathPane.h"
@ -34,17 +34,17 @@ PathPane::PathPane(QWidget* parent) : QWidget(parent)
void PathPane::Browse() void PathPane::Browse()
{ {
QString dir = QDir::toNativeSeparators( QString dir = QDir::toNativeSeparators(
QFileDialog::getExistingDirectory(this, tr("Select a Directory"), QDir::currentPath())); DolphinFileDialog::getExistingDirectory(this, tr("Select a Directory"), QDir::currentPath()));
if (!dir.isEmpty()) if (!dir.isEmpty())
Settings::Instance().AddPath(dir); Settings::Instance().AddPath(dir);
} }
void PathPane::BrowseDefaultGame() void PathPane::BrowseDefaultGame()
{ {
QString file = QDir::toNativeSeparators( QString file = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
QFileDialog::getOpenFileName(this, tr("Select a Game"), Settings::Instance().GetDefaultGame(), this, tr("Select a Game"), Settings::Instance().GetDefaultGame(),
tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs " tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs "
"*.ciso *.gcz *.wia *.rvz *.wad *.m3u);;All Files (*)"))); "*.ciso *.gcz *.wia *.rvz *.wad *.m3u);;All Files (*)")));
if (!file.isEmpty()) if (!file.isEmpty())
Settings::Instance().SetDefaultGame(file); Settings::Instance().SetDefaultGame(file);
@ -52,7 +52,7 @@ void PathPane::BrowseDefaultGame()
void PathPane::BrowseWiiNAND() void PathPane::BrowseWiiNAND()
{ {
QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory( QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
this, tr("Select Wii NAND Root"), QString::fromStdString(Config::Get(Config::MAIN_FS_PATH)))); this, tr("Select Wii NAND Root"), QString::fromStdString(Config::Get(Config::MAIN_FS_PATH))));
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
@ -63,7 +63,7 @@ void PathPane::BrowseWiiNAND()
void PathPane::BrowseDump() void PathPane::BrowseDump()
{ {
QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory( QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
this, tr("Select Dump Path"), QString::fromStdString(Config::Get(Config::MAIN_DUMP_PATH)))); this, tr("Select Dump Path"), QString::fromStdString(Config::Get(Config::MAIN_DUMP_PATH))));
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
@ -74,7 +74,7 @@ void PathPane::BrowseDump()
void PathPane::BrowseLoad() void PathPane::BrowseLoad()
{ {
QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory( QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
this, tr("Select Load Path"), QString::fromStdString(Config::Get(Config::MAIN_LOAD_PATH)))); this, tr("Select Load Path"), QString::fromStdString(Config::Get(Config::MAIN_LOAD_PATH))));
if (!dir.isEmpty()) if (!dir.isEmpty())
{ {
@ -85,7 +85,7 @@ void PathPane::BrowseLoad()
void PathPane::BrowseResourcePack() void PathPane::BrowseResourcePack()
{ {
QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory( QString dir = QDir::toNativeSeparators(DolphinFileDialog::getExistingDirectory(
this, tr("Select Resource Pack Path"), this, tr("Select Resource Pack Path"),
QString::fromStdString(Config::Get(Config::MAIN_RESOURCEPACK_PATH)))); QString::fromStdString(Config::Get(Config::MAIN_RESOURCEPACK_PATH))));
if (!dir.isEmpty()) if (!dir.isEmpty())
@ -97,7 +97,7 @@ void PathPane::BrowseResourcePack()
void PathPane::BrowseSDCard() void PathPane::BrowseSDCard()
{ {
QString file = QDir::toNativeSeparators(QFileDialog::getOpenFileName( QString file = QDir::toNativeSeparators(DolphinFileDialog::getOpenFileName(
this, tr("Select a SD Card Image"), QString::fromStdString(Config::Get(Config::MAIN_SD_PATH)), this, tr("Select a SD Card Image"), QString::fromStdString(Config::Get(Config::MAIN_SD_PATH)),
tr("SD Card Image (*.raw);;" tr("SD Card Image (*.raw);;"
"All Files (*)"))); "All Files (*)")));