mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Implements 'Insert...' menu item.
This commit is contained in:
parent
21c41ed4cb
commit
387500f01a
@ -139,12 +139,16 @@ void MainWindow::createActions() {
|
|||||||
|
|
||||||
// Add a separator and then an 'Insert...'.
|
// Add a separator and then an 'Insert...'.
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
QAction *const insertAct = new QAction(tr("&Insert..."), this);
|
insertAction = new QAction(tr("&Insert..."), this);
|
||||||
insertAct->setStatusTip(tr("Open an existing file"));
|
insertAction->setStatusTip(tr("Open an existing file"));
|
||||||
connect(insertAct, &QAction::triggered, this, [] {
|
insertAction->setEnabled(false);
|
||||||
// TODO.
|
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.
|
// Add Help menu, with an 'About...' option.
|
||||||
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||||
@ -178,6 +182,16 @@ QString MainWindow::getFilename(const char *title) {
|
|||||||
return fileName;
|
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) {
|
void MainWindow::launchFile(const QString &fileName) {
|
||||||
targets = Analyser::Static::GetTargets(fileName.toStdString());
|
targets = Analyser::Static::GetTargets(fileName.toStdString());
|
||||||
if(!targets.empty()) {
|
if(!targets.empty()) {
|
||||||
@ -299,6 +313,11 @@ void MainWindow::launchMachine() {
|
|||||||
timer->startWithMachine(timedMachine, &machineMutex);
|
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;
|
} break;
|
||||||
|
|
||||||
case Machine::Error::MissingROM: {
|
case Machine::Error::MissingROM: {
|
||||||
@ -347,15 +366,18 @@ void MainWindow::dropEvent(QDropEvent* event) {
|
|||||||
switch(uiPhase) {
|
switch(uiPhase) {
|
||||||
case UIPhase::NoFileSelected: {
|
case UIPhase::NoFileSelected: {
|
||||||
// Treat exactly as a File -> Open... .
|
// Treat exactly as a File -> Open... .
|
||||||
// TODO: permit multiple files dropped at once.
|
|
||||||
const auto fileName = event->mimeData()->urls()[0].toLocalFile();
|
const auto fileName = event->mimeData()->urls()[0].toLocalFile();
|
||||||
launchFile(fileName);
|
launchFile(fileName);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case UIPhase::RunningMachine: {
|
case UIPhase::RunningMachine: {
|
||||||
// Attempt to insert into the running machine.
|
// Attempt to insert into the running machine.
|
||||||
|
const auto fileName = event->mimeData()->urls()[0].toLocalFile();
|
||||||
|
insertFile(fileName);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
// TODO: permit multiple files dropped at once in both of the above cases.
|
||||||
|
|
||||||
case UIPhase::RequestingROMs: {
|
case UIPhase::RequestingROMs: {
|
||||||
// Attempt to match up the dragged files to the requested ROM list;
|
// Attempt to match up the dragged files to the requested ROM list;
|
||||||
// if and when they match, copy to a writeable QStandardPaths::AppDataLocation
|
// if and when they match, copy to a writeable QStandardPaths::AppDataLocation
|
||||||
|
@ -82,6 +82,9 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
|
|||||||
void start_zx80();
|
void start_zx80();
|
||||||
void start_zx81();
|
void start_zx81();
|
||||||
|
|
||||||
|
QAction *insertAction = nullptr;
|
||||||
|
void insertFile(const QString &fileName);
|
||||||
|
|
||||||
void launchFile(const QString &fileName);
|
void launchFile(const QString &fileName);
|
||||||
void launchTarget(std::unique_ptr<Analyser::Static::Target> &&);
|
void launchTarget(std::unique_ptr<Analyser::Static::Target> &&);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user