Fix for windows and update tool menu after closing settings dialog

This commit is contained in:
Jan Dalheimer 2014-02-16 11:49:55 +01:00
parent 616c372690
commit c88c639b8e
3 changed files with 60 additions and 44 deletions

View File

@ -360,6 +360,51 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
myMenu.exec(view->mapToGlobal(pos)); myMenu.exec(view->mapToGlobal(pos));
} }
void MainWindow::updateToolsMenu()
{
if (ui->actionLaunchInstance->menu())
{
ui->actionLaunchInstance->menu()->deleteLater();
}
QMenu *launchMenu = new QMenu(this);
QAction *normalLaunch = launchMenu->addAction(tr("Launch"));
connect(normalLaunch, &QAction::triggered, [this](){doLaunch();});
launchMenu->addSeparator()->setText(tr("Profilers"));
for (auto profiler : MMC->profilers().values())
{
QAction *profilerAction = launchMenu->addAction(profiler->name());
QString error;
if (!profiler->check(&error))
{
profilerAction->setDisabled(true);
profilerAction->setToolTip(tr("Profiler not setup correctly. Go into settings, \"External Tools\"."));
}
else
{
connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());});
}
}
launchMenu->addSeparator()->setText(tr("Tools"));
for (auto tool : MMC->tools().values())
{
QAction *toolAction = launchMenu->addAction(tool->name());
QString error;
if (!tool->check(&error))
{
toolAction->setDisabled(true);
toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\"."));
}
else
{
connect(toolAction, &QAction::triggered, [this, tool]()
{
tool->createDetachedTool(m_selectedInstance, this)->run();
});
}
}
ui->actionLaunchInstance->setMenu(launchMenu);
}
void MainWindow::repopulateAccountsMenu() void MainWindow::repopulateAccountsMenu()
{ {
accountMenu->clear(); accountMenu->clear();
@ -933,6 +978,7 @@ void MainWindow::on_actionSettings_triggered()
// FIXME: quick HACK to make this work. improve, optimize. // FIXME: quick HACK to make this work. improve, optimize.
proxymodel->invalidate(); proxymodel->invalidate();
proxymodel->sort(0); proxymodel->sort(0);
updateToolsMenu();
} }
void MainWindow::on_actionManageAccounts_triggered() void MainWindow::on_actionManageAccounts_triggered()
@ -1429,47 +1475,7 @@ void MainWindow::instanceChanged(const QModelIndex &current, const QModelIndex &
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription()); m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
updateInstanceToolIcon(m_selectedInstance->iconKey()); updateInstanceToolIcon(m_selectedInstance->iconKey());
if (ui->actionLaunchInstance->menu()) updateToolsMenu();
{
ui->actionLaunchInstance->menu()->deleteLater();
}
QMenu *launchMenu = new QMenu;
QAction *normalLaunch = launchMenu->addAction(tr("Launch"));
connect(normalLaunch, &QAction::triggered, [this](){doLaunch();});
launchMenu->addSeparator()->setText(tr("Profilers"));
for (auto profiler : MMC->profilers().values())
{
QAction *profilerAction = launchMenu->addAction(profiler->name());
QString error;
if (!profiler->check(&error))
{
profilerAction->setDisabled(true);
profilerAction->setToolTip(tr("Profiler not setup correctly. Go into settings, \"External Tools\"."));
}
else
{
connect(profilerAction, &QAction::triggered, [this, profiler](){doLaunch(true, profiler.get());});
}
}
launchMenu->addSeparator()->setText(tr("Tools"));
for (auto tool : MMC->tools().values())
{
QAction *toolAction = launchMenu->addAction(tool->name());
QString error;
if (!tool->check(&error))
{
toolAction->setDisabled(true);
toolAction->setToolTip(tr("Tool not setup correctly. Go into settings, \"External Tools\"."));
}
else
{
connect(toolAction, &QAction::triggered, [this, tool]()
{
tool->createDetachedTool(m_selectedInstance, this)->run();
});
}
}
ui->actionLaunchInstance->setMenu(launchMenu);
MMC->settings()->set("SelectedInstance", m_selectedInstance->id()); MMC->settings()->set("SelectedInstance", m_selectedInstance->id());
} }

View File

@ -141,6 +141,8 @@ slots:
void showInstanceContextMenu(const QPoint&); void showInstanceContextMenu(const QPoint&);
void updateToolsMenu();
public public
slots: slots:
void instanceActivated(QModelIndex); void instanceActivated(QModelIndex);

View File

@ -23,8 +23,16 @@ void MCEditTool::runImpl()
{ {
return; return;
} }
const QString program = QDir mceditDir(mceditPath);
QDir(mceditPath).absoluteFilePath("mcedit.py"); QString program;
if (mceditDir.exists("mcedit.py"))
{
program = mceditDir.absoluteFilePath("mcedit.py");
}
else if (mceditDir.exists("mcedit.exe"))
{
program = mceditDir.absoluteFilePath("mcedit.exe");
}
QProcess::startDetached(program, QStringList() << save, mceditPath); QProcess::startDetached(program, QStringList() << save, mceditPath);
} }
@ -53,7 +61,7 @@ bool MCEditFactory::check(const QString &path, QString *error)
*error = QObject::tr("Path does not exist"); *error = QObject::tr("Path does not exist");
return false; return false;
} }
if (!dir.exists("mcedit.py")) if (!dir.exists("mcedit.py") && !dir.exists("mcedit.exe"))
{ {
*error = QObject::tr("Path does not contain mcedit.py"); *error = QObject::tr("Path does not contain mcedit.py");
return false; return false;