2011-02-18 10:36:52 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-02-18 10:36:52 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2011-02-18 10:36:52 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2011-02-18 10:36:52 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
#include "outlinefactory.h"
|
2010-07-30 22:16:59 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-07-14 16:46:54 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2010-07-08 11:15:26 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/ieditor.h>
|
2011-01-24 12:29:48 +01:00
|
|
|
|
|
|
|
|
#include <QtGui/QVBoxLayout>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
|
#include <QtGui/QStackedWidget>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
2010-07-08 11:15:26 +02:00
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) :
|
|
|
|
|
QStackedWidget(),
|
|
|
|
|
m_factory(factory),
|
2010-07-16 11:04:20 +02:00
|
|
|
m_syncWithEditor(true),
|
|
|
|
|
m_position(-1)
|
2010-07-08 11:15:26 +02:00
|
|
|
{
|
|
|
|
|
QLabel *label = new QLabel(tr("No outline available"), this);
|
|
|
|
|
label->setAlignment(Qt::AlignCenter);
|
2010-07-13 14:15:54 +02:00
|
|
|
|
|
|
|
|
// set background to be white
|
|
|
|
|
label->setAutoFillBackground(true);
|
|
|
|
|
label->setBackgroundRole(QPalette::Base);
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
addWidget(label);
|
|
|
|
|
|
|
|
|
|
m_toggleSync = new QToolButton;
|
2010-07-30 22:16:59 +02:00
|
|
|
m_toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
2010-07-08 11:15:26 +02:00
|
|
|
m_toggleSync->setCheckable(true);
|
|
|
|
|
m_toggleSync->setChecked(true);
|
|
|
|
|
m_toggleSync->setToolTip(tr("Synchronize with Editor"));
|
|
|
|
|
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleCursorSynchronization()));
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
m_filterButton = new QToolButton;
|
2010-07-30 22:16:59 +02:00
|
|
|
m_filterButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
|
2010-07-14 16:46:54 +02:00
|
|
|
m_filterButton->setToolTip(tr("Filter tree"));
|
|
|
|
|
m_filterButton->setPopupMode(QToolButton::InstantPopup);
|
2012-02-01 21:39:05 +01:00
|
|
|
m_filterButton->setProperty("noArrow", true);
|
2010-07-14 16:46:54 +02:00
|
|
|
m_filterMenu = new QMenu(m_filterButton);
|
|
|
|
|
m_filterButton->setMenu(m_filterMenu);
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
|
|
|
|
connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
|
|
|
|
|
this, SLOT(updateCurrentEditor(Core::IEditor*)));
|
|
|
|
|
updateCurrentEditor(editorManager->currentEditor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutlineWidgetStack::~OutlineWidgetStack()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QToolButton *OutlineWidgetStack::toggleSyncButton()
|
|
|
|
|
{
|
|
|
|
|
return m_toggleSync;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
QToolButton *OutlineWidgetStack::filterButton()
|
|
|
|
|
{
|
|
|
|
|
return m_filterButton;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-05 11:05:28 +01:00
|
|
|
static inline QString outLineKey(int position)
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("Outline.") + QString::number(position) + QLatin1String(".SyncWithEditor");
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 11:04:20 +02:00
|
|
|
void OutlineWidgetStack::restoreSettings(int position)
|
|
|
|
|
{
|
|
|
|
|
m_position = position; // save it so that we can save/restore in updateCurrentEditor
|
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-01-05 11:05:28 +01:00
|
|
|
const bool toggleSync = settings->value(outLineKey(position), true).toBool();
|
2010-07-16 11:04:20 +02:00
|
|
|
toggleSyncButton()->setChecked(toggleSync);
|
|
|
|
|
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
|
|
|
|
|
outlineWidget->restoreSettings(position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineWidgetStack::saveSettings(int position)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(position == m_position);
|
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2012-01-05 11:05:28 +01:00
|
|
|
settings->setValue(outLineKey(position), toggleSyncButton()->isEnabled());
|
2010-07-16 11:04:20 +02:00
|
|
|
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
|
|
|
|
|
outlineWidget->saveSettings(position);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
bool OutlineWidgetStack::isCursorSynchronized() const
|
|
|
|
|
{
|
|
|
|
|
return m_syncWithEditor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineWidgetStack::toggleCursorSynchronization()
|
|
|
|
|
{
|
|
|
|
|
m_syncWithEditor = !m_syncWithEditor;
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
|
|
|
|
|
outlineWidget->setCursorSynchronization(m_syncWithEditor);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
void OutlineWidgetStack::updateFilterMenu()
|
|
|
|
|
{
|
|
|
|
|
m_filterMenu->clear();
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
|
|
|
|
|
foreach (QAction *filterAction, outlineWidget->filterMenuActions()) {
|
|
|
|
|
m_filterMenu->addAction(filterAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-22 13:02:47 +02:00
|
|
|
m_filterButton->setEnabled(!m_filterMenu->actions().isEmpty());
|
2010-07-14 16:46:54 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
IOutlineWidget *newWidget = 0;
|
|
|
|
|
|
|
|
|
|
if (editor) {
|
|
|
|
|
foreach (IOutlineWidgetFactory *widgetFactory, m_factory->widgetFactories()) {
|
|
|
|
|
if (widgetFactory->supportsEditor(editor)) {
|
|
|
|
|
newWidget = widgetFactory->createWidget(editor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newWidget != currentWidget()) {
|
|
|
|
|
// delete old widget
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
|
2010-07-16 11:04:20 +02:00
|
|
|
if (m_position > -1)
|
|
|
|
|
outlineWidget->saveSettings(m_position);
|
2010-07-08 11:15:26 +02:00
|
|
|
removeWidget(outlineWidget);
|
|
|
|
|
delete outlineWidget;
|
|
|
|
|
}
|
|
|
|
|
if (newWidget) {
|
2010-07-16 11:04:20 +02:00
|
|
|
if (m_position > -1)
|
|
|
|
|
newWidget->restoreSettings(m_position);
|
2010-07-08 11:15:26 +02:00
|
|
|
newWidget->setCursorSynchronization(m_syncWithEditor);
|
|
|
|
|
addWidget(newWidget);
|
|
|
|
|
setCurrentWidget(newWidget);
|
|
|
|
|
}
|
2010-07-22 13:02:47 +02:00
|
|
|
|
|
|
|
|
updateFilterMenu();
|
2010-07-08 11:15:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<IOutlineWidgetFactory*> OutlineFactory::widgetFactories() const
|
|
|
|
|
{
|
|
|
|
|
return m_factories;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineFactory::setWidgetFactories(QList<IOutlineWidgetFactory*> factories)
|
|
|
|
|
{
|
|
|
|
|
m_factories = factories;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString OutlineFactory::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr("Outline");
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-09 14:35:26 +02:00
|
|
|
int OutlineFactory::priority() const
|
|
|
|
|
{
|
|
|
|
|
return 600;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-09 12:07:41 +01:00
|
|
|
Core::Id OutlineFactory::id() const
|
2010-07-08 11:15:26 +02:00
|
|
|
{
|
2011-11-09 12:07:41 +01:00
|
|
|
return Core::Id("Outline");
|
2010-07-08 11:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QKeySequence OutlineFactory::activationSequence() const
|
|
|
|
|
{
|
|
|
|
|
return QKeySequence();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::NavigationView OutlineFactory::createWidget()
|
|
|
|
|
{
|
|
|
|
|
Core::NavigationView n;
|
|
|
|
|
OutlineWidgetStack *placeHolder = new OutlineWidgetStack(this);
|
|
|
|
|
n.widget = placeHolder;
|
2010-07-14 16:46:54 +02:00
|
|
|
n.dockToolBarWidgets.append(placeHolder->filterButton());
|
2010-07-22 12:58:19 +02:00
|
|
|
n.dockToolBarWidgets.append(placeHolder->toggleSyncButton());
|
2010-07-08 11:15:26 +02:00
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 08:18:56 +02:00
|
|
|
void OutlineFactory::saveSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
OutlineWidgetStack *widgetStack = qobject_cast<OutlineWidgetStack *>(widget);
|
|
|
|
|
Q_ASSERT(widgetStack);
|
2010-07-16 11:04:20 +02:00
|
|
|
widgetStack->saveSettings(position);
|
2010-07-16 08:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineFactory::restoreSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
OutlineWidgetStack *widgetStack = qobject_cast<OutlineWidgetStack *>(widget);
|
|
|
|
|
Q_ASSERT(widgetStack);
|
2010-07-16 11:04:20 +02:00
|
|
|
widgetStack->restoreSettings(position);
|
2010-07-16 08:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace TextEditor
|