From 5864d9d7510fe8304a426135bcbacb0afd2999e1 Mon Sep 17 00:00:00 2001 From: con <qtc-committer@nokia.com> Date: Tue, 16 Feb 2010 16:11:51 +0100 Subject: [PATCH] Make it possible to disable modes. --- src/plugins/coreplugin/coreplugin.pro | 3 +- src/plugins/coreplugin/imode.cpp | 50 ++++++++++++++++++++++++++ src/plugins/coreplugin/imode.h | 12 ++++++- src/plugins/coreplugin/modemanager.cpp | 12 +++++++ src/plugins/coreplugin/modemanager.h | 1 + 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 src/plugins/coreplugin/imode.cpp diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index 78f57d79abf..f54108e8d05 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 00000000000..e687432aa6c --- /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 a736131e8bd..dbeb538b1d4 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 408bcb23e0f..a725363f878 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 9435d862f20..f33ac7dba2b 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; -- GitLab