Adds the Image menu to the QT debugger's main window.

This allows the user to mount disk/c images from the UI.
[Andrew Gardner]
This commit is contained in:
Andrew Gardner 2013-05-30 04:29:41 +00:00
parent a8836f3b65
commit 800c6fd7c3
2 changed files with 105 additions and 4 deletions

View File

@ -38,7 +38,7 @@ MainWindow::MainWindow(running_machine* machine, QWidget* parent) :
setCentralWidget(mainWindowFrame);
//
// Menu bars
// Options Menu
//
// Create two commands
QAction* breakpointSetAct = new QAction("Toggle Breakpoint At Cursor", this);
@ -73,9 +73,17 @@ MainWindow::MainWindow(running_machine* machine, QWidget* parent) :
optionsMenu->addSeparator();
optionsMenu->addActions(rightBarGroup->actions());
//
// Images menu
//
image_interface_iterator imageIterTest(m_machine->root_device());
if (imageIterTest.first() != NULL)
{
createImagesMenu();
}
//
// Dock windows
// Dock window menu
//
QMenu* dockMenu = menuBar()->addMenu("Doc&ks");
@ -281,8 +289,8 @@ void MainWindow::executeCommand(bool withClear)
// Send along the command
debug_console_execute_command(*m_machine,
command.toLocal8Bit().data(),
true);
command.toLocal8Bit().data(),
true);
// Add history & set the index to be the top of the stack
addToHistory(command);
@ -300,6 +308,58 @@ void MainWindow::executeCommand(bool withClear)
}
void MainWindow::mountImage(bool changedTo)
{
// The image interface index was assigned to the QAction's data memeber
const int imageIndex = dynamic_cast<QAction*>(sender())->data().toInt();
image_interface_iterator iter(m_machine->root_device());
device_image_interface *img = iter.byindex(imageIndex);
if (img == NULL)
{
debug_console_printf(*m_machine, "Something is wrong with the mount menu.\n");
refreshAll();
return;
}
// File dialog
QString filename = QFileDialog::getOpenFileName(this,
"Select an image file",
QDir::currentPath(),
tr("All files (*.*)"));
if (!img->load(filename.toUtf8().data()))
{
debug_console_printf(*m_machine, "Image could not be mounted.\n");
refreshAll();
return;
}
// Activate the unmount menu option
QAction* unmountAct = sender()->parent()->findChild<QAction*>("unmount");
unmountAct->setEnabled(true);
debug_console_printf(*m_machine, "Image %s mounted successfully.\n", filename.toUtf8().data());
refreshAll();
}
void MainWindow::unmountImage(bool changedTo)
{
// The image interface index was assigned to the QAction's data memeber
const int imageIndex = dynamic_cast<QAction*>(sender())->data().toInt();
image_interface_iterator iter(m_machine->root_device());
device_image_interface *img = iter.byindex(imageIndex);
img->unload();
// Deactivate the unmount menu option
dynamic_cast<QAction*>(sender())->setEnabled(false);
debug_console_printf(*m_machine, "Image successfully unmounted.\n");
refreshAll();
}
void MainWindow::debugActClose()
{
m_machine->schedule_exit();
@ -326,6 +386,42 @@ void MainWindow::addToHistory(const QString& command)
}
void MainWindow::createImagesMenu()
{
QMenu* imagesMenu = menuBar()->addMenu("&Images");
int interfaceIndex = 0;
image_interface_iterator iter(m_machine->root_device());
for (device_image_interface *img = iter.first(); img != NULL; img = iter.next())
{
astring menuName;
menuName.format("%s : %s", img->device().name(), img->exists() ? img->filename() : "[empty slot]");
QMenu* interfaceMenu = imagesMenu->addMenu(menuName.cstr());
interfaceMenu->setObjectName(img->device().name()); // TODO: FIX
QAction* mountAct = new QAction("Mount...", interfaceMenu);
QAction* unmountAct = new QAction("Unmount", interfaceMenu);
mountAct->setObjectName("mount");
mountAct->setData(QVariant(interfaceIndex));
unmountAct->setObjectName("unmount");
unmountAct->setData(QVariant(interfaceIndex));
connect(mountAct, SIGNAL(triggered(bool)), this, SLOT(mountImage(bool)));
connect(unmountAct, SIGNAL(triggered(bool)), this, SLOT(unmountImage(bool)));
if (!img->exists())
unmountAct->setEnabled(false);
interfaceMenu->addAction(mountAct);
interfaceMenu->addAction(unmountAct);
// TODO: Cassette operations
interfaceIndex++;
}
}
//=========================================================================
// MainWindowQtConfig
//=========================================================================

View File

@ -42,6 +42,9 @@ private slots:
void executeCommand(bool withClear=true);
void mountImage(bool changedTo);
void unmountImage(bool changedTo);
// Closing the main window actually exits the program
void debugActClose();
@ -57,6 +60,8 @@ private:
int m_historyIndex;
std::vector<QString> m_inputHistory;
void addToHistory(const QString& command);
void createImagesMenu();
};