We need to keep the action around, not the command.

Fixes broken enabled/ disabled qemu start button behavior.
This commit is contained in:
kh1
2010-05-18 15:37:34 +02:00
parent 239a95710f
commit a9645059ee
2 changed files with 24 additions and 32 deletions

View File

@@ -65,7 +65,7 @@ MaemoManager::MaemoManager()
, m_runConfigurationFactory(new MaemoRunConfigurationFactory(this)) , m_runConfigurationFactory(new MaemoRunConfigurationFactory(this))
, m_packageCreationFactory(new MaemoPackageCreationFactory(this)) , m_packageCreationFactory(new MaemoPackageCreationFactory(this))
, m_settingsPage(new MaemoSettingsPage(this)) , m_settingsPage(new MaemoSettingsPage(this))
, m_qemuCommand(0) , m_qemuAction(0)
{ {
Q_ASSERT(!m_instance); Q_ASSERT(!m_instance);
@@ -139,30 +139,28 @@ MaemoManager::addQemuSimulatorStarter(Project *project)
{ {
if (projects.contains(project)) if (projects.contains(project))
return; return;
projects.insert(project); projects.insert(project);
if (m_qemuCommand) { if (m_qemuAction) {
m_qemuCommand->action()->setVisible(true); m_qemuAction->setVisible(true);
return; return;
} }
m_qemuAction = new QAction("Maemo Emulator", this);
m_qemuAction->setEnabled(false);
m_qemuAction->setIcon(icon.pixmap(iconSize));
m_qemuAction->setToolTip(tr("Start Maemo Emulator"));
connect(m_qemuAction, SIGNAL(triggered()), this, SLOT(triggered()));
Core::ICore *core = Core::ICore::instance(); Core::ICore *core = Core::ICore::instance();
Core::ModeManager *modeManager = core->modeManager();
Core::ActionManager *actionManager = core->actionManager(); Core::ActionManager *actionManager = core->actionManager();
Core::Command *qemuCommand = actionManager->registerAction(m_qemuAction,
"MaemoEmulator", QList<int>() << Core::Constants::C_GLOBAL_ID);
qemuCommand->setAttribute(Core::Command::CA_UpdateText);
qemuCommand->setAttribute(Core::Command::CA_UpdateIcon);
QAction *action = new QAction("Maemo Emulator", this); Core::ModeManager *modeManager = core->modeManager();
action->setIcon(icon.pixmap(iconSize)); modeManager->addAction(qemuCommand, 1);
action->setToolTip(tr("Start Maemo Emulator"));
m_qemuCommand = actionManager->registerAction(action, "MaemoEmulator",
QList<int>() << Core::Constants::C_GLOBAL_ID);
modeManager->addAction(m_qemuCommand, 1);
action->setEnabled(false);
m_qemuCommand->action()->setEnabled(false);
m_qemuCommand->setAttribute(Core::Command::CA_UpdateText);
m_qemuCommand->setAttribute(Core::Command::CA_UpdateIcon);
connect(m_qemuCommand->action(), SIGNAL(triggered()), this, SLOT(triggered()));
} }
void void
@@ -170,16 +168,16 @@ MaemoManager::removeQemuSimulatorStarter(Project *project)
{ {
if (projects.contains(project)) { if (projects.contains(project)) {
projects.remove(project); projects.remove(project);
if (projects.isEmpty() && m_qemuCommand) if (projects.isEmpty() && m_qemuAction)
m_qemuCommand->action()->setVisible(false); m_qemuAction->setVisible(false);
} }
} }
void void
MaemoManager::setQemuSimulatorStarterEnabled(bool enable) MaemoManager::setQemuSimulatorStarterEnabled(bool enable)
{ {
if (m_qemuCommand) if (m_qemuAction)
m_qemuCommand->action()->setEnabled(enable); m_qemuAction->setEnabled(enable);
} }
void void
@@ -191,7 +189,7 @@ MaemoManager::triggered()
void void
MaemoManager::updateQemuSimulatorStarter(bool running) MaemoManager::updateQemuSimulatorStarter(bool running)
{ {
if (m_qemuCommand) { if (m_qemuAction) {
QIcon::State state = QIcon::Off; QIcon::State state = QIcon::Off;
QString toolTip(tr("Start Maemo Emulator")); QString toolTip(tr("Start Maemo Emulator"));
if (running) { if (running) {
@@ -199,9 +197,8 @@ MaemoManager::updateQemuSimulatorStarter(bool running)
toolTip = tr("Stop Maemo Emulator"); toolTip = tr("Stop Maemo Emulator");
} }
QAction *action = m_qemuCommand->action(); m_qemuAction->setToolTip(toolTip);
action->setToolTip(toolTip); m_qemuAction->setIcon(icon.pixmap(iconSize, QIcon::Normal, state));
action->setIcon(icon.pixmap(iconSize, QIcon::Normal, state));
} }
} }

View File

@@ -35,13 +35,8 @@
#include <QtGui/QIcon> #include <QtGui/QIcon>
QT_BEGIN_NAMESPACE QT_FORWARD_DECLARE_CLASS(QAction);
class QAction;
QT_END_NAMESPACE
namespace Core {
class Command;
}
namespace ProjectExplorer { namespace ProjectExplorer {
class Project; class Project;
class ToolChain; class ToolChain;
@@ -95,7 +90,7 @@ private:
QIcon icon; QIcon icon;
int m_runCount; int m_runCount;
QSet<Project*> projects; QSet<Project*> projects;
Core::Command *m_qemuCommand; QAction *m_qemuAction;
}; };
} // namespace Internal } // namespace Internal