mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
GBA: Add import and export save options to context menu.
This commit is contained in:
@ -229,6 +229,36 @@ void GBAWidget::DoState(bool export_state)
|
||||
false);
|
||||
}
|
||||
|
||||
void GBAWidget::ImportExportSave(bool export_save)
|
||||
{
|
||||
if (!CanControlCore() && !export_save)
|
||||
return;
|
||||
if (!m_core_info.has_rom)
|
||||
return;
|
||||
|
||||
QString save_path = QDir::toNativeSeparators(
|
||||
(export_save ? DolphinFileDialog::getSaveFileName :
|
||||
DolphinFileDialog::getOpenFileName)(this, tr("Select a File"), QString(),
|
||||
tr("Save Game Files (*.sav);;"
|
||||
"All Files (*)"),
|
||||
nullptr, QFileDialog::Options()));
|
||||
|
||||
if (save_path.isEmpty())
|
||||
return;
|
||||
|
||||
Core::RunOnCPUThread(
|
||||
[export_save, core = m_core, save_path = save_path.toStdString()] {
|
||||
if (auto core_ptr = core.lock())
|
||||
{
|
||||
if (export_save)
|
||||
core_ptr->ExportSave(save_path);
|
||||
else
|
||||
core_ptr->ImportSave(save_path);
|
||||
}
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
void GBAWidget::Resize(int scale)
|
||||
{
|
||||
showNormal();
|
||||
@ -371,6 +401,14 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event)
|
||||
reset_action->setEnabled(CanResetCore());
|
||||
connect(reset_action, &QAction::triggered, this, &GBAWidget::ResetCore);
|
||||
|
||||
auto* savefile_menu = new QMenu(tr("Save Game"), menu);
|
||||
auto* save_import_action = new QAction(tr("&Import Save Game..."), savefile_menu);
|
||||
save_import_action->setEnabled(CanControlCore() && m_core_info.has_rom);
|
||||
connect(save_import_action, &QAction::triggered, this, [this] { ImportExportSave(false); });
|
||||
auto* save_export_action = new QAction(tr("&Export Save Game..."), savefile_menu);
|
||||
save_export_action->setEnabled(m_core_info.has_rom);
|
||||
connect(save_export_action, &QAction::triggered, this, [this] { ImportExportSave(true); });
|
||||
|
||||
auto* state_menu = new QMenu(tr("Save State"), menu);
|
||||
auto* import_action = new QAction(tr("&Import State..."), state_menu);
|
||||
import_action->setEnabled(CanControlCore());
|
||||
@ -418,12 +456,16 @@ void GBAWidget::contextMenuEvent(QContextMenuEvent* event)
|
||||
menu->addAction(card_action);
|
||||
menu->addAction(reset_action);
|
||||
menu->addSeparator();
|
||||
menu->addMenu(savefile_menu);
|
||||
menu->addMenu(state_menu);
|
||||
menu->addSeparator();
|
||||
menu->addAction(mute_action);
|
||||
menu->addSeparator();
|
||||
menu->addMenu(options_menu);
|
||||
|
||||
savefile_menu->addAction(save_import_action);
|
||||
savefile_menu->addAction(save_export_action);
|
||||
|
||||
state_menu->addAction(import_action);
|
||||
state_menu->addAction(export_state);
|
||||
|
||||
|
Reference in New Issue
Block a user