Merge pull request #918 from abcdjdj/open-recent
Add option to open recent files
This commit is contained in:
commit
162a0f4fb6
|
@ -72,6 +72,8 @@ char MicWavPath[1024];
|
|||
|
||||
char LastROMFolder[1024];
|
||||
|
||||
char RecentROMList[10][1024];
|
||||
|
||||
int EnableCheats;
|
||||
|
||||
bool EnableJIT;
|
||||
|
@ -166,6 +168,17 @@ ConfigEntry PlatformConfigFile[] =
|
|||
|
||||
{"LastROMFolder", 1, LastROMFolder, 0, "", 1023},
|
||||
|
||||
{"RecentROM_0", 1, RecentROMList[0], 0, "", 1023},
|
||||
{"RecentROM_1", 1, RecentROMList[1], 0, "", 1023},
|
||||
{"RecentROM_2", 1, RecentROMList[2], 0, "", 1023},
|
||||
{"RecentROM_3", 1, RecentROMList[3], 0, "", 1023},
|
||||
{"RecentROM_4", 1, RecentROMList[4], 0, "", 1023},
|
||||
{"RecentROM_5", 1, RecentROMList[5], 0, "", 1023},
|
||||
{"RecentROM_6", 1, RecentROMList[6], 0, "", 1023},
|
||||
{"RecentROM_7", 1, RecentROMList[7], 0, "", 1023},
|
||||
{"RecentROM_8", 1, RecentROMList[8], 0, "", 1023},
|
||||
{"RecentROM_9", 1, RecentROMList[9], 0, "", 1023},
|
||||
|
||||
{"EnableCheats", 0, &EnableCheats, 0, NULL, 0},
|
||||
|
||||
{"", -1, NULL, 0, NULL, 0}
|
||||
|
|
|
@ -86,6 +86,8 @@ extern char MicWavPath[1024];
|
|||
|
||||
extern char LastROMFolder[1024];
|
||||
|
||||
extern char RecentROMList[10][1024];
|
||||
|
||||
extern int EnableCheats;
|
||||
|
||||
}
|
||||
|
|
|
@ -1013,6 +1013,14 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||
actOpenROM = menu->addAction("Open ROM...");
|
||||
connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile);
|
||||
|
||||
recentMenu = menu->addMenu("Open Recent");
|
||||
for(int i = 0; i < 10; ++i)
|
||||
{
|
||||
if(strlen(Config::RecentROMList[i]) > 0)
|
||||
recentFileList.push_back(Config::RecentROMList[i]);
|
||||
}
|
||||
updateRecentFilesMenu();
|
||||
|
||||
//actBootFirmware = menu->addAction("Launch DS menu");
|
||||
actBootFirmware = menu->addAction("Boot firmware");
|
||||
connect(actBootFirmware, &QAction::triggered, this, &MainWindow::onBootFirmware);
|
||||
|
@ -1441,20 +1449,11 @@ QString MainWindow::loadErrorStr(int error)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::onOpenFile()
|
||||
void MainWindow::loadROM(QString filename)
|
||||
{
|
||||
emuThread->emuPause();
|
||||
|
||||
QString filename = QFileDialog::getOpenFileName(this,
|
||||
"Open ROM",
|
||||
Config::LastROMFolder,
|
||||
"DS ROMs (*.nds *.dsi *.srl);;GBA ROMs (*.gba);;Any file (*.*)");
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
emuThread->emuUnpause();
|
||||
return;
|
||||
}
|
||||
recentFileList.removeAll(filename);
|
||||
recentFileList.prepend(filename);
|
||||
updateRecentFilesMenu();
|
||||
|
||||
// TODO: validate the input file!!
|
||||
// * check that it is a proper ROM
|
||||
|
@ -1501,6 +1500,60 @@ void MainWindow::onOpenFile()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::onOpenFile()
|
||||
{
|
||||
emuThread->emuPause();
|
||||
|
||||
QString filename = QFileDialog::getOpenFileName(this,
|
||||
"Open ROM",
|
||||
Config::LastROMFolder,
|
||||
"DS ROMs (*.nds *.dsi *.srl);;GBA ROMs (*.gba);;Any file (*.*)");
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
emuThread->emuUnpause();
|
||||
return;
|
||||
}
|
||||
|
||||
loadROM(filename);
|
||||
}
|
||||
|
||||
void MainWindow::onClearRecentFiles()
|
||||
{
|
||||
recentFileList.clear();
|
||||
memset(Config::RecentROMList, 0, 10 * 1024);
|
||||
updateRecentFilesMenu();
|
||||
}
|
||||
|
||||
void MainWindow::updateRecentFilesMenu()
|
||||
{
|
||||
recentMenu->clear();
|
||||
|
||||
for(int i = 0; i < recentFileList.size(); ++i)
|
||||
{
|
||||
QAction *actRecentFile_i = recentMenu->addAction(QString("%1. %2").arg(i+1).arg(recentFileList.at(i)));
|
||||
actRecentFile_i->setData(recentFileList.at(i));
|
||||
connect(actRecentFile_i, &QAction::triggered, this, &MainWindow::onClickRecentFile);
|
||||
|
||||
if(i < 10)
|
||||
strncpy(Config::RecentROMList[i], recentFileList.at(i).toStdString().c_str(), 1024);
|
||||
}
|
||||
|
||||
QAction *actClearRecentList = recentMenu->addAction("Clear");
|
||||
connect(actClearRecentList, &QAction::triggered, this, &MainWindow::onClearRecentFiles);
|
||||
|
||||
if(recentFileList.empty())
|
||||
actClearRecentList->setEnabled(false);
|
||||
|
||||
Config::Save();
|
||||
}
|
||||
|
||||
void MainWindow::onClickRecentFile()
|
||||
{
|
||||
emuThread->emuPause();
|
||||
QAction *act = (QAction *)sender();
|
||||
loadROM(act->data().toString());
|
||||
}
|
||||
|
||||
void MainWindow::onBootFirmware()
|
||||
{
|
||||
// TODO: check the whole GBA cart shito
|
||||
|
|
|
@ -191,6 +191,8 @@ signals:
|
|||
|
||||
private slots:
|
||||
void onOpenFile();
|
||||
void onClickRecentFile();
|
||||
void onClearRecentFiles();
|
||||
void onBootFirmware();
|
||||
void onSaveState();
|
||||
void onLoadState();
|
||||
|
@ -236,6 +238,11 @@ private slots:
|
|||
void onFullscreenToggled();
|
||||
|
||||
private:
|
||||
QList<QString> recentFileList;
|
||||
QMenu *recentMenu;
|
||||
void updateRecentFilesMenu();
|
||||
void loadROM(QString filename);
|
||||
|
||||
void createScreenPanel();
|
||||
|
||||
QString loadErrorStr(int error);
|
||||
|
|
Loading…
Reference in New Issue