diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index 78f57d79abf61941298e432ad7908906617a1561..f54108e8d05698151ca962ee93670f3d5ca51de5 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -78,7 +78,8 @@ SOURCES += mainwindow.cpp \ dialogs/ioptionspage.cpp \ dialogs/iwizard.cpp \ settingsdatabase.cpp \ - eventfilteringmainwindow.cpp + eventfilteringmainwindow.cpp \ + imode.cpp HEADERS += mainwindow.h \ editmode.h \ tabpositionindicator.h \ diff --git a/src/plugins/coreplugin/imode.cpp b/src/plugins/coreplugin/imode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e687432aa6cb0c674aec36842efd97d34d07d8a3 --- /dev/null +++ b/src/plugins/coreplugin/imode.cpp @@ -0,0 +1,50 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "imode.h" + +using namespace Core; +IMode::IMode(QObject *parent) + : IContext(parent), + m_isEnabled(true) +{ +} + +void IMode::setEnabled(bool enabled) +{ + if (m_isEnabled == enabled) + return; + m_isEnabled = enabled; + emit enabledStateChanged(m_isEnabled); +} + +bool IMode::isEnabled() const +{ + return m_isEnabled; +} diff --git a/src/plugins/coreplugin/imode.h b/src/plugins/coreplugin/imode.h index a736131e8bded24300b69ee9aa2ad5ca01d4894d..dbeb538b1d4a501f881deb4bc6cf467cfe365ccb 100644 --- a/src/plugins/coreplugin/imode.h +++ b/src/plugins/coreplugin/imode.h @@ -43,14 +43,24 @@ namespace Core { class CORE_EXPORT IMode : public IContext { Q_OBJECT + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) public: - IMode(QObject *parent = 0) : IContext(parent) {} + IMode(QObject *parent = 0); virtual ~IMode() {} virtual QString displayName() const = 0; virtual QIcon icon() const = 0; virtual int priority() const = 0; virtual QString id() const = 0; + + void setEnabled(bool enabled); + bool isEnabled() const; + +signals: + void enabledStateChanged(bool enabled); + +private: + bool m_isEnabled; }; } // namespace Core diff --git a/src/plugins/coreplugin/modemanager.cpp b/src/plugins/coreplugin/modemanager.cpp index 408bcb23e0f9703f9ec0a3b1702985e021ac6341..a725363f878c109510d1a2cf6f29f11485a53d0a 100644 --- a/src/plugins/coreplugin/modemanager.cpp +++ b/src/plugins/coreplugin/modemanager.cpp @@ -140,6 +140,7 @@ void ModeManager::objectAdded(QObject *obj) m_modes.insert(index, mode); m_modeStack->insertTab(index, mode->widget(), mode->icon(), mode->displayName()); + m_modeStack->setTabEnabled(index, mode->isEnabled()); // Register mode shortcut ActionManager *am = m_mainWindow->actionManager(); @@ -165,6 +166,8 @@ void ModeManager::objectAdded(QObject *obj) m_signalMapper->setMapping(shortcut, mode->id()); connect(shortcut, SIGNAL(activated()), m_signalMapper, SLOT(map())); + connect(mode, SIGNAL(enabledStateChanged(bool)), + this, SLOT(enabledStateChanged())); } void ModeManager::updateModeToolTip() @@ -177,6 +180,15 @@ void ModeManager::updateModeToolTip() } } +void ModeManager::enabledStateChanged() +{ + IMode *mode = qobject_cast<IMode *>(sender()); + QTC_ASSERT(mode, return); + int index = m_modes.indexOf(mode); + QTC_ASSERT(index >= 0, return); + m_modeStack->setTabEnabled(index, mode->isEnabled()); +} + void ModeManager::aboutToRemoveObject(QObject *obj) { IMode *mode = Aggregation::query<IMode>(obj); diff --git a/src/plugins/coreplugin/modemanager.h b/src/plugins/coreplugin/modemanager.h index 9435d862f20e2605e928818619d0f3cd054d5ab0..f33ac7dba2b410eaf543b1f2868834e85b893232 100644 --- a/src/plugins/coreplugin/modemanager.h +++ b/src/plugins/coreplugin/modemanager.h @@ -86,6 +86,7 @@ private slots: void currentTabAboutToChange(int index); void currentTabChanged(int index); void updateModeToolTip(); + void enabledStateChanged(); private: int indexOf(const QString &id) const;