1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Implements 'Insert...' menu item.

This commit is contained in:
Thomas Harte 2020-06-26 18:25:56 -04:00
parent 21c41ed4cb
commit 387500f01a
2 changed files with 31 additions and 6 deletions

View File

@ -139,12 +139,16 @@ void MainWindow::createActions() {
// Add a separator and then an 'Insert...'.
fileMenu->addSeparator();
QAction *const insertAct = new QAction(tr("&Insert..."), this);
insertAct->setStatusTip(tr("Open an existing file"));
connect(insertAct, &QAction::triggered, this, [] {
// TODO.
insertAction = new QAction(tr("&Insert..."), this);
insertAction->setStatusTip(tr("Open an existing file"));
insertAction->setEnabled(false);
connect(insertAction, &QAction::triggered, this, [this] {
const QString fileName = getFilename("Insert...");
if(!fileName.isEmpty()) {
insertFile(fileName);
}
});
fileMenu->addAction(insertAct);
fileMenu->addAction(insertAction);
// Add Help menu, with an 'About...' option.
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
@ -178,6 +182,16 @@ QString MainWindow::getFilename(const char *title) {
return fileName;
}
void MainWindow::insertFile(const QString &fileName) {
if(!machine) return;
auto mediaTarget = machine->media_target();
if(!mediaTarget) return;
Analyser::Static::Media media = Analyser::Static::GetMedia(fileName.toStdString());
mediaTarget->insert_media(media);
}
void MainWindow::launchFile(const QString &fileName) {
targets = Analyser::Static::GetTargets(fileName.toStdString());
if(!targets.empty()) {
@ -299,6 +313,11 @@ void MainWindow::launchMachine() {
timer->startWithMachine(timedMachine, &machineMutex);
}
// If the machine can accept new media while running, enable
// the inert action.
if(machine->media_target()) {
insertAction->setEnabled(true);
}
} break;
case Machine::Error::MissingROM: {
@ -347,15 +366,18 @@ void MainWindow::dropEvent(QDropEvent* event) {
switch(uiPhase) {
case UIPhase::NoFileSelected: {
// Treat exactly as a File -> Open... .
// TODO: permit multiple files dropped at once.
const auto fileName = event->mimeData()->urls()[0].toLocalFile();
launchFile(fileName);
} break;
case UIPhase::RunningMachine: {
// Attempt to insert into the running machine.
const auto fileName = event->mimeData()->urls()[0].toLocalFile();
insertFile(fileName);
} break;
// TODO: permit multiple files dropped at once in both of the above cases.
case UIPhase::RequestingROMs: {
// Attempt to match up the dragged files to the requested ROM list;
// if and when they match, copy to a writeable QStandardPaths::AppDataLocation

View File

@ -82,6 +82,9 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
void start_zx80();
void start_zx81();
QAction *insertAction = nullptr;
void insertFile(const QString &fileName);
void launchFile(const QString &fileName);
void launchTarget(std::unique_ptr<Analyser::Static::Target> &&);